
Weitere Beispiele mit der Impacket-Bibliothek, die für Lernzwecke entwickelt wurden.
Dieses Repository enthält ein paar kurze Python-Skripte, die mit der Bibliothek Impacket erstellt wurden. Das Hauptziel dieses Projekts ist es, mir selbst und anderen zu helfen, die den Übergang von der Verwendung der mitgelieferten Impacket-Beispiele zur Modifizierung/Erstellung eigener Skripte anstreben. Diese Skripte sind nicht unbedingt auf Nützlichkeit oder OPSEC-Belange optimiert, aber ich habe versucht, sie so dynamisch wie möglich zu gestalten, falls jemand ihr Standardverhalten ändern möchte.

Das Skript wmi_reg_exec.py wurde entwickelt, um eine Datei ausschließlich über WMI auszuführen, indem es in die Windows-Registrierung schreibt. Dazu schreibt es zunächst die base64-kodierte Datei zusammen mit einem PowerShell-AMSI/ETW-Bypass an einen Ziel-Registrierungsspeicherort. Anschließend wird ein PowerShell-Stager verwendet, um den AMSI/ETW-Bypass und die angegebene Datei reflektiv im Arbeitsspeicher auszuführen. C#-Binaries werden 'nativ' unterstützt, solange ihr Haupt-Namespace, ihre Klasse und ihre Methode alle öffentlich verfügbar sind. Sofern nicht angegeben, versucht das Skript automatisch, den Namespace anhand des Dateinamens zu erraten. Wenn eine Nicht-.NET-Datei angegeben wird, wird sie zunächst mithilfe des Donut-Syscall-Branches von @s4ntiago_p in Shellcode umgewandelt und dann in den C#-D/Invoke-Selbstinjektor von @Snovvcrash eingefügt. Der Selbstinjektor wird anschließend mit MCS kompiliert und wie jedes andere C#-Binary verwendet.
usage: wmi_reg_exec.py [-h] [-f file] [-a args] [-n namespace] [-r key] [-p patch] [-rp remotePath] [-nooutput] [-H hash] [-k]
[-dc-ip IPAddress]
target
Store exe in registry and execute via powershell
positional arguments:
target Target host to execute file on
optional arguments:
-h, --help show this help message and exit
-f file, -file file File to execute
-a args, -args args Command line arguments for file
-n namespace, -namespace namespace
Namespace.Class containing main method to execute (Ex: Rubeus.Program)
-r key, -reg-key key Registry key to write file to (Default: HKLM\Software\Microsoft\Edge)
-p patch, -patch patch
File containing AMSI/ETW patch to perform before execution
-rp remotePath, -remote-path remotePath
The remote path to write files to (Default: C:\Windows\Temp)
-nooutput Do not attempt to get/print output
authentication:
-H hash, -hash hash NTHash for login via PtH
-k Use Kerberos authentication with credentials from the KRB5CCNAME ccache file
-dc-ip IPAddress IP Address of the domain controller (useful for Kerberos auth)
Das Skript dll_proxy_exec.py wurde entwickelt, um eine angegebene DLL-Datei mithilfe eines LOLBin auszuführen – per DLL-Hijacking/Proxying/Side-Loading oder wie auch immer man es nennen möchte. Die angegebene DLL wird zunächst über SMB auf das Ziel hochgeladen. Anschließend kopiert das Skript die angegebene System32-EXE in denselben Ordner wie die hochgeladene DLL. Schließlich wird die System32-EXE vom neuen Speicherort aus ausgeführt, was dazu führt, dass sie die angegebene DLL lädt/ausführt.
usage: dll_proxy_exec.py [-h] [-f file] [-e exe] [-output] [-H hash] [-k] [-dc-ip IPAddress] [-rp remotePath] target
Execute file via DLL proxying on a remote host.
positional arguments:
target [[domain/]username[:password]@]<hostname or address>
optional arguments:
-h, --help show this help message and exit
-f file, -file file DLL file to execute
-e exe, -exe exe System32 EXE used to execute DLL file
-output Attempt to get output
-rp remotePath, -remote-path remotePath
The remote path to write files to (Default: C:\Windows\Temp)
authentication:
-H hash, -hash hash NTHash for login via PtH
-k Use Kerberos authentication with credentials from the KRB5CCNAME ccache file
-dc-ip IPAddress IP Address of the domain controller (useful for Kerberos auth)
Das Skript remote_ssp_dump.py wurde entwickelt, um Creds aus LSASS von einem entfernten Host mithilfe der Nanodump-SSP-DLL auszudumpen. Standardmäßig verwendet das Skript die unveränderte SSP-DLL und den unveränderten Loader, die in die Datei eingebettet sind. Alternativ verwendet das Skript eine modifizierte DLL oder einen modifizierten Loader, falls diese unter ihren Standardnamen (nanodump_ssp.x64.dll bzw. load_ssp.x64.exe) im aktuellen Verzeichnis vorhanden sind. Bei der Ausführung lädt das Skript die DLL und den Loader auf das Ziel hoch, führt den Loader aus, lädt den LSASS-Dump herunter und parst ihn mithilfe von Pypykatz auf Hashes. Darüber hinaus wurde dieses Skript in die Skripte wmi_reg_exec.py und dll_proxy_exec.py integriert, was unterschiedliche Möglichkeiten zur Ausführung des SSP-Loaders bietet.
usage: remote_ssp_dump.py [-h] [-t timeout] [-rp remotePath] [-re] [-dp] [-f dll] [-e exe] [-r key] [-H hash] [-k]
[-dc-ip IPAddress]
target
Dump creds from LSASS remotely using Nanodump SSP
positional arguments:
target [[domain/]username[:password]@]<hostname or address>
optional arguments:
-h, --help show this help message and exit
-t timeout, -timeout timeout
Timeout in seconds to wait for LSASS dump file to be created (Default: 3)
-rp remotePath, -remote-path remotePath
The remote path to write files to (Default: C:\Windows\Temp)
-re, -reg-exec Execute SSP loader by writing it to the registry and executing it in memory with PowerShell
-dp, -dll-proxy Execute SSP loader via DLL Proxying (See below for options)
dll proxying options:
-f dll, -file dll DLL file to execute
-e exe, -exe exe System32 EXE used to execute DLL file
registry execute options:
-r key, -reg-key key Registry key to write file to (Default: HKLM\Software\Microsoft\Edge)
authentication:
-H hash, -hash hash NTHash for login via PtH
-k Use Kerberos authentication with credentials from the KRB5CCNAME ccache file
-dc-ip IPAddress IP Address of the domain controller (useful for Kerberos auth)
Das Skript dump_ntds_creds.py wurde entwickelt, um alle Domänen-Hashes von einem Ziel-Domänencontroller auszudumpen, zu exfiltrieren und zu parsen. Zuerst führt es den LOLBin ntdsutil.exe über WMI aus, um den Dump zu erstellen, und lädt dann die resultierenden Dateien ntds.dit, SYSTEM und SECURITY über SMB herunter. Anschließend parst es alle Domänen-Anmeldeinformationen aus der gedumpten Datei und speichert die Ergebnisse in einer Datei.
usage: dump_ntds_creds.py [-h] [-nooutput] [-o filename] [-H hash] [-k] [-dc-ip IPAddress] [-rp remotePath] target
Dump NTDS.dit file, exfiltrate, and parse locally.
positional arguments:
target [[domain/]username[:password]@]<hostname or address>
optional arguments:
-h, --help show this help message and exit
-nooutput Do not print dumped hashes to console
-o filename, -outfile filename
Name to save output files with (Default: DomainDump)
-rp remotePath, -remote-path remotePath
The remote path to write files to (Default: C:\Windows\Temp)
authentication:
-H hash, -hash hash NTHash for login via PtH
-k Use Kerberos authentication with credentials from the KRB5CCNAME ccache file
-dc-ip IPAddress IP Address of the domain controller (useful for Kerberos auth)
wmi_reg_exec.py kann die Ausgabe einer Nicht-.NET-PE-Datei nicht abrufen, ohne auf die Festplatte zu schreiben. Wenn du in diesem Fall versuchen möchtest, eine Ausgabe zu erhalten, muss die PE-Datei selbst ihre eigene Ausgabe unter dem im Skript angegebenen Dateinamen schreiben. Dies könnte fest in die PE-Datei einprogrammiert sein oder über das Flag -a des Skripts übergeben werden, wenn die PE bereits über ein Argument zum Schreiben ihrer Ausgabe in eine Datei verfügt. Ein Beispiel hierfür findest du im GIF "Example PE Demo", das diesen Prozess mit Mimikatz demonstriert.wmi_reg_exec.py in die Registrierung schreibt, ist LANGSAM. Nach meinen Tests kann es bis zu 4 Minuten pro MB dauern. Ich bin mir nicht ganz sicher, warum das so ist. Wenn du einen Weg kennst, es zu beschleunigen, ohne das Ganze neu schreiben zu müssen, sind Pull-Requests jederzeit willkommen. :)remote_ssp_dump.py verwendet wird: https://github.com/helpsystems/nanodumpwmi_reg_exec.py verwendet wird: https://github.com/S4ntiagoP/donut/tree/syscallswmi_reg_exec.py verwendet wird: https://twitter.com/snovvcrash/status/1558837027122167810