Sitemap

NoSQL Injection

4 min readNov 11, 2024

In this room, you will learn about NoSQL Injection. While SQL-based databases are a popular choice for data storage of web applications, several database options that are not based on SQL also exist. Database solutions such as MongoDB, a NoSQL database solution, have seen a significant rise in popularity in recent years. However, the fundamental principle of injection attacks remains the same. If we have the ability to inject into the database query itself, we have the opportunity to manipulate it!

Bypassing the Login Screen

Start connection VPN and turn on the machine.

Press enter or click to view image in full size

We try logging in.

Press enter or click to view image in full size

But the login was unsuccessful.

Press enter or click to view image in full size

We come back to look at code PHP, Web application making a query database using MongoDB.

Press enter or click to view image in full size

We find more information for $ne , In MongoDB, $ne is an operator used in a query to select a document with any field. not equal to the specified value, It means we can use $ne bypass login page.

$ne
Press enter or click to view image in full size

Let try login and using Burp Proxy.

Press enter or click to view image in full size
Press enter or click to view image in full size

We change to user[$ne]=xxxx&pass[$ne]=yyyy and Forward

user[$ne]=xxxx&pass[$ne]=yyyy
Press enter or click to view image in full size

Finally we can login.

Logging in as Other Users

Let’s start we login and using Burp Proxy.

Press enter or click to view image in full size

We use $nin operator receives a list of values ​​to ignore.

$nin
Press enter or click to view image in full size

Forward request, we can login other user.

Extracting Users’ Passwords

Let’s start we login and using Burp Proxy.

Press enter or click to view image in full size

$regex operator operator in MongoDB is used for pattern matching in queries using regular expressions. It allows you to search for documents where the value of a specified field matches a given regex pattern. Regular expressions are powerful tools for searching, replacing, or validating strings based on specific patterns.

we will use pass[$regex]=^.{9}: This is using a regular expression ($regex) to specify that the pass (password) must exactly match a pattern. The pattern ^.{9} indicates that the password must be exactly 9 characters long, where ^ denotes the start of the string, matches any character, and {9} specifies that exactly 9 characters are required.

pass[$regex]=^.{9}
Press enter or click to view image in full size

Then send, But response ?err=1.

Press enter or click to view image in full size

We try decrease numbers user=john&pass[$regex]=^.{8}&remember=on

and send.

user=john&pass[$regex]=^.{8}&remember=on
Press enter or click to view image in full size

We got it password have length 8.

Press enter or click to view image in full size

Next guess first password use [$regex]=^2.......

[$regex]=^2.......
Press enter or click to view image in full size

2 is incorrect.

Press enter or click to view image in full size

Guess first password use [$regex]=1…….

[$regex]=1…….
Press enter or click to view image in full size

1 is correct, We just need to do this with the next one.

Press enter or click to view image in full size

We got password.

Press enter or click to view image in full size

Next, Use the same method as before until you get the password.

Press enter or click to view image in full size

We connect ssh, Get flag.txt

Press enter or click to view image in full size

Finding Syntax Injection

We can test Syntax injection by simply injecting a ‘ character.

The following line in the error message shows us that there is Syntax Injection:

for x in mycol.find({"$where": "this.username == '" + username + "'"}):
Press enter or click to view image in full size

we have confirmed Syntax Injection, we can use the payload of ‘||1||’

'||1||'

Get the last email.

--

--

GrimTheRipper
GrimTheRipper

Written by GrimTheRipper

You get the best out of others when you give the best of yourself

No responses yet