
基本的に、NimExecは Service Control Manager Remote Protocol (MS-SCMR) を使用するファイルレスなリモートコマンド実行ツールです。LocalSystemが実行するランダムまたは指定されたサービスのバイナリパスを変更し、ターゲット上で指定されたコマンドを実行し、後でWinAPI呼び出しの代わりに手作りRPCパケットを介して復元します。これらのパケットはSMB2とsvcctl名前付きパイプを介して送信されます。
NimExecはターゲットマシンへの認証にNTLMハッシュを必要とし、手作りパケットを介してNTLM認証方式でこの認証プロセスを完了します。
必要なネットワークパケットはすべて手作業で作成され、オペレーティングシステム固有の関数は使用されないため、NimExecはNimのクロスコンパイルサポートを利用して異なるオペレーティングシステムで使用できます。
このプロジェクトは Julio's SharpNoPSExec ツールに触発されました。NimExecはSharpNoPSExecのクロスコンパイル可能でPass the Hashを組み込みでサポートしたバージョンと考えることができます。また、必要なネットワークパケット構造は Kevin Robertson's Invoke-SMBExec Script から学びました。
nim c -d:release --gc:markAndSweep -o:NimExec.exe Main.nim
上記のコマンドは異なるガベージコレクタを使用しています。これは、Nimのデフォルトのガベージコレクタがサービスの検索中にSIGSEGVエラーを発生させるためです。
また、以下のコマンドでNimble経由で必要なNimモジュールをインストールできます:
nimble install ptr_math nimcrypto hostname
test@ubuntu:~/Desktop/NimExec$ ./NimExec -u testuser -d TESTLABS -h 123abcbde966780cef8d9ec24523acac -t 10.200.2.2 -c 'cmd.exe /c "echo test > C:\Users\Public\test.txt"' -v
_..._
.-'_..._''.
_..._ .--. __ __ ___ __.....__ __.....__ .' .' '.\
.' '. |__|| |/ `.' `. .-'' '. .-'' '. / .'
. .-. ..--.| .-. .-. ' / .-''"'-. `. / .-''"'-. `. . '
| ' ' || || | | | | |/ /________\ \ ____ _____/ /________\ \| |
| | | || || | | | | || |`. \ .' /| || |
| | | || || | | | | |\ .-------------' `. `' .' \ .-------------'. '
| | | || || | | | | | \ '-.____...---. '. .' \ '-.____...---. \ '. .
| | | ||__||__| |__| |__| `. .' .' `. `. .' '. `._____.-'/
| | | | `''-...... -' .' .'`. `. `''-...... -' `-.______ /
| | | | .' / `. `. `
'--' '--' '----' '----'
@R0h1rr1m
[+] Connected to 10.200.2.2:445
[+] NTLM Authentication with Hash is succesfull!
[+] Connected to IPC Share of target!
[+] Opened a handle for svcctl pipe!
[+] Bound to the RPC Interface!
[+] RPC Binding is acknowledged!
[+] SCManager handle is obtained!
[+] Number of obtained services: 265
[+] Selected service is LxpSvc
[+] Service: LxpSvc is opened!
[+] Previous Service Path is: C:\Windows\system32\svchost.exe -k netsvcs
[+] Service config is changed!
[!] StartServiceW Return Value: 1053 (ERROR_SERVICE_REQUEST_TIMEOUT)
[+] Service start request is sent!
[+] Service config is restored!
[+] Service handle is closed!
[+] Service Manager handle is closed!
[+] SMB is closed!
[+] Tree is disconnected!
[+] Session logoff!
Ubuntu 20.04 および Windows 10 マシンから Windows 10&11、Windows Server 16&19&22 に対してテストされています。
-v | --verbose Enable more verbose output.
-u | --username <Username> Username for NTLM Authentication.*
-h | --hash <NTLM Hash> NTLM password hash for NTLM Authentication.**
-p | --password <Password> Plaintext password.**
-t | --target <Target> Lateral movement target.*
-c | --command <Command> Command to execute.*
-d | --domain <Domain> Domain name for NTLM Authentication.
-s | --service <Service Name> Name of the service instead of a random one.
--help Show the help message.
許可されたセキュリティテスト専用です。明示的な許可なくシステムに対してこのツールを悪用することは違法です。