The Art of Exploiting Logical Flaws in Web Apps Sumit sid Siddharth - - PowerPoint PPT Presentation

the art of exploiting logical flaws in web apps
SMART_READER_LITE
LIVE PREVIEW

The Art of Exploiting Logical Flaws in Web Apps Sumit sid Siddharth - - PowerPoint PPT Presentation

The Art of Exploiting Logical Flaws in Web Apps Sumit sid Siddharth Richard deanx Dean A GREAT COLLABORATION! 2 competitors working together! Thanks to: 7Safe, Part of PA Consulting Group Portcullis Computer Security Limited


slide-1
SLIDE 1

The Art of Exploiting Logical Flaws in Web Apps

Sumit “sid” Siddharth Richard “deanx” Dean

slide-2
SLIDE 2

A GREAT COLLABORATION!

2 competitors working together! Thanks to: 7Safe, Part of PA Consulting Group Portcullis Computer Security Limited

slide-3
SLIDE 3

About Me...

i. Global Head of Penetration testing ii. 7Safe- Part of PA Consulting Group iii. 7 + years in IT Security iv. Specialist in Application and Database security v. Speaker at Black Hat, DEF CON, OWASP Appsec etc vi. Co-author of book: SQL Injection: Attacks and Defence 2nd Edition

slide-4
SLIDE 4

and About Me...

i. No snazzy job title ii. Portcullis CLS iii. 6 years in IT Security iv. Enjoys building things up or breaking them down in to first principles v. Was a Semi-conducting Polymer researcher in a previous life vi. Co-author of a Cover article from Advanced Materials

slide-5
SLIDE 5

Overview

What & Why Logic Flaws? Some Examples Where to Look? What To Look For? Some More Examples The Take homes

slide-6
SLIDE 6

Other Researchers Work

Trustwave’s Presentation at Appsec 2012: Anatomy of a Logical Flaw

https://www.owasp.org/images/b/b6/ASDC12-Anatomy_of_a_Logic_Flaw.pdf

MDSEC’s presentation: Beyond OWASP Top 10

http://blog.mdsec.co.uk/2012/04/beyond-owasp-top-10.html

slide-7
SLIDE 7
  • A problem where the application does not behave

as expected from a given state

  • When an expected workflow can be avoided /

circumvented

  • When a developer has not considered external

influences to the current execution path

What Is A Logic Flaw?

slide-8
SLIDE 8
  • Very little awareness/mention of them
  • Beyond the scope of automated tools
  • Requires understanding of the application
  • Requires out-of-box thinking
  • They are a lot more interesting than most other

web application flaws*

* May not be a view held by all of this talks presenters

Why Logic Flaws?

slide-9
SLIDE 9

“You cannot comprehensively test for logic flaws unless you know what the application is supposed to be doing”

Key Axiom

slide-10
SLIDE 10

Example

Classic parameter manipulation attacks, the server trusts a client supplied value:

  • a. Change the price of an item in a shopping basket
  • b. Change a hidden form value such as “UID”
  • c. Transfer Negative Funds
slide-11
SLIDE 11
  • Poor Design
  • No thorough documentation of logical flows
  • Lack of understanding of technologies used
  • Laxed SDLC
  • Lack of rigorous testing both security and

functional

Root Causes

slide-12
SLIDE 12

The First Attack

2 Step Authenticated banking application

slide-13
SLIDE 13

Authentication schema

slide-14
SLIDE 14

Pin Verification

slide-15
SLIDE 15
  • What happens authentication when fails

Pin Verification

Same indices asked again?

slide-16
SLIDE 16

Pin Verification

Same indices asked again? Account lockout after certain attempts

Only 3-5 attempts to guess the write PIN 1000 attempts to brute force

Unless you can do something clever....

Game Over!

N O YES

slide-17
SLIDE 17
  • If the application does not validate the

indices and accepts the user submitted value then....

– What will be the value for non-existing indices – Such as index 7, 8, 9 for a 6 digit PIN – Null equals Null... – Tip: Often pentesters/scanners focus on parameter value but not parameter!

What about the indices?

slide-18
SLIDE 18

Null Equals Null

Note: The index value changed from 1, 3 and 4 to 7, 8 and 9

slide-19
SLIDE 19

And Bang!

slide-20
SLIDE 20

Solution

  • It’s a server side piece of knowledge,

keep it server side

  • Definitely Don’t trust user supplied data
  • Remind you of CVE-2004-0627

– Mysql Auth Bypass

slide-21
SLIDE 21

“Attacks on uninitialized local variables”

  • Halvar Flake – Black Hat Federal 2006

#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { int b; printf(“%lx”, b); }

slide-22
SLIDE 22

Local Variable = = Session Variable Function Calls = HTTP Requests

#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { int b; printf(“%lx”, b); }

An Analogy

slide-23
SLIDE 23

Do we control “Local Variables”? Do we control “Function Calls”? What can be done?

An Analogy

Local Variable = = Session Variable Function Calls = HTTP Requests

slide-24
SLIDE 24

Simple Messaging App

  • After a bit of recognisance the following is found:

– Normal users can send each other messages – Normal users can edit their own profile – Admin users can edit other users profiles

slide-25
SLIDE 25

User Messaging

First a user is selected from the list

slide-26
SLIDE 26

User Messaging

slide-27
SLIDE 27

User Messaging

Then the message is composed

slide-28
SLIDE 28

Nothing to Play With?

slide-29
SLIDE 29

Session Data

  • Application did not require the id of user whom

the message was sent to in final POST

  • This info must be saved session side
  • So we can control at least 1 session variable
slide-30
SLIDE 30

Session Variable Use

if ( !isset ($_SESSION['target_id'])){ // check if session variable exists $target = $_SESSION['target_id']; $message = $_POST[‘message’]; send_messge($target, $message); // do something }else { error(“User Not Selected”); // do something else }

slide-31
SLIDE 31

Look Similar?

slide-32
SLIDE 32

Even More Interesting

Message User Select Edit User Select

slide-33
SLIDE 33

Exploit

  • Visit “User Edit Page”
  • Open second window to “User Messaging”
  • Select User in Messaging Dialogue + Next
  • Blank out one of the required fields on “User Edit

Page”

  • Hit “Update”
  • Page returns with other users info
  • Use password recovery to get access to any

accounts.

slide-34
SLIDE 34

Variable Reuse

if ( !isset($_SESSION['target_id'])){ // checks if session variable exists update_profile($_SESSION['target_id']); // do something }else { update_profile($_SESSION[‘uid']); // do something else } Developer has assumed that as the `target_id’ is a session variable it cannot be controlled by the user, forgetting that the variable *can* be controlled during the messaging phase.

slide-35
SLIDE 35

Where to Look?

  • Cracks in the application

– Places where difgerent dev teams have been used – Places where extra functionality has been bolted on – Boundaries between frameworks and bespoke code

slide-36
SLIDE 36

What to Look For?

  • Obviously difgerent coding styles

– May indicate coding guidelines not followed

  • Missing framework elements

– May indicate framework security is missing

  • Complex user journeys

– More complex more scope for mistakes

  • New functionality that is added
  • Similarities between difgerent function
slide-37
SLIDE 37
  • Typically common in e-commerce website
  • Problem:

– lack of co-ordination between functional testing and security testing

  • General Crack - new functionality added for

specific purpose

Discount Voucher Fun

slide-38
SLIDE 38

Discount Voucher Fun

slide-39
SLIDE 39

Hot DEAL!

slide-40
SLIDE 40

Free Gift==Discount?

slide-41
SLIDE 41

Free Gift==Discount?

slide-42
SLIDE 42

Facebook Abuse

Another bolt-on functionality problem

slide-43
SLIDE 43

Facebook Abuse

  • “Locate the person who you want to view photos of”
slide-44
SLIDE 44
slide-45
SLIDE 45

Facebook Abuse

  • “Locate the person who you want to view photos of”
  • “Click on Report/Block. From the popup menu,

select Inappropriate Profile photo and press continue.”

slide-46
SLIDE 46
slide-47
SLIDE 47

Facebook Abuse

  • “Locate the person who you want to view photos of”
  • “Click on Report/Block. From the popup menu,

select Inappropriate Profile photo and press continue.”

  • “Select Nudity or pornography and press continue.”
slide-48
SLIDE 48
slide-49
SLIDE 49

Facebook Abuse

  • “Locate the person who you want to view photos of”
  • “Click on Report/Block. From the popup menu,

select Inappropriate Profile photo and press continue.”

  • “Select Nudity or pornography and press continue.”
  • “Only check Report to Facebook and press continue.”
slide-50
SLIDE 50
slide-51
SLIDE 51

Facebook Abuse

  • “Locate the person who you want to view photos of”
  • “Click on Report/Block. From the popup menu,

select ‘Inappropriate Profile photo’ and press continue.”

  • “Select ‘Nudity or pornography’ and press continue.”
  • “Only check ‘Report to Facebook’ and press

continue.”

  • “Only select ‘Help us take action by selecting

additional photos to include with your report’ and press Okay.”

slide-52
SLIDE 52
slide-53
SLIDE 53

Understand Your Tech

slide-54
SLIDE 54
  • Typically, the clear text password and

username are submitted to server

  • Server creates a hash (often salted hash)

and then compare the hash stored in back-end

  • If hash is correct, authentication is

successful.

Authentication Hashes

slide-55
SLIDE 55
  • CVE 2010-2861
  • Reference:

– http://www.gnucitizen.org/blog/coldfusion-directory-traversal-faq- cve-2010-2861/

Authentication Hashes

slide-56
SLIDE 56

Pwning Coldfusion

slide-57
SLIDE 57
  • Bad

– http://server/CFIDE/administrator/enter.cfm?locale=../../../../../boot.ini%00en

  • Worse

– http://server/CFIDE/administrator/enter.cfm?locale=../../../../../ColdFusion8/lib/ password.properties%00en

Directory Traversal

slide-58
SLIDE 58

password.properties file

slide-59
SLIDE 59
  • Good security practice?

– Not too bad, could have been better with salt?

  • Only if you understand the salting

Unsalted SHA1 Hash

slide-60
SLIDE 60

Authentication Request

slide-61
SLIDE 61
  • The javascript running on webpage will automatically

converts password into SHA1 hash and then use a salt to create a HMAC

  • The HMAC and salt are sent to server
  • Server computes HMAC based on password hash

stored at back-end and salt value received

  • If the 2 HMAC are same, authentication is successful
  • Grrrrr! #FAIL

CF Authentication

slide-62
SLIDE 62
  • We can use the same javascript function to create

HMAC from password hash (without needing the password)

javascript:hex_hmac_sha1($salt, $password)

Generating HMAC

slide-63
SLIDE 63

Generating HMAC

slide-64
SLIDE 64

Generated HMAC

slide-65
SLIDE 65

Modifying the request

slide-66
SLIDE 66

All your CFMs belong...

slide-67
SLIDE 67
  • Bad Design?
  • Lack of understanding of principles why

and how salted hashes are used

Root Cause

slide-68
SLIDE 68

A GWT Aside

  • What is Google Web Toolkit?

– A way of writing a javascript front end in java – Converts java to javascript – Can produce fat clients – Uses a text based message format

slide-69
SLIDE 69

5|0| //protocol version and flags 7| //string table length http://localhost:8080/testproject/| 29F4EA1240F157649C12466F01F46F60| com.test.client.GreetingService| greetServer| java.lang.String| //data type myInput1| //user input myInput2| 1|2|3|4|2|5|5|6|7| // payload

slide-70
SLIDE 70

Fat Clients Problems

  • More processing happens on client
  • More “security” decisions are made
  • Tendency to work on client side security

model

slide-71
SLIDE 71

s/no/yes/

  • Client side security model
  • Client contained all the code to access

“Admin” functionality

  • Client asked server which functions it

could access

  • We can therefore lie to the client
slide-72
SLIDE 72

s/OK.0,..,0,7]/OK[1,[],0,7]/

slide-73
SLIDE 73
  • We now have admin access, but not to

all functionality

  • Shows inconsistent security controls

~Admin Access

slide-74
SLIDE 74

So what can we do?

  • Is there any interesting functionality?
  • Data export to “local” location
  • Original folder was

–c:\data\export\

slide-75
SLIDE 75

Windows Integration

  • We can control the export path
  • We can use a UNC path
  • No Local egress firewall
  • No Hosting environment egress firewall
  • Ended up with a complete copy of database,

inc.

– Login details – All client data – Other companies client data

slide-76
SLIDE 76

Take Homes - Attack

  • You can’t test properly logic flaws until

you know what is supposed to happen

  • Take inspiration from bugs found in non

web applications

  • Look for the cracks in applications
  • Tools can help but it’s hard graft and a

little flair that wins

slide-77
SLIDE 77

Take Homes - Defence

  • Make sure your security Team know the

intended functionality

  • Use frameworks consistently
  • Take care when integrating new

functionality

  • Make sure you understand technologies

being used

  • Use a Good SDLC integrating Pen Testing at

key stages not just the end

slide-78
SLIDE 78

Questions?

sid@pentest.7safe.com rid@portcullis-security.com