Python ist eine sehr wichtige und vielseitige Programmiersprache, die auch sehr anfängerfreundlich ist. Nachdem wir die Python Basics bereits kennengelernt haben, bekommen wir hier Wissen für Penetration-Tester vermittelt.
Was genau, erfahren wir in der Einleitung:
Throughout this room, you will see how to:
- Use Python to enumerate the target’s subdomain
- Build a simple keylogger
- Scan the network to find target systems
- Scan any target to find the open ports
- Download files from the internet
- Crack hashes
Task 1 Introduction
Frage 1:
What other tool can be used to convert Python scripts to Windows executables?
PyInstaller wird ja bereits im Text erklärt, ein anderes Programm lässt sich mit Google finden.
Antwort 1:
py2exe
Frage 2:
Start the machine on this task
Antwort 2:
Keine Antwort benötigt.
Task 2 Subdomain Enumeration
Frage 1:
What other protocol could be used for subdomain enumeration?
Das gesuchte Protokoll ist das DNS-System. Es sorgt für eine Auflösung der URL und findet die zugehörige IP Adresse, ähnlich wie ein Telefonbuch.
Antwort 1:
DNS
Frage 2:
What function does Python use to get the input from the command line?
Hierzu schauen wir uns den Python Code an:
import requests
import sys
sub_list = open("subdomains.txt").read()
subdoms = sub_list.splitlines()
for sub in subdoms:
sub_domains = f"http://{sub}.{sys.argv[1]}"
try:
requests.get(sub_domains)
except requests.ConnectionError:
pass
else:
print("Valid domain: ",sub_domains)
Hier findet man gute Beispiele zu sys.argv.
Antwort 2:
sys.argv
Task 3 Directory Enumeration
Wichtig ist hier, dass die Python Datei (direnum.py) und die Wordlist aus Task 1 im selben Verzeichnis sind, sonst sieht der Befehl für die Kommandozeile anders aus. Außerdem müssen wir entweder die Wordlist umbenennen (von wordlist2.txt zu wordlist.txt) oder wir fügen dem Code eine 2 hinzu:
import requests
import sys
sub_list = open("wordlist2.txt").read()
directories = sub_list.splitlines()
for dir in directories:
dir_enum = f"http://{sys.argv[1]}/{dir}.html"
r = requests.get(dir_enum)
if r.status_code==404:
pass
else:
print("Valid directory:" ,dir_enum)
Den Code speichern wir in einer neue Datei und nennen sie direnum.py. Dann starten wir unser Script:
python3 direnum.py MACHINE_IP
└─$ python3 direnum.py 10.10.200.109
Valid directory: http://10.10.200.109/surfer.html
Valid directory: http://10.10.200.109/private.html
Valid directory: http://10.10.200.109/apollo.html
Valid directory: http://10.10.200.109/index.html
Frage 1:
How many directories can your script identify on the target system? (extensions are .html)
Antwort 1:
4
Frage 2:
What is the location of the login page?
Probieren wir alle gefundenen Directorys in unserem Browser:
Antwort 2:
private.html
Frage 3:
Where did you find a cryptic hash?
Antwort 3:
apollo.html
Frage 4:
Where are the usernames located?
Antwort 4:
surfer.html
Frage 5:
What is the password assigned to Rabbit?
Das Passwort finden wir im user.html Verzeichnis:
Antwort 5:
LOUSYRABBO
Task 4 Network Scanner
Frage 1:
What module was used to create the ARP request packets?
Da wir ganz am Anfang des Codes scapy importiert haben, ist die Antwort sehr einfach:
Antwort 1:
scapy
Frage 2:
Which variable would you need to change according to your local IP block?
In der Variablen „ip_range“ ist der zu scannende Bereich der IPs angegeben.
Antwort 2:
ip_range
Frage 3:
What variable would you change to run this code on a system with the network interface named ens33?
Der Name des Interfaces ist in der Variablen „interface“ angegeben. Im Beispiel heißt das Interface „eth0“.
Antwort 3:
interface
Task 5 Port Scanner
Frage 1:
What protocol will most likely be using TCP port 22?
Auf Port 22 läuft meistens das SSH Protokol.
Antwort 1:
ssh
Frage 2:
What module did we import to be able to use sockets?
Die Liste der Module im Code gibt den Namen sehr einfach preis:
Antwort 2:
socket
Frage 3:
What function is likely to fail if we didn’t import sys?
Funktionen aus Modulen fangen immer mit dem Modulnamen an, daher handelt es sich um:
Antwort 3:
sys.stdout.flush()
Frage 4:
How many ports are open on the target machine?
Wir kopieren den Code und erstellen eine neue Datei mit dem Namen „scanner.py“. Dort fügen wir den Code ein und passen die IP unserer MACHINE in Zeile 10 an:
ip = 'MACHINE_IP'
Danach starten wir unser kleines Programm (aus dem Verzeichnis, in dem die Datei gespeichert wurde):
python3 scanner.py
Als Ergebnis erhalten wir folgendes (es dauert eine halbe Ewigkeit):
Open Ports are:
[22]
[80]
[2100]
Antwort 4:
3
Frage 5:
What is the highest port number open on the target system?
Antwort 5:
2100
Task 6 File Downloader
Hier erhalten wir, neben dem Python Download-Tool, auch eine kleine Exkursion zu PSexec. Weitere Infos gibt es hier und hier.
Frage 1:
What is the function used to connect to the target website?
Requests erlaubt es uns die get Funktion zu benutzen, um die Inhalte herunterzuladen:
Antwort 1:
requests.get()
Frage 2:
What step of the Unified Cyber Kill Chain can PSexec be used in?
Dazu können wir uns hier informieren und auch das Whitepaper herunterladen.
Antwort 2:
lateral movement
Task 7 Hash Cracker
Frage 1:
What is the hash you found during directory enumeration?
Erinnert ihr euch an die ganzen Verzeichnisse aus Task 3? Unter apollo.html haben wir einen Hash gefunden.
Antwort 1:
cd13b6a6af66fb774faa589a9d18f906
Frage 2:
What is the cleartext value of this hash?
Wir kopieren den Code wieder in eine Datei und nennen diese hash.py und starten das Programm:
python3 hash.py
Dann geben wir die Daten ein:
Enter wordlist file location: /usr/share/wordlists/rockyou.txt
Enter hash to be cracked: cd13b6a6af66fb774faa589a9d18f906
Und weil das alles viel zu lange dauert nehmen wir ein Onlinetool zur Hilfe:
Antwort 2:
rainbow
Frage 3:
Modify the script to work with SHA256 hashes.
Hier müssen wir den Code in Zeile 12 ändern:
hash_ob = hashlib.sha256(line.strip().encode())
Antwort 3:
Keine Antwort benötigt.
Frage 4:
Using the modified script find the cleartext value for 5030c5bd002de8713fef5daebd597620f5e8bcea31c603dccdfcdf502a57cc60
Antwort 4:
redwings
Task 8 Keyloggers
Frage 1:
What package installer was used?
Pip ist der Standard-Installer für Python Module, hier haben wir die Version 3 für Python3 benutzt, um „keyboard“ zu installieren.
Antwort 1:
pip3
Frage 2:
What line in this code would you change to stop the result from being printed on the screen?
Die letzte Zeile im Code gibt die eingegebenen Tasten wieder aus, das wollen wir natürlich nicht.
Antwort 2:
keyboard.play(keys)
Task 9 SSH Brute Forcing
Frage 1:
What username starting with the letter „t“ did you find earlier?
Task 3 surfer.html enthält die Benutzernamen:
Antwort 1:
tiffany
Frage 2:
What is the SSH password of this user?
Wie gehabt kopieren wir den Code in eine neue Datei (brute.py) und führen sie aus:
#An dieser Stelle imm Fehlermeldung in Python bekommen, noch nachforschen!
#Habe vorerst Hydra benutzt hydra -l tiffany -P /usr/share/wordlists/rockyou.txt 10.10.200.109 -t 64 ssh
Antwort 2:
trustno1
Frage 3:
What is the content of the flag.txt file?
Wir loggen uns per ssh und tiffanys Account auf der MACHINE ein:
ssh tiffany@MACHINE_IP
Und wir erhalten eine Shell:
$ ls
flag.txt
$ cat flag.txt
THM-737390028
Antwort 3:
THM-737390028
Task 10 Extra challenges
Hier gibt es keine Fragen mehr, nur noch ein paar „Fleißaufgaben“.
Ein sehr toller Raum, welcher auch etwas über den Tellerrand blicken lies. Da kann man sich nur auf die nächsten Schritte freuen.