-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_inj_https.py
More file actions
68 lines (60 loc) · 2.85 KB
/
Copy pathcode_inj_https.py
File metadata and controls
68 lines (60 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
# Rebuild - Separate Script for testing with OWASP Juice Shop which I think is Https
# We are testing here locally against OWASP Juice Shop
# http://127.0.0.1:42000/#/
import netfilterqueue
from scapy.layers.inet import IP, TCP
from scapy.layers.dns import Raw
import re
# Take our modified load and set it to the actual load
def set_load(packet, load):
packet[Raw].load = load
# For scapy to recalculate IP and Chksum values for our updated load
# You need to delete them
del packet[IP].len
del packet[IP].chksum
del packet[TCP].chksum
return packet
# Payload has: Accept-Encoding\r\nContent-Encoding: gzip\r\n
# The following Regex should also work here.
AcceptEncodingRegex = "Accept-Encoding:.*?\\r\\n"
def process_packet(packet):
scapy_packet= IP(packet.get_payload())
if scapy_packet.haslayer(Raw):
if scapy_packet.haslayer(TCP):
# print("\n[+] Packet has layer TCP")
# print(scapy_packet.show())
if scapy_packet[TCP].dport == 443:
print("[+] This is a HTTP Request on port 443: ")
if "Accept-Encoding" in scapy_packet[Raw].load:
print("[+] Accept Encoding in Payload: ")
print(scapy_packet[Raw].load)
elif scapy_packet[TCP].dport == 55114:
print("[+] This is a HTTP Request on port 55114: ")
elif scapy_packet[TCP].dport == 42000:
print("[+] This is a HTTP Request on port 42000: ")
if "Accept-Encoding" in scapy_packet[Raw].load:
print("[+] Accept Encoding in Payload: ")
print(scapy_packet[Raw].load)
# TODO ************************
# Write a loop to cycle through ports
# How about autodect ports being used for HTTP traffic
# Do the same things as here for replace_download
# The actual idea would be to have scripts adaptable to any scenerio
# END TODO ********************
# Find string "Accept-Encoding" in the payload of HTTP Request Raw layer
# replace with nothing, and save in modified_load
# modified_load = re.sub(AcceptEncodingRegex, "", scapy_packet[Raw].load)
# print(modified_load)
# new_packet = set_load(scapy_packet, modified_load)
# set the new packet with the updated payload to the actual packet
# packet.set_payload(str(new_packet))
# Remove elif for testing modify payload in HTTP request
# elif scapy_packet[TCP].sport == 80:
# print("[+] This is a HTTP Response: ")
# print(scapy_packet.show())
packet.accept()
if __name__ == "__main__":
queue = netfilterqueue.NetfilterQueue()
queue.bind(2, process_packet)
queue.run()