Sitemap
Wilklins Nyatteng

Wilklins Nyatteng

Cyber Security Engineer | Wazuh Ambassador | AWS Community Builder

SQLMap — TryHackMe WriteUp

4 min readJul 10, 2023

Learn about and use Sqlmap to exploit the web application

Sqlmap is an open source penetration testing tool developed by Bernardo Damele Assumpcao Guimaraes and Miroslav Stampar that automates the process of detecting and exploiting SQL injection flaws and taking over database servers. It comes with a powerful detection engine, many niche features for the ultimate penetration tester, and a broad range of switches lasting from database fingerprinting, fetching data from the database, to accessing the underlying file system and executing commands on the operating system via out-of-band connections.

Started by running the default Nmap scan

Press enter or click to view image in full size

I found port 80 to be open.

I then ran the service scan and default script scan

Press enter or click to view image in full size

I accessed the website and found out this

Press enter or click to view image in full size

Next I ran the Gobuster tool to find any available directories. I found /blood.

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

It had a login page and registration. I click on the login and then use Burpsuite to intercept the login page and save it to a TXT file

Press enter or click to view image in full size

We now use SQLMap to enumarate the Databases for Usernames, Passwords and all data that can be found in it.

Get Wilklins Nyatteng’s stories in your inbox

Join Medium for free to get updates from this writer.

To enumerate for current database

Press enter or click to view image in full size

We find the DB to be blood

Now that we know the name of the Database we look for tables available in the DB

Press enter or click to view image in full size

Now that we are interested in the flag table. We run the dump command to find its details

Press enter or click to view image in full size

Conclusion

Mitigating against exploiting SQL injection flaws and protecting database servers is crucial for maintaining data security and preventing unauthorized access. You need consider:

  1. Implementing Input Validation and Parameterized Queries: Apply stringent input validation techniques to sanitize user inputs and eliminate potentially malicious SQL statements. Utilize parameterized queries or prepared statements to ensure that user inputs are treated as data rather than executable code.
  2. Applying Principle of Least Privilege: Restrict database user privileges to the minimum required for their respective tasks. Avoid using privileged accounts for routine operations and assign specific access rights based on user roles. This limits the potential damage an attacker can inflict even if they manage to exploit an SQL injection flaw.
  3. Regularly Updating and Patching Database Software: Keep the database management system (DBMS) software up to date with the latest security patches. Stay informed about vulnerabilities and exploits related to the specific DBMS and promptly apply relevant patches to protect against known attack vectors.
  4. Employ Web Application Firewalls (WAFs): Implement a WAF that is capable of detecting and blocking SQL injection attempts. WAFs can analyze incoming requests, identify suspicious SQL statements, and prevent them from reaching the database server. This adds an additional layer of defense against SQL injection attacks.
  5. Conducting Regular Security Audits and Penetration Testing: Perform comprehensive security audits and penetration tests on your application and database infrastructure. Engage with experienced security professionals to identify and address any existing vulnerabilities or weaknesses. Regular testing helps in proactively identifying SQL injection flaws and taking appropriate mitigation measures.

By following these key points, organizations can significantly reduce the risk of SQL injection attacks and ensure the integrity and security of their database servers. It is essential to adopt a proactive approach to security, keeping up with the latest best practices and staying vigilant against emerging threats.

--

--

Wilklins Nyatteng
Wilklins Nyatteng

Written by Wilklins Nyatteng

Cyber Security Engineer | Wazuh Ambassador | AWS Community Builder