Hack The Box — Mongod con MongoDB

Guía práctica de la máquina Mongod: conecta con mongosh, resuelve incompatibilidades, explora bases y colecciones y recupera la bandera con db.flag.find()

8 sept 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

En este artículo rehago y traduzco la guía de la máquina Mongod de Hack The Box, parte de los laboratorios Starting Point con dificultad muy fácil. Es una máquina VIP, por lo que necesitarás una suscripción de pago. Desde Q2BSTUDIO, empresa de desarrollo de software, aplicaciones a medida, especialistas en inteligencia artificial, ciberseguridad y mucho más, compartimos este walkthrough para ayudarte a practicar buenas técnicas de auditoría y pentesting. Si tu organización necesita fortalecer su seguridad, descubre nuestros servicios de ciberseguridad y pentesting.

Qué es MongoDB

MongoDB es una base de datos NoSQL orientada a documentos. En lugar de tablas y filas, organiza la información en una jerarquía simple: bases de datos, colecciones, documentos y datos. Imagina un archivador grande, dentro hay carpetas que serían las colecciones, cada carpeta guarda documentos y dentro de cada documento está la información real como textos, números o fechas. El formato se parece a JSON con pares clave valor. En entornos mal configurados puede darse el inicio de sesión anónimo, permitiendo acceder sin credenciales, lo que equivale a dejar el archivador abierto en un lugar público.

Cómo acceder y navegar

Usaremos la shell de MongoDB, mongosh, para conectarnos, listar bases de datos, explorar colecciones y leer documentos.

Instalación rápida de mongosh reciente en Linux Debian Ubuntu

Comandos de referencia: sudo dpkg -i mongodb-mongosh_2.5.7_amd64.deb para instalar, sudo apt-get install -f para dependencias faltantes, which mongosh para verificar la ruta.

Conexión inicial

Ejecuta mongosh mongodb://IP:27017 para conectar al puerto por defecto. En esta máquina apareció un error de compatibilidad porque el servidor usa MongoDB 3.6 wire version 6 y el cliente nuevo esperaba al menos wire version 8 de MongoDB 4.2.

Instalar una versión de mongosh compatible

Descarga y usa una versión más antigua del cliente mongosh con estos comandos: curl -O https://downloads.mongodb.com/compass/mongosh-2.3.2-linux-x64.tgz, tar xvf mongosh-2.3.2-linux-x64.tgz, cd mongosh-2.3.2-linux-x64, cd bin. Luego conecta con ./mongosh mongodb://IP:27017.

Enumeración dentro de MongoDB

Una vez conectado como usuario anónimo, puedes listar las bases con show dbs; cambiar de base con use nombre_basedatos; verificar la base actual con db; y listar colecciones con show collections;. Para ver el contenido de una colección usa db.nombreColeccion.find().

Ejemplo práctico

Con show dbs se visualizan las bases disponibles. Cambia a use sensitive_information y ejecuta show collections para ver sus colecciones. Si existe una colección llamada flag, consulta con db.flag.find() para volcar todos los documentos y recuperar la bandera.

Escaneo previo con Nmap

Antes de conectarnos conviene reconocer puertos abiertos. Un escaneo típico sería nmap -p- --min-rate=1000 -sV IP. El modificador -p- recorre todos los puertos TCP, -sV intenta detectar versiones, --min-rate acelera el envío de paquetes por segundo.

Solución de las tareas

Tarea 1 Cuántos puertos TCP están abiertos en la máquina 2

Tarea 2 Qué servicio corre en el puerto 27017 MongoDB 3.6.8

Tarea 3 Qué tipo de base de datos es MongoDB SQL o NoSQL NoSQL

Tarea 4 Comando para lanzar la shell interactiva mongosh

Tarea 5 Comando para listar todas las bases de datos show dbs

Tarea 6 Comando para listar colecciones show collections

Tarea 7 Comando para volcar el contenido de la colección flag db.flag.find()

Pasos resumidos para capturar la bandera

Realiza un escaneo nmap para identificar puertos abiertos, detecta el servicio MongoDB en 27017, conecta con mongosh. Si hay incompatibilidad de versiones, usa una versión de mongosh acorde al servidor. Dentro de MongoDB ejecuta show dbs, usa sensitive_information, show collections. Finalmente, ejecuta db.flag.find() para ver la bandera. Al enviarla en la plataforma aparecerá el mensaje Mongod has been Pwned.

Q2BSTUDIO, tu aliado tecnológico

En Q2BSTUDIO diseñamos aplicaciones a medida y software a medida con arquitecturas modernas, integraciones de servicios cloud aws y azure, y capas de ciberseguridad desde el diseño. Incorporamos inteligencia artificial e ia para empresas con agentes IA que automatizan tareas críticas, y ofrecemos servicios inteligencia de negocio con cuadros de mando en power bi. Si quieres productos robustos y seguros, conoce nuestro enfoque de desarrollo en aplicaciones a medida y software a medida, y refuerza tu postura defensiva con nuestros expertos de ciberseguridad y pentesting.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat