Session 1
Session 2
https://docs.oracle.com/cd/E18283_01/network.112/e10836/img/netag074.gif
https://upload.wikimedia.org/wikipedia/en/f/ff/Osi_model_trad.jpg
OSI Model
7. Application
6. Presentation
5. Session
4. Transport
3. Network
2. Data-Link
1. Physical
Example Protocols
HTTP, FTP, IRC, SSH, DNS, SMTP
SSL, TLS
Sockets Setup - Conceptual Protocol
TCP, UDP
ICMP
ETHERNET, PPP, 802.11
Fiber, Wireless
The HTTP is a stateless protocol is based on a series of client requests and web server responses
HTTP requests and responses are comprised of Headers, followed by request or response body
HTTP requests must specify request method.
HTTP responses must contain a Status Code
HTTP is a plain-text protocol
GET Method
LalaNg:~ mac$ curl -G -v hcmiu.edu.vn
* Rebuilt URL to: hcmiu.edu.vn/
* Trying 125.234.3.178...
* Connected to hcmiu.edu.vn (125.234.3.178) port 80 (#0)
> GET / HTTP/1.1
> Host: hcmiu.edu.vn
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Type: text/html; charset=utf-8
< Server: Microsoft-IIS/7.5
POST Method
LalaNg:~ mac$ curl -d user=lalang -v hcmiu.edu.vn
* Rebuilt URL to: hcmiu.edu.vn/
* Trying 125.234.3.178...
* Connected to hcmiu.edu.vn (125.234.3.178) port 80 (#0)
> POST / HTTP/1.1
> Host: hcmiu.edu.vn
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Length: 11
> Content-Type: application/x-www-form-urlencoded
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
Common Codes
200 OK
302 Location
401 Unauthorized
403 Forbidden
404 Not Found
500 Internal Server Error
Originally, HTTP protocol does not maintain state between requests.
To maintain state, must use a state tracking mechanism
A session identifier (Session ID) is typically passed within a request to associate requests with a session
Session ID's are typically passed in one of three places:
Cookie HTTP Header
URL
Most common place to pass session identifier
To initiate a session, server sends a Set-Cookie header
Begins with a NAME=VALUE pair
Set-Cookie: SID=5KXIOt4cS; expires=Mon, 31-May-2010 20:46:01 GMT; path=/; domain=.abc.com; HttpOnly
A1: Injection
A2: Cross Site Scripting (XSS)
A3: Broken Authentication and Session Management
A7: Insecure Cryptographic Storage
A5: Cross Site Request Forgery (CSRF)
A6: Security Misconfiguration
A4: Insecure Direct Object Reference
A8: Failure to
Restrict URL Access
A9: Insufficient Transport Layer Protection
A10: Unvalidated Redirect & Forward
The OWASP Top Ten List (2010)
Arise when mixing Code and Input in the same context
Hostile input is parsed as code by interpreter
Server Side Code:
String query = "SELECT user_id FROM user_data
WHERE user_name = '" + input.getValue("userID") + "'
and user_password = '" + input.getValue("pwd") +"'";
Input Form:
Username:
Password:
JohnSmith
Secret
Interpreted by SQL Server:
SELECT user_id FROM user_data WHERE user_id = 'JohnSmith'
and user_password = 'Secret';
Server Side Code:
String query = "SELECT user_id FROM user_data
WHERE user_name = '" + input.getValue("userID") + "'
and user_password = '" + input.getValue("pwd") +"'";
Input Form:
Username:
Password:
JohnSmith
1' or '1'='1
Interpreted by SQL Server:
SELECT user_id FROM user_data WHERE user_id = 'JohnSmith'
and user_password = '1' or '1'='1';
Mehh, No Password Check !
Step 1: Fingerprint database.
Step 2: Test if the server is inject-able
Step 3: Extract data through UNION statements
Step 4: Enumerate database schemas
Step 5: Dump data
Step 6: Escalate privilege & pwn the OS
Generally Three Types of Cross Site Scripting
Text
http://hwang.cisdept.cpp.edu/swanew/images/RXSS.gif
Text
http://hwang.cisdept.cpp.edu/swanew/images/SXSS.gif
Common categories of testing when hacking web apps
Fuzz Testing
What happens when unexpected data is sent into the
application?
Authentication Testing
Are authentication requirements always enforced?
Authorization Testing
Can authorization ever be bypassed?
Information Disclosure
Is information disclosed that might directly or indirectly help compromise the application?
Active Scanner (Nexus, w3af)
Passive Scanner (Skavenger, Burp, Watcher, etc)
CGI Scanner (Nikto)
Identify key requests / functionality during crawl
Use logs as input for fuzzing GET & POST parameters
Use authenticated log to uncover unprotected resources
Use privileged log to uncover resources without proper authorization
Analyze logs for other potential weaknesses
Two pages have the same origin if the protocol, port (if one is specified), and host are the same for both pages.
- Mozilla Developers
Test URL | Outcome | Reason |
---|---|---|
http://store.company.com/dir2/other.html | ||
http://store.company.com/dir/inner/another.html | ||
https://store.company.com/secure.html | Different protocol | |
http://store.company.com:81/dir/etc.html | Different port | |
http://news.company.com/dir/other.html | Different host |
Given the URL http://store.company.com/dir/page.html
JavaScript executing in context of one document should not be allowed to access context of another document, unless:
– protocol, hostname and port all match!
var invocation = new XMLHttpRequest();
var url = 'http://bar.other/resources/post-here/';
var body = '<?xml version="1.0"?><person><name>Arun</name></person>';
invocation.open('POST', url, true);
invocation.setRequestHeader('Content-Type', 'application/xml');
invocation.onreadystatechange = handler;
invocation.send(body);
A web browser makes a cross-origin HTTP request when it requests a resource from a different domain than the one which served itself.
Domain A
Domain B
3. Send XmlHttpRequest
1. Send HTTP Request
4. Return images
2. Render webpage
Domain A
Domain B
3. Send XmlHttpRequest
1. Send HTTP Request
4. Return Error
2. Render webpage
Under Same-Origin Policy
Domain A
Domain B
3. Send XmlHttpRequest
1. Send HTTP Request
4. Return Images
2. Render webpage
Allow Cross-Domain Access Control (CORS)
https://krystal.co.uk/blog/wp-content/uploads/2015/05/csrf.png
Paper src: https://www.eecs.berkeley.edu/~daw/teaching/cs261-f11/reading/csrf.pdf
Normal URL | Exploit URL |
---|---|
/AccountInfo.aspx?AcctId=03962480 | /AccountInfo.aspx?AcctId=03962490 |