-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequestgenerator.py
More file actions
174 lines (133 loc) · 4.25 KB
/
requestgenerator.py
File metadata and controls
174 lines (133 loc) · 4.25 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env python3
import os
import sys
import concurrent.futures
from urllib.parse import urlparse
# ===== GUI CHECK =====
try:
import tkinter as tk
from tkinter import messagebox
GUI_AVAILABLE = True
except:
GUI_AVAILABLE = False
OUTPUT_TXT = "req.txt"
OUTPUT_XML = "burp.xml"
THREADS = 10
# ===== HEADERS =====
BASE_HEADERS = {
"User-Agent": "Mozilla/5.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.9",
"Connection": "close"
}
# ===== PARSE =====
def parse_url(url):
if not url.startswith("http"):
url = "http://" + url
p = urlparse(url)
return p if p.netloc else None
# ===== BUILD REQUEST =====
def build_request(url, method, body):
p = parse_url(url)
if not p:
return None, None
path = p.path if p.path else "/"
if p.query:
path += "?" + p.query
req1 = f"{method} {path} HTTP/1.1\r\n"
req1 += f"Host: {p.netloc}\r\n"
for k, v in BASE_HEADERS.items():
req1 += f"{k}: {v}\r\n"
if method == "POST" and body:
req1 += "Content-Type: application/x-www-form-urlencoded\r\n"
req1 += f"Content-Length: {len(body)}\r\n"
req1 += "\r\n" + body
else:
req1 += "\r\n"
# HTTP/2
req2 = f":method: {method}\n"
req2 += f":path: {path}\n"
req2 += f":authority: {p.netloc}\n"
req2 += f":scheme: {p.scheme}\n\n"
return req1, req2
# ===== PROCESS =====
def process(urls, method, body):
results = []
with concurrent.futures.ThreadPoolExecutor(max_workers=THREADS) as ex:
futures = [ex.submit(build_request, u, method, body) for u in urls]
for f in concurrent.futures.as_completed(futures):
r1, r2 = f.result()
if r1:
results.append((r1, r2))
with open(OUTPUT_TXT, "w") as f:
for r1, r2 in results:
f.write(r1 + "\n")
f.write(r2 + "\n")
with open(OUTPUT_XML, "w") as f:
f.write("<items>")
for r1, _ in results:
f.write(f"<item><request><![CDATA[{r1}]]></request></item>")
f.write("</items>")
return len(results)
# ===== CLI =====
def cli_mode():
print("\n[CLI MODE]\n", flush=True)
raw = input("[?] Enter URLs (comma separated): ").strip()
urls = [x.strip() for x in raw.split(",") if x.strip()]
if not urls:
print("[X] No URLs!", flush=True)
return
method = input("[?] Method (GET/POST): ").upper().strip()
if method not in ["GET", "POST"]:
method = "GET"
body = ""
if method == "POST":
body = input("[?] POST data: ")
count = process(urls, method, body)
print(f"\n[+] Generated: {count}", flush=True)
print(f"[+] Saved: {OUTPUT_TXT}, {OUTPUT_XML}\n", flush=True)
# ===== GUI =====
def gui_mode():
root = tk.Tk()
root.title("Request Generator")
tk.Label(root, text="URLs (one per line)").pack()
text = tk.Text(root, height=10)
text.pack()
method_var = tk.StringVar(value="GET")
tk.OptionMenu(root, method_var, "GET", "POST").pack()
tk.Label(root, text="POST Body").pack()
body_entry = tk.Entry(root)
body_entry.pack()
def run():
urls = text.get("1.0", "end").strip().split("\n")
method = method_var.get()
body = body_entry.get()
count = process(urls, method, body)
messagebox.showinfo("Done", f"{count} requests generated")
tk.Button(root, text="Generate", command=run).pack()
root.mainloop()
# ===== FORCE MENU =====
def main():
while True:
print("\n========== MENU ==========", flush=True)
print("1. CLI Mode", flush=True)
print("2. GUI Mode", flush=True)
print("0. Exit", flush=True)
print("==========================\n", flush=True)
choice = input("[?] Select option (1/2/0): ").strip()
if choice == "1":
cli_mode()
break
elif choice == "2":
if GUI_AVAILABLE:
gui_mode()
break
else:
print("[!] GUI not available!", flush=True)
elif choice == "0":
sys.exit(0)
else:
print("[!] Invalid input, try again...", flush=True)
# ===== RUN =====
if __name__ == "__main__":
main()