2 Introduction
2 Introduction
will need before you begin your web application security testing.
2.2 Encoding
2.4 Cookies
2.5 Session
HEADERS\r\n
\r\n \r (Carriage Return): moves the cursors to the
beginning of the line
\n (Line Feed): moves the cursor down to the next line
\r\n: is the same of hitting enter on your keyboard
MESSAGE BODY\r\n
GET / HTTP/1.1
Host: www.google.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101
Firefox/36.0
Accept: text/html,application/xhtml+xml
Accept-Encoding: gzip, deflate
Connection: keep-alive
This is the file you are requesting. The home page of a website is
always "/". Other pages can be requested, of course, such as:
/downloads/index.php. Your request always refers to the root
folder to specify the requested file (hence the leading "/").
This is the HTTP protocol version that your browser wants to talk
with. This basically informs the web server about which version of
HTTP you would like to use in any further communication.
This is the beginning of HTTP Request Headers. HTTP Headers have the
following structure: Header-name:Header-Value.
After each request header, you will find its corresponding value. In
this case you want to reach the Host www.google.com.
Note: Host value + Path combine to create the full URL you are
requesting: the home page of www.google.com/
All web browsers have their own user-agent identification string. This is
how most web sites recognize the type of browser in use.
With HTTP 1.1 you can keep your connection to the remote web
server open for an unspecified amount of time using the value
"keep-alive". This indicates that all requests to the web server will
continue to be sent through this connection without initiating a
new connection every time (as in HTTP 1.0).
In response to the HTTP Request, the web server will respond with
the requested resource, preceded by a bunch of new Headers.
These new headers from the server will be used by your web
browser to interpret the content contained in the Response
content.
<PAGE CONTENT>
<PAGE CONTENT>
<PAGE CONTENT>
<PAGE CONTENT>
• 403 Forbidden, the client does not have enough privileges and the server refuses to fulfill the
request.
• 404 Not Found, the server cannot find a resource matching the request.
• 500 Internal Server Error, the server does not support the functionality required to fulfill the
request.
<PAGE CONTENT>
Date represents the date and time at which the message was
originated.
<PAGE CONTENT>
The Cache headers allow the Browser and the Server to agree about caching
rules. Cached contents save bandwidth because, in short, they prevent your
browser from re-requesting contents that have not changed when the same
resource is to be used.
<PAGE CONTENT>
Content-Type lets the client know how to interpret the body of the
message.
<PAGE CONTENT>
<PAGE CONTENT>
The Server header displays the Web Server banner. Apache and IIS
are common web servers. Google uses a custom webserver
banner: gws (that stands for Google Web Server).
<PAGE CONTENT>
<PAGE CONTENT>
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
Firefox (as well as other web browsers) already have some features
that allow us to inspect HTTP Headers on the fly.
Once Firefox starts, open the options menu and select Developer -
> Network.
GET / SSL/TLS
HTTP/1.1 HTTP
http://unicode-table.com/en/#0032
http://www.w3.org/International/articles/definitions-characters/
The numbers 8,16 and 32 are the amount of bits used to represent
code points.
There are two main issues to address: inform the user agent on
which character encoding is going to be used in the document, and
preserve the real meaning of some characters that have special
significance
HTML5
<meta charset="UTF-8">
https://tools.ietf.org/html/rfc2616
For example, the symbol < describes the start of an HTML tag, and
obviously that tag will not be shown to the end user; the symbol >
indicates the end, and so on.
http://www.w3schools.com/tags/ref_urlencode.asp
<img_src="data:image/gif;base64,R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAA
DwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBi
eSBVbGVhZCBTbWFydFNhdmVyIQAAOw=="alt="Base64 encoded image"
width="150"height="150"/>
http://www.elswapt.site
http://www.elswapt.site
http://www.elswapt.site:80
Suppose you are logged in to your bank site and suppose your
friend invites you to visit his new website. Also, suppose your
friend is a malicious friend.
Your evil friend could build a crafted page, instigate you to visit it,
and once visited by you, access (some) personal information from
your bank account.
As you can see without SOP you could not surf the Internet.
Example 1 Example 2
a.elswapt.site b.elswapt.site
index.html home.html
window.location document.domain
Write
<html>
…
<body>
<iframe src="http//www.elearnsecurity.com/index.html">
</iframe>
</body>
</html>
window.frames[0].location=http://www.google.com;
a.elswapt.site b.elswapt.site
<script> <script>
document.domanin="elswapt.site" document.domanin="elswapt.site"
</script> </script>
index.html home.html
Web Application Penetration Testing 3.0 – Caendra Inc. © 2018
The new HTML5 feature known as Cross Window Messaging
permits different documents (iframes, popups, current window) to
communicate with each other regardless of the same origin policy
by using a simple synchronous mechanism.
For example, this means that a browser will handle cookies with
these domain values the:
• .elswapt.site
• elswapt.site
Unspecified cookie
Specified cookie domain
domain
Internet Explorer
exception
Suppose that the cookie domain value is wapt.site and that the
target domain requested by the browser is els.wapt.site. For
example we are requesting the page
• http://els.wapt.site/index.php
The browser will send this cookie in HTTP requests matching the
following URLs:
• http[s]://elswapt.site/*
• http[s]://www.elswapt.site/*
• http[s]://www.lab.elswapt.site/*
• http[s]://*.elswapt.site/*
On the reverse side, higher domains cannot set cookies for lower-
level subdomains. Indeed elswapt.site cannot set cookies for
anysubdomain.elswapt.site.
Note that the RFC uses the term host instead of domain.
POST /login.php
Host: www.google.com
usr=John&Pass=mypass
GET /mail.php
Host: www.google.com
Cookie=authenticated="1";
POST (http://a.elswapt.site/login.php)
The cookie is
accepted and will HTTP RESPONSE HEADER:
be available only …
Set-Cookie: SESSID=d8a4z21
to the target Path =/
domain
a.elswapt.site,
since the domain GET (http://a.elswapt.site/logout.php)
value was not HTTP Request Header:
specified. …
Cookie SESSID:=d8a4z21
• http://elswapt.site/* • http://*.elswapt.site/*
• https://elswapt.site/* • https://*.elswapt.site/*
GET (http://a.elswapt.site/page1.php)
Web Browser HTTP Request Header:
…
Cookie SESSID:=d8a4z21
b.elswapt.site
GET (http://b.elswapt.site/index.php)
HTTP Request Header:
…
Cookie SESSID:=d8a4z21
So, this cookie will be sent in each request matching the following
URLs:
• http://a.elswapt.site/learning/*
• https://a.elswapt.site/learning/*
POST (http://a.elswapt.site/login.php)
The cookie is not
HTTP RESPONSE HEADER:
accepted
…
because the Set-Cookie: SESSID=d8a4z21;
domain domain:= b.elswapt.test ;
b.elswapt.test is Path =/
not a suffix of
the domain GET (http://a.elswapt.site/logout.php)
a.elswapt.site HTTP Request Header:
that sent the …
cookie. < No Cookie >
POST (http://a.elswapt.site/login.php)
The cookie is not
HTTP RESPONSE HEADER:
accepted because
…
the cookie Set-Cookie: SESSID=d8a4z21;
domain value domain:= b.elswapt.test ;
b.elswapt.site is Path =/
not a suffix of the
domain GET (http://a.elswapt.site/page1.php)
a.elswapt.site HTTP Request Header:
emitting it. …
< No Cookies>
This happens in order to hide the application logic or just to avoid the
back and forth data transmission, which is typical behavior of cookies.
Also, session variables expire with the session and sessions usually
expire sooner than cookies do.
Var1=abc
Var2=123
SessionID=02ab12
• SESSION=0wvCtOBWDH8w
• PHPSESSID=l3Kn5Z6Uo4pH
• JSESSIONID=W7DPUBgh7kTM
http://example.site/resource.php?sessid=k27rds7h8w
Moreover you will see how HTTP sessions work and how they use
cookies.
Having tools that help in the study and analysis of web application
behavior is critical.
http://portswigger.net/burp/ https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project
http://www.squid-cache.org/
You can
download the
Free Edition
here. http://portswigger.net/burp/download.html
You can modify the header and the body of a message either by
hand or, automatically.
To run Burp you can double click on the jar file you downloaded or
run
For now, just leave the default options as they are, you will see
how to use those features later on.
Even if you leave the master interception off, Burp will still collect
information on the HTTP traffic coming to and from your browser.
You can do the same thing by using other tools such as netcat or
telnet, but Burp provides you:
• Syntax highlighting
• Raw and rendered responses
• Integration with other Burp tools
Every request
must have at
least an HTTP
VERB (GET, POST,
...)
Moreover you will see how to configure and use other features of
both Burp and ZAP, according to the penetration test engagement
goals.
http://tools.ietf.org/html/rfc6265 http://portswigger.net/burp/
ZAP
https://www.owasp.org/index.php/OWASP_Zed_Atta
ck_Proxy_Project