<script> functionbuyFlag() { fetch("/shop", { method: 'POST', // or 'PUT' headers: new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' }) }) .then(res => res.text())
.then(function (response) { alert(response) })
.catch(error =>alert(error)) } functionreset() { if(confirm("This will reset all Jinkelas , Are U Sure?")){ fetch("/api/auth"); setTimeout(()=>window.location.reload(),500); } } functionwork() { fetch("/work?name=bot&do=bot is working") .then(()=>window.location.reload()); }
auth << {flag: ENV["FLAG"]} auth = JWT.encode auth,ENV["SECRET"] , 'HS256' cookies[:auth] = auth json({title:"success",message:"jkl is good thing"}) end end
defislogin if cookies[:auth].nil? then redirect to('/shop') end end
重点关注work路由
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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
可以看到 /work 那里有 ERB 模板,还直接把可控参数 name 拼进去了,那么这里我们就可以传入一些构造过的参数,来达到我们的目的了。但是限制了payload的长度为7。比如 name=<%=1%>,就会得 1。