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
|
from flask import Flask, request, session, render_template_string, abort, redirect, url_for, make_response, Response
import ...
app = Flask(__name__)
def generate_secret_key():
prefix = "Yulin"
suffix = ''.join(random.choices(string.ascii_letters + string.digits, k=16))
return prefix + suffix
app.secret_key = generate_secret_key()
flag = ""
if os.path.isfile("/flag"):
with open("/flag", "r") as f:
flag = f.read().strip()
os.remove("/flag")
os.remove("/start.sh")
else:
flag = "[ ]"
@app.route('/')
def index():
if session.get('is_admin'):
return f'<h1>你好,Admin</h1><p>Flag: YulinSec{{{flag}}}</p>'
return ......
@app.route('/download')
def download():
......
allowed_proc_files = ['/proc/self/maps', '/proc/self/mem']
if file_path in allowed_proc_files:
pass
else:
......
if file_path == '/proc/self/maps':
try:
with open(file_path, 'r') as f:
content = f.read()
...
return response
except Exception as e:
...
if file_path == '/proc/self/mem':
if end <= start:
end = start + 1048576 # 1MB
def generate():
try:
with open(file_path, 'rb') as f:
f.seek(start)
remaining = end - start
while remaining > 0:
chunk_size = min(1024 * 1024, remaining) # 每次最多读取1MB
data = f.read(chunk_size)
if not data:
break
yield data
remaining -= len(data)
except Exception as e:
app.logger.error(f"Error reading memory: {str(e)}")
yield f"Error reading memory content from {start} to {end}".encode()
return Response(
generate(),
mimetype='application/octet-stream',
headers={'Content-Disposition': f'attachment; filename=memory_{start}_{end}.bin'}
)
try:
with open(file_path, 'rb') as f:
content = f.read()
except Exception as e:
...
sanitized_content = re.sub(
rb'flag\{.*?\}',
b'[ ]',
content,
flags=re.IGNORECASE
)
....
return response
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
|