Skip to main content

Solving PIVAA part 1 : sql injection in android ٩(^ᴗ^)۶ (day 25)

Image result for vulnerable meme

Purposefully Insecure and Vulnerable Android Application (PIVAA) is an updated version of Damn Insecure Vulnerable Application and when I look at this application I think its really cool and I want to try to test it

Sauce link: https://github.com/HTBridge/pivaa

But in this post, we are going to focus on the database security and best practice part of the application.

1st challenge:

Cleartext SQLite database

The mobile application uses an unencrypted SQLite database. This database can be accessed by an attacker with physical access to the mobile device or a malicious application with root access to the device. The application should not store sensitive information in clear text.

before we move on to the actual testing, I just want to say that I think this is actually rather a best practice not a vulnerability in android penetration testing.

to solve this problem, first, I try to do some simple static analysis to find which class that contains string "SQLiteDatabase"


ok we got hit and it seems it only shows one class which is DatabaseHelper.java

Let's try to open with it and we find the following information about the database:



the database name is "pivaaDB" and there are little information show us what is the column name that is used by the application. Next, install the application in your emulator and browse to its directory using adb tool.


Download the database use adb again and open it using sqlite3 command utility


According to OWASP MSTG sensitive data need to be stored inside encrypted database and you can enable encryption in sqlite3 database using this method:

SQLiteDatabase secureDB = SQLiteDatabase.openOrCreateDatabase(database, "password123", null);

link: https://github.com/OWASP/owasp-mstg/blob/master/Document/0x05d-Testing-Data-Storage.md

2nd challenge:

User-supplied input in SQL queries

Inclusion of user-supplied input into SQL queries can potentially lead to a local SQL injection vulnerability in the mobile application. The correct approach is to use prepared SQL statements beyond user's control.

I think the explanation is pretty straightforward to never trust input from user and don't forget to sanitize the input before you process it.

application need to use content provider to interact with database so we need to find which class that handling content provider. You can do this by using static analysis using grep again


we got hit and file with name VulnerableContentProvider.java seems promising lets take a look at it.


 if you try to read the source code it is show that our input is passed to the "query" function and inside the function they use object name "db" from DatabaseHelper to execute our input using "rawSQLQueryCursor". Also, it seems that our input is also show in the log (Log.i)

lets check this DatabaseHelper class




Navigate you attention to the "rawSQLQueryCursor" function, notice that our input is execute as sql query and lucky for us it is not sanitize. This make us capable to do sql injection. To execute this i will use drozer tools to interact with the database.




from the result we can see that the application have one content provider that is exported by other application.

To exploit the content provider, type:



Yesss we are able to retrieve the database using sql injection and as you can see our input is log and you are able to see it using adb logcat

cheers :)

Comments

Popular posts from this blog

Having fun analyzing nginx log to find malicious attacker in the net (ง'̀-'́)ง (day 37)

  What makes you sleepless at night? is it because of a ghost or scary stories? is it because you have an important meeting tomorrow? or is it because you have an exam? For me, what keeps me up all night is that I keep thinking about what happens to a website that I just created, is it safe from an attacker (certainly not) or did I missing some security adjustments that lead to vulnerability? well I'm not the best secure programmer in the world, I'm still learning and there is a big possibility that I can make a mistake but for me, a mistake can be a valuable investment to myself or yourself to be better so from this idea, I want to know more about what attackers casually do when attacking a website. Here in this post, I'm going to show you how I analyzed attack to the website that I have permission to design and also some interesting findings that I could get from the analysis Background: All of this analysis comes from the traffic that is targeted to th...

Utilize Pwntools for crafting ROP chain :') (day 69)

who doesn't like pwntools? it is a very versatile tool and can be customized according to our need using the python script but did you need to know that pwntools itself can help us to automatically craft a rop chain for us? so in this post, I will show you how to make rop chain less painful and make pwntools do all the heavy lifting. To demonstrate this I will use the binary challenge callme 64 bit from ropemporium link: https://ropemporium.com/challenge/callme.html Crashing the app: Like any other exploitation process, we need to crash the program by generating a long string pattern to determine the offset. based on the information from the above figure we can see that we required to provide 40 bytes of offset Fun stuff: now this where the fun stuff began write the following python script: as in the guideline of the challenged said we need to chain the function call by first to call the callme_one function, callme_two function and then callme_three funct...

Easy Web Application Security Machine: CSharp VulnJSON ಠ_ಠ (day 101)

Hi everyone! Welcome back to another vulnhub machine walkthrough. In this post, we will try to solve the the Csharp VulnJSON machine, this particular machine are focus on introducing some key concept of known web application attacks. We will go through each of the vulnerability and we will see how we can elevate this into a working exploit. Background: Setting up this machine is easy, the author provide us with .ova file and all we have to do is just import the file then we good to go.     Information Gathering: first, we need to find out what is the machine ip address, to do this I used nmap to do ping sweep on my local network. from the result above we can see that the target machine is with 192.168.1.7. Now that we have our target IP address, let's proceed with scanning the open port on the machine. cool! so the machine only open port 80 and this will make it much more simple. If we go to the web server, we are welcomed with two forms: first is used for create a user and th...