Last active
March 21, 2021 23:19
-
-
Save doorbash/a77e9fecb51129032f015ea3ab681fab to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python3 | |
from scapy.all import * | |
import threading | |
interface_left_name = "Wi-Fi" | |
interface_left_default_gateway = "192.168.1.1" | |
interface_right_name = "SSTAP 1" | |
conf.verb = 0 | |
interface_left = IFACES.dev_from_name(interface_left_name) | |
interface_right = IFACES.dev_from_name(interface_right_name) | |
mac_left = get_if_hwaddr(interface_left) | |
ip_left = get_if_addr(interface_left) | |
mac_default_gateway_left = sr1(ARP(pdst=interface_left_default_gateway,op=1), timeout=5, retry=3,iface=interface_left)[ARP].hwsrc | |
print("default::::", mac_default_gateway_left) | |
mac_right = get_if_hwaddr(interface_right) | |
ip_right = get_if_addr(interface_right) | |
print("---------------------------------------------") | |
print("interface_left: ", mac_left, " ", ip_left) | |
print("interface_right: ", mac_right, " ", ip_right) | |
print("---------------------------------------------") | |
def spoof_and_send_left(packet): | |
if not packet.haslayer(Ether): | |
return None | |
if packet[Ether].dst != mac_left or packet[Ether].src == mac_left: | |
return None | |
if not packet.haslayer(IP): | |
packet[Ether].src = mac_left | |
packet[Ether].dst = mac_default_gateway_left | |
sendp(packet, iface=interface_left) | |
print(interface_left_name, packet.summary()) | |
return None | |
if packet[IP].src != ip_left and packet[IP].dst != ip_left: | |
print(interface_left_name, ": ", packet[IP].src, "(" + packet[Ether].src + ")", " -> ", packet[IP].dst, "(" + packet[Ether].dst + ")", " ", packet.summary()) | |
if packet.haslayer(TCP): | |
return Ether(src=mac_right) / packet[IP] | |
else: | |
# print(interface_left_name, ": ", packet[IP].src, "(" + packet[Ether].src + ")", " -> ", packet[IP].dst, "(" + packet[Ether].dst + ")", " ", packet.summary(), len(packet)) | |
sendp(Ether(src=mac_left ,dst = mac_default_gateway_left) / packet[IP], iface=interface_left) | |
return None | |
return None | |
def spoof_and_send_right(packet): | |
if packet[Ether].dst != mac_right or packet[Ether].src == mac_right: | |
return None | |
if not packet.haslayer(IP): | |
packet[Ether].src = mac_right | |
packet[Ether].dst = mac_right | |
sendp(packet, iface=interface_right) | |
print(interface_right_name, packet.summary()) | |
return None | |
if packet[IP].src != ip_right and packet[IP].dst != ip_right: | |
print(interface_right_name, ": ", packet[IP].src, "(" + packet[Ether].src + ")", " -> ", packet[IP].dst, "(" + packet[Ether].dst + ")", " ", packet.summary()) | |
if packet.haslayer(TCP): | |
# print((Ether(src=mac_left) / packet[IP])[TCP].dport) | |
return Ether(src=mac_left) / packet[IP] | |
else: | |
# print(interface_right_name, ": ", packet[IP].src, "(" + packet[Ether].src + ")", " -> ", packet[IP].dst, "(" + packet[Ether].dst + ")", " ", packet.summary(), len(packet)) | |
return None | |
return None | |
bridge_and_sniff(if1=interface_left, if2=interface_right, xfrm12=spoof_and_send_left, xfrm21=spoof_and_send_right, store=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment