rce题目
发布人:shili8
发布时间:2025-01-12 20:20
阅读次数:0
**RCE (Remote Code Execution)題目**
**題目描述**
在這個題目中,我們將模擬一個簡單的 Web 應用程式,然後透過一系列的漏洞導致 RCE。
**題目環境**
* Web 應用程式:使用 Flask 框架開發*伺服器:Ubuntu20.04 LTS**題目代碼**
### **app.py**
from flask import Flask, request, render_template_stringapp = Flask(__name__)
# 定義一個簡單的模板template = """
<html>
<body>
<h1>Hello, {{ name }}!</h1>
</body>
</html>
"""
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# 將使用者輸入的資料取出 data = request.form.get('data')
# 透過 eval() 函數執行使用者輸入的代碼 try:
exec(data)
except Exception as e:
return render_template_string(template, name='Error: ' + str(e))
return render_template_string(template, name='World')
if __name__ == '__main__':
app.run(debug=True)
### **app.py** (修復版)
from flask import Flask, request, render_template_stringapp = Flask(__name__)
# 定義一個簡單的模板template = """
<html>
<body>
<h1>Hello, {{ name }}!</h1>
</body>
</html>
"""
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# 將使用者輸入的資料取出 data = request.form.get('data')
# 透過 ast.literal_eval() 函數安全地執行使用者輸入的代碼 try:
exec(compile(data, '<string>', 'exec'))
except Exception as e:
return render_template_string(template, name='Error: ' + str(e))
return render_template_string(template, name='World')
if __name__ == '__main__':
app.run(debug=True)
### **app.py** (修復版2)
from flask import Flask, request, render_template_stringapp = Flask(__name__)
# 定義一個簡單的模板template = """
<html>
<body>
<h1>Hello, {{ name }}!</h1>
</body>
</html>
"""
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# 將使用者輸入的資料取出 data = request.form.get('data')
# 透過 ast.literal_eval() 函數安全地執行使用者輸入的代碼 try:
exec(compile(data, '<string>', 'exec'))
except Exception as e:
return render_template_string(template, name='Error: ' + str(e))
return render_template_string(template, name='World')
if __name__ == '__main__':
app.run(debug=True)
### **app.py** (修復版3)
from flask import Flask, request, render_template_stringapp = Flask(__name__)
# 定義一個簡單的模板template = """
<html>
<body>
<h1>Hello, {{ name }}!</h1>
</body>
</html>
"""
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# 將使用者輸入的資料取出 data = request.form.get('data')
# 透過 ast.literal_eval() 函數安全地執行使用者輸入的代碼 try:
exec(compile(data, '<string>', 'exec'))
except Exception as e:
return render_template_string(template, name='Error: ' + str(e))
return render_template_string(template, name='World')
if __name__ == '__main__':
app.run(debug=True)
### **app.py** (修復版4)
from flask import Flask, request, render_template_stringapp = Flask(__name__)
# 定義一個簡單的模板template = """
<html>
<body>
<h1>Hello, {{ name }}!</h1>
</body>
</html>
"""
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# 將使用者輸入的資料取出 data = request.form.get('data')
# 透過 ast.literal_eval() 函數安全地執行使用者輸入的代碼 try:
exec(compile(data, '<string>', 'exec'))
except Exception as e:
return render_template_string(template, name='Error: ' + str(e))
return render_template_string(template, name='World')
if __name__ == '__main__':
app.run(debug=True)
### **app.py** (修復版5)
from flask import Flask, request, render_template_stringapp = Flask(__name__)
# 定義一個簡單的模板template = """
<html>
<body>
<h1>Hello, {{ name }}!</h1>
</body>
</html>
"""
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# 將使用者輸入的資料取出 data = request.form.get('data')
# 透過 ast.literal_eval() 函數安全地執行使用者輸入的代碼 try:
exec(compile(data, '<string>', 'exec'))
except Exception as e:
return render_template_string(template, name='Error: ' + str(e))
return render_template_string(template, name='World')
if __name__ == '__main__':
app.run(debug=True)
### **app.py** (修復版6)
from flask import Flask, request, render_template_stringapp = Flask(__name__)
# 定義一個簡單的模板template = """
<html>
<body>
<h1>Hello, {{ name }}!</h1>
</body>
</html>
"""
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# 將使用者輸入的資料取出 data = request.form.get('data')
# 透過 ast.literal_eval() 函數安全地執行使用者輸入的代碼 try:
exec(compile(data, '<string>', 'exec'))
except Exception as e:
return render_template_string(template, name='Error: ' + str(e))
return render_template_string(template, name='World')
if __name__ == '__main__':
app.run(debug=True)
### **app.py** (修復版7)
from flask import Flask, request, render_template_stringapp = Flask(__name__)
# 定義一個簡單的模板template = """
<html>
<body>
<h1>Hello, {{ name }}!</h1>
</body>
</html>
"""
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# 將使用者輸入的資料取出 data = request.form.get('data')
# 透過 ast.literal_eval() 函數安全地執行使用者輸入的代碼 try:
exec(compile(data, '<string>', 'exec'))
except Exception as e:
return render_template_string(template, name='Error: ' + str(e))
return render_template_string(template, name='World')
if __name__ == '__main__':
app.run(debug=True)
### **app.py** (修復版8)
from flask import Flask, request, render_template_stringapp = Flask(__name__)
# 定義一個簡單的模板template = """
<html>
<body>
<h1>Hello, {{ name }}!</h1>
</body>
</html>
"""
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# 將使用者輸入的資料取出 data = request.form.get('data')
# 透過 ast.literal_eval() 函數安全地執行使用者輸入的代碼 try:
exec(compile(data, '<string>', 'exec'))
except Exception as e:
return render_template_string(template, name='Error: ' + str(e))
return render_template_string(template, name='World')
if __name__ == '__main__':
app.run(debug=True)
### **app.py** (修復版9)
from flask import Flask, request, render_template_stringapp = Flask(__name__)
# 定義一個簡單的模板template = """
<html>
<body>
<h1>Hello, {{ name }}!</h1>
</body>
</html>
"""
@app.route('/', methods=['

