96
.lu software verification & validation V V S Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities Julian Thomé, Lwin Khin Shar and Lionel Briand 1

Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Embed Size (px)

Citation preview

Page 1: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

.lusoftware verification & validationVVS

Security Slicing for Auditing XML, XPath, and SQL Injection

VulnerabilitiesJulian Thomé, Lwin Khin Shar and Lionel Briand

1

Page 2: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 3: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 4: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 5: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 6: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 7: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 8: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 9: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Source

Page 10: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

req.getParameter("password");

Account :

Password:

Submit

Source

Page 11: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Sink

Page 12: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

NodeList nl = xpath.evaluate(q, doc, XPathConstants.NODESET);

String q = "/users/user[@nick='" + account + "' and @password='" + password + "']";

Sink

Page 13: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

password = req.getParameter("password");

Account :

Password:

Submit

XPath Injection

Page 14: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

password = req.getParameter("password");

Account :

Password:

Submit

test' or '1'='1

XPath Injection

Page 15: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Account :

Password:

Submit

test' or '1'='1

password = "test' or '1'='1";

XPath Injection

Page 16: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

password = "test' or '1'='1";

NodeList nl = xpath.evaluate(q, doc, XPathConstants.NODESET);

String q = "/users/user[@nick='" + account + "' and @password='" + password + "']";

XPath Injection

Page 17: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

NodeList nl = xpath.evaluate(q, doc, XPathConstants.NODESET);

String q = "/users/user[@nick='" + account + "' and @password='" + password + "']";

password = "test' or '1'='1";

XPath Injection

Page 18: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

NodeList nl = xpath.evaluate(q, doc, XPathConstants.NODESET);

String q = "/users/user[@nick='' and @password='test' or '1'='1']";

password = "test' or '1'='1";

XPath Injection

Page 19: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

NodeList nl = xpath.evaluate(q, doc, XPathConstants.NODESET);

String q = "/users/user[@nick='' and @password='test' or '1'='1']";

XPath Injection

Page 20: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

NodeList nl = xpath.evaluate( "/users/user[@nick='' and @password='test' or '1'='1']",doc, XPathConstants.NODESET);

XPath Injection

Page 21: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 22: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 23: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 24: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 25: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 26: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 27: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 28: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 29: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 30: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Taint Analysis

Page 31: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Taint Analysis

Focus on Integrity

No Filtering

False Positives

Page 32: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Security Slicing

Page 33: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 34: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

System Dependence Graph

Construction

Page 35: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Chopping

System Dependence Graph

Construction

Page 36: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Filtering

Chopping

Security Slices

System Dependence Graph

Construction

Page 37: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 38: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

// …

allowUser(req.getParameter(“account”), req.getParameter(“password”));// …

protected boolean allowUser(String account, String password) {

// …org.w3c.dom.Document doc = builder.parse("db.xml");// …XPath xpath = xPathfactory.newXPath();String q = "/database/table[@name='customers']/entry[@nick='"

+ account + "' and @password='" + password + "']";// …NodeList nl = (NodeList) xpath.evaluate(q,doc,

XPathConstants.NODESET);// …

}

Page 39: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Filtering

Chopping

SDG Construction

Security Slices

Page 40: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

“account”

getParameter()

account = getParameter()

fpar0 … ret

account

password = getParameter()

allowUser()

account password

password

… q= … nl = xpath.evaluate() …

evaluate()

apar0 …

fpar0 … ret

Page 41: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

“account”

getParameter()

account = getParameter()

fpar0 … ret

account

password = getParameter()

allowUser()

account password

password

… q= … nl = xpath.evaluate() …

evaluate()

apar0 …

fpar0 … ret

account

account password

password

q= …

apar0

Page 42: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

account

account password

password

q= …

apar0

Page 43: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

account

account password

password

q= …

apar0

Filtering

Chopping

SDG Construction

Security Slices

Page 44: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 45: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Declassification

Page 46: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

HH LL

HL

LH

Page 47: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

HH

LL

HL

LH

High ConfidentialityHigh Integrity

Low ConfidentialityHigh Integrity

Low ConfidentialityLow Integrity

High ConfidentialityLow Integrity

HH LLHL

LH

Page 48: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

HH LL

HL

LH

Secret

Page 49: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

HH LL

HL

LH

WritableSecret

Page 50: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

HH LL

HL

LH

WritableSecret

Page 51: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

HH LL

HL

LH

WritableSecret

Page 52: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

account

account password

password

q= …

apar0

Page 53: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

account

account password

password

q= …

apar0

HL HL

HH

HH LL

HL

LH

Page 54: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

account

account password

password

q= …

apar0

HL HL

HH

HH LL

HL

LH

Page 55: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 56: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

protected boolean allowUser(String account, String password) {

account = ESAPI.encoder().encodeForXPath(account);password = ESAPI.encoder().encodeForXPath(password);

// …org.w3c.dom.Document doc = builder.parse("db.xml");// …XPath xpath = xPathfactory.newXPath();String q = "/database/table[@name='customers']/entry[@nick='"

+ account + "' and @password='" + password + "']";// …NodeList nl = (NodeList) xpath.evaluate(q,doc,

XPathConstants.NODESET);// …

}

Page 57: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

“account”

getParameter()

account = getParameter()

fpar0 … ret

account

password = getParameter()

allowUser()

account password

password

… q= … nl = xpath.evaluate() …

encodeForXpath()

apar0 … ret

evaluate()

apar0 …

fpar0 … ret

HL HL

HH

HL HH

account

account password

password

q= …

apar0 … ret

apar0

HL HL

HH

HL HH

Page 58: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

HH LL

HL

LH

account

account password

password

q= …

apar0 … ret

apar0

HL HL

HH

HL HH

Page 59: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

account

account password

password

q= …

apar0 … ret

apar0

HL HL

HH

HL HH

HH LL

HL

LH

Page 60: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Known-Good Irrelevant

Page 61: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 62: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 63: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 64: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 65: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Automated Fixing

Page 66: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

protected boolean allowUser(String account, String password) {

// …org.w3c.dom.Document doc = builder.parse("db.xml");// …XPath xpath = xPathfactory.newXPath();String q = "/database/table[@name='customers']/entry[@nick='"

+ account + "' and @password='" + password + "']";// …NodeList nl = (NodeList) xpath.evaluate(q,doc,

XPathConstants.NODESET);// …

}

Page 67: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

password

password

q= …

apar0

HL

HH

Page 68: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

protected boolean allowUser(String account, String password) {// …org.w3c.dom.Document doc = builder.parse("db.xml");// …XPath xpath = xPathfactory.newXPath();

String q = "/database/table[@name=‘customers’]/entry[@nick='" + ESAPI.encoder().encodeForXPath(account) +

"' and @password='" + ESAPI.encoder().encodeForXPath(password) + "']";

// …NodeList nl = (NodeList) xpath.evaluate(q,doc,

XPathConstants.NODESET);// …

}

Page 69: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 70: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Filtering

Chopping

SDG Construction

Security Slices

Page 71: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Contributions

Page 72: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Filtering

Chopping

SDG Construction

Security Slices

Page 73: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Automatic detection of sources, sinks and declassifiers

Extensive library of sources, sinks and declassifiers

Page 74: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Filtering

Chopping

SDG Construction

Security Slices

Page 75: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Extraction of path conditions, control dependencies,

data dependencies

Threat Categorisation

Automatic annotation of sources, sinks and declassifiers

Page 76: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Filtering

Chopping

SDG Construction

Security Slices

Page 77: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Information Flow Control/ Declassification

Known-Good/Irrelevant

Automated Fixing

Page 78: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Filtering

Chopping

SDG Construction

Security Slices

Page 79: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Evaluation

Page 80: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Test SubjectsSubject KLOC #Servlets #Sources #Sinks #Declassifiers

XML XPath SQL XML XPath SQLWebGoat 24.6 14 40 3 1 29 0 0 25

Roller 52.4 3 14 13 0 0 11 0 0Pebble 36.5 3 6 7 0 0 3 0 0Regain 23.1 1 1 1 0 0 3 0 0PubSub 1.9 4 16 3 4 0 4 0 0

Page 81: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Comparison between Chopping and Security Slicing

#SDG

Nod

es

1

10

100

1000

10000

100000

1000000

WebGoat Roller Pebble Regain PubSub

SDG Construction Chopping Security Slicing

Page 82: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Comparison between Chopping and Security Slicing

#SDG

Nod

es

1

10

100

1000

10000

100000

1000000

SDG Construction Chopping Security Slicing

Total Mean Median

Page 83: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Chopping

SecSlicing

#Chops to be audited0 20 40 60 80

21

73

Page 84: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Execution Time in msSubject SDG

GenerationSource/SinkIdentification Chopping Filtering Total

WebGoat 124,301 504 12,266 694 137,765Roller 23,815 56 763 69 24,703Pebble 4,570 20 128 53 4,771Regain 44,311 40 285 30 44,666PubSub 39,213 85 965 153 40,416

Page 85: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Future Work

Page 86: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 87: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

String Operations + Path Conditions

Page 88: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Threat ModelsString Operations + Path Conditions

Page 89: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities

Threat Models

Constraint Solver

String Operations + Path Conditions

Page 90: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 91: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 92: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 93: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 94: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 95: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities
Page 96: Security Slicing for Auditing XML, XPath, and SQL Injection Vulnerabilities