# Course #300: Introduction to jsql for SQL Injection Testing

## Section 1: Installation and Configuration on Kali Linux

### Overview of jsql

`jsql` is a powerful Java-based tool designed for detecting and exploiting SQL injection vulnerabilities in web applications. Automated testing tools like `jsql` can save penetration testers a significant amount of time and effort during engagements. In this section, we will cover the installation and configuration of `jsql`, how to use it effectively, and explore its capabilities through real-world applications.

### Installation of jsql on Kali Linux

Kali Linux comes pre-installed with a version of `jsql`, but it may not always be the latest. Installing or updating `jsql` involves a few straightforward steps:

1. **Open Terminal**: Start by opening your terminal application on Kali Linux.

2. **Update the Package List**: Ensure your package list is up to date by running:

3. **Install Java**: Since `jsql` is a Java-based application, you need to have Java installed. If you do not have Java, you can install it using:

4. **Download jsql**: Navigate to the official GitHub repository of `jsql` to download the latest version. You can use `wget` to download the `.jar` file directly:


wget https://github.com/joaomatosf/jsql-injection/releases/latest/download/jsql.jar -O jsql.jar

5. **Running jsql**: You can run `jsql` using the following command:

6. **Verify Installation**: Once you execute the command, a graphical user interface should open, confirming `jsql` is installed correctly.

### Configuration

Configuring `jsql` for optimal use is vital for an effective penetration test.

1. **Specify Proxy Settings**: If you need to route your traffic through a proxy, you can configure this in the 'Settings' menu in the `jsql` GUI.

2. **Database Type**: Select the type of database you wish to test against in `jsql`. The tool supports various databases including MySQL, PostgreSQL, MSSQL, and Oracle.

3. **Set User-Agent Strings**: Adjust the User-Agent strings in the settings to mimic common web browsers or to match the application you are testing.

### Step-by-Step Usage of jsql

Now that we have installed and configured `jsql`, let’s go through a step-by-step usage scenario.

#### Step 1: Scanning for Vulnerabilities

1. **Launch jsql**: Execute the command to launch the application you’ve installed.
2. **Input Target URL**: In the GUI, find the input field for the target URL. Enter the URL of the web application you want to test, e.g., `http://example.com/vulnerable.php?id=1`.
3. **Initiate Scan**: Click on the ‘Scan’ button. `jsql` will start scanning the URL for potential SQL injection points.
4. **Analyze Results**: Once the scan finishes, `jsql` will present the results, highlighting any found vulnerabilities.

#### Step 2: Exploiting Identified Vulnerabilities

1. **Select Vulnerability**: From the results, select a vulnerability to exploit. For example, a boolean-based SQL injection.
2. **Testing Payloads**: You can test various payloads through the interface. Click on the ‘Payloads’ tab to see suggested payloads.
3. **Execute Injection**: After selecting a payload, execute the injection to fetch data from the database.

#### Step 3: Extracting Data

1. **Database Enumeration**: Use `jsql` to enumerate databases. Type `1' UNION SELECT NULL, database(), NULL– ` in the injection input field.
2. **Extract Tables**: Execute payloads designed to extract table names, such as:
[/dm_code_snippet]sql
1' UNION SELECT NULL, GROUP_CONCAT(table_name), NULL FROM information_schema.tables WHERE table_schema=database()–
[/dm_code_snippet]
3. **Fetching Data**: You can fetch specific data from the tables identified in the previous step, for example:
[/dm_code_snippet]sql
1' UNION SELECT NULL, username, password FROM users–
[/dm_code_snippet]

### Real-World Use Cases

#### Case Study 1: E-commerce Website Vulnerability Assessment

A penetration tester may use `jsql` to assess an e-commerce website's security. The tester identifies input fields on product pages that interact with the database. By applying `jsql`, they can quickly scan for SQL injection vulnerabilities. If found, the tester can further exploit these vulnerabilities to access sensitive customer data, providing valuable insights to the development team for remediation.

#### Case Study 2: Corporate Intranet Security Testing

In a corporate environment, `jsql` can help in assessing internal web applications or intranets. Many times, internal applications have lax security practices. By using `jsql`, security professionals can expose vulnerabilities that could lead to data breaches, ensuring that sensitive corporate data remains protected.

### Detailed Technical Explanations

#### SQL Injection Types

Understanding the types of SQL injections that `jsql` can detect and exploit is crucial for effective testing:

– **In-Band SQL Injection**: This occurs when the attacker uses the same channel to launch the attack and gather results. Example payloads include error-based and union-based injections.

– **Inferential SQL Injection (Blind SQL Injection)**: Here, the attacker doesn't see the result of the query but can infer information based on the application's response. Tools like `jsql` can automate the guessing of queries.

– **Out-of-Band SQL Injection**: This method relies on the database server's ability to make DNS or HTTP requests. It's less common but can be automated by `jsql`.

### External References and Resources

For further research, here are some valuable resources:

– [OWASP SQL Injection](https://owasp.org/www-community/attacks/SQL_Injection)
– [SQL Injection Cheat Sheet](https://github.com/mbcrump/sql-injection-cheat-sheet)
– [Security Focus: SQL Injection](http://www.securityfocus.com/infocus/1796)

### Code Examples for WordPress

If you are looking to integrate SQL queries within a WordPress context using PHP, here’s a simple example illustrating how SQL queries can be executed in a WordPress environment:

"`php
global $wpdb;
$id = $_GET['id']; // Assume this is user input, be cautious!
$id = intval($id); // Sanitize input to prevent SQL injection

$result = $wpdb->get_results("SELECT * FROM wp_users WHERE id = $id");

if($result) {
foreach($result as $user) {
echo 'Username: ' . $user->user_login . '
';
}
} else {
echo 'No user found';
}
"`

In this example, you can see that sanitizing user inputs is essential to prevent vulnerabilities. Always validate and sanitize inputs when working with SQL queries.

In conclusion, `jsql` is a robust tool that offers powerful capabilities for discovering and exploiting SQL injection vulnerabilities. Familiarity with its installation, configuration, usage, and exploitation techniques equips penetration testers with valuable skills for web application security.

Made by pablo rotem / פבלו רותם

Pablo Guides