当前位置:网站首页>[SCTF2019]Flag Shop
[SCTF2019]Flag Shop
2022-07-30 12:12:00 【New Reading of the Classic of Tea.】
[SCTF2019]Flag Shop

点击buy flag会显示你的JinKela不够,如果点击resetwill reset youruid(好像没啥用),Click to work on yoursJinKela会上升,But not significantly increased

f12并没有发现什么东西,dirsearch扫描一下发现了robots.txt

访问得/filebak
![]()

Continue to visit to get the source code:
![]()
require 'sinatra'
require 'sinatra/cookies'
require 'sinatra/json'
require 'jwt'
require 'securerandom'
require 'erb'
set :public_folder, File.dirname(__FILE__) + '/static'
FLAGPRICE = 1000000000000000000000000000
ENV["SECRET"] = SecureRandom.hex(64)
configure do
enable :logging
file = File.new(File.dirname(__FILE__) + '/../log/http.log',"a+")
file.sync = true
use Rack::CommonLogger, file
end
get "/" do
redirect '/shop', 302
end
get "/filebak" do
content_type :text
erb IO.binread __FILE__
end
get "/api/auth" do
payload = { uid: SecureRandom.uuid , jkl: 20}
auth = JWT.encode payload,ENV["SECRET"] , 'HS256'
cookies[:auth] = auth
end
get "/api/info" do
islogin
auth = JWT.decode cookies[:auth],ENV["SECRET"] , true, { algorithm: 'HS256' }
json({uid: auth[0]["uid"],jkl: auth[0]["jkl"]})
end
get "/shop" do
erb :shop
end
get "/work" do
islogin
auth = JWT.decode cookies[:auth],ENV["SECRET"] , true, { algorithm: 'HS256' }
auth = auth[0]
unless params[:SECRET].nil?
if ENV["SECRET"].match("#{params[:SECRET].match(/[0-9a-z]+/)}")
puts ENV["FLAG"]
end
end
if params[:do] == "#{params[:name][0,7]} is working" then
auth["jkl"] = auth["jkl"].to_i + SecureRandom.random_number(10)
auth = JWT.encode auth,ENV["SECRET"] , 'HS256'
cookies[:auth] = auth
ERB::new("<script>alert('#{params[:name][0,7]} working successfully!')</script>").result
end
end
post "/shop" do
islogin
auth = JWT.decode cookies[:auth],ENV["SECRET"] , true, { algorithm: 'HS256' }
if auth[0]["jkl"] < FLAGPRICE then
json({title: "error",message: "no enough jkl"})
else
auth << {flag: ENV["FLAG"]}
auth = JWT.encode auth,ENV["SECRET"] , 'HS256'
cookies[:auth] = auth
json({title: "success",message: "jkl is good thing"})
end
end
def islogin
if cookies[:auth].nil? then
redirect to('/shop')
end
end发现了jwt字样,bp抓包发现了jwt内容


解密(JSON Web Tokens - jwt.io)Find the same information as the title website
但是在jwtNeed to modify the amount of moneysecret,And the code is also givensecret的生成方式
if params[:do] == "#{params[:name][0,7]} is working" then
auth["jkl"] = auth["jkl"].to_i + SecureRandom.random_number(10)
auth = JWT.encode auth,ENV["SECRET"] , 'HS256'
cookies[:auth] = auth
ERB::new("<script>alert('#{params[:name][0,7]} working successfully!')</script>").result需要传参,传do和name,Generated when the two are equalsecret,但是也发现了ERB(【技术分享】手把手教你如何完成Ruby ERB模板注入 - 安全客,安全资讯平台),需要<%= xxx %>传值,在ERB中发现ruby,查看ruby预定义变量(globals - Documentation for Ruby 2.4.0),发现$'Indicates the last match of the string on the right.

于是开始构造payload:/work?SECRET=&name=<%=$'%> is working

出现了400 Bad Request,It may be that some characters are filtered and the characters are carried outurl加密(在线url网址编码、解码器-BeJSON.com),构造出新的payload:/work?SECRET=&name=%3c%25%3d%24%27%25%3e&do=%3c%25%3d%24%27%25%3e%20is%20working,Incoming is obtainedsecret

有了secret就可以修改jwt了

填入secret,Then modify the amount,Scientific notation is used here,As long as it is larger than the required amount,得到新的jwt,返回bp传入,Here to startGET改为POST

Back to us againjwt,Take it to decrypt itflag

至此结束,撒花
边栏推荐
- 历时两月,终拿字节跳动offer,算法面试题分享「带答案」
- [Database basics] redis usage summary
- 嵌入式环境下并发控制与线程安全
- Kubernetes之本地存储
- 【CVA估值训练营】如何快速读懂上市公司年报——第五讲
- Reverse linked list - recursive inversion method
- IO/多路复用(select/poll/epoll)
- 开源出来的fuse版pfs文件系统主要就是解决缓存问题吧。nfs挂载参数带sync规避缓存问题是不是
- PyQt5快速开发与实战 8.4 设置窗口背景 && 8.5 不规则窗口的显示
- PanGu-Coder: 函数级的代码生成模型
猜你喜欢

Performance testing of API Gateway APISIX on Google Cloud T2A and T2D

ECCV 2022 | 新加坡国立大学提出:全新可恢复型模型遗忘框架LIRF!

C# 枚举类型 于xaml 中区别

Verilog grammar basics HDL Bits training 07

Difference between C# enumeration type and xaml

Horizontal comparison of 5 commonly used registration centers, whether it is used for interviews or technical selection, is very helpful

【32. 图中的层次(图的广度优先遍历)】

概率论的学习整理--番外1:可重复且无次序的计数公式C(n+k-1,k) 的例题 : 同时丢3个骰子,会有多少种情况?答案不是216而是56!

程序环境和预处理(详解)

作业7.29 目录相关函数和文件属性相关函数
随机推荐
unity初学6——简易的UI制作(血条制作)和音频加入以及NPC的对话气泡(2d)
nodeJs--fs模块
英 文 换 行
Get the original data API on 1688app
Taobao/Tmall taobao comments q&a list interface API
Scheduling of combined electric-heating system based on multi-objective two-stage stochastic programming method
爱可可AI前沿推介(7.30)
基于MySQL数据库,Redis缓存,MQ消息中间件,ES搜索引擎的高可用方案解析
Flexible distribution parameters of mechanical system modeling and control of research and development
历时两月,终拿字节跳动offer,算法面试题分享「带答案」
Apifox 生成接口文档 教程与操作步骤
【数据库基础】redis使用总结
微信视频号视频如何下载提取?视频号直播回放如何下载?方法很简单!
Matlab基础(3)——元胞与结构体
Transfer Learning Technology Training
Matlab基础(5)——符号运算
Niuke-TOP101-BM42
Interviewer: Redis bloom filter and the cuckoo in the filter, how much do you know?
Manage reading notes upward
HJY-F931A/YJ three-phase voltage relay