using z ray for lightning
play

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


  1. Using Z-Ray for Lightning Fast Security Analysis Martin Bednorz ZendCon Las Vegas 2018 1

  2. Introduction 10+ years of web development experience ● IT security background ● Web application security ○ Incremental static code analysis ○ CTO / Co-Founder RIPS Technologies ● Static code analysis for security with strong focus on PHP ○ 2

  3. Usual Workflow 3

  4. Usual Workflow 4

  5. Usual Workflow 5

  6. Improved Workflow 6

  7. Improved Workflow Idea: Combine runtime information with static code analysis 7

  8. Static Code Analysis 8

  9. Simplified Approach Transform code into abstract syntax tree (AST) 9

  10. Simplified Approach $cookie = $_COOKIE['text']; Transform code into abstract syntax tree (AST) 10

  11. Simplified Approach $cookie = $_COOKIE['text']; $cookie = $_COOKIE['text']; Transform code into abstract syntax tree (AST) 11

  12. Simplified Approach $cookie = $_COOKIE['text']; $cookie = $_COOKIE['text']; Transform code into abstract syntax tree (AST) Assign var expr $cookie $_COOKIE variable array dim 'text' string 12

  13. Simplified Approach Split AST into basic blocks 13

  14. Simplified Approach Split AST into basic blocks Analyze data flow within each basic block ● 14

  15. Simplified Approach Split AST into basic blocks Analyze data flow within each basic block ● Summarize data flow in block and function summaries ● 15

  16. Simplified Approach Connect basic blocks to a control flow graph 16

  17. Simplified Approach Perform backwards-directed taint analysis for each sensitive sink 17

  18. Simplified Approach Perform backwards-directed taint analysis for each sensitive sink 18

  19. Context-Sensitive Taint Analysis 1 $id = $_POST['id']; 2 if (...) { 3 $id = (int)$id; 4 } else { 5 $id = htmlentities($id); 6 } 7 echo "<div id='$id'>..."; 19

  20. Context-Sensitive Taint Analysis $id = $_POST['id']; 1 $id = $_POST['id']; 2 if (...) { 3 $id = (int)$id; $id = (int)$id; $id = htmlentities($id); 4 } else { 5 $id = htmlentities($id); 6 } echo "<div id='$id'>..."; 7 echo "<div id='$id'>..."; 20

  21. Context-Sensitive Taint Analysis $id = $_POST['id']; Variable $id is used in sensitive sink Markup context: HTML attribute single-quoted $id = (int)$id; $id = htmlentities($id); echo "<div id='$id'>..."; 21

  22. Context-Sensitive Taint Analysis $id = $_POST['id']; Sanitized: integer only No further actions required $id = (int)$id; $id = htmlentities($id); echo "<div id='$id'>..."; 22

  23. Context-Sensitive Taint Analysis $id = $_POST['id']; Sanitizes only: “ < > $id = (int)$id; $id = htmlentities($id); echo "<div id='$id'>..."; 23

  24. Context-Sensitive Taint Analysis $id = $_POST['id']; Sanitizes only: “ < > Vulnerable: All user input allowed except characters stated above $id = (int)$id; $id = htmlentities($id); echo "<div id='$id'>..."; 24

  25. Results WordPress RCE ● Magento RCE ● Joomla! LDAP injection ● Moodle RCE ● wooCommerce PHP Object Injection ● Roundcube RCE ● phpMyAdmin RCE ● … ● Visit ripstech.com/vulndb for more 25

  26. Performance Wordpress (333 KLOC) 13m Magento (2.4 MLOC) 30m Joomla! (722 KLOC) 11m Moodle (2.2 MLOC) 39m 26

  27. Performance 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. 27

  28. Incremental Analysis State-of-the-art: Static analysis of only the code that changed ● Problem: function definition changes ● All call sites need reanalysis ○ If a function is called in a function, it needs reanalysis as well ○ Changed to global variables ○ .... ○ Average of only 50% scan time improvement in our experiments ● 28

  29. Boost Code Analysis with Z-Ray 29

  30. Z-Ray Available with Zend Server ● Runtime (dynamic) analysis ● Deep insights into your PHP application ● Inspect ○ Debug ○ Optimize ○ Many plugins and extensions available ● 30

  31. Z-Ray 31

  32. Execution Times 32

  33. Database Query Information 33

  34. Application-Specific Information 34

  35. Stacktrace 35

  36. Stacktrace - Used Files // page_a.php do_something(); // index.php include('functions.php'); switch($_GET['page']) { case 'a': include('page_a.php'); // page_b.php case 'b': include('export.php'); include('page_b.php'); do_something_export(); } 36

  37. Stacktrace - Used Files 37

  38. Stacktrace - Used Files index.php?page=a 38

  39. Stacktrace - Used Files index.php?page=b 39

  40. Stacktrace - Used Files 40

  41. Request Information 41

  42. Request Information - Performance 42

  43. Request Information - Performance 43

  44. Request Information - Performance 44

  45. Request Information - Performance 45

  46. Request Information - Performance 46

  47. Request Information - Performance 47

  48. Request Information - Performance admin(); user(); guest(); 48

  49. Example $id = $_POST['id']; 1 $id = $_POST['id']; 2 if (...) { 3 $id = (int)$id; $id = (int)$id; $id = htmlentities($id); 4 } else { 5 $id = htmlentities($id); 6 } echo "<div id='$id'>..."; 7 echo "<div id='$id'>..."; 49

  50. Example $id = $_POST['id']; 1 $id = $_POST['id']; 2 if (...) { 3 $id = (int)$id; $id = (int)$id; $id = htmlentities($id); 4 } else { 5 $id = htmlentities($id); 6 } echo "<div id='$id'>..."; 7 echo "<div id='$id'>..."; 50

  51. Example $id = $_POST['id']; 1 $id = $_POST['id']; 2 if (...) { 3 $id = (int)$id; $id = (int)$id; $id = htmlentities($id); 4 } else { 5 $id = htmlentities($id); 6 } echo "<div id='$id'>..."; 7 echo "<div id='$id'>..."; 51

  52. Example $id = $_POST['id']; 1 $id = $_POST['id']; 2 if (...) { 3 $id = (int)$id; $id = (int)$id; 4 } else { 5 $id = htmlentities($id); 6 } echo "<div id='$id'>..."; 7 echo "<div id='$id'>..."; 52

  53. Pitfall // ... if (!isset($_SESSION['id'])) { $_SESSION['id'] = select_id(); } select_from_db($_SESSION['id']); 53

  54. Pitfall // ... // ... if (!isset($_SESSION['id'])) { $_SESSION['id'] = select_id(); $_SESSION['id'] = select_id(); } select_from_db($_SESSION['id']); select_from_db($_SESSION['id']); 54

  55. Pitfall // ... // ... if (!isset($_SESSION['id'])) { $_SESSION['id'] = select_id(); $_SESSION['id'] = select_id(); } select_from_db($_SESSION['id']); select_from_db($_SESSION['id']); 55

  56. Pitfall // ... // ... if (!isset($_SESSION['id'])) { $_SESSION['id'] = select_id(); $_SESSION['id'] = select_id(); } select_from_db($_SESSION['id']); select_from_db($_SESSION['id']); 56

  57. Request Information - Verification 57

  58. Request Information - Verification http://mysite.com/search?category=book 58

  59. Request Information - Verification http://mysite.com/search?category=book&t= 59

  60. Request Information - Verification http://mysite.com/search?category=book&t= <script>alert(1);</script> 60

  61. Request Information - Verification http://mysite.com/search?category=book&t= ’ onclick=’alert(1);’ 61

  62. Prototype Integrate into already available Zend Server plugin ● Zend Server UI plugin ○ Scan deployed applications or virtual hosts ○ Full scans only ○ Zend Server Z-Ray plugin ● Scan single requests ○ Implement the most significant performance optimizations ○ 62

  63. Prototype Zend Server Plugin UI 63

  64. Prototype Add Z-Ray component to our plugin ● Access data via the Z-Ray API ○ Run first batch of optimizations ○ Zend Server Plugin Z-Ray API UI Z-Ray 64

  65. Prototype Add Z-Ray component to our plugin ● Access data via the Z-Ray API ○ Run first batch of optimizations ○ Send relevant source code to static code analysis tool ● Static Code Analysis Zend Server Plugin Z-Ray API UI Z-Ray 65

  66. Prototype Add Z-Ray component to our plugin ● Access data via the Z-Ray API ○ Run first batch of optimizations ○ Send relevant source code to static code analysis tool ● Extend taint analysis with data provided by Z-Ray ● Static Code Analysis Zend Server Plugin Z-Ray API UI Z-Ray Z-Ray 66

  67. Prototype Implementation 67

  68. Prototype Implementation Full scan ● ~2,4M Lines of Code ○ ~30 Minutes scan time ○ QuickScan ● ~70k Lines of Code ○ ~1 Minutes scan time ○ Can still be greatly improved ● 68

  69. Prototype Implementation Full scan ● ~2,4M Lines of Code ○ ~30 Minutes scan time ○ QuickScan ● ~70k Lines of Code ○ ~1 Minutes scan time ○ Can still be greatly improved ● 69

  70. Prototype Implementation Full scan ● ~2,4M Lines of Code ○ ~30 Minutes scan time ○ QuickScan ● ~70k Lines of Code ○ ~1 Minutes scan time ○ Can still be greatly improved ● 70

  71. Demo 71

Recommend


More recommend