Sqlinjection
What is SQL Injection?
SQL Injection (SQLi) is a code injection technique that exploits vulnerabilities in an application's software by manipulating SQL queries. It allows attackers to interfere with the queries that an application makes to its database. This can lead to unauthorized access to sensitive data, data manipulation, and even complete control over the database server.
Types of SQL Injection:
In-band SQL Injection: The simplest and most common form, where the attacker uses the same communication channel to both launch the attack and gather results.
Error-based SQLi: Relies on error messages thrown by the database server.
Union-based SQLi: Uses the UNION SQL operator to combine results from multiple SELECT statements.
Inferential SQL Injection: The attacker does not see the output of the query but can infer information based on the application's response.
Boolean-based SQLi: The attacker sends a query that forces the application to return a different result based on a true or false condition.
Time-based SQLi: The attacker determines if the query is true or false based on the time it takes for the application to respond.
Out-of-band SQL Injection: This type occurs when the attacker is unable to use the same channel to launch the attack and gather results, often relying on features like email or DNS to retrieve data.
How SQL Injection Works
SQL Injection typically occurs when user input is improperly sanitized before being included in SQL queries. For example, consider the following SQL query:
language-sql
Copy code
SELECT * FROM users WHERE username = '$username' AND password = '$password';
If an attacker inputs admin' -- as the username, the query becomes:
language-sql
Copy code
SELECT * FROM users WHERE username = 'admin' --' AND password = '$password';
The -- comment syntax causes the rest of the query to be ignored, allowing the attacker to bypass authentication.
Using Sqlmap on Termux
Sqlmap is an open-source penetration testing tool that automates the process of detecting and exploiting SQL injection vulnerabilities. Termux is a terminal emulator for Android that allows you to run a Linux environment on your device. Here’s how to set up and use Sqlmap on Termux:
Step 1: Install Termux
Download and install Termux from the Google Play Store or F-Droid.
Open Termux and update the package list:
language-bash
Copy code
pkg update && pkg upgrade
Step 2: Install Required Packages
You need to install Python and Git to run Sqlmap:
language-bash
Copy code
pkg install python git
Step 3: Clone the Sqlmap Repository
Clone the Sqlmap repository from GitHub:
language-bash
Copy code
git clone https://github.com/sqlmapproject/sqlmap.git
Step 4: Navigate to the Sqlmap Directory
Change to the Sqlmap directory:
language-bash
Copy code
cd sqlmap
Step 5: Run Sqlmap
You can now run Sqlmap against a target URL. Here’s a basic command structure:
language-bash
Copy code
python sqlmap.py -u "http://targetsite.com/vulnerable.php?id=1" --risk=3 --level=5 --batch
-u: Specifies the target URL.
--risk: Sets the risk level (1-3).
--level: Sets the level of tests to perform (1-5).
--batch: Runs in non-interactive mode, using default answers.
Step 6: Analyze the Results
Sqlmap will provide detailed output regarding the vulnerabilities it finds, including the type of SQL injection, the database management system (DBMS) in use
, and potential data that can be extracted.

Comments
Post a Comment