Skip to content

Commit

Permalink
TryHackMe Python For Pentesters
Browse files Browse the repository at this point in the history
enhance python_noob_to_professional.md
update requirements.txt, .gitignore, README.md
  • Loading branch information
juba0x00 committed Sep 28, 2022
1 parent 1e0863a commit 40f6812
Show file tree
Hide file tree
Showing 18 changed files with 2,381 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ test*.py
.mypy_cache/
.pytest_cache/
.vscode/
Py4CyberSec_venv
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Py4CyberSec
Python For Cyber Security
notes while my learning journey
# Python For Penetration Testing

- Python For Cyber Securit
- My projects and notes while my learning journey

## References

# References
- Python for Hackers by Joas Antonio
- keylogger inspired by [david bombal](https://github.com/davidbombal/python-keylogger/blob/main/keylogger.py)
- CnC-Telegram inspired by [Petr Bergmann](https://github.com/bergmpet/cnc-telegram)
- CnC-Telegram inspired by [Petr Bergmann](https://github.com/bergmpet/cnc-telegram)
5 changes: 5 additions & 0 deletions THM-rooms/Python-For-Pentesters/FileDownloader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from requests import get
url = input('URL: ')
FileName = url.split('/')[-1]
req = get(url, allow_redirects=True)
open(f"{FileName}", 'w').write(str(req.content))
77 changes: 77 additions & 0 deletions THM-rooms/Python-For-Pentesters/HashKiller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import hashlib
import pstats
from time import perf_counter
from colorama import Fore
from argparse import ArgumentParser, Namespace
from cProfile import Profile
start: float
hash: str
hash_algo: str
args: Namespace

def parse_arguments() -> Namespace:
parser = ArgumentParser()
parser.add_argument('hash_file', help='file containing hash')
parser.add_argument('wordlist_name', help='plain-text wordlist')
parser.add_argument('hash_algo', help='Hashing Algorithm')
parser.add_argument('-v', '--verbose', action='store_true', help='increase verbosity')
return parser.parse_args()


def check(plain_text: str) -> None:
match(hash_algo.lower()):
case 'md5':
result = hashlib.md5(plain_text.encode()).hexdigest()
case 'sha384':
result = hashlib.sha384(plain_text.encode()).hexdigest()
case 'sha3_384':
result = hashlib.sha3_384(plain_text.encode()).hexdigest()
case 'sha1':
result = hashlib.sha1(plain_text.encode()).hexdigest()
case 'sha224':
result = hashlib.sha224(plain_text.encode()).hexdigest()
case 'sha256':
result = hashlib.sha256(plain_text.encode()).hexdigest()
case 'sha384':
result = hashlib.sha384(plain_text.encode()).hexdigest()
case 'sha512':
result = hashlib.sha512(plain_text.encode()).hexdigest()


if args.verbose:
print(f'{Fore.GREEN}{hash}{Fore.RESET} ?= {Fore.GREEN}{result}{Fore.RESET}')
if result == hash:
print(f'{Fore.RED}{plain_text}{Fore.RESET}')
print(f'Cracking Time: {Fore.RED}{perf_counter() - start}{Fore.RESET}')




def main():
global start, hash, hash_algo, args
start = perf_counter()
args = parse_arguments()
hash = open(args.hash_file).readline().replace('\n', '')
hash_algo = args.hash_algo

with open(args.wordlist_name, 'r') as file:
lines: list = file.readlines()


for line in lines:
line = line.replace('\n', '') if line.endswith('\n') else line
check(line)


if __name__ == '__main__':
with Profile() as pr:
main()

stats = pstats.Stats(pr)
stats.sort_stats(pstats.SortKey.TIME)
# stats.print_stats()
print('before')

stats.dump_stats(filename='file.prof')
print('after')

51 changes: 51 additions & 0 deletions THM-rooms/Python-For-Pentesters/PortScanner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from sys import stdout
from socket import socket, AF_INET, SOCK_STREAM
from argparse import ArgumentParser
from time import perf_counter

def parse_arguments():
parser = ArgumentParser()
parser.add_argument('IP', help='Host or network IP')
parser.add_argument('start_port', help='starting port number', type=int)
parser.add_argument('end_port', help='ending port number', type=int)
return parser.parse_args()


def probe_port(ip, port, result=1):
try:
sock = socket(AF_INET, SOCK_STREAM)
sock.settimeout(0.5)
r = sock.connect_ex((ip, port))
if r == 0:
print(port)
sock.close()
return 0

except Exception as e:
pass
return r


if __name__ == '__main__':
start = perf_counter()
args = parse_arguments()
open_ports =[]
ports = range(args.start_port, args.end_port)

for port in ports:
stdout.flush()
response = probe_port(args.IP, port)
if response == 0:
open_ports.append(port)


if open_ports:
print ("Open Ports are: ")
print (sorted(open_ports))

else:
print ("Looks like no ports are open :(")

end = perf_counter()
print(end-start)

Loading

0 comments on commit 40f6812

Please sign in to comment.