Using Z-Ray for Lightning Fast Security Analysis
Martin Bednorz ZendCon Las Vegas 2018
1
Using Z-Ray for Lightning Fast Security Analysis Martin Bednorz - - PowerPoint PPT Presentation
Using Z-Ray for Lightning Fast Security Analysis Martin Bednorz ZendCon Las Vegas 2018 1 Introduction 10+ years of web development experience IT security background Web application security Incremental static code analysis
Martin Bednorz ZendCon Las Vegas 2018
1
○ Web application security ○ Incremental static code analysis
○ Static code analysis for security with strong focus on PHP
2
3
4
5
6
7
Idea: Combine runtime information with static code analysis
8
Transform code into abstract syntax tree (AST)
9
Transform code into abstract syntax tree (AST)
10
$cookie = $_COOKIE['text'];
Transform code into abstract syntax tree (AST)
11
$cookie = $_COOKIE['text']; $cookie = $_COOKIE['text'];
Transform code into abstract syntax tree (AST)
12
$cookie = $_COOKIE['text']; $cookie = $_COOKIE['text']; Assign $cookie $_COOKIE 'text'
variable array string var expr dim
Split AST into basic blocks
13
Split AST into basic blocks
14
Split AST into basic blocks
15
Connect basic blocks to a control flow graph
16
Perform backwards-directed taint analysis for each sensitive sink
17
Perform backwards-directed taint analysis for each sensitive sink
18
1 $id = $_POST['id']; 2 if (...) { 3 $id = (int)$id; 4 } else { 5 $id = htmlentities($id); 6 } 7 echo "<div id='$id'>...";
19
1 $id = $_POST['id']; 2 if (...) { 3 $id = (int)$id; 4 } else { 5 $id = htmlentities($id); 6 } 7 echo "<div id='$id'>...";
20
$id = $_POST['id']; $id = (int)$id; $id = htmlentities($id); echo "<div id='$id'>...";
21
$id = $_POST['id']; $id = (int)$id; $id = htmlentities($id); echo "<div id='$id'>..."; Variable $id is used in sensitive sink Markup context: HTML attribute single-quoted
22
$id = $_POST['id']; $id = (int)$id; $id = htmlentities($id); echo "<div id='$id'>..."; Sanitized: integer only No further actions required
23
$id = $_POST['id']; $id = (int)$id; $id = htmlentities($id); echo "<div id='$id'>..."; Sanitizes only: “ < >
24
$id = $_POST['id']; $id = (int)$id; $id = htmlentities($id); echo "<div id='$id'>..."; Sanitizes only: “ < > Vulnerable: All user input allowed except characters stated above
Visit ripstech.com/vulndb for more
25
26
Wordpress (333 KLOC) 13m Magento (2.4 MLOC) 30m Joomla! (722 KLOC) 11m Moodle (2.2 MLOC) 39m
27
Wordpress (333 KLOC) 13m Magento (2.4 MLOC) 30m Joomla! (722 KLOC) 11m Moodle (2.2 MLOC) 39m
Lightning fast compared to other SAST solutions that scan 8h or 1 week.
28
○ All call sites need reanalysis ○ If a function is called in a function, it needs reanalysis as well ○ Changed to global variables ○ ....
29
○ Inspect ○ Debug ○ Optimize
30
31
32
33
34
35
36
// index.php include('functions.php'); switch($_GET['page']) { case 'a': include('page_a.php'); case 'b': include('page_b.php'); } // page_a.php do_something(); // page_b.php include('export.php'); do_something_export();
37
38
index.php?page=a
39
index.php?page=b
40
41
42
43
44
45
46
47
48
admin(); user(); guest();
1 $id = $_POST['id']; 2 if (...) { 3 $id = (int)$id; 4 } else { 5 $id = htmlentities($id); 6 } 7 echo "<div id='$id'>...";
49
$id = $_POST['id']; $id = (int)$id; $id = htmlentities($id); echo "<div id='$id'>...";
1 $id = $_POST['id']; 2 if (...) { 3 $id = (int)$id; 4 } else { 5 $id = htmlentities($id); 6 } 7 echo "<div id='$id'>...";
50
$id = $_POST['id']; $id = (int)$id; $id = htmlentities($id); echo "<div id='$id'>...";
1 $id = $_POST['id']; 2 if (...) { 3 $id = (int)$id; 4 } else { 5 $id = htmlentities($id); 6 } 7 echo "<div id='$id'>...";
51
$id = $_POST['id']; $id = (int)$id; $id = htmlentities($id); echo "<div id='$id'>...";
1 $id = $_POST['id']; 2 if (...) { 3 $id = (int)$id; 4 } else { 5 $id = htmlentities($id); 6 } 7 echo "<div id='$id'>...";
52
$id = $_POST['id']; $id = (int)$id; echo "<div id='$id'>...";
// ... if (!isset($_SESSION['id'])) { $_SESSION['id'] = select_id(); } select_from_db($_SESSION['id']);
53
// ... if (!isset($_SESSION['id'])) { $_SESSION['id'] = select_id(); } select_from_db($_SESSION['id']);
54
// ... $_SESSION['id'] = select_id(); select_from_db($_SESSION['id']);
// ... if (!isset($_SESSION['id'])) { $_SESSION['id'] = select_id(); } select_from_db($_SESSION['id']);
55
// ... $_SESSION['id'] = select_id(); select_from_db($_SESSION['id']);
// ... if (!isset($_SESSION['id'])) { $_SESSION['id'] = select_id(); } select_from_db($_SESSION['id']);
56
// ... $_SESSION['id'] = select_id(); select_from_db($_SESSION['id']);
57
58
59
60
61
○ Zend Server UI plugin ○ Scan deployed applications or virtual hosts ○ Full scans only
○ Scan single requests ○ Implement the most significant performance optimizations
62
63
Zend Server Plugin UI
64
Zend Server Plugin UI Z-Ray Z-Ray API
○ Access data via the Z-Ray API ○ Run first batch of optimizations
65
Zend Server Plugin UI Z-Ray Z-Ray API Static Code Analysis
○ Access data via the Z-Ray API ○ Run first batch of optimizations
66
Zend Server Plugin UI Z-Ray Z-Ray API Static Code Analysis Z-Ray
○ Access data via the Z-Ray API ○ Run first batch of optimizations
67
○ ~2,4M Lines of Code ○ ~30 Minutes scan time
○ ~70k Lines of Code ○ ~1 Minutes scan time
68
○ ~2,4M Lines of Code ○ ~30 Minutes scan time
○ ~70k Lines of Code ○ ~1 Minutes scan time
69
○ ~2,4M Lines of Code ○ ~30 Minutes scan time
○ ~70k Lines of Code ○ ~1 Minutes scan time
70
71
○ Allows for a workflow similar to tests
○ Improve taint analysis with runtime information ○ Fix some of the pitfalls
72
73