you from trying to use source code scanner • Is TO SHARE my perspecMves when choosing a commercial soluMon • Is TO SHARE how to use available soluMons to build your own scanner
md5 issues, and maybe 19.9% others results in False PosiMve • Not much supports in the mobile apps – However most soluMons have funcMonaliMes which allows us to do some customizaMon
mobile apps became be^er • But all I did was increasing the keywords to look for, more sophisMcated checks could be customized, but that also increases our learning curve – Kind of makes me feel like just wriMng a grep script
false posiMve/ negaMve rate, maybe it is because of the small sample space • So I just googled 2 random XSS from phpmyadmin with a CVE number assigned – CVE-‐2008-‐4775 – CVE-‐2013-‐1937
specified in the CVE • But wait, maybe it is only because the source code of phpmyadmin are too complicated already – So I decided to scan just the code snippets for both XSS
the eval feature is deprecated, and thus should not be used, but sMll it’s everywhere and should be considered as a serious threat <?php $string = $_REQUEST[‘foo’]; $string = preg_replace('/(.*)/e', 'strtoupper($1)', $string); ?>
– False PosiMve/NegaMve Rate – Framework support issues – CustomizaMon issues – Need more support on Mobile applicaMons – Can’t detect simple pa^erns of XSS – No support for detecMng eval modifier • What I didn’t menMon – Code execuMon flow are prone to mistake • Probably more
we had expected, and will probably never be perfect • To understand more about it, I decided to write my own scanner and see – I targeted Android because that’s what I was mostly doing at that Mme
• Strategies – Grep ? – Build our own tree and parse through it ? – Write our own compiler ? • Or just take a look at what people are doing in the open source community
all node with the name “Nodename” • / : Select from the root node • // : Select node from the current node no ma^er where they are • . : Selects the current node • .. : Select the parent of the current node • [] : Predicates, used to find specific node or a node that contains a specific value
pmd Eclipse plugin uses the XML presented AST (Abstract Syntax Tree) generated by Eclipse, coming from the source code • Scans it with rulesets created by XPath :D
already a topic about using the PMD plugin – Teaching an old dog new tricks securing development with PMD – From the good people of Gotham Digital Science
!! • So I started study XPath, and created several dozens different rules – SSL cerMficaMon checks – Insecure storage – And more .. • 50% in Mme could be saved in actual projects, and sMll able to find most of the issues I found while doing it manually
PHP: PHP-‐Parser by nikic + XPath • Ruby: parser by whitequack + XPath • JavaScript: Esprima + Xpath • I decided to challenge PHP, because I want to know how hard it is to scan the 2 XSS I menMoned
check if htmlspecialchars() are used or not. • <?php htmlspecialchars($_GET[‘foo’]); ?> <node:Stmt_Echo> <node:Expr_FuncCall> <scalar:string>htmlspecialchars</scalar:string> <scalar:string>_GET</scalar:string> <scalar:string>foo</scalar:string> </node:Expr_FuncCall> </node:Stmt_Echo>
from $_REQUEST, and was assigned into a $GLOBAL variable //node:Stmt_Echo [.//scalar:string=preceding-‐sibling::node:* [.//scalar:string="GLOBALS"][.//scalar:string="_REQUEST"] //scalar:string] //scalar:string=.//scalar:string
following – DetecMng the 2 CVEs, and the simple code injecMon – Write rules in a W3C defined language • No need to learn a new set of API even with other languages like Java nor Ruby – Almost no cost, hey it is all online
are constraints in the current soluMon – Specific vs coverage – Can’t handle dynamically generated contents like the file path while calling include/require – Framework support – Template engine support • Smarty: scan the files in templates_c folder – AST largely depends on how good the parser is – Well, and no execuMon flow charts – Maybe more …