Degree Project-2
Degree Project-2
I am pleased to dedicate this space to express my sincere appreciation and gratitude to all
those who have supported me throughout my internship journey. I am truly thankful for the
unwavering support and guidance I received during my time at DefensyLAB. My heartfelt
thanks extend to each individual who contributed to my personal and professional growth
during this period.
I am especially grateful to my supervisors, Mr. Aziz Ifaoui and Mr. Seif-Allah Homrani,
whose mentorship was invaluable. Their guidance enabled me to enhance my skills and capabilities
significantly, and for that, I am profoundly grateful.
i
Acronyms
RE Reverse Engineering
UML Unified Modeling Language
ELF Executable and Linkable Format
PE Portable Executable
GCC GNU Compiler Collection
VM Virtual Machine
ENIC Electronic Numerical Integrator and Computer
DRM Digital Rights Management
RELRO Relocation Read-Only
GOT Global Offset Table
ROP Return-oriented programming
LTS Long Term Support
ii
Contents
General Introduction 1
1 Company Presentation 2
1.1 DefensyLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.2 Who are DefensyLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.3 DefensyLAB’s Security Solutions . . . . . . . . . . . . . . . . . . . . . . 3
1.1.4 DefensyLAB Work Pillars . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Project Overview 5
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Cybersecurity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.1 The Essence of Cybersecurity . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.2 Key Domains within Cybersecurity . . . . . . . . . . . . . . . . . . . . . 5
2.2.3 Challenges and Threats in Cybersecurity . . . . . . . . . . . . . . . . . . 7
2.2.3.1 Common Cybersecurity Threats: . . . . . . . . . . . . . . . . . 7
2.3 Web Exploitation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3.1 Web Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3.2 The Client-Server Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3.3 Request-Response Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.4 The Browser Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.3.5 Browser Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.3.6 Web Exploitation Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.6.1 Fundamentals of Web Exploitation . . . . . . . . . . . . . . . . 12
2.3.6.2 Key Elements of Web Exploitation . . . . . . . . . . . . . . . . 12
2.4 Working Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.4.1 Code editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
iii
CHAPTER CONTENTS
3 Project Execution 20
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.1 Executed tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.1.1 HTTP Parameter Pollution(HPP) . . . . . . . . . . . . . . . . . . . . . . 20
3.1.1.1 Building The Web Application . . . . . . . . . . . . . . . . . . 21
3.1.1.2 Exploiting The Application . . . . . . . . . . . . . . . . . . . . 22
3.1.2 Cross-site scripting (XSS) . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.1.2.1 Building The Application . . . . . . . . . . . . . . . . . . . . . 26
3.1.2.2 Exploiting The Application . . . . . . . . . . . . . . . . . . . . 27
3.2 Building an Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
General Conclusion 33
Webography 34
iv
List of Figures
v
CHAPTER LIST OF FIGURES
vi
General Introduction
During my internship, I embraced significant responsibilities, which led to acquiring new and
meaningful experiences.The completed tasks proved to be very interesting and very enriching
for my professional experience.
The report is organized into three section,for The first chapter I will be going through
a general introduction for DefensyLAB company and also writing about some of its major
services.
In the second chapter I will give a complete study about the project I worked on during
this internship, by describing the needs and the solutions and mentioning the needed tools for
the realization.
The final chapter will present an in-depth analysis of the tasks I have fulfilled and the
various dimensions of my role throughout the internship.
Finally,I will conclude this report with a comprehensive summary that highlights the overarching
impact and the value gained from this internship.
1
Chapter 1
Company Presentation
1.1 DefensyLAB
1.1.1 Introduction
2
CHAPTER 1: COMPANY PRESENTATION
3
CHAPTER 1: COMPANY PRESENTATION
DefensyLAB is a company that operates on four main pillars to help businesses improve
their security posture. These pillars are :
• Administered Security, where the company provides managed security services to help
organizations alleviate the pressure of daily security operations;
• Automated Processes, which aims to automate repetitive and tedious tasks to free up
the security analyst’s time;
1.1.5 Conclusion
4
Chapter 2
Project Overview
2.1 Introduction
In this chapter, I will present an introduction to the project, including an overview of the
web architecture, the tools, and the software utilized. Additionally, I will explain some of the
fundamental concepts encountered during the research phase of the project.
2.2 Cybersecurity
Cybersecurity involves the use of protective strategies to keep computer systems, software,
personal information, and financial assets safe from unauthorized access and various online
threats like viruses and ransomware. It plays a crucial role in maintaining the safety and
privacy of digital information across different devices and networks, from personal smartphones
to large business systems. The aim of cybersecurity is to ensure that digital spaces are secure
for everyone to use and conduct their activities without fear of intrusion or theft.
Cybersecurity is a broad and diverse area that covers many specialized fields. Important
areas within cybersecurity include:
5
CHAPTER 2: PROJECT OVERVIEW
2. Network Security: This domain focuses on protecting the integrity and usability of
network and data. It involves implementing measures to prevent unauthorized access,
misuse, modification, or denial of the network and network-accessible resources.
3. Application Security: This area deals with measures and processes that protect applications
from threats that can come through flaws in the application design, development, deployment,
upgrade, or maintenance phases. Application security encompasses the security considerations
that happen during application development and design, but it also involves systems and
approaches to protect apps after they get deployed.
5. Security Operations Center (SOC): SOC teams monitor, detect, analyze, and respond
to cybersecurity threats and incidents in real time using security information and event
management (SIEM) tools, threat intelligence feeds, and other security technologies.
7. End-User Education: Understanding that mistakes made by people can cause major
security problems, end-user education aims to teach individuals how to use safe practices
and recognize potential threats. This area is crucial for strengthening the user, often the
most vulnerable point in cybersecurity defenses.
6
CHAPTER 2: PROJECT OVERVIEW
Cybersecurity encounters ongoing challenges and threats, with risks constantly evolving in
the digital landscape. These include technical vulnerabilities and the potential for unauthorized
access, compounded by a shortage of skilled professionals. Ensuring data privacy and adhering
to regulatory standards further complicate the security efforts needed to protect digital assets
effectively. Continuous vigilance and adaptive security strategies are essential to mitigate these
risks.
• Phising: This is a tactic used by attackers to deceive individuals into providing sensitive
information, such as passwords and credit card numbers, by masquerading as a trustworthy
entity in an electronic communication. Phishing attacks often come in the form of
malicious emails or messages that urge the recipient to click on a link or download an
attachment, leading to the theft of personal data or the installation of malware.
• Malware: Short for malicious software, malware includes viruses, worms, trojans, and
ransomware. It is designed to harm or exploit any programmable device, service, or
network. Cybercriminals use malware for various purposes, including stealing, encrypting,
or deleting sensitive data, monitoring users’ computer activity, and disrupting business
operations.
• Ransomware: A type of malware that encrypts the victim’s files, with the attacker
then demanding a ransom from the victim to restore access to the data upon payment.
Ransomware attacks can cause significant disruption to operations and result in the loss
of critical information if backup measures are not in place.
• DoS and DDoS Attacks:These attacks aim to overwhelm the targeted servers, systems,
or networks with a flood of Internet traffic, rendering them unavailable to users. DDoS
attacks are executed from multiple compromised computer systems, amplifying the attack’s
impact.
• MitM Attacks: In these attacks, an attacker intercepts and possibly alters the communication
between two parties who believe they are directly communicating with each other. This
allows the attacker to eavesdrop or impersonate one of the entities, making it possible to
steal personal information, login credentials, or financial data.
7
CHAPTER 2: PROJECT OVERVIEW
The World Wide Web, it is an information system designed to share information over the
Internet in user-friendly ways. This approach aims to engage not only IT specialists and
hobbyists but also the general public, making digital content accessible and navigable for
everyone. By utilizing web browsers and simple interfaces, the Web democratizes access to
information, allowing people from all walks of life to explore, learn, and communicate online.
It bridges the gap between complex technology and everyday users, fostering a global exchange
of knowledge and culture.
• Client Overview: In this architecture, clients are typically software applications such
as web browsers or mobile apps that initiate requests to servers for specific resources or
services. These requests can vary from retrieving web pages to querying databases. The
primary role of the client is to initiate communication, specify the needed resource or
service, and then process and display the response from the server.
8
CHAPTER 2: PROJECT OVERVIEW
The client-server model enhances data exchange efficiency, enabling applications to scale
and meet growing demand while maintaining performance and security standards. Centralizing
resources on servers simplifies data management and updates, allows for more straightforward
application of security patches, and controls access to sensitive information. This model also
supports robust security protocols on the server side, providing a critical defense layer against
cyber threats
9
CHAPTER 2: PROJECT OVERVIEW
• Request Mechanics: A request is initiated by the client when it needs to retrieve data or
perform an operation on the server. This could involve requesting a web page, submitting
form data, or querying a database. The request includes all necessary information for the
server to understand and fulfill what is being asked. This information might be embedded
in the URL, request headers, or the body of the request in the case of more complex
operations.
• Response Dynamics: Upon receiving a request, the server processes it based on the
provided information and the server’s current state. The server’s response to the client
includes the status of the request (example: success or error) and the requested data or
the result of the performed operation. The response also contains headers with metadata
about the response and, depending on the request, the body with the actual data being
returned.
The request-response model is an integral part of web communication, providing a clear and
efficient way for clients and servers to interact. Its design allows for scalable web applications
and services that, with proper security and state management practices, offer a robust platform
for the modern web ecosystem
The browser provides a graphical interface that simplifies internet navigation, allowing users
to enter URLs to access specific web resources or perform searches through search engines. Upon
receiving a URL, the browser interprets the request and sends it to the respective server. Once
the browser sends a request to the server, the server processes the request and sends a response
back to the browser. The response can be a web page (in HTML), an image, a video file, or
any other type of content supported by the browser. The browser then interprets the received
content and presents it to the user in a readable and organized manner.
10
CHAPTER 2: PROJECT OVERVIEW
• HTML(The Structure): is the backbone of any website. It provides the basic structure
of sites, which is enhanced and modified by other technologies like CSS and JavaScript.
HTML uses tags to denote elements such as headings, paragraphs, links, images, and
other content blocks. These tags are interpreted by web browsers to display the content
of a web page.
• CSS(The Styling): is used for styling the visual presentation of web pages. It allows
you to apply styles to HTML elements, such as colors, fonts, spacing, layout designs,
and much more. CSS can be included directly within an HTML document, linked as an
external file, or even embedded in HTML tags via the "style" attribute.
• JS(The Behavior): is a powerful scripting language that enables interactive web pages.
It is used to create dynamic content updates, handle multimedia, animate images, and
pretty much anything else. (Okay, not everything, but JavaScript is incredibly versatile.)
Scripts are embedded in or included from HTML documents and run client-side by the
web browser.
Web exploitation encompasses the strategies and tactics utilized by attackers to manipulate
vulnerabilities in web applications for malicious purposes. These vulnerabilities, inherent in the
application’s code, configuration, or environment, can compromise data integrity, user privacy,
and overall system security. The essence of understanding web exploitation lies in recognizing
the dual imperative of protecting digital assets while foreseeing potential avenues of attack.
11
CHAPTER 2: PROJECT OVERVIEW
• Attack Vectors: These are the methods or pathways an attacker uses to exploit vulnerabilities,
tailored to the specific weaknesses of the system. Understanding these vectors is pivotal for
developing effective security measures and for anticipating potential attack scenarios. It
also aids in the creation of more resilient systems, designed to mitigate the risks associated
with these exploitation paths.
Several core vulnerabilities are commonly targeted by attackers due to their prevalence and
impact. Understanding these is vital for both securing applications and comprehending the
landscape of web security threats:
• SQL Injection: This involves injecting malicious SQL code into input fields to manipulate
a database query, allowing unauthorized access to or manipulation of data. It exploits
weaknesses in data validation and input sanitization, enabling attackers to execute arbitrary
SQL commands within a target database. This vulnerability underscores the importance
of employing prepared statements and parameterized queries in database interactions to
enhance security.
12
CHAPTER 2: PROJECT OVERVIEW
• Local File Inclusion(LFI): LFI vulnerabilities allow attackers to read or execute files
on the server that hosts the web application. This can lead to unauthorized access to
sensitive information or execution of malicious scripts on the server. To mitigate LFI
risks, developers should validate and sanitize user inputs, ensuring that file paths cannot
be manipulated to include files outside of intended directories.
Web exploitation poses a significant risk in the realm of cybersecurity, underscoring the
constant struggle to balance effective security measures against the innovative methods used
by cyber attackers. This journey through various vulnerabilities, including SQL Injection,
Cross-Site Scripting (XSS), Local File Inclusion (LFI), Insecure Direct Object References
(IDOR), and Command Injection, sheds light on the complex challenges faced in protecting web
applications. To counter these threats, a comprehensive approach is essential, incorporating
careful code examination, strict checking of user inputs, and robust security protocols. As
technology evolves, the need to understand and combat web exploitation grows increasingly
important. Protecting our digital environments is crucial for maintaining the security and
privacy of information in our interconnected world.
13
CHAPTER 2: PROJECT OVERVIEW
Every project requires specific software tools, and this project is no different. In this part I
will outline the essential software that supported the completion of our tasks. These tools were
key to making our work more efficient and played a crucial role in achieving our project goals.
Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop
and is available for Windows, macOS and Linux. It comes with built-in support for JavaScript,
TypeScript and Node.js and has a rich ecosystem of extensions for other languages and run
times (such as C++, C, Java, Python, PHP, Go, .NET).
The Snyk extension for Visual Studio Code (VS Code) represents a sophisticated enhancement
aimed at bolstering the security posture of software development projects. Seamlessly integrated
within the VS Code environment, this extension facilitates the proactive identification and
remediation of vulnerabilities within project dependencies. It accomplishes this by conducting
real-time scans and analyses, thereby ensuring that any security vulnerabilities in libraries
or packages are promptly identified and addressed. Moreover, the Snyk extension provides
developers with actionable insights and solutions for mitigating identified security issues, thereby
upholding the integrity and security of the software being developed.
14
CHAPTER 2: PROJECT OVERVIEW
Through its intuitive interface and deep integration with VS Code, the Snyk extension
serves as an essential tool for developers seeking to adhere to stringent security protocols while
minimizing impact on productivity.
Burp Suite is an integrated platform designed for securing web applications. It combines
multiple tools for testing web security within a single interface, including automated vulnerability
scans, traffic interception for analysis and modification, and targeted attack simulations. Widely
used by security professionals and developers alike, Burp Suite helps identify and exploit web
vulnerabilities effectively, ensuring comprehensive application security testing. Its versatility
and depth make it a staple in the toolkit of those dedicated to enhancing web application
security.
15
CHAPTER 2: PROJECT OVERVIEW
make it a favorite among cybersecurity experts for conducting thorough security assessments
and for educational purposes in the field of information security.
2.4.5 Docker
16
CHAPTER 2: PROJECT OVERVIEW
Docker is a powerful platform designed to make it easier to create, deploy, and run applications
by using containers. Containers allow a developer to package up an application with all of the
parts it needs, such as libraries and other dependencies, and ship it all out as one package.
Here’s an overview of Docker’s key functionalities:
• Image Management: Docker uses images as the basis for containers. An image is a
lightweight, stand-alone, executable software package that includes everything needed to
run a piece of software, including the code, a runtime, libraries, environment variables,
and config files. Docker images are immutable, which makes them a solid foundation for
deploying applications.
• Docker Hub and Registries:Docker Hub is a cloud-based registry service that allows
you to link to code repositories, build your images, test them, store manually pushed
images, and link to Docker Cloud so you can deploy images to your hosts. It provides a
centralized resource for container image discovery, distribution, and change management.
• Volumes and Storages: Docker offers volumes, which are persistent data storage areas
and storage options. Volumes are completely managed by Docker and are the best way
to persist data in Docker.
• Docker Compose: This is a tool for defining and running multi-container Docker
applications. With Compose, you use a YAML file to configure your application’s services,
networks, and volumes, and then create and start all the services from your configuration
with a single command.
• Security: Docker provides security features and best practices to build, ship, and run
containers securely. Namespaces provide the first level of isolation: each aspect of a
container runs in a separate namespace and its access is restricted to that namespace.
17
CHAPTER 2: PROJECT OVERVIEW
In the landscape of virtualization technologies, Docker stands apart from traditional Virtual
Machines (VMs) by offering a more streamlined, resource-efficient approach to application
deployment through containerization. Unlike VMs, which simulate entire hardware systems
and require full operating systems for each instance, Docker containers share the host’s OS
kernel, significantly reducing overhead and improving performance. This inherent efficiency of
Docker does not only translate to faster deployment times and lower resource consumption but
also presents a unique advantage in terms of security. While the isolation level of VMs is higher
due to their complete separation of operating environments, Docker’s model facilitates easier
management and patching of vulnerabilities within the containerized applications. By allowing
for rapid updates and consistent environments across development, testing, and production,
Docker can mitigate security risks more efficiently than the more static and compartmentalized
VMs. This makes Docker an appealing option for developers and organizations aiming to
maintain high security standards while leveraging the benefits of virtualization technology.
2.5 Conclusion
In this chapter, we explored the realm of cybersecurity, with a focus on web exploitation
and the critical tools necessary for identifying and addressing vulnerabilities.
18
CHAPTER 2: PROJECT OVERVIEW
Moving forward, the next chapter will cover the practical processes involved in investigating
common web vulnerabilities, alongside methodologies for testing and securing your applications
against such threats.
19
Chapter 3
Project Execution
Introduction
In the last chapter, we identified the main concept and tools for our project. This chapter
will focus on implementing the project, including the initial setup, the important features we
are adding, and finally, presenting the work we have completed.
20
CHAPTER 3: PROJECT EXECUTION
To find vulnerabilities in a Web application, we built and hosted it locally using a Docker file
and other configuration files provided.
First of all, We need to build an image to run our container using this command:
Here the dot (.) refers to the current working directory which contains the Docker file,
and the -t flag stands for "tag". It allows you to assign a name and optionally a tag in the
’name:tag’ format to the image.
After that we need to run a container which is an instance of the image using the command:
Here we used –name to name our container and the Image ID that we are going to use
21
CHAPTER 3: PROJECT EXECUTION
22
CHAPTER 3: PROJECT EXECUTION
First thing we notice when we login is that we have a Username, Balance , and a Wallet
Address.
After looking over the code, we noticed that taking out exactly 1337 from the account lets
us get the flag. The problem is, the account is empty – we have no money in it. We first
thought about how to put money in or maybe even take out a negative amount, but none of
those ideas worked. Then, after checking the data sent to the database, we spotted a problem
with the website’s HTTP parameters that we might be able to use to our advantage.
23
CHAPTER 3: PROJECT EXECUTION
24
CHAPTER 3: PROJECT EXECUTION
And we try to inject the parameter which can print the flag for us
And there we have our flag which means we have successfully exploited the vulnerability
25
CHAPTER 3: PROJECT EXECUTION
We will follow the same steps to set the second Web Application using Docker, first we build
the image:
26
CHAPTER 3: PROJECT EXECUTION
Upon inspecting the source code within our code editor, we utilized the Snyk extension and
identified a susceptibility to cross-site scripting (XSS) within the codebase.
27
CHAPTER 3: PROJECT EXECUTION
We have discovered that the "Halloween Name" entry field has a security issue that allows
for XSS attacks.
However, a CSP (Content Security Policy) was in place, aimed at preventing such exploits
by restricting scripts to certain sources.
Despite the CSP, I found a workaround by using a CDN (Content Delivery Network) allowed
by the policy. I hosted a malicious script on GitHub, then used jsDelivr, a service included in
the CSP’s whitelist, to serve the script to the application. This method exploited the CSP’s
allowance for specific external scripts.
Now our finale payload which we are going to use in the vulnerable input field should be
like this
28
CHAPTER 3: PROJECT EXECUTION
And if we check the URL for the "Webhook.site" we provided in our malicious JavaScript
file we will find a cookie session.
Now we grab the cookie and try to decode it and there we have our flag which means we
successfully exploited the XSS vulnerability.
29
CHAPTER 3: PROJECT EXECUTION
During my internship, I had the opportunity to work on a unique project: creating a small
application known as a "Python Jail." This project focused on building a secure environment
for running code. My goal was to make the application as safe as possible and to package it
using Docker for better isolation and deployment.
The script at first was like this:
30
CHAPTER 3: PROJECT EXECUTION
We have established a blacklist to prevent certain inputs by users, as well as a specific set
of characters that are permitted for use.Not only that but The ’safe eval’ function is designed
to securely execute user-provided Python code by limiting access to only a few trusted built-in
functions
Unfortunately, after trying to break from this sandbox I found a payload that can bypass all
the restrictions.
This payload is designed to take advantage of the flexible and deep-looking features of
Python to escape or break free from a secured coding area, often called a Python Jail. It
cleverly moves through Python’s built-in settings and structures to find and use the breakpoint
function.
The breakpoint function in Python stops the code’s execution and starts a debugging session
at the point where it is called. Think of it as hitting a pause button on your code to look around
and see what is happening at that moment. This can be very useful for developers trying to
figure out what their code is doing, but it should not be accessible in a secured environment
because it can be misused to inspect or alter the code’s execution flow in ways that were not
intended.
I have refined my script to extend the blacklist, now also excluding specific terms and characters
such as ".", ",", "[","]", "class", "register", "builtins", and "breakpoint".
The revised blacklist significantly improves the application’s security by disallowing the
use of previously exploitable inputs. Nevertheless, the possibility remains that individuals
could discover alternate methods to bypass these restrictions, thereby posing a challenge to the
application’s integrity. This highlights the need to keep making security better and to keep an
eye out for any weak spots that could be exploited.
31
CHAPTER 3: PROJECT EXECUTION
The entrypoint.sh script is used to set up the Docker container’s environment and run any
initialization tasks required before the main application starts. The start.sh script typically
handles the actual starting of the application process within the container after any preliminary
setup is completed.
Conclusion
This chapter was about mainly about giving an overview of the build and setup of this
project, as well as the finished work.
32
General Conclusion
My time at DefensyLab has been a period of substantial growth and learning, particularly
in the sphere of web exploitation, a field that requires a methodical approach to understand
and protect against vulnerabilities in web applications. I dived deep into various attack vectors,
learning not only how to exploit these weaknesses but also how to reinforce defenses against
them.
Simultaneously, learning about Docker was a key experience. Docker allows us to package
an application with everything it needs to run. This makes the application secure and easy
to move from one computer system to another. I’ve learned important Docker commands and
how to manage containers, which are like little packages of software. This knowledge is crucial
for setting up software in a way that is protected against many common security issues.
33
Webography
34