1
Security Testing
Checking for what shouldn’t happen
Azqa Nadeem
PhD Student @ Cyber Security Group
The Cyber Security lecture series
Security Testing Checking for what shouldnt happen Azqa Nadeem PhD - - PowerPoint PPT Presentation
Security Testing Checking for what shouldnt happen Azqa Nadeem PhD Student @ Cyber Security Group The Cyber Security lecture series 1 Agenda for today Part I Latest security news Security vulnerabilities in Java
1
Checking for what shouldn’t happen
PhD Student @ Cyber Security Group
The Cyber Security lecture series
2
– Latest security news – Security vulnerabilities in Java – Types of Security testing
– SAST under the hood
– SAST Tools performance
3
4
5
– Latest security news – Security vulnerabilities in Java – Types of Security testing
– SAST under the hood
– SAST Tools performance
6
7
https://ivan.barreraoro.com.ar/signal-desktop-html-tag-injection/
8
https://ivan.barreraoro.com.ar/signal-desktop-html-tag-injection/
9
https://thehackernews.com/2018/03/biggest-ddos-attack-github.html
10
https://thehackernews.com/2018/03/biggest-ddos-attack-github.html
Caused by misconfigured Memcached servers
11
– Java Virtual Machine – Libraries in native code
https://w3techs.com/technologies/details/pl-java/all/all
12
– Awareness document – Web application security
– U.S govt. repository – General security flaws
13
https://www.cvedetails.com/product/19116/Oracle-JDK.html?vendor_id=93
14
https://www.cvedetails.com/product/19116/Oracle-JDK.html?vendor_id=93
15
16
17
18
19
20
21
22
23
24
– Stop adding plugins – Limit privileges
25
https://www.thezdi.com/blog/2018/4/25/when-java-throws-you-a-lemon-make-limenade-sandbox-escape-by-type-confusion
26
https://www.thezdi.com/blog/2018/4/25/when-java-throws-you-a-lemon-make-limenade-sandbox-escape-by-type-confusion
27
https://access.redhat.com/security/cve/cve-2014-3558
28
https://access.redhat.com/security/cve/cve-2014-3558
Java Security Manager
29
https://access.redhat.com/security/cve/cve-2014-3558
Java Security Manager
30
https://access.redhat.com/security/cve/cve-2014-3558
Java Security Manager
31
https://access.redhat.com/security/cve/cve-2014-3558
Java Security Manager
32
– Set JSM to null
https://access.redhat.com/security/cve/cve-2014-3558
Java Security Manager
33
– Set JSM to null
https://access.redhat.com/security/cve/cve-2014-3558
Java Security Manager
34
https://access.redhat.com/security/cve/cve-2013-7285
35
https://access.redhat.com/security/cve/cve-2013-7285
36
https://access.redhat.com/security/cve/cve-2013-7285
37
– Via malicious input XML
https://access.redhat.com/security/cve/cve-2013-7285
38
– Via malicious input XML
https://access.redhat.com/security/cve/cve-2013-7285
39
https://pivotal.io/security/cve-2018-1273
40
https://pivotal.io/security/cve-2018-1273
41
https://pivotal.io/security/cve-2018-1273
42
– Via specially crafted request parameters
https://pivotal.io/security/cve-2018-1273
43 https://www.waratek.com/alert-oracle-guidance-cpu-april-2018/
44
Attack surface Exploit
45 https://www.dignitasdigital.com/blog/easy-way-to-understand-sdlc/
Risk assessment & Abuse cases Threat modelling Design for security Secure implementation Security testing & Code reviews Patching & Updating
SECURE
46
Manual Automated
47
Manual Automated Static Dynamic
48
Manual Automated Static Dynamic Blackbox Whitebox
49
Manual Automated Static Dynamic Blackbox Whitebox
Reverse Engineering Risk Analysis Code checking Tainting Fuzzing Dynamic validation Penetration testing
50
– Code reviews – Efficient use of human expertise – Labour intensive
51
– Code reviews – Efficient use of human expertise – Labour intensive
– Automated code checking – Can check MLOC in seconds – Incomparable to human expertise
52
Manual Automated Static Dynamic Blackbox Whitebox
Reverse Engineering Risk Analysis Code checking Tainting Fuzzing Dynamic validation Penetration testing
53
– Code review by computers – Checks all possible code paths – Relatively easy to extract results – Limited capabilities
54
– Code review by computers – Checks all possible code paths – Relatively easy to extract results – Limited capabilities
– Execute code and observe behaviour – Checks functional code paths only – Much advanced analysis – Difficult to set up
55
Manual Automated Static Dynamic Blackbox Whitebox
Reverse Engineering Risk Analysis Code checking Tainting Fuzzing Dynamic validation Penetration testing
56
– Unknown internal structure – Study Input → Output correlation – Generic technique – Requires end-to-end system – May miss components
57
– Unknown internal structure – Study Input → Output correlation – Generic technique – Requires end-to-end system – May miss components
– Known internal structure – Analysis of internal structure – GUI not necessarily required – Thorough testing and debugging – Time consuming
58
Manual Automated Static Dynamic Blackbox Whitebox
Reverse Engineering Risk Analysis Code checking Tainting Fuzzing Dynamic validation Penetration testing
59
– Disassemble application to extract internal structure – Black box to White box – Useful for gaining information
60
– Model worst case scenarios – Threat modelling for test case generation
61
– Checks for rule violations via code structure – Parsers, Control Flow graphs, Data flow analysis – Identifies bad coding practices, potential security issues, etc.
62
Manual Automated Static Dynamic Blackbox Whitebox
Reverse Engineering Risk Analysis Code checking Tainting Fuzzing Dynamic validation Penetration testing
63
– Tracking variable values controlled by user
– Bombard with garbage data to cause crashes
– Functional testing based on requirements
– End-to-end black box testing
Topic for next lecture
64
65
Which type of testing aims to convert a black box system to white box? Reverse Engineering
66
Which vulnerability allows a remote attacker to change which instruction will be executed next? Remote Code Execution
67
Why is Java safe from buffer overflows? It’s not!
68
– Latest security news – Security vulnerabilities in Java – Types of Security testing
– SAST under the hood
– SAST Tools performance
69
Why doesn’t the perfect static analysis tool exist?
70
71
– No missed vulnerability (0 FNs) – No alarm → no vulnerability exists
72
– No missed vulnerability (0 FNs) – No alarm → no vulnerability exists
– No false alarms (0 FPs) – Raises an alarm → vulnerability found
73
– No missed vulnerability (0 FNs) – No alarm → no vulnerability exists
– No false alarms (0 FPs) – Raises an alarm → vulnerability found
74
75
Pattern matching Regular expressions
76
Pattern matching Syntax analysis Abstract Syntax Tree Control flow graph Data flow analysis Regular expressions
77
– Regular Expressions – Finite State Automata
78
– Regular Expressions – Finite State Automata
b u g !b !u !g
79
– Regular Expressions – Finite State Automata
b u g !b !u !g
80
– Regular Expressions – Finite State Automata
b u g !b !u !g
81
– Regular Expressions – Finite State Automata
b u g !b !u !g
82
– Regular Expressions – Finite State Automata
b u g !b !u !g
83
– Regular Expressions – Finite State Automata
b u g !b !u !g
84
– Regular Expressions – Finite State Automata
b u g !b !u !g
Match!
85
– Regular Expressions – Finite State Automata
b u g !b !u !g
86
– Regular Expressions – Finite State Automata
b u g !b !u !g
87
– Regular Expressions – Finite State Automata
b u g !b !u !g
88
– Regular Expressions – Finite State Automata
b u g !b !u !g
89
– Regular Expressions – Finite State Automata
b u g !b !u !g No Match!
90
– Regular Expressions – Finite State Automata
b u g !u !g !b
91
– Regular Expressions – Finite State Automata
b u g !u !g !b
92
– Regular Expressions – Finite State Automata
b u g !u !g !b anything
93
– Misconfigurations (port 22 open for everyone) – Bad imports (System.io.*) – Call to dangerous functions (strcpy, memcpy)
94
– Misconfigurations (port 22 open for everyone) – Bad imports (System.io.*) – Call to dangerous functions (strcpy, memcpy)
– Lots of FPs – Limited support
95
– Misconfigurations (port 22 open for everyone) – Bad imports (System.io.*) – Call to dangerous functions (strcpy, memcpy)
– Lots of FPs – Limited support
96
– Misconfigurations (port 22 open for everyone) – Bad imports (System.io.*) – Call to dangerous functions (strcpy, memcpy)
– Lots of FPs – Limited support
97
– Parse Tree – Concrete representation – Abstract Syntax Tree – Abstract representation
Lexer Parser
Stream Tokens Parse Tree
98
99
100
5 1 SUB
101
5 1 MUL 4 SUB
102
5 1 MUL 4 SUM 2 SUB
103
104
105
= DEBUG false
106
if = DEBUG false
107
if = DEBUG false cond EQ true DEBUG
108
if = DEBUG false cond EQ true DEBUG body Println() Debug line 1 Println() Debug line 2 Println() Debug line 3
109
if = DEBUG false cond EQ true DEBUG body Println() Debug line 1 Println() Debug line 2 Println() Debug line 3
110
SAST Tool
Errors AST Ruleset
111
SAST Tool
Errors
Rule # 1: Allow 3 methods
AST Ruleset
112
SAST Tool
Errors
Rule # 1: Allow 3 methods
AST Ruleset
113
SAST Tool
Errors xyz() abc() akw() blah() class methods members
Rule # 1: Allow 3 methods
AST Ruleset
114
SAST Tool
Errors xyz() abc() akw() blah() class methods members
Rule # 1: Allow 3 methods Error: Too many methods!
AST Ruleset
115
Rule # 2: printf(format_string, args_to_print) SAST Tool
Errors AST Ruleset
116
Rule # 2: printf(format_string, args_to_print) SAST Tool
Errors AST Ruleset
117
Rule # 2: printf(format_string, args_to_print)
func x printf = Hello World! x
SAST Tool
Errors AST Ruleset
118
Rule # 2: printf(format_string, args_to_print) Error: Missing param!
func x printf = Hello World! x
SAST Tool
Errors AST Ruleset
119
https://dzone.com/articles/how-draw-control-flow-graph
120
If-then-else while case
https://dzone.com/articles/how-draw-control-flow-graph
121
122
123
124
T
125
T
126
T F
127
T F
n=?
Only traces control
128
T F
n=?
Only traces control
129
T F
n=?
Only traces control
130
T F
n=?
Only traces control
131
T F
n=?
Only traces control
132
T F
n=?
Only traces control
133
T F
n=?
Only traces control
134
T F
n=?
Only traces control
135
136
– No untainted data is expected – No tainted data is used
137
– No untainted data is expected – No tainted data is used
SQL st. Sink: Database Source: Contact
138
– No untainted data is expected – No tainted data is used
SQL st. Sink: Database Source: Contact ‘ or 1=1#
139
data is tainted println() expects untainted
140
– Top-down approach – Possible values of a variable
141
– Top-down approach – Possible values of a variable
142
– Top-down approach – Possible values of a variable
143
– Top-down approach – Possible values of a variable
144
– Top-down approach – Possible values of a variable
145
– Top-down approach – Possible values of a variable
146
– Top-down approach – Possible values of a variable
147
– Top-down approach – Possible values of a variable
148
– Top-down approach – Possible values of a variable
149
– Top-down approach – Possible values of a variable
150
151
b1 b2 b3 b4 b5 b6
152
a b c b1
b2 0, a++
b6
b2 b3 b4 b5 b6
153
a b c b1
b2 0, a++
b6
b2 b3 b4 b5 b6
154
a b c b1
b2 0, a++
b6
b2 b3 b4 b5 b6
155
a b c b1
b2 0, a++
b6
b2 b3 b4 b5 b6
156
a b c b1
b2 0, a++
b6
b2 b3 b4 b5 b6
157
a b c b1
b2 0, a++
b6
b2 b3 b4 b5 b6
158
a b c b1
b2 0, a++
b6
b2 b3 b4 b5 b6
159
a b c b1
b2 0, a++
b6
b2 b3 b4 b5 b6
a = {0, 1, 2, 3, …} b = {0, 10} c = {1, b} → {0, 1, 10} Data Flow Analysis
160
a b c b1
b2 0, a++
b6
b2 b3 b4 b5 b6
a = {0, 1, 2, 3, …} b = {0, 10} c = {1, b} → {0, 1, 10} Data Flow Analysis
161
a b c b1
b2 0, a++
b6
b2 b3 b4 b5 b6
a = {0, 1, 2, 3, …} b = {0, 10} c = {1, b} → {0, 1, 10} Data Flow Analysis
162
a b c b1
b2 0, a++
b6
b2 b3 b4 b5 b6
a = {0, 1, 2, 3, …} b = {0, 10} c = {1, b} → {0, 1, 10} Data Flow Analysis
163
a b c b1
b2 0, a++
b6
b2 b3 b4 b5 b6
a = {0, 1, 2, 3, …} b = {0, 10} c = {1, b} → {0, 1, 10} Data Flow Analysis
164
a b c b1
b2 0, a++
b6
b2 b3 b4 b5 b6
a = {0, 1, 2, 3, …} b = {0, 10} c = {1, b} → {0, 1, 10} Data Flow Analysis Sound but imprecise
165
166
– Sanitization problems – Code injection (Update attack) – Deserialization vulnerability
167
– Sanitization problems – Code injection (Update attack) – Deserialization vulnerability
168
– Sanitization problems – Code injection (Update attack) – Deserialization vulnerability
– Type confusion vulnerability – Use-after-free vulnerability
169
– Sanitization problems – Code injection (Update attack) – Deserialization vulnerability
– Type confusion vulnerability – Use-after-free vulnerability
170
– – – SpotBugs – FindSecBugs
– Coverity – CheckMarx
171
–
–
– SpotBugs
– FindSecBugs
– Coverity
– CheckMarx
172
–
–
– SpotBugs
– FindSecBugs
– Coverity
– CheckMarx
173
174
175
176
177
sometimes complains about issues that are not really issues...”
hug after fixing SonarQube reports...”
178
sometimes complains about issues that are not really issues...”
hug after fixing SonarQube reports...”
179
problems
vulnerabilities
– Useful – Difficult to integrate – Limited in capabilities
180
SQL-and-LDAP-injections
them
Familial Classification." Nordic Conference on Secure IT Systems. Springer, Cham, 2018.
Icons courtesy: www.flaticons.com by FlatIcons, FreePik, SmashIcons, Eucalyp, Monkik
181
182
Control
183
Control Data
184
Control Data a ← {0} a ← {7} a ← {0, 7}
185
code on vulnerable installations of Oracle Java. The user must visit a malicious page or open a malicious file to exploit this vulnerability.
in insufficient validation of supplied image data inside the native function readImage(). An attacker can leverage this vulnerability to execute arbitrary code under the context of the current process.
https://www.zerodayinitiative.com/advisories/ZDI-16-032/