Web Application
Web Application
Web Application
1
Professional
1. Web application
technologies 101
Introduction
Web applications are applications running on web servers and accessible
via web browsers. It makes bridge between user and server.
Encoding Schemes
HTTP Cookies
www.grayhat.in
HTTP Request
HTTP Response
USER (Client)
SERVER
As the name suggests, GET method sometimes also called HTTP “verb” is
used to fetch or request data from the server.
</>
POST method: Query POST /login/login_form.php HTTP/1.1
Host: grayhat.in
strings are sent in HTTP Username=demo&password=demo
message body of POST
method
500 Internal Server Error Server does not process such request
HTTPS
HTTP is a clear-text protocol, as sniffers can intercept the traffic
between two user or sometimes whole network.
This is where HTTPS comes into action. HTTPS or HTTP over SSL/TLS
Provides strong encryption by encrypting the data transmitted in the
wire.
HTTPS
HTTPS makes authenticated session with confidentiality and integrity
as follows:
???..
SSL/TLS
User Server
WAPTP v3.1 - gray hat security c 2017 16
HTTP/S Protocol Basics
Common Myth
If SSL/TLS is there, server will not be hacked or it is protected well.
As of now, you can understand that SSL/TLS will not protect from
attacks such as, SQLi, XSS, CSRF etc.. Or even application itself.
References
HTTP status codes definitions:
https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
Encoding Schemes
URL Encoding
Since, the URL can only be sent over internet using ASCII-characters.
And URL encoding fulfills the same requirements.
URL Encoding
In URL, some reserved characters such as / that is used to separate
paths in URL. If this character is used by somemeans, then it must be
encoded otherwise URL parser will be throwing errors.
http://www.asciitable.com/
URL Encoding
URL Encoded characters Table:
Character Encoded Character Encoded Character Encoded Character Encoded
Double Encoding
Double Encoding is similar to URL/percent encoding. Encoding takes
place two times at this time while it is encoded one time in URL
encoding.
This technique was used in famous IIS “Directory Traversal Attack” 2001
(../../ or dot dot slash). Pretty useful in evading filters.
Double Encoding
Double Encoding doesn’t need to be memorized.
URL Encoded:
https%3A%2F%2F2.gy-118.workers.dev/%3A443%2Fhttp%2Fgrayhat.in%2Fcourses%2FWAPTP
Double Encoded:
http%253A%252F%252Fgrayhat.in%252Fcourses%252FWAPTP
Double Encoding
XSS Filter Evasion using Double Encoding XSS Filter Decoded the
“Double encoded payload”,
and becomes URL/Percent
encoded finally at server and
http://grayhat.in/search.php?q=<script> executed successfully.
alert('XSS')</script>
http://grayhat.in/search.php?q=
http://grayhat.in/search.php?q=%253Cscript%2
%3Cscript%3Ealert(%27XSS%27)%3C%2
53Ealert(%2527XSS%2527)%253C%252Fscript%253E
Fscript%3E
Base64 Encoding
Base64 is a encoding mechanism that was first used in email (RFC
1421) to send binary data such as attachments sent in ASCII format. It
is very common in website to encode session IDs, parameters, media
Base64 Encoding
Base64 Encoding process: Base64 Encoding Table
• Input bytes stream are divided into blocks of Value Encoded Value Encoded Value Encoded Value Encoded
3 bytes.
• 3 bytes joined to make 24 bits
• 24 bits divided into 4 groups of 6 bits each.
• Each 6 bits are mapped to decimal first then
map each group of 6 bits to 1 printable
character set from encoding table.
• If the last 3 byte block has only 1 byte of
input data, then 2 byte of zero are padded.
And at last these padding are overridden
with 2 equal signs (==).
• If the last 3 byte block has 2 byte of input
data, then 1 byte of zero are padded. And
after encoding it is overridden with 1 equal
sign(=).
WAPTP v3.1 - gray hat security c 2017 28
Encoding Schemes
Base64 Encoding
Example:
Input data: G
Input bits(bin): 01000111
Padding: 01000111 00000000 00000000
Joined(24bits): 010001110000000000000000
Divided(6bits each): 010001 110000 000000 000000
Decimal value: 17 48 = =
Base64 encoded: R w = =
Encoded: Rw==
Base64 Encoding of (gray hat security) : Z3JheSBoYXQgc2VjdXJpdHk=
WAPTP v3.1 - gray hat security c 2017 29
Encoding Schemes
References
URI characters defined in RFC 3986:
https://www.ietf.org/rfc/rfc3986.txt
URL Encoder/decoder:
http://meyerweb.com/eric/tools/dencoder/
Same Origin Policy determines the origin (in browser) on behalf of:
Example:
A JavaScript code on: https://www.grayhat.in:941
Same Origin Policy is used for JavaScript but also for AJAX, Flash,
Cookies and most importantly origin-separated data stored in local
storage of webserver.(for multiple domain).
SOP applies only to the actual code of a script. We can still add
external resources using HTML tags like <img>, <iframe>, <script>,
object and so on.
References
Same Origin Policy (SOP):
https://www.w3.org/Security/wiki/Same_Origin_Policy
HTTP Cookies
The web browser send it back to the server in the next request to
validate the same textual information (cookie) stored by web server
to the browser.
• Session management
• Shopping carts
• gaming site to remember scores
• Keep users logged-in
• Tracking user behavior
#Browser sends cookie in each request to its corresponding domain and subdomains
WAPTP v3.1 - gray hat security c 2017 39
HTTP Cookies
When server does not set domain attribute in cookies, the browser
set it automatically with server domain and set as host-only Flag.
Host-Only Flag means, cookie will be set and valid for that specified
domain only( i.e grayhat.in)
grayhat.in
Sub1.grayhat.in Sub2.grayhat.in
grayhat.in
Sub1.grayhat.in Sub2.grayhat.in
Set-Cookie: v=cookiedata;
Host-Only grayhat.in
Sub1.grayhat.in Sub2.grayhat.in
References
HTTP Cookies Explained:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
RFC 6265:How Server installs a cookie in browser and more about its functionality
https://tools.ietf.org/html/rfc6265
CORS
Source: https://developer.mozilla.org
References
Cross-origin Resource Sharing (CORS) detailed explanations:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS