Web Attacks
Fingerprinting with nc
, openssl
& httprint
nc
, openssl
& httprint
Web applications use different technologies and programming paradigms compared to desktop apps:
Web applications often make up the vast majority of the internet-facing surface.
It can be done manually and by using automatic tools.
Fingerprinting a web server means:
Web Server Service: IIS, Apache, nginx.
Version.
OS hosting the server.
HTTP Verbs
REST APIs are specific type of webapp that relies strongly on almost all HTTP verbs
In REST APIs is common to use PUT for saving data, and not for saving files
If you confirm a PUT or DELETE during an engagement, you should confirm its exact impact twice
Exploiting Misconfigured HTTP verbs
1st you enumerate verbs with an OPTIONS message in
nc
To exploit the DELETE verb, you just have to specify the file you want to delete from the server
Exploiting PUT is more complex, because you have to know the size of the file you want to upload on the server, you can measure with
wc -m file
to count how long, in bytes, a payload is.Misconfigured HTTP verbs are becoming rare in web servers.
You can still find a lot of misconfigured HTTP methods in embedded devices, IP cameras, digital video recorders and other smart devices.
nc
nc
Directories and Files Enumeration
Ability to:
Find and utilize testing features
Exploit information saved in backup or old files
Find hidden resources
Enumeration helps you find those "hidden" resources that often contain:
New and untested features
Backup files
Testing information
Developer's notes
Two ways of enumerating resources:
Pure brute-force
Dictionary attacks
Tool:
OWASP Dirbuster
Java application that can perform web resources enumeration
You can choose if you want to perform a pure brute-force or a dictionary-based brute-force
It's Linux alternative:
dirb
Dirb
Dirbuster
Find hidden files via dirbuster:
You might find a config.old
file where the MySQL database connection parameters are visible.
Google Hacking
Perform information gathering without contacting your targets, ability to find hidden resources: site:
, intitle:
, inurl:
, filetype:
, AND
, OR
, &
, |
, -
Cross Site Scripting
The attacker can target the web applications's users, and:
Modify the content of the site at run-time
Inject malicious contents
Steal the cookies, thus the session of a user
Perform actions on the web application as if it was a legitimate user
User input is any parameter coming from the client-side of the webapp, as:
Request headers
Cookies
Form inputs
POST parameters
GET parameters
Actors of a XSS attack:
Vulnerable Website | User/Visitor (Victim) | Penetration Tester |
---|---|---|
Inputs should always be validated server side | Code executed/rendered by the browser of the visiting users | Making their browsers load malicous content |
Never ever trust user input | XSS vulnerabilities have low priority for developers, as it can be really hard for a victim to realize that an attack is in progress | Performing operations on their behalf, like buying a product or changing a password |
Stealing the session cookies, thus being able to impersonate them on the vulnerable site |
Reflection Point: When a search parameter is submitted through a form and gets displayed on the output in an XSS attack
After finding a reflection point, you have to understand if you can inject HTML code and see if it somehow gets to the output of the page
Test XSS:
<script>alert('XSS')</script>
XSS Types
Reflected
When the malicious payload is carried inside the request that browser of the victim sends to the vulnerable website
When users click on the link , the users trigger the attack
http://victim.site/search.php?find=<payload>
Called 'reflected' because an input field of the HTTP request sent by the browser gets immediately reflected to the output page
Google Chrome has a reflected XSS filter built in to avoid this attack, but only trivial ones
Persistent
Occur when the payload is sent to the vulnerable web server and then stored.
When a web page of the vulnerable website pulls the stored malicious code and puts it within the HTML output, it will deliver the XSS payload
The malicious code gets delivered each and every time a web browser hits the "injected" web page
A single attack can exploit multiple web applications
The most common vector for persistent attacks are HTML forms that submit content to the web server and then display that content back to the users
Element such as comments, user profiles, and forum posts are potential vector for XSS attacks
DOM Based
Cookie Stealing via XSS
When
HttpOnly
flag is disabled, cookies can be stolen<script>alert(document.cookie)</script>
With the following code, you can send cookies content to an attacker-controlled site:
SQL Injections
They allow an unauthorized user to take control over SQL statements used by a web application. This kind of attack has a huge impact on a web site because getting control over a backend database means controlling:
User's credentials
Data of the web application
Credit Card numbers
Shopping transactions
To find SQL injections, we need to check any user input (every input must be tested to conduct a professional pentest):
GET parameters
POST parameters
HTTP Headers
User-Agent
Cookie
Accept
Tests can be:
String terminators:
' and ''
SQL commands:
SELECT
,UNION
and othersSQL comments:
#
or--
SQL basics
Vulnerable Dynamic Queries
Boolean Based SQLi
Once penetration testers find a way to tell when a condition is true or false, they can ask the database some simple True/False questions:
Is the first letter of the username 'a'?
Does this database contain three tables?
...
We can use two MySQL functions: user()
and substring()
:
UNION Based SQL Injections
Many times some of the results of a query are directly displayed on the output page. This behavior can be exploited using the UNION SQL command.
To exploit a SQL injection you first need to know how many fields the vulnerable query selects, you do this by trial and error. We know there's an injection by ' UNION SELECT null; -- -
, this should display:
We can try with two fields:
' UNION SELECT null null; -- -
and three even to confirm that the original query only has two fields.Once we know how many fields are in the query it's time to test which fields are part of the output page.
You can do that by injecting some known values and checking thee results in the output page, as in:
' UNION SELECT 'elsid1', 'elsid2'; -- -
.Now we can exploit the injection:
' UNION SELECT user(), 'elsid2'; -- -
.Not only
SELECT
queries are vulnerable.
SQLMap
Can detect and exploit SQL injections
Needs to know the vulnerable URL and the parameter to test for a SQLi
From discord (to test)
Last updated