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 का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
Quick Fingerprinting
Useful Express indicators during recon:
X-Powered-By: Expressor stack traces mentioningexpress,body-parser,qs,cookie-parser,express-session, orfinalhandler- Cookies prefixed with
s:(signed cookie) orj:(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 tokeninbody-parser, orURIErrorduring 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.
Cookie Signature
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 bycookie-parserorexpress-sessionj:<json>JSON cookies that are automatically parsed bycookie-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.
Single cookie with a specific name
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
एक नया cookie encode और sign करें
यदि आप 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 करें:
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.hostnameviaX-Forwarded-Hostreq.protocolviaX-Forwarded-Protoreq.ip/req.ipsviaX-Forwarded-For
यह उपयोगी है:
- Password reset poisoning and absolute URL poisoning
- IP-आधारित allowlists, rate limits, या audit trails को बायपास करना
req.protocolपर आधारित apps मेंsecurecookie 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 बढ़ जाता है।MemoryStoreproduction में आमतौर पर कमजोर operational maturity और restarts के दौरान अस्थिर session व्यवहार को दर्शाता है।
एक व्यावहारिक fixation workflow:
- लक्ष्य से एक anonymous session cookie प्राप्त करें।
- उस cookie को किसी victim को भेजें या खुद उससे authenticate करें।
- जाँचें कि क्या login authenticated state को मौजूदा SID से bind करता है।
- यदि ऐसा होता है, तो अलग 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/DELETEroutes तक पहुँच - केवल
req.methodकी जाँच करने वाले route-specific middleware को बायपास करना - जब application केवल outer request method को validate करती है तो CSRF के माध्यम से state-changing handlers को ट्रिगर करना
डिफ़ॉल्ट रूप से middleware आम तौर पर केवल POST को ओवरराइड करता है, इसलिए header, body, और query-string override values वाले POST requests को प्राथमिकता दें।
संदर्भ
- https://expressjs.com/en/guide/behind-proxies.html
- https://portswigger.net/research/server-side-prototype-pollution
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 का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।


