Perform A Web Penetration Test
Perform A Web Penetration Test
And
as a result, what security issues do website developers and
integrators face on a daily basis?
Educational goals :
At the end of this course, you will be able to:
Prepare a web penetration test.
Familiarize yourself with the ecosystem of a web application.
Analyze in detail the content of a web application.
Identify vulnerabilities specific to a web application.
Return the results of a web penetration test.
Tools :
Kali
ROOT Me
Perform a web penetration test
Contents
Get the most out of this course
Discover the content of course
Follow the red thread project of course
Upgrade if needed
Discover the principle of an intrusion test
Find out what a penetration test is
Understand the value of penetration testing
different types of penetration testing
Summary
Adopt the posture of a PENTESTER
Put yourself in the shoes of an attacker
Embody professional ethics
Act within a legal framework
Discover the actors who govern the practice of PENTEST
Summary
Frame your intervention based on the objectives of the test
Hold a meeting to qualify needs
Have a meeting to start mission
Terms of delivery
Scope of the service
Summary
Prepare your work environment
Penetration Testing Tools
benchmark tool
Familiarize yourself with the Kali
Be aware of the limit of tools
Document everything you do
Summary
Find information about the target and its ecosystem
Harness the full power of Google
It's up to you
Use other data sources
In summary
Collect more information with active reconnaissance
Find related targets
Exercise your duty to advise on the extension of the perimeter
In summary
Identify entry points on the underlying target server
Perform a port scan
Up to you !
Identify vulnerable services
Interpret the results and take a step back from Exercise
In summary
Check the presence and quality of exchange encryption
Understand the concept of encryption
Check encryption quality
Distinguish Between Cipher Protocols and Cipher Suites
Apply best practices
It's up to you
In summary
INTERCEPTING PROXIES
Understand the value of a web-intercepting proxy
Control your requests with a web intercept proxy
Master the essential functions of BURP
Up to you !
In summary
Collect technical information about the application
Observe the target and look for technical information
Collect available technical information
In summary
Go in search of unlisted functions
Map the website
Accelerate your mapping
Up to you !
Avoid traps
In summary
Change client-side application behavior
Discover the most common vulnerabilities
Manipulate the user with XSS
In summary
Attack the database with SQL injections
Recover database contents with SQL injections
Leverage SQL injections
Up to you !
In summary
Take control of the server
Manipulate Server Included Files
Take control of the server with RCE
Up to you !
In summary
Evaluate the strength of authentication
Understand the concept of authentication
BYPASS Authentication
Find a password with CREDENTIAL GUESSING
It's up to you
Hijack user sessions and cookies
In summary
Check the reliability of access control
Understand the concept of empowerment
Test horizontal partitioning
Test vertical partitioning
Equip yourself to test these points effectively
Summary
Challenge business logic and configuration points
Report dangerous features
Check web application regulatory compliance
In summary
Write your audit report
Pay attention to the form of the report
Write a detailed report
In summary
Formalize recommendations and action plan
Help the sponsor make decisions
Facilitate the implementation of your recommendations
Up to you !
In summary
Return your work
Prepare the presentation material
Up to you !
Showcase your work
Collect feedback from your audience
Go further
In summary
Get the most out of this course
So, welcome to this course: you will follow step by step the
realization of a web intrusion test !
In this course, you will learn how to conduct a penetration test from
start to finish, going through the following phases:
By following it, you will learn how to develop good posture and apply
good practices. You can also discover his expert advice
Regularly, you will have the opportunity to put into practice what you
have learned through small exercises. They are presented in the
form of challenges and powered by ROOT Me, an online learning
platform dedicated to developing hacking skills. You will find them in
the “It’s up to you” sections.
Upgrade if needed
Are you ready to discover and learn this exciting profession? So let's
go !
Discover the principle of an intrusion test
Find out what a penetration test is
Knowing the English terms is important for this course, because the
majority of the resources you will find are in English, as are the
biggest conferences on the subject ( DEF CON , Black HAT to name
a few). However, France is not to be outdone and you will be able to
meet and discuss with other PENTESTORS at conferences such as
the SSTIC , or the Hack in Paris .
The best hackers come from all over the world! The language of
exchange and knowledge sharing is therefore English by default.
Understand the value of penetration testing
However :
black box " intrusion test , the PENTESTER puts itself in the shoes
of an attacker who has little or no information about the
application : a simple URL, the IP address of the target server, or
the company's showcase site.
Without the gray box approach, there is a risk of not testing a whole
section of the application: it often happens to have a vulnerability in
the authenticated part, or even in the part reserved for administrators
(which would allow for example to take the control of the server or to
extract the contents of a database).
Stay as comprehensive as possible with the white box approach
But then, intrusion test and security audit, is it the same thing?
Differentiate between "penetration test" and "security audit"
What you will learn in this course can be reused for other test
perimeters because it is posture and good reflexes that matter the
most: the methodology to follow and the technologies used remain
the same
In summary
In this course, you will learn how to attack a web application to find
vulnerabilities. You will therefore get closer to what a “hacker” does!
But do you know where this term comes from?
Initially, it does not only refer to people who attack systems without
permission. In the 1950s, it was used by MIT students to designate a
student who had developed an original technical process by
diverting a telephone system from its original use.
The word “hacker” does not necessarily designate someone with bad
intentions (we will rather speak of “cracker”, in this case). Rather, it
designates someone who has the ability to think differently (“out of
the box” in English).
It is in this reflection and this posture that lies the essence of our
profession.
In the same way, you will be brought to identify within the framework
of your missions of the unknown vulnerabilities hitherto in
applications or even products used by various customers.
Is public disclosure possible in this case or not? Is it ethical and
allowed to publicly disclose a vulnerability found in an audited
product?
No, it's not allowed because you are under contract, and paid to find
vulnerabilities. Public disclosure of a product used by different
customers should be discussed with the publisher or manager in that
case.
The term "RESPONSIBLE DISCLOSURE" does not always have the same
meaning depending on who defines it. On our side, we consider that a
vulnerability has been the subject of a RESPONSIBLE DISCLOSURE as
soon as it has been reported to the publisher concerned, and that it is
only publicly released once the correction has been published. .
There are some special cases that are exceptions to this rule, but
consider that you do not have the right to attack a system for which
you have not been mandated.
In addition to the Penal Code, there is the Data Protection Act (LIL)
as well as the General Data Protection Regulations (RGPD), and
therefore the National Commission for Computing and Freedoms
(CNIL), which complete the legal arsenal.
This course does not aim to prepare you for the PASSI qualification,
even if certain elements will converge.
Finally, there are standards that "force" to carry out an intrusion test
in the various regulated sectors:
PCI-DSS in banking;
GDPR for any system containing personal data;
ISO 27001 if the scope is certified, etc.
In summary
Also remember to specify to the customer that you are not doing
an intentional denial of service (DOS) , but express a reservation
on the fact that it can happen because zero risk does not exist ,
even if you take the usual precautions. A little anecdote on the
subject:
During a small business penetration test, I took the network down for
a few minutes. Disaster, you say! Yes and no. Yes because it
shouldn't happen, no because I could hardly have foreseen that it
was going to happen. In my opinion, I had the right reflexes with the
client: I had foreseen that this activity could have an impact, so I did
it at a time that had little impact for the company, at the very end of
the day. -noon.
Script
Good morning,
THANKS.
Cordially,
Mikael Leroy
CTO – example.com
Order
Important information that Jessica specifies: you must offer the client
to do the mission remotely because he is too far from your offices
and wants a quick start, which will involve listing the prerequisites
you will need.
In this exercise, you will list the different questions that Thibaut
can ask in a meeting to qualify the need and obtain all the
prerequisites.
Step 2: Define the scope of the test Here are several questions that will be
relevant to ask during the qualification meeting:
Why is it important for the company, what are the main risks
identified by the customer on this application?
Do not commit to a schedule that is not realistic for you, and even
take a margin of shift if possible.
Finally, you can address the question of the budget . In the majority
of cases, the client will tell you that they don't have a budget in mind
(which can be wrong most of the time).
Explain why you want to know the budget: it is not to adjust your
price to the client's budget, but to see if there is an unrealistic gap
between what the client will want to pay and what he is asking .
Have a meeting to launch the mission
The kick-off meeting occurs once the sponsor has accepted your
proposal.
Step 1: Confirm framework and prerequisites
If this is not the case, some teams may react badly, be on the
defensive, or even put obstacles in your way (such as isolating your
position or blocking your IP).
The kick-off meeting may seem optional if the scope is very clear
and the customer is mature. However, I advise you to always do it.
T E R MS OF D E L IV E RY
The information contained in this document is strictly confidential and
intended solely for the duly authorized personnel of <CLIENT>.
● <list of IP addresses>
● <list of URLs>
● <Description of the scope if impossible to list the upstream
IPs/URLs>
Activities
Intrusion tests will be conducted in black box and gray box over the entire
perimeter.
Deliverables
The deliverables of the service will be as follows:
●A detailed audit report , containing:
○a managerial summary;
○a risk analysis;
○ details of vulnerabilities and recommendations;
○ full details of the tests carried out.
●A presentation support for the restitution meeting.
●A plan of action .
The auditors can be reached throughout the duration of the audit at the
following coordinates:
At the request of the lead auditor, the auditors will collaborate with the
various teams and individuals indicated. In particular, as part of the
management of a security incident, the auditors may be asked to determine
whether the intrusion test in progress is the cause.
2. Terms of exchange
All documents exchanged as part of the service are confidential and will be
communicated between <CLIENT> and <PROVIDER> in encrypted form,
with the password exchanged following the kick-off meeting.
3. Language of deliverables
The deliverables as well as the presentations will be written in French .
Prerequisites
As part of the audit, for the smooth running of the service, the following
prerequisites were identified:
●…
Unless expressly authorized by the lead auditor, the following activities will
not be performed during the audit:
● XXX
However, carrying out intrusion tests always involves a risk of altering the
service, the discovery or confirmation of a vulnerability being very often
linked to its exploitation. In this case, the handling of the incident will be
carried out jointly between the lead auditor and the auditors.
In the event that the auditors manage to access <data or functionality>, no
further processing can be carried out / any further processing must be
subject to the express authorization of the lead auditor.
Responsibilities
The tests and more generally the entire service will only begin after the
signing of this document. If <PROVIDER> were to fail in one of the
elements of this document, in particular at the level of the perimeter or the
confidentiality of the data, <PROVIDER> undertakes to inform <CLIENT>
of the breach as soon as possible.
<PROVIDER> undertakes that the actions carried out within the framework
of the service remain strictly in line with the objectives of the service. If the
scope of the audit were to change, an update of this document and the
signing of the update would be necessary.
The sponsor guarantees that it has all the rights of ownership and access to
the scope of the service (information systems, material media, etc.) or that it
has obtained the agreement of any third parties, and in particular its service
providers or its partners, whose information systems would fall within the
scope. In particular, he undertakes to have obtained the hosting provider's
agreement within the framework of an intrusion test hosted externally, if the
hosting provider's policy with regard to security tests involves a declaration
or the collection of his agreement.
The sponsor and the service provider fulfill all the legal and regulatory
obligations necessary for the audit activities. In addition, the auditors
selected for the mission all have a contractual relationship with
<PROVIDER> and do not have a cracker past.
Privacy
All of the data and information collected or processed as part of the audit
are strictly confidential and must not be communicated to third parties
without the written authorization of the audit manager. In fact, the only
people authorized at <PROVIDER> to access the data are the people
participating in the audit. At <CLIENT>, the people authorized to access
the data are at the discretion of the lead auditor, who will then relay the
information to these people.
Unless the sponsor formally and explicitly refuses, the <PROVIDER> will
only keep the deliverables of the assignment at the end of the assignment,
as well as certain ANONYMIZED data for automated processing purposes.
The deliverables will only be accessible to people who participated in the
service. All other audit data, including evidence, recovered files, and audit
trails, will be securely deleted.
Done at .
Signature
The framework document is signed by both parties (your company and that
of the client). Normally, testing does not begin until this document is
signed.
We still strongly advise you to make this document and remind the
customer that it is necessary to start the tests. Indeed, it will serve as
a basis for discussion in the event of a problem with the scope or the
test periods.
In summary
In the next chapter, we will continue in our preparation for the tests,
with the preparation of its working environment, to avoid wasting
time at the start of the audit.
Prepare your work environment
In the previous chapter, we dealt with all the framing part of the tests.
It is now necessary to prepare to be directly operational on the day
of the audit.
"Give me six hours to chop down a tree, I'll spend four preparing my
axe."
Explore Penetration Testing Tools
In this course, we will use the Kali tool because it is the reference
distribution.
If you have problems with the keyboard potentially being qwerty the
first time, you can change the configuration:
Now that you have your environment installed and logged in, you
should have something like this interface:
Kali's app menu
Don't try different tools without a specific goal. Each tool meets a
particular need and you will be more lost than anything by launching
them all to “see what it looks like”. Be patient ! We will use the right
tools when the time comes.
For the rest, it's like a standard Linux system, with the same basic
commands (cat, LS…). If you know the basics of a Linux system, this
will be familiar to you.
Be aware of the limits of the tools
A point on which we will insist between the lines of the course: the
tools are not magic and do not do everything, on their own. They are
only task accelerators that you must understand and know how to do
on your own, normally.
Just because you've just installed a distro designed for offensive
security doesn't mean you're an accomplished hacker now.
Unfortunately, there is no magic recipe for this but all the same some
advice that we will have the opportunity to put into practice:
1. Keep track of what was tested, what worked and what didn't.
2. Know what you did and at what time. In the event of an incident
with the customer, you will be able to prove to him that it is not
you (if of course it is the case).
You will have to be very strict on this. For this you need a tool to:
1. to take notes.
2. take screenshots (or even videos for the sometimes complex
cutscenes).
Take notes
Select a tool with which you are comfortable: word processing like Word or
slideshow like PowerPoint; Mark down files (the formatting of README
files on Git Hub, for example), or a tool like OneNote, for example. It's up
to you to choose yours according to the constraints imposed on you by
the company or by the client.
Pay attention :
data storage: some customers do not want data to be stored on SAAS
services such as Notion, Office 365 or Google WORKPLACE.
the security of the notes: this is sometimes very sensitive information that must
be protected accordingly!
Remember to note the times of the different actions you perform ,
especially those that may have an impact on the system. In the event of a
problem, you can tell your client whether it was your fault or not. This will
save him from having to trigger security incident management, for example.
Take screenshots
Take lots of screenshots , even if you think it's irrelevant. I've seen far too
many PENTESTERS say to themselves when writing the report “Damn, I
don't have this screenshot to prove the vulnerability”. And I guarantee you
that it is much more difficult to defend in front of a person at the client who
insists that there is no vulnerability, if you do not have proof of it.
You can use your usual shortcuts to take screenshots, or use tools
like GREENSHOT on Windows or SKITCH on Mac.
The Kali Linux work environment will then be used to carry out
the technical actions of this course, and more generally in your
PENTESTER life.
Tools are just accelerators, and they can fail you. As part of a
PENTEST, keep this in mind and be vigilant about behaviors
that you do not expect.
Note taking is essential in PENTEST, because you will be testing
a lot of things: it will be very difficult to remember everything,
and impossible to prove it if you haven't taken any screenshots.
Don't make this mistake!
In the next part, we will initiate the first phase of our penetration test: the
discovery and recognition phase. Ready ? Let's go !
A bank's main vault is the one that holds the most wealth…so it's normally
very secure. Before rushing headlong, you're going to want to get as much
information as possible. It's the same thing during a penetration test. And to
get the first information on the target, what better than… Google!
Harness the full power of Google
indexes the web by browsing all the pages that its robots
encounter;
understands your question;
and passes it all through his mill to answer you.
But did you know that it is possible to use Google to:
find vulnerabilities;
recover sensitive data;
all this based on the results of the exploration and indexing of
websites by the Google bot robot?
Be careful, this does not allow Google to bring out results that it does not
have the right to index. This just allows you to precisely filter the results, a
bit like an SQL query.
The Exploit-DB site (in English) lists a list of Google DORKS in what
they call the Google Hacking Data base (GHDB).
OK but I would still have liked to see what it does when you find a
flaw this way… Impossible to see what it would look like?
Ah, we suspected that you would be a little disappointed. Don't worry, it
will change with the little experiment you are going to do now!
Up to you
Remember:
This is your first penetration test mission, I can't let you go like that:
you're going to hone your skills on virtual machines and ROOT Me
challenges.
challenge
Chapter: Find information about the target and its ecosystem Section:
Here is a query you could type into the Google search bar to find an answer:
Only one result! Not common on Google, and ultimately little room
for doubt. Congratulations if you found it!
Use other data sources
Many data sources are available on the internet. They are grouped
together in what is called OSINT for Open Source Intelligence (or
intelligence in open sources, in French).
Google is only a way to search in some of these sources, either with a
normal query or with Google DORKS.
The authenticated part of ROOT Me can for example fall into this last
category!
In the next chapter, we will see together how to extend the perimeter, if of
course we have the authorization from the client.
Collect more information with active
reconnaissance
After several hours of research on your target, you find nothing very
interesting, at most a few names, email addresses and postal addresses of
collaborators. Not enough to go in and leave with the contents of the bank
vault for the moment. And above all, one question remains: is there really
only one building that belongs to this bank?
Attacking the main target is not always the easiest because all the
attention is focused on it. While attacking related targets sometimes
achieves the same ends.
There are several techniques for finding information and extending the
attack surface (this is the accepted term):
The community produces very good tools to facilitate and make this
phase more accessible. Here, it is the OWASP foundation itself that
develops and maintains the most complete and most used tool in
recent times: AMASS!
As with all tools, the default configuration does not necessarily return
the most exhaustive results . It will take time to configure it by going for
example to look for your API keys in the different data sources, find the
most complete list possible for the enumeration of subdomains, etc.
Exercise your duty to advise on the extension of the perimeter
Before expanding the attack surface by looking for other entry points
(related subdomains, for example, the target's acceptance or
development environment), check with your sponsor that you have
the right !
dev.example.com
preprod.example.com
app.dev.example.com
At the end of the mapping and for the continuation of the course, we have
the following 3 environments:
1. *.dev.example.com (development),
2. *.preprod.example.com (pre-production),
3. *.example.com (production);
And for each of these environments, we have the following subdomains that
correspond to different modules of the application:
1. api.*.example.com
2. app.*.example.com
3. admin.*.example.com
We therefore asked the sponsor if we could extend our mapping a little, and
he gave us his agreement.
In the next chapter, we will begin to actively dialogue with our target to
identify the services that are open on the server.
Identify entry points on the underlying target
server
We have seen how it was possible to search for related targets, if the defined
perimeter allows it. We will now refocus on our main target: the
application.
These entry points into the building where the target is located (inside the
bank) are the equivalent of our services listening on the server hosting the
web application to be tested.
Scan target entry points
To discover the entry points, we are going to need to perform a port scan .
Indeed, the server itself will not tell you all the services it exposes.
Perform a port scan
In our example we are going to use NMAP, this is the main thing to know.
In its basic use, NMAP is relatively simple:
This generally has little impact on recent systems, but can have some on
more fragile systems. Do you remember my anecdote about the fact that I
had saturated the firewall ? Well it was partly because of that. Since the
requests were never closed, the firewall waited while I continued to fill its
connections table, then overflowed.
SSH to port 22 ;
HTTPS on 443 ;
SMB on the 445 , etc.
But if the server administrator decides, he can also
mix everything up and run the SSH service on port
443 and HTTPS on port 22 !
Some recommendations even invite you to change
the default port of the administration services (like
SSH, to make it run on a port that is not 22 ). This
prevents it from being detected too easily by mass
scans.
Last point, the scans we do are not very visible : if you need discretion,
you will have to push your understanding of the tool and port scanning in
general much further! But that's not the purpose of this course, so we won't
dwell on it here.
Up to you !
It's your turn to do a port scan. You will do this exercise on the
DVWA environment specially designed for this course, and hosted
by ROOT Me.
challenge
1. Log in to ROOT Me .
2. Click on this link ( https://www.root-me.org/?
page=login&lang=fr&url=%2F%3Fpage%3Dstart_ctf_alltheday
%26id_environnement_virtuel%3D227 ) to start or join the
environment.
3. Once on the page, wait for a green box to appear:
scan the machine to identify its exposure and find the number of
ports that are open;
find out which service is listening on port 2121.
Identify vulnerable services
You can carry out complete research on the CVE Details site , which
provides useful additional information in the context of a PENTEST, such
as the CVSS score of the vulnerability (we will define this notion in part 4),
or even if a public execution code exist. However, this search remains
manual, which is not very practical when you have a lot of services or
technologies to analyze.
Vulnerability scanners are there to save you time: their main purpose is
to tell you if the detected service is affected by a vulnerability , and in
particular a CVE. They are generally based on the detected version of the
service, but not only.
Nessus ;
QUALYS VM ;
or even NEXPOSE from Rapid7 .
Some have free versions for personal use. In the open source category, we
mainly find OPENVAS from GREENBONE .
These products can also scan web applications and find web-specific
vulnerabilities like XSS, SQL injections, which we will see later in this
course. However, this is not their core business and they are generally less
reliable at detecting these kinds of vulnerabilities. You will better
understand why later in the course.
That an SSH service is listening on the server and accessible to the entire
internet is not normal and increases the attack surface. Imagine that
tomorrow a critical vulnerability is published on the service that offers the
SSH connection, what will happen? Most likely a massive attack by
opportunistic hackers who will seek to access the server and compromise it,
to steal information or turn it into a zombie for further attacks.
The returns from network scanning tools are always to be taken with a
grain of salt because they are extremely dependent on various external
factors, such as network congestion, latency or packet loss!
Beyond that, keep in mind that the more aggressive you are on a scan (the
more packets you send), the more likely you are to skew your results .
And this is even more true on the Internet than on a corporate network.
Remember that the target is generally protected, and that some UTMs (
UNIFIED THREAT Management), which are sort of advanced firewalls,
sometimes deliberately distort the results when they detect that they are
being scanned. Not nice !
If you have performed a vulnerability scan and vulnerabilities are
identified, test them to verify if the server is indeed vulnerable, as these
are sometimes false positives!
In summary
We use the term " decryption " when we know the keys to find the message
in clear, and the term " decryption " when we do not know the decryption
key and we must find it.
That's why hackers decrypt encrypted streams: they don't have the key!
1. The client contacts the server and tells it which protocols and
cipher suites it supports.
2. The server responds by communicating its certificate and
indicating which protocol and which suite will be used.
3. This is followed by several operations and exchanges between
the client and the server to complete what is called "TLS
negotiation" or "TLS HANDSHAKE". in English and thus
secure future communication.
TLS communications
The encrypted version of the HTTP communication protocol is
HTTPS. HTTP protocol encryption relies on asymmetric
cryptography using x.509 certificates for key exchange and then
symmetric cryptography for data exchange.
The certificate can have several defects, and these are the most
annoying, because it is mainly on this that recent browsers rely to
indicate whether a site is secure or not.
the certificate key size , which must not be too small (< 2048
bits);
the hashing algorithm (SHA-256 with RSA or higher).
We will also verify that the libraries used are not vulnerable or do not
contain weaknesses that could degrade the robustness of the encryption.
Because yes, encryption is not magic and is operated by the code contained
in these libraries, the best known and widespread being OPENSSL.
Like any piece of code, these libraries may contain vulnerabilities
and weaknesses that are discovered over time.
encryption protocols;
cipher suites.
Let's now see how to understand these notions, at our PENTESTER level,
in the context of an audit or an intrusion test. We are not asked to have the
skills of a CRYPTOLOGIST!
Distinguish between cipher protocols and cipher suites
Encryption protocols
SSL v2;
SSL v3;
TLSv1.0;
TLS v1.1;
TLS v1.2;
TLS v1.3.
For each protocol, there is a list of compatible and accepted cipher suites.
Cipher suites
Cryptography is a field that may seem complex, but its application is not!
For example, if you are testing a 10-year-old application that has never
evolved for various technical reasons, chances are that you cannot do much
about the quality of the encryption! Already, if the application has an
encryption of flows, the sponsor will be able to consider himself lucky… It
is therefore to be taken into account in your recommendations.
Up to you
To participate in this challenge, you need an account on ROOT Me, it's free.
1. Log in to ROOT Me .
2. Click on this link ( https://www.root-me.org/?
page=ctf_alltheday&lang=fr&id_salle=9&id_environnement_vir
tuel=227 ) to start or join the environment.
3. Once on the page, wait for a green box to appear:
We're done for this part! In the next one, we'll start to take a closer look at
the web application itself, and discover the tool you'll be working with the
most: the interception proxy!
Familiarize yourself with INTERCEPTING
PROXIES
In the previous parts, we learned how to learn about the target, its
ecosystem, the exposed services, check its encryption, etc. But we normally
haven't even looked at what the app looks like yet!
Understand the value of a web interception proxy
Before you start testing and performing malicious actions on it, I strongly
advise you to take 30 minutes to 1 hour (depending on its complexity) to
familiarize yourself with the application , in order to:
To view the data that is exchanged between you and the application, you
could use your browser's debug console (usually via the F12 key ):
Firefox Debug Console (F12)
This is why in web penetration testing, the use of a web interception proxy
is highly recommended!
It will make it possible to meet all the needs mentioned above, and much
more. Let's see right away what it is.
Control your requests with a web intercept proxy
The project SECLISTS compiles a good starting base for dictionary attacks
and content discovery. In Kali, you can install it through the APT package
manager:
I will sometimes use the term "dictionary attack" in the course to refer to
testing a very large number of possibilities.
Up to you !
challenge
In the next part, we will learn to identify the technical base of our target to
collect further information on the latter.
Collect technical information about the
application
In this chapter, we will learn how to identify the technical elements that
constitute the target (server type and version, technical STACK , etc.) and
how to find these elements with the proxy.
Observe the target and look for technical information
So far, you haven't done anything really wrong. You have inquired about the
bank: are there premises on which the name of the bank is displayed in
bulk? What are the entry points to the main building? Suspicious to anyone
watching, but not necessarily reprehensible.
As part of our intrusion test, we will now try to find out what constitutes
our technical base , roughly what are the brands of the windows, the
different doors that we have identified (basement, maintenance access, main
door, etc.).
This will allow us to know if there are any default elements that can be
useful to us, such as a default password, which would be equivalent to the
factory key for a lock. Or if this base has technical vulnerabilities or
weaknesses that have not been detected by our vulnerability scanner
(remember, it is always possible because the tools are not infallible).
better target the lists you will use for your recognition;
better target the types of vulnerabilities that you will look for
on the application;
identify the CVEs that you will want to exploit;
find out if there are any default configurations ;
find out if there are any default passwords ;
look for blog posts that discuss the security of target
technologies.
Do not underestimate this recognition phase, it sometimes happens (and in
internal penetration testing, very often) that certain equipment and certain
applications still have their default passwords!
Collect available technical information
The easiest way is to look at the source code of the page and in particular
the JavaScript/CSS files. Just by the name, you will know which technology
is used and sometimes even which version is used.
Then, information is sometimes given by error pages , such as the one that
displays "Page not found" or "This page does not exist" that you have
surely already encountered:
This page gives for example the type and version of the web server used:
Apache 2.4.10.
Also note that the “Server” HTTP header, in its default configuration, also
gives information of this type, in particular the type of server and
sometimes its version:
In the next chapter, we will search for “hidden” pages, at least for standard
users.
In this chapter, we will reuse some of the lessons from the previous chapter
to gain relevance in the mapping of the web application!
Map the website
Here, we will adopt the same approach, but at the scale of the target
application. It won't be out of scope, and it's even mandatory so as not to
miss something!
It's time to activate the intercepting proxy and navigate through the
application. We take the opportunity to note interesting modules, error
pages with technical information, etc.
Accelerate your mapping
As for enumerating hidden parts , you can also do the job by hand:
The exercise will be successful when you find this page using FFUF.
No need to find the flag, it's not part of the exercise. But if you want to go
to the end of the challenge, it's up to you!
Solution
As with other types of scans, there can be pitfalls and false positives, or
worse, false negatives! Since these are tools that automate…
If for example you pass them a request but a particular header is missing,
the enumeration will always return the same HTTP code (for example 404
or 403 ). This will be because you have incorrectly copied the headers
which, for the application, were mandatory!
When I'm not sure how it works, I route all requests for these tools through
BURP . Too bad for the performance, but at least I'm sure what is sent to
the application!
analyze the application before automating
Also keep in mind that there may be protection mechanisms in front of the
website, such as a Web Application Firewall (WAF). It is a device capable
of detecting abnormal behavior and applying, for example, a ban on the
client.
In summary
It's over for this part. The next part will be dense but exciting: we will
finally tackle the search for vulnerabilities in the application!
Modify client-side application behavior
In our bank robbery metaphor, now is the time to take action and execute
our plan: it's D-Day, put on your masks!
Throughout this fourth part of the course, we will review the main
vulnerabilities that can be found on a web application, in other words the
most frequently identified .
These vulnerabilities can be found in the OWASP Top 10, a "ranking list"
periodically updated by OWASP. Each time one of these vulnerabilities is
mentioned, I will specify the category concerned from the OWASP Top 10.
Today there are many families of vulnerabilities; within these families, sub-
groups, and for each sub-group, sometimes specific features depending on
the technology used by the application.
Take, for example, injections. This is a large family: they are grouped
together in the A03:2021-Injections category :
Client-side injections;
Server-side injections;
SQL injections:
ERROR -BASED
BOOLEAN -BASED
time BASED
control injections;
XXE injections.
XSS injections are what we call client-side injections : they will have an
impact on the client of the application , therefore the user and not directly
on the server. This injection family is mostly to be combined with a bit of
social engineering to make the attack work end-to-end.
If you want to learn about the other two types of XSS, you can check out
the OWASP .
Escaping characters means: encoding them correctly so that they are not
treated as code (HTML in the context of an XSS) but as characters to be
displayed.
The Chrome browser doesn't always let us intercept
requests sent locally (even explicitly telling browser
extensions, to handle PROXIES , to intercept local
requests).
All the exercises were done on Firefox in a Kali virtual machine.
Let's do together step by step the detection and exploitation of this type of
vulnerability:
Fortunately, we meet them less and less. But it is very important to know
how to detect and exploit them!
Recover Database Content with SQL Injections
So that the application can store its data in the database and then read it, it
will perform SQL queries with an account that has been configured for it.
The web server sends an SQL query to the database server to retrieve the
data it needs. Sometimes these queries are contextualized with data
provided by app users.
The principle of SQL injection consists in modifying the SQL query that
will be sent.
How do you modify an SQL query?
By injecting special SQL characters into the field(s) that will be taken as
parameters to build the SQL query:
How SQL injection works
Today there are three types of SQL injections:
ERROR-BASED.
BOOLEAN BASED.
Time- BASED.
THE SQLI ERROR-BASED are the easiest to identify and exploit. They
are generally found less often in nature: as they are easily detectable, they
are usually quickly identified and corrected.
The detection is quite simple: if the code is vulnerable, when you enter a
special character (like an apostrophe ' or a quote “ ) in a field that will be
used as a parameter in an SQL query, the query will BUGG.
If the errors are displayed, you'll get an error message that sometimes even
tells you what's wrong, like the response from the demo application:
Basically, these are the same queries as for ERROR-BASED, except that the
error message is not sent back to the client. We then speak of BLIND SQL
Injection because detection and exploitation are done by trial and error.
Instead, a default page or result will be returned.
Now let's assume that the application has a feature to search for other users
of the application, and that this field is vulnerable to SQL injections. The
SQL query will be of the form:
looking for.
Note the apostrophe ' that we added before the name we are looking for.
There, you'll likely get an error that quotes aren't closed properly, or that
bob isn't a valid keyword. You have your SQL injection! You just have to
use it correctly then to exfiltrate the data that interests you.
“Selects the first and last name of users where this is true”
The two dashes and the space at the end of the query (-- ) allow you to
comment out the last condition contained in the code (it would cause the
query to crash if it were read by the database engine). Attention, the space
after the hyphens is important with MySQL engines!
To fetch more interesting data, such as user passwords, you would have to
complete this query. We will not see this in this course because it is "post-
exploitation", that is to say that it is part of operations that generally take
place after an exploitation.
We are not going to go into the details of the countermeasures , but these
vulnerabilities are relatively “easy” to avoid or correct: just use what are
called parameterized SQL queries ( PREPARED STATEMENTS , in English)!
There are some in most, if not all, programming languages.
Up to you !
challenge
https://www.root-me.org/en/Challenges/Web-Server/SQL-injection-
Authentication?q=%2Ffr%2FChallenges%2FWeb-Server%2FSQL-
injection-authentication&lang=en
Good luck and to your keyboards!
Solution
In this chapter, we are going to focus on the vulnerabilities that allow you to
put one foot, or even both, on the system part of the server. These
vulnerabilities are generally considered important (in the case of read-only)
or even serious (in the case of the execution of arbitrary code).
Let's start with the vulnerabilities that mainly allow reading arbitrary files
on the server:
In the context of this course and to simplify the concept, we will consider
that these are two names to designate the same thing: the fact of being able
to tell the server to display the content of an arbitrary file on the server.
2. https://example.com/page=login.php
3. https://example.com/page=backend.php
There are therefore three files in the application
directory, respectively named home. PHP , login. PHP
, BACKEND.PHP .
What do you think will happen if you try to go up the tree, or even call the
absolute path of a known file?
The application will stupidly follow the path that the parameter tells it...
And if you control this parameter, you can tell it what you want:
Take control of the server with RCEs
retrieve information;
try to gain higher privileges on the server;
install persistence;
or bounce on the internal network from the server then
considered compromised.
In most cases, an RCE on an application implies the total compromise
of the application , since one can generally modify the source code, or
access the database from the command line.
order injections ;
FILE UPLOAD vulnerabilities ;
the LFIs we saw just above, in some cases;
REMOTE File Inclusions .
I'll show you the first two:
1. order injections ;
2. and the file UPLOAD vulnerabilities which respectively allow
obtaining " reverse SHELLS " and "web SHELLS" (which can then be
transformed into reverse SHELLS if necessary).
A web shell is a web page through which we can send commands to the
server to execute them.
Control injections
verify that their application can contact the other servers it needs
to function;
Avoid asking production teams to do these repetitive tests for
them.
>&1 '
Reverse Shell
https://www.php.net/manual/fr/function.exec.php
The risks are the same as for the previous type of vulnerability: code
execution on the server, and therefore by extension compromise of the
application and the server.
In its most basic form, a web shell can be a simple text field in which we
can enter our command, and which will then return the result of this
command.
The best way to protect against this is to only accept MIME file types that
we need for functionality, and do this server-side checking .
Additional protective measures can be added:
challenge
To check that you have mastered command injection, I suggest you solve
the PHP challenge – Command injection.
https://www.root-me.org/en/Challenges/Web-Server/PHP-Command-
Injection?q=%2Ffr%2FChallenges%2FWeb-Server%2FCommand-Injection
Good luck !
Solution
You're getting used to it: we're not giving you a ready-made solution, but
everything you need to know is in this chapter.
In summary
Authorization is the fact of verifying that someone has the right to do what
he asks.
Be careful when testing system authentication! If you are not careful, you
risk blocking an important account, such as:
Well, now let's get to the heart of the matter: testing the authentication
mechanisms!
When we are interested in the problems that can impact the authentication
kinematics, we will generally talk about different types:
I'm not going to dwell too much on the subject of authentication BYPASS
because, in a sense, we have already seen through injections. But in your
opinion, what happens if the authentication screen we are testing has SQL
injection?
We'll look at this technique in a little more detail, because that's often where
the problems lie.
The CREDENTIAL GUESSING is the act of successfully
finding the right password for a given user. We
understand in the CREDENTIAL GUESSING finding:
default passwords, such as ADMIN ;
So much for the theoretical approach, but it's still better if we prove that the
authentication is weak. This is the grail if in addition we find valid
identifiers, especially if it is those of an administrator account!
If you block your account, it may be difficult to continue the tests without
unblocking it… and it can take time (up to several hours, sometimes).
This is why, as part of a penetration test, two accounts of the same “level of
privileges” are generally required to access the same things within the
application. This makes it possible to test authentication and the presence of
blocking mechanisms without cutting the branch on which you are sitting.
This assumption is not true for “default” accounts, whose password may
have been forced into the database by the developers, or even hard-coded
into the application code. You have to test them separately, just in case.
The third point to check is the following: are we able to identify the
existence of valid accounts or not?
Step 3: Identify the existence of valid accounts
You know, this feature made for users who forget their identifiers, where the
authentication screen responds differently depending on whether the
account exists or does not exist? I'm talking about this one, which allows
us, as attackers, to build a list of valid identifiers (email address, nickname
or other). That's already one of the two elements necessary to authenticate,
known!
We must take advantage of all the sources of data and all the information
we have:
Online attacks are dictionary attacks or brute force attacks against remote
servers.
Offline attacks are local password cracking when you have recovered the
password hash (via SQL injection, for example).
Offline attacks are infinitely faster than online attacks, because they don't
take network transport time, and the hardware used for cracking is often
specifically made for that.
As you're starting to get used to: we don't give you the answer directly but
the demonstration video above should help you.
Cookies are one of the ways to persist the session and maintain
authentication in web applications. If an attacker steals your session cookie,
he doesn't even have to bother trying to find your password, he will have
access to the application in the same way as if he had found it!
forged ;
stolen ;
used without your knowledge , as part of CSRF attacks (cross
site REQUEST FORGERY ) .
A forged cookie
A cookie can be forged if the attacker can figure out how the cookie is
created by the application. This rarely happens these days, because all
development languages provide the session persistence layer, and it is no
longer necessary to implement it. This considerably limits errors. But from
time to time, we come across a cookie that is out of the ordinary; at that
point, you will have to take a closer look!
A stolen cookie
If the application is not protected against CSRF attacks, the attacker just has
to make the victim send the forged request to the web server.
To do this, he can, for example, send a link
containing all the necessary arguments to the victim,
and have him click on it to execute the request and
trigger the attack! It can also insert requests into
<IMG> tags so that they run automatically when the
browser wants to display what it mistakenly thinks is
an image . Here, change the password of the user in
question.
Authentication is verifying that someone is who they say they are. We talk
about authentication when a secret factor comes into play (like a password).
Otherwise, we speak of identification.
Authorization is the fact of verifying that someone has the right to do what
he asks.
Test horizontal partitioning
We call horizontal partitioning the fact of verifying that a user A cannot
access the perimeter of a user B .
For example, in the example.com app we're testing, it's about seeing if a
doctor (who has their own patients) can access another doctor's patient
records.
The horizontal partitioning
Another example: in a banking application, it is the fact that you, as a user,
cannot access the accounts of another user.
Reminder: the gray box approach consists of having user accounts with
different rights and perimeters, to test the authenticated parties from the
point of view of these accounts.
For example, with a “nurse” or “stretcher bearer” profile, we will try to see
if we are accessing data normally reserved for doctors, or even
administrators:
Vertical partitioning
The method is therefore strictly the same, and the two can be treated at the
same time.
A point to
remember when
testing vertical
partitioning: test
access to features
and data without
authentication.
Yes, it counts as a
break in vertical
partitioning since
you can access
normally restricted
functionalities,
without
authorization or
authentication!
Equip yourself to test
these points effectively
Partitioning can be
tested manually:
by opening
different browsers
with incognito
tabs, for example;
or by replaying the
requests one by
one in the BURP REPEATER , (but admit that it is not very
practical…).
The vulnerabilities that we will see in this chapter do not require any
technical skills. Let's say that they appeal rather to the right state of mind
(or the wrong one, precisely… the one we mentioned in the first chapters:
thinking like an attacker!).
Report unsafe features
During an intrusion test, you may come across features that you believe are
dangerous.
Joke originally used to poke fun at software vendors who fail to recognize
errors in their products.
Check the regulatory compliance of the web application
This is not where we are going to find technical vulnerabilities that allow
the application to be compromised, but it is something that I have become
accustomed to checking because it can represent a risk that will weigh on
the application .
In theory, if the application we are testing does not comply with the
regulatory constraints, the sponsor and owner of the application may be
exposed to sanctions from the CNIL (National Commission for Computing
and Liberties) or of its equivalents. It is a financial risk for him, even of
image.
We are not lawyers, and this course is not a digital law course. I will
therefore rely on the regulatory texts to:
Attention ! All web applications intended for physical users are concerned,
including those developed for internal needs.
see when and how cookies are set through BURP 's history ;
use a tool like a browser add-on such as Cookie Quick Manager in
Firefox ;
look in your browser's developer tools. Example :
Directory listing vulnerabilities are not inherently dangerous and I will not
explain this weakness in this course, as it is a configuration error more than
a technical vulnerability. But if they provide access to sensitive data, the
customer will want to know that his data is public!
In summary
We are done with the findings. It's time to move on to the part that auditors
generally like less, but which is just as necessary as the tests: the
formalization and the restitution. Let's go!
Write your audit report
In this course, I wanted to take a maximalist approach to show you how to
write a very comprehensive report. This approach echoes the elements
expected in a report written according to PASSI requirements (part 6, step
5).
But before talking about the substance, let's talk about the form.
Pay attention to the form of the report
First step: check in the framework document what has been agreed in
terms of format : full text report, slide show, or action plan in spreadsheet
format?
You can even explain in the introduction that the choice of formalization
has been focused on such and such a format and specify the reasons. An
informed reader will understand that the report has been constructed to meet
the specific needs of the sponsor, and that it does not necessarily reflect the
form and content of other reports that you may write.
Your report may quickly contain many pages, in particular because of the
captures or the exhaustiveness of the tests and explanations. It is therefore
important that it is pleasant to read !
For this, the same techniques as for any document are applicable:
captions to any screenshots or technical evidence;
highlighting important elements;
short sentences, no more than 3 lines (1.5 lines on average);
a clear separation of the different parties;
and above all, no spelling mistakes!
This summary must be relatively short (one to two pages) and must be
understandable by non-expert populations.
The objective of this part is that anyone with access to the report
understands in a few minutes what are the main ones:
The purpose of an audit is not to identify culprits, but to help the sponsor
improve the security of its application.
In the points to be corrected, the idea is to remain at a very high level and
to link, as far as possible, identified vulnerabilities to a problem or a
risk for the business. We can talk about SQL injections or command
execution, but emphasizing what these vulnerabilities allow to do rather
than the vulnerability itself. We will only cite the most important points,
not the details that do not really allow the application to be reached.
At the end of reading the managerial summary, the sponsor, whoever he is,
must have understood what we have managed to do on the application. He
must have the keys to decide, for example, if the application can go into
production as is, or if corrective measures must be implemented
beforehand.
Part n°2: the result of the intrusion tests
This part of the audit report is intended for the technical populations, in
particular the people who will be responsible for implementing the
recommendations and (possibly) verifying the correct application of the
correction by testing the application again.
1. Vulnerabilities , with:
This part is usually the most substantial part of the report. It details and
explains all the tests that have been carried out on the target , whether
they have led to the discovery of a vulnerability, or on the contrary brought
proof of the absence of vulnerability.
The idea of this section is to tell the story of your penetration test, what you
tried, why, and what was the result.
Before writing the report, check with your sponsor that the
planned format meets their needs.
By default, I recommend a complete approach to the deliverable
with a managerial summary, the result of the vulnerabilities
found and recommendations, then the detailed sequence of the
tests carried out. This is the approach also recommended by
ANSSI in PASSI.
Take care of the form of the report and proofread it, several
times if necessary!
Each part of the report is aimed at a specific audience:
the managerial summary is aimed at executive functions
such as managers, heads of departments, and “business”
populations without specific IT knowledge, and even less
security;
the list of vulnerabilities and recommendations is intended
for the technical populations, who will have to implement
the recommendations and understand why the vulnerability
exists;
the details of the tests are also intended for the technical
population if they wish to understand the entire progress of
the PENTESTER , but also for future testers or other auditors
who may need the results of the audit for another mission.
In the following chapter, we will see in detail how to approach and
formulate the recommendations so that they are as actionable as possible
by the sponsor's teams.
Faced with the results of the test, the sponsor will immediately ask himself
the following questions:
Personally, I use short term (less than 1 month); medium term (1 month
to 6 months); long term (6 months and more). The notion of “short term” is
very relative depending on the company! We can therefore add a “very
short term” level for very urgent recommendations.
But how to decide the priority without doing it with a wet finger?
We decide according to the vulnerability that it corrects, and the risk that it
reduces or attenuates.
The more the recommendation fixes a critical vulnerability (or the more it
mitigates a significant risk), the higher the priority.
The cost, complexity and burden can be confusing for those who don't use
your scale on a regular basis: if I end up bringing in outside contractors to
do the work, is that a cost or is it time? Or both ?
Your action plan is not a holy book! It is a working basis that the sponsor
can use to build his action plan
Facilitate the implementation of your recommendations
With that, normally the different people or teams of our sponsor have all the
elements to correct the vulnerability that we have found!
Up to you !
Order
Here is the list of the 16 vulnerabilities (in Excel or Open Document format
) that we found during our penetration test on example.com .
Can you write the associated recommendations?
In summary
The action plan that you formalize is a proposal for the sponsor
to help him prioritize actions.
Your action plan is not a holy book that holds absolute truth.
The action plan must be directly actionable for your sponsor:
except for certain complex recommendations which may require
projects in their own right, the client should be able to
immediately launch most corrective projects.
To be actionable, the recommendations must be prioritized, and
have the maximum number of useful characteristics for the
client: estimated cost, working time required, typical team
responsible, etc.
The recommendations must be as detailed as possible to leave a
minimum of room for questioning and interpretation. If you can
refer to official documentation (manufacturer, publisher,
language, etc.), add it!
Return your work
Prepare the presentation material
These two elements, but not only and far from it!
Self-supporting does not mean literal: out of the question to copy and paste
the report into slides, and present it like that.
Step 1: recall the context
Some people will be particularly busy and quick to pass through the
meeting. To these people, summarize the positive aspects and points to
work on the application, early in the presentation .
Step 3: Show the vulnerabilities in order of criticality
Order the vulnerabilities by criticality (from the most critical to the least
critical).
We are not at the cinema trying to keep the sponsor in suspense by leaving
suspense before announcing the most important vulnerabilities.
Like any human being, he has a limited attention span. You might as well
use the time when he is completely focused to get the important messages
across to him, and leave the time when he is likely to drop out for the less
critical things.
Provide diagrams and include the most relevant screenshots you took
during testing and, if you have them, videos of a vulnerability exploit.
Up to you !
Order
example.com application , we found a nice CSRF vulnerability on the
functionality allowing doctors to issue prescriptions.
If an attacker knows the name of the drug, the prescription and the patient
information, he can unknowingly have a doctor prescribe drugs! For
example, he may prescribe restricted medications such as morphine or
narcotics. And as the prescriptions are communicated by email to their
beneficiary, the attacker can retrieve the prescription in his inbox. Not a
great scenario… Can you schematize it to explain this somewhat special
vulnerability in a feedback meeting?
Solution
Your medium is ready? Let the show begin: you left for 1 hour of
presentation (be careful, it goes by very quickly).
To put the odds on your side, keep in mind the objective: to improve the
security level of the application. You must be an ally of the sponsor to build
with him the final elements of the security of the system.
The restitution meeting should in no way be a witch hunt to find out who
made this or that mistake.
Sometimes, the sponsors will have specific ideas of what they expect from
the restitution: releasing the budget, decommissioning an application,
embarking the businesses in a security approach, for example. If these
objectives are compatible with your posture, nothing prevents you from
directing your speech a little or certain recommendations to go in the
direction of the sponsor.
I'm not telling you to write what the sponsor asks of you! An audit or
penetration test should normally be independent, and therefore by definition
the results should not be influenced!
To do this, recall these objectives at the start of the meeting . Then run
the presentation as you built and planned it.
Do not go too quickly over the summary part, nor over the good points: it is
also of interest to the teams to know on which subjects they have done a
good job!
Take the time to:
If one of the meeting members disputes one of the vulnerabilities, you have
two options:
1. Either you have the technical proof and you bring it out to
discuss it.
2. Either you do not have it (or it is insufficient). In this case,
suggest that the sponsor redo the test for this vulnerability. It is
better to verify your statements than to persist if you cannot
prove what you are saying.
Collect feedback from your audience
And here we come to the end of this mission. Everything went well from
your point of view, but what about the sponsor's point of view?
Ask him !
Then, suggest that they review again in 3 months, to see how the action
plan has progressed and maintain the relationship with them.
This course is over, congratulations ! I hope I have taught you all the
basics so that you feel ready to carry out your first web penetration test.
Go further
You are at the beginning of your journey in the world of penetration testing:
I encourage you to increase your skills by monitoring and experimenting.
In summary