Skip to content

Commit 0771345

Browse files
committed
add ip spoofer tutorial
1 parent cf194de commit 0771345

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
1616
- [How to Build a WiFi Scanner in Python using Scapy](https://www.thepythoncode.com/article/building-wifi-scanner-in-python-scapy). ([code](scapy/wifi-scanner))
1717
- [How to Make a SYN Flooding Attack in Python](https://www.thepythoncode.com/article/syn-flooding-attack-using-scapy-in-python). ([code](scapy/syn-flood))
1818
- [How to Inject Code into HTTP Responses in the Network in Python](https://www.thepythoncode.com/article/injecting-code-to-html-in-a-network-scapy-python). ([code](scapy/http-code-injector/))
19+
- [How to Perform IP Address Spoofing in Python](https://thepythoncode.com/article/make-an-ip-spoofer-in-python-using-scapy). ([code](scapy/ip-spoofer))
1920
- [Writing a Keylogger in Python from Scratch](https://www.thepythoncode.com/article/write-a-keylogger-python). ([code](ethical-hacking/keylogger))
2021
- [Making a Port Scanner using sockets in Python](https://www.thepythoncode.com/article/make-port-scanner-python). ([code](ethical-hacking/port_scanner))
2122
- [How to Create a Reverse Shell in Python](https://www.thepythoncode.com/article/create-reverse-shell-python). ([code](ethical-hacking/reverse_shell))

Diff for: scapy/ip-spoofer/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# [How to Perform IP Address Spoofing in Python](https://thepythoncode.com/article/make-an-ip-spoofer-in-python-using-scapy)
2+
To run this:
3+
- `pip install -r requirements.txt`
4+
- `python ip_spoofer.py [target_ip]`

Diff for: scapy/ip-spoofer/ip_spoofer.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Import the neccasary modules.
2+
import sys
3+
from scapy.all import sr, IP, ICMP
4+
from faker import Faker
5+
from colorama import Fore, init
6+
7+
# Initialize colorama for colored console output.
8+
init()
9+
# Create a Faker object for generating fake data.
10+
fake = Faker()
11+
12+
# Function to generate a fake IPv4 address.
13+
def generate_fake_ip():
14+
return fake.ipv4()
15+
16+
# Function to craft and send an ICMP packet.
17+
def craft_and_send_packet(source_ip, destination_ip):
18+
# Craft an ICMP packet with the specified source and destination IP.
19+
packet = IP(src=source_ip, dst=destination_ip) / ICMP()
20+
# Send and receive the packet with a timeout.
21+
answers, _ = sr(packet, verbose=0, timeout=5)
22+
return answers
23+
24+
# Function to display a summary of the sent and received packets.
25+
def display_packet_summary(sent, received):
26+
print(f"{Fore.GREEN}[+] Sent Packet: {sent.summary()}\n")
27+
print(f"{Fore.MAGENTA}[+] Response: {received.summary()}")
28+
29+
# Check if the correct number of command-line arguments is provided.
30+
if len(sys.argv) != 2:
31+
print(f"{Fore.RED}[-] Error! {Fore.GREEN} Please run as: {sys.argv[0]} <dst_ip>")
32+
sys.exit(1)
33+
34+
# Retrieve the destination IP from the command-line arguments.
35+
destination_ip = sys.argv[1]
36+
# Generate a fake source IP.
37+
source_ip = generate_fake_ip()
38+
# Craft and send the packet, and receive the response.
39+
answers = craft_and_send_packet(source_ip, destination_ip)
40+
# Display the packet summary for each sent and received pair.
41+
for sent, received in answers:
42+
display_packet_summary(sent, received)

Diff for: scapy/ip-spoofer/requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
scapy
2+
faker
3+
colorama

0 commit comments

Comments
 (0)