forked from SniperOJ/Attack-Defense-Framework
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfake_requests.py
137 lines (124 loc) · 4.66 KB
/
fake_requests.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
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import threading
import time
import random
from core.obfs.fake_payloads import *
from core.obfs.get_arg import *
timeout = 0.1
def send_http(request):
prepared = request.prepare()
session = requests.Session()
try:
session.send(prepared, timeout=timeout)
except Exception as e:
print e
def handle_single_http(request):
send_http(request)
def handle_get(url, root, flag_path):
all_requests = []
http_get = get_all(root, "_GET")
plain_payloads = get_fake_plain_payloads(flag_path)
base64_payloads = get_fake_base64_payloads(flag_path)
for item in http_get:
path = item[0]
args = item[1]
for arg in args:
for payload in plain_payloads:
new_url = "%s%s?%s=%s" % (url, path[len("./"):], arg[len("$_GET['"):-len("']")], payload)
request = requests.Request("GET", new_url)
all_requests.append(request)
for payload in base64_payloads:
new_url = "%s%s?%s=%s" % (url, path[len("./"):], arg[len("$_GET['"):-len("']")], payload)
request = requests.Request("GET", new_url)
all_requests.append(request)
return all_requests
def handle_post(url, root, flag_path):
all_requests = []
http_get = get_all(root, "_POST")
plain_payloads = get_fake_plain_payloads(flag_path)
base64_payloads = get_fake_base64_payloads(flag_path)
for item in http_get:
path = item[0]
args = item[1]
for arg in args:
for payload in plain_payloads:
new_url = "%s%s" % (url, path[len("./"):])
request = requests.Request("POST", new_url)
request.data = {
arg[len("$_POST['"):-len("']")]:payload
}
all_requests.append(request)
for payload in base64_payloads:
new_url = "%s%s" % (url, path[len("./"):])
request = requests.Request("POST", new_url)
request.data = {
arg[len("$_POST['"):-len("']")]:payload
}
all_requests.append(request)
return all_requests
def handle_cookie(url, root, flag_path):
all_requests = []
http_get = get_all(root, "_COOKIE")
plain_payloads = get_fake_plain_payloads(flag_path)
base64_payloads = get_fake_base64_payloads(flag_path)
for item in http_get:
path = item[0]
args = item[1]
for arg in args:
for payload in plain_payloads:
new_url = "%s%s" % (url, path[len("./"):])
request = requests.Request("GET", new_url)
request.cookies = {
arg[len("$_COOKIE['"):-len("']")]:payload
}
all_requests.append(request)
for payload in base64_payloads:
new_url = "%s%s" % (url, path[len("./"):])
request = requests.Request("GET", new_url)
request.cookies = {
arg[len("$_COOKIE['"):-len("']")]:payload
}
all_requests.append(request)
return all_requests
def get_targets():
targets = []
with open("targets") as f:
for line in f:
host = line.split(":")[0]
port = int(line.split(":")[1])
targets.append((host, port))
return targets
def main():
flag_path = "/home/web/flag/flag"
root = "./sources"
round_time = 60
all_requests = []
targets = get_targets()
for target in targets:
print "-" * 32
host = target[0]
port = target[1]
print "[+] Generating requests to fake %s:%d" % (host, port)
url = "http://%s:%d/" % (host, port)
print "[+] Requests number : [%d]" % (len(all_requests))
all_requests += handle_get(url, root, flag_path)
print "[+] Requests number : [%d]" % (len(all_requests))
all_requests += handle_post(url, root, flag_path)
print "[+] Requests number : [%d]" % (len(all_requests))
all_requests += handle_cookie(url, root, flag_path)
each_second = len(all_requests) / round_time
print "[+] Each second should send %d requests" % (each_second)
random.shuffle(all_requests)
for request in all_requests:
sleep_time = 1.0 / each_second
print "[+] Sleeping %f seconds" % (sleep_time)
time.sleep(sleep_time)
print "[+] Sending http requests ..."
print "%s => %s" % (request.method, request.url)
thread = threading.Thread(target=handle_single_http, args=(request,))
thread.start()
thread.join()
if __name__ == "__main__":
main()