@@ -87,7 +87,6 @@ public function getBranches($node){
87
87
$ catch_branch = new Branch ($ catch ->type , $ catch ->stmts ) ;
88
88
array_push ($ branches , $ catch_branch ) ;
89
89
}
90
-
91
90
break ;
92
91
93
92
case 'Expr_Ternary ' :
@@ -276,6 +275,12 @@ private function assignHandler($node,$block,$dataFlow,$type){
276
275
if ($ part && $ part ->getType () == "Expr_Ternary " ){
277
276
BIFuncUtils::ternaryHandler ($ type , $ part , $ dataFlow ) ;
278
277
}
278
+
279
+ //处理双引号中包含的变量
280
+ if ($ part && $ part ->getType () == "Scalar_Encapsed " ){
281
+ $ symbol = SymbolUtils::getSymbolByNode ($ part ) ;
282
+ $ dataFlow ->setValue ($ symbol ) ;
283
+ }
279
284
280
285
281
286
}//else
@@ -485,7 +490,8 @@ public function functionHandler($node, $block, $fileSummary){
485
490
$ funcName = NodeUtils::getNodeFunctionName ($ node );
486
491
//判断是否为sink函数,返回格式为array(true,funcname) or array(false)
487
492
$ ret = NodeUtils::isSinkFunction ($ funcName , $ scan_type );
488
- if ($ ret [0 ] != null ){
493
+
494
+ if ($ ret [0 ] != null && $ ret [0 ] === true ){
489
495
//如果发现了sink调用,启动污点分析
490
496
$ analyser = new TaintAnalyser () ;
491
497
//获取危险参数的位置
@@ -495,7 +501,6 @@ public function functionHandler($node, $block, $fileSummary){
495
501
}
496
502
//获取到危险参数位置的变量
497
503
$ argArr = NodeUtils::getFuncParamsByPos ($ node , $ argPosition );
498
-
499
504
//遍历危险参数名,调用污点分析函数
500
505
if (count ($ argArr ) > 0 ){
501
506
foreach ($ argArr as $ item ){
@@ -511,16 +516,14 @@ public function functionHandler($node, $block, $fileSummary){
511
516
512
517
}
513
518
}else {
514
-
515
519
//如果不是sink调用,启动过程间分析
516
520
$ context = Context::getInstance () ;
517
521
$ funcBody = $ context ->getClassMethodBody (
518
522
$ funcName ,
519
523
$ this ->fileSummary ->getPath (),
520
524
$ this ->fileSummary ->getIncludeMap ()
521
525
);
522
-
523
-
526
+
524
527
//check
525
528
if (!$ funcBody || !is_object ($ funcBody )) return ;
526
529
@@ -559,9 +562,10 @@ public function functionHandler($node, $block, $fileSummary){
559
562
if ($ funcBody ->getType () == "Stmt_ClassMethod " ){
560
563
$ funcBody ->stmts = $ funcBody ->stmts [0 ] ;
561
564
}
562
-
565
+
563
566
//构建相应方法体的block和summary
564
567
$ nextblock = $ this ->CFGBuilder ($ funcBody ->stmts , NULL , NULL , NULL ) ;
568
+
565
569
//ret危险参数的位置比如:array(0)
566
570
$ ret = $ this ->sinkFunctionHandler ($ funcBody , $ nextblock , $ block );
567
571
@@ -767,8 +771,8 @@ public function CFGBuilder($nodes,$condition,$pEntryBlock,$pNextBlock){
767
771
//print_r($currBlock->getBlockSummary()) ;
768
772
return $ currBlock ;
769
773
}else {
770
- $ currBlock ->addNode ($ node );
771
- //print_r($currBlock->getBlockSummary()) ;
774
+ $ currBlock ->addNode ($ node );
775
+ //print_r($currBlock->getBlockSummary()) ;
772
776
}
773
777
}
774
778
@@ -1025,10 +1029,9 @@ public function leaveNode(Node $node){
1025
1029
* @return array
1026
1030
*/
1027
1031
public function sinkMultiBlockTraceback ($ argName ,$ block ,$ flowsNum =0 ){
1028
- //print_r("enter sinkMultiBlockTraceback<br/>");
1029
1032
$ mulitBlockHandlerUtils = new multiBlockHandlerUtils ($ block );
1030
1033
$ blockList = $ mulitBlockHandlerUtils ->getPathArr ();
1031
-
1034
+
1032
1035
$ flows = $ block ->getBlockSummary ()->getDataFlowMap ();
1033
1036
//当前块flows没有遍历完
1034
1037
if (count ($ flows ) != $ flowsNum )
@@ -1144,34 +1147,35 @@ public function sinkTracebackBlock($argName,$block,$flowsNum){
1144
1147
}
1145
1148
1146
1149
1147
- //扫描漏洞类型
1148
- $ scan_type = 'ALL ' ;
1149
- echo "<pre> " ;
1150
-
1150
+ // //扫描漏洞类型
1151
+ // $scan_type = 'ALL';
1152
+ // echo "<pre>" ;
1151
1153
1152
1154
// //从用户那接受项目路径
1153
1155
// $project_path = 'E:/School_of_software/information_security/PHPVulScanner_project/simple-log_v1.3.12/upload/';
1154
- // //$project_path = "D:/MySoftware/wamp/www/code/phpvulhunter/test/test.php" ;
1156
+ // $project_path = "D:/MySoftware/wamp/www/code/phpvulhunter/test/test.php" ;
1157
+ // $project_path = "E:/School_of_software/information_security/PHPVulScanner_project/74cms_3.3/" ;
1155
1158
// $allFiles = FileUtils::getPHPfile($project_path);
1159
+
1156
1160
// //初始化
1157
1161
// $initModule = new InitModule() ;
1158
1162
// $initModule->init($project_path, $allFiles) ;
1159
1163
1160
1164
1161
- $ cfg = new CFGGenerator () ;
1162
- $ visitor = new MyVisitor () ;
1163
- $ parser = new PhpParser \Parser (new PhpParser \Lexer \Emulative ) ;
1164
- $ traverser = new PhpParser \NodeTraverser ;
1165
- $ path = CURR_PATH . '/test/test.php ' ;
1166
- $ cfg ->getFileSummary ()->setPath ($ path );
1167
- $ code = file_get_contents ($ path );
1168
- $ stmts = $ parser ->parse ($ code ) ;
1169
- $ traverser ->addVisitor ($ visitor ) ;
1170
- $ traverser ->traverse ($ stmts ) ;
1171
- $ nodes = $ visitor ->getNodes () ;
1172
- $ pEntryBlock = new BasicBlock () ;
1173
- $ pEntryBlock ->is_entry = true ;
1174
- $ ret = $ cfg ->CFGBuilder ($ nodes , NULL , NULL , NULL ) ;
1165
+ // $cfg = new CFGGenerator() ;
1166
+ // $visitor = new MyVisitor() ;
1167
+ // $parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative) ;
1168
+ // $traverser = new PhpParser\NodeTraverser ;
1169
+ // $path = CURR_PATH . '/test/test.php';
1170
+ // $cfg->getFileSummary()->setPath($path);
1171
+ // $code = file_get_contents($path);
1172
+ // $stmts = $parser->parse($code) ;
1173
+ // $traverser->addVisitor($visitor) ;
1174
+ // $traverser->traverse($stmts) ;
1175
+ // $nodes = $visitor->getNodes() ;
1176
+ // $pEntryBlock = new BasicBlock() ;
1177
+ // $pEntryBlock->is_entry = true ;
1178
+ // $ret = $cfg->CFGBuilder($nodes, NULL, NULL, NULL) ;
1175
1179
1176
1180
1177
1181
0 commit comments