Esss Record H
Esss Record H
No:411622149007
TABLE OF CONTENTS
Exp.no Title of experiments Date Pg no Signature
Ex no:1
Implement the SQL injection attack
Date:
AIM:
To implement SQL injection testing in a Linux environment using SQLMap to identify
SQL vulnerabilities. This experiment helps understand SQL injection types and methods for
securing databases against them.
Requirements:
1. Linux Environment: Any Linux distribution (Ubuntu, Kali Linux, etc.).
2. SQLMap Tool: A penetration testing tool for automated detection and exploitation
of SQL injection vulnerabilities.
Procedure:
1. Setup a Testing Environment:Ensure you have a sample web application with a
database backend vulnerable to SQL injection.
2. Identify a Target URL: Identify a URL in the test web application where SQL input
parameters exist (e.g., `http://example.com/page?id=1`).
3. SQLMap Execution:Run SQLMap against the target URL. Use various SQLMap
options to analyze injection vulnerabilities.
4. Analyze Output:Review SQLMap’s findings to see where vulnerabilities might exist
and what type of SQL injection could be performed.
5. Apply Security Fixes: Implement defensive coding practices (e.g., parameterized
queries, stored procedures) based on the findings to secure the application .
Execution Commands:
1. Basic SQLMap Command:
bash
sqlmap -u "http://example.com/page?id=1"
( Specifies the target URL.)
Output:
Register
No:411622149007
1. Identify Input Fields: Start by locating the login form on a vulnerable website that asks for a
username and password. For this example, assume the login form does not properly sanitize
user inputs.
2. Inject SQL Syntax: Enter test' as the username and OR '1'='1 as the password. These inputs
are designed to manipulate the SQL query running on the server.
3 .SQL Query Manipulation: The input changes the query structure, potentially transforming it
Sql to access the database:
SELECT * FROM users WHERE username='test' AND password='' OR '1'='1';
Here, OR '1'='1 is always true, bypassing the password requirement.
Vulnweb.com(testing website)
Result:
Thus the SQL injection was successfully demonstrated using SQLMap, identifying
potential vulnerabilities in the web application
Register
No:411622149007
Ex no:2
Implement the buffer overflow
Date:
AIM:
To demonstrate a buffer overflow vulnerability in a controlled Linux environment using
C programming, helping students understand the concept and how to mitigate it through
secure coding practices.
Algorithm :
1. Set up a Simple C Program:
o Write a C program that demonstrates a buffer overflow by not checking the
bounds of an input buffer.
o The program will intentionally allow buffer overflow to observe how it
works.
2. Compile the Program:
o Compile the program in a Linux environment without security protections to
see the effect of a buffer overflow.
3. Run the Program:
o Execute the program with input that exceeds the buffer size, causing a
buffer overflow.
4. Observe the Outcome:
o Note the program’s behavior and any unexpected outputs. Optionally, use
debugging tools to analyze memory changes.
5. Apply Mitigations:
o Recode the program to prevent buffer overflow by limiting input size or
using safer functions.
Register
No:411622149007
Program :
Below is a simple C program that demonstrates a basic buffer overflow vulnerability.
#include <stdio.h>
#include <string.h>
printf("Program executed.\n");
return 0;
}
Register
No:411622149007
Commands
1. Compile the Program without Protections:
o To observe the effects of the buffer overflow, compile without stack
protections:
Bash:
gcc -fno-stack-protector -z execstack -o buffer_overflow_demo
buffer_overflow_demo.c
o -fno-stack-protector: Disables stack protection.
o -z execstack: Allows execution on the stack (for demonstration purposes).
2. Run the Program with Safe Input:
Bash:
./buffer_overflow_demo Hello
3. Run the Program with Overflow Input:
o Pass an input string longer than 10 characters to trigger the overflow.
Bash
./buffer_overflow_demo AAAAAAAAAAAAAAA
Output:
Normal Input (e.g., Hello): The program will print the buffer content and exit normally.
Overflow Input (e.g., AAAAAAAAAAAAAAA): The program may crash or exhibit unexpected
behavior due to the buffer overflow, potentially overwriting adjacent memory. In some
cases, this may also reveal the program’s vulnerability to attacks.
Mitigation
To prevent buffer overflows:
Use safer functions like strncpy instead of strcpy, ensuring bounds checking.
Enable stack protection during compilation:
bash
gcc -o buffer_overflow_demo buffer_overflow_demo.c
Result:
Thus the experiment demonstrates how a buffer overflow occurs in C and highlights the
Register
No:411622149007
importance of secure coding practices. Implementing this vulnerability allows to apply mitigations
Exp No:3
Aim
To understand Cross-Site Scripting (XSS) and implement HTML code to demonstrate
XSS attacks and prevention measures.
Algorithm
1. Create an HTML form that allows user input.
2. Inject malicious script in the form input.
3. Display the output on the page to demonstrate vulnerability.
4. Implement preventive techniques like sanitizing input, encoding output, and
enforcing a Content Security Policy (CSP).
<p id="display"></p>
<script>
// Display the input value directly without sanitization
const urlParams = new URLSearchParams(window.location.search);
const username = urlParams.get('username');
if (username) {
document.getElementById("display").innerHTML = "Hello, " + username;
}
</script>
</body>
</html>
<script>
function escapeHTML(input) {
const div = document.createElement('div');
div.appendChild(document.createTextNode(input));
return div.innerHTML;
Register
No:411622149007
}
// Get and escape the username parameter
const urlParams = new URLSearchParams(window.location.search);
const username = urlParams.get('username');
if (username) {
document.getElementById("display").innerHTML = "Hello, "
+escapeHTML(username);
}
</script>
</body>
</html>
Output
Results
Register
No:411622149007
Thus the Cross - Site Scripting was successfully executed and the output
was verified.
Algorithm
1. Information Gathering
Steps:
2. Vulnerability Scanning
Steps:
2. Use OWASP ZAP or Burp Suite for automated and manual vulnerability
scanning.
3. Exploitation
Steps:
Register
No:411622149007
1.SQL Injection:
4. Post-Exploitation
Objective: Assess the extent of the compromise and gather further information.
Steps:
5. Reporting
Steps:
Program
SQLi:
import requests
if "error" in response.text:
else:
Register
No:411622149007
# Example usage
url = http://example.com/vulnerable.php?id=
sql_injection_test(url, payload)
XSS:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get(url + payload)
if "alert" in driver.page_source:
else:
driver.quit()
# Example usage
url = "http://example.com/vulnerable.php?search="
payload = "<script>alert('XSS')</script>"
xss_test(url, payload)
COMMANDS
Using sqlmap
sqlmap is a powerful tool for automating the detection and exploitation of SQL injection
Register
No:411622149007
vulnerabilities.
sqlmap -u http://example.com/vulnerable.php?id=1
2. Enumerate Databases:
3. Enumerate Tables:
XSS Commands
Using XSSer
XSSer is a tool for automating the detection and exploitation of XSS vulnerabilities.
Output
SQL Injection Program Output
Information about the SQL injection vulnerability, including the type of database
and potential payloads.
2. Enumerate Databases:
3. Enumerate Tables:
Result:
Register
No:411622149007
Thus penetration testing exercise aimed to identify and exploit SQL Injection and Cross-Site Scripting
(XSS) vulnerabilities in a web application using tools available in Kali Linux.
Register
No:411622149007
Ex.No: 5
Date: Develop and Test the secure test cases
AIM:
To identify SQL injection vulnerabilities by testing input fields, verifying input sanitization, and
ensuring continuous protection through automated security tests.
Manual Testing:
Automated Scanning:
Continuous Integration:
Testing Environments:
Algorithms:
o Burp Suite: A comprehensive tool for intercepting and modifying requests, useful for
crafting SQL injection payloads.
o Postman: Useful for sending custom HTTP requests to test different payloads on
specific endpoints.
o OWASP ZAP (Zed Attack Proxy): An open-source security scanner that helps in
finding SQL injection vulnerabilities.
o SQLMap: An automated tool specifically for detecting and exploiting SQL injection
vulnerabilities. Best used in controlled environments.
Register
No:411622149007
o Acunetix or Netsparker: Commercial web vulnerability scanners that can detect SQL
injection and other vulnerabilities.
o GitHub Actions, Jenkins, GitLab CI/CD: Automate the running of security tests as
part of the CI/CD pipeline, ensuring tests are consistently run on new code.
5. Testing Environments:
o Damn Vulnerable Web Application (DVWA), OWASP Juice Shop, and PortSwigger
Web Security Academy Labs: These provide safe, controlled environments to
practice and refine SQL injection test cases.
Workflow:
File: adder.py
Code:
python
Copy code
return a + b
File: test_adder.py
Purpose: Validate the functionality of add by testing it with positive, negative, and zero
values.
Code:
python
Copy code
import unittest
class TestAdder(unittest.TestCase):
def test_add_positive_numbers(self):
self.assertEqual(add(2, 3), 5)
def test_add_negative_numbers(self):
def test_add_zero(self):
self.assertEqual(add(0, 0), 0)
def test_add_positive_and_negative(self):
self.assertEqual(add(-1, 1), 0)
if __name__ == '__main__':
unittest.main()
File: .github/workflows/python-app.yml
Purpose: Automate the testing process with each code push to the repository.
Code:
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
uses: actions/checkout@v2
uses: actions/setup-python@v2
with:
python-version: '3.x'
Register
No:411622149007
run: |
run: |
Expected Output:
o A successful run displays a green checkmark in the GitHub Actions tab of the
repository.
o The output log in GitHub Actions should confirm that all tests ran and passed.
o If any test fails, GitHub Actions logs the failure and provides information for
debugging.
Output:
Running Tests Locally (test_adder.py)
plaintext
Copy code
....
----------------------------------------------------------------------
Result:
Thus the python program for secure test cases was successfully executed and the output
was verified.
Register
No:411622149007
Ex.No: 6
Date: Penetration Test using Kali Linux
Aim :
To perform Penetration Testing on a web application using Kali Linux
Setup the Environment :
Tools Needed:
Kali Linux : install on a Virtual Machine
DVWA(Damn Vulnerable Web App)
Burp Suit
Install DVWA:
1.Download and Setup DVWA:
$ git clone https://github.com/digininja/DVWA.git
$ cd DVWA/config
$ cp config.inc.php.dist config.inc.php
Register
No:411622149007
Select “Manual proxy configuration” and set HTTP Proxy to 127.0.0.1 and Port to
8080.
Check the box “Use this proxy server for all protocols.”
Register
No:411622149007
Step 4: Exploitation
1.Exploiting SQL injection vulnerability found in the previous step
Open DVWA:
Navigate to XSS:
Create a simple PHP backdoor file, shell.php, with the following content:
<?php
if(isset($_REQUEST['cmd'])) {
?>
2. Upload shell.php:
http://127.0.0.1/DVWA/hackable/uploads/shell.php?cmd=ls
Step 6: Reporting
Penetration Testing Report
Introduction
The purpose of this penetration test was to identify vulnerabilities in the target
web application and assess their potential impact.
Methodology
Register
No:411622149007
Recommendations
Sanitize input fields to prevent SQL injection.
Implement proper output encoding to prevent XSS.
Result:
Thus the Penetrating Testing using Kali Linux was performed on DVWA
and The Vulnerabilities found are Reported Successfully.