Lab File (4) (It Security)
Lab File (4) (It Security)
(CSSF2113)
R2142220865
Installation
3 LAB: 2: NMAP and Wireshark 25.01.2024
Provide Suitable Solution based on the Questions (In terms of Image, Words, or Reports)
1.) What is the purpose of entering different User ID values and clicking Submit in the basic
commands section?
3) What does the SQL injection payload '% or 1=1#' accomplish in the context of displaying values
based on the surname condition?
** Display all the values which passes the surname condition not check the Username **
%' or 1=1#
4) Why is there a deliberate SQL syntax error in the command 'select first_name,
last_name from users where user_id ='%' or '1'='1';'?
5)How does the URL injection payload in the provided links demonstrate SQL injection in a
web application?
** URL Injection **
http://172.16.15.128/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#
http://172.16.15.128/dvwa/vulnerabilities/sqli/?id=2&Submit=Submit#
6)Explain the purpose of the SQL injection payloads used for displaying database version,
hostname, username, and database name.
Payload Injection **
Display the name of the Version of Database **
%' union select null, version() #
** Display Hostname of Database **
%' union select null, @@hostname #'
7)What is the significance of the command '% and 1=0 union select null, table_name from
information_schema.tables #' in listing tables in the information schema?
10)Explain how the payload '% and 1=0 union select null,
concat(first_name,0x0a,last_name,0x0a,user,0x0a,password) from users #' displays the content
of user-related columns.
12)Compare the usage of John the Ripper and Hashcat in the context of decrypting hashed
passwords. How do they differ in their approaches?
wordlists –h
hashcat -h
hashcat -a 0 -m 0 -o hashoutput.txt hash.txt usr/share/wordlists/rockyou.tx
What is SQL injection (SQLi)?
SQL injection is a commonly employed attack by hackers to exploit SQL database-driven web
applications. It involves inserting SQL code or statements into execution fields with the aim of
altering database contents, extracting valuable information, causing repudiation issues,
spoofing identity, and more. Consider a straightforward scenario with a web application
featuring a login form with username and password fields. If PHP is used for development, the
code might appear as follows:
<?php $query = "SELECT * FROM users WHERE username = '" . $_POST['username'] . "'"; $query .= "
AND password = '" . $_POST['password'] . "'"; ?>
For instance, if a user named Karen with the password '12345' attempts to log in, the
generated SQL query sent to the database would be:
However, if an attacker knows the username and aims to bypass the login window, they might
input something like 'Karen;--' in the username field. The resulting SQL query would then look
like:
Here, the attacker adds '--' (double-dash) to comment out the remaining SQL statement,
enabling them to retrieve information from the password field and bypass the login screen.
Attacker: Exploits features of the database server to execute commands and gather results
using the same communication channel.
Types of SQLi
1. In-band SQLi
2. Blind SQL Injection/Inferential SQLi
3. Out-of-Band SQLi
In-band SQLi refers to a type of SQL injection where the attacker is able to gather results
directly through the same communication channel used to launch the attack. This is the most
common type of SQL injection as it provides a straightforward and efficient means for attackers
to access the database server. In-band SQLi can be further categorized into Error-based SQLi
and Union-based SQLi.
Error-based SQL Injection: In this type of SQL injection, the attacker intentionally
triggers errors in the database by injecting malicious SQL code. The goal is to exploit error
messages generated by the database system to gain information about the structure and
content of the database. By causing errors, the attacker can extract details that aid in further
attacks or unauthorized access.
Union-based SQLi: It uses the `UNION` SQL operator to combine the result sets of
two or more SELECT statements. The attacker leverages the UNION operator to retrieve
data from other tables and concatenate it with the original query's results. This technique is
often used to extract information from the database and gather details not directly accessible
through the original query. The combined result is then returned along with the normal
HTTP response.
Blind SQL Injection/Inferential SQLi occurs when attackers cannot directly retrieve data
from the web application's response. Instead, they infer information about the database
structure by sending malicious payloads and analyzing the application's response. Blind SQLi
is categorized into Content-based SQLi and Time-based SQLi.
Content-based SQLi: Forces the web application to return different results based on
whether the injected SQL query returns TRUE or FALSE. Analyzing the variations in the
application's response helps attackers determine the query result.
Time-based SQLi: Sends a query that forces the application to delay its response for a
specific duration. The attacker uses the response time to determine whether the query result
is TRUE or FALSE.
Out-of-Band SQLi: It occurs when the attacker uses the same communication channel to both
launch the attack and gather results. This type is less common than In-band SQLi and relies on
specific features of the database server. Out-of-Band SQLi provides an alternative for injection
attacks, particularly when server responses are unstable.
SQLi based on 1=1 is Always True: Attacker inputs statements with ‘OR’ condition
to access all records in a table. Exploits the always true condition to gain unauthorized
access.
SQLi based on "=" is Always True: Uses OR statements like “or” “=” to retrieve
combinations of related data. Manipulates query results based on the true condition.
The 2020/2021 Accellion Data Breach: Attackers used SQL injection vulnerability to
access Accellion File Transfer Appliance. Resulted in a widespread data breach affecting
multiple companies.
Use of Stored Procedures: Utilize stored procedures to control access to the database.
Helps in restricting the execution of arbitrary SQL code.
Web Application Firewall (WAF): Implement a WAF to filter and monitor HTTP
traffic. Identifies and blocks SQL injection attempts, enhancing overall security.
Preventing SQL injection attacks requires a multifaceted approach, including secure coding
practices, input validation, and the implementation of specific tools and techniques tailored to
the programming language and database engine used.
Pre-requisites
This tutorial assumes that you have a functioning DVWA (Damn Vulnerable Web Application)
setup. If DVWA is not yet installed on your Kali Linux system, please refer to the step-by-step
guide provided in the related article for a comprehensive installation process.
Step 9: Display all the columns fields in the information_schema user table
Print all the columns present in the "users" table, including column information like User_ID,
first_name, last_name, user, and password. Enter the input in the User_ID field. Understanding
the columns in the "users" table is essential for targeted data extraction.
Conclusion
This article demonstrates that SQL injection is a critical vulnerability that can exist in a system.
Attackers can exploit it not only to reveal user or customer information but also to corrupt the
entire database, potentially bringing down the entire system. As of the writing of this post
(2021), Injection is listed as the number one vulnerability in the OWASP Top 10 Vulnerabilities
summary. DVWA serves as a valuable resource for both penetration testers aiming to enhance
their skills and web developers aiming to develop systems with security in mind. Continuous
awareness and proactive measures are essential for mitigating SQL injection risks and
maintaining robust cybersecurity practices.