Skip to content

Commit 82b78e4

Browse files
author
exploit
committed
bugfix for taint analyser
1 parent c540d8c commit 82b78e4

File tree

38 files changed

+141
-129
lines changed

38 files changed

+141
-129
lines changed

CFGGenerator.php

+34-30
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public function getBranches($node){
8787
$catch_branch = new Branch($catch->type, $catch->stmts) ;
8888
array_push($branches, $catch_branch) ;
8989
}
90-
9190
break ;
9291

9392
case 'Expr_Ternary':
@@ -276,6 +275,12 @@ private function assignHandler($node,$block,$dataFlow,$type){
276275
if($part && $part->getType() == "Expr_Ternary"){
277276
BIFuncUtils::ternaryHandler($type, $part, $dataFlow) ;
278277
}
278+
279+
//处理双引号中包含的变量
280+
if($part && $part->getType() == "Scalar_Encapsed"){
281+
$symbol = SymbolUtils::getSymbolByNode($part) ;
282+
$dataFlow->setValue($symbol) ;
283+
}
279284

280285

281286
}//else
@@ -485,7 +490,8 @@ public function functionHandler($node, $block, $fileSummary){
485490
$funcName = NodeUtils::getNodeFunctionName($node);
486491
//判断是否为sink函数,返回格式为array(true,funcname) or array(false)
487492
$ret = NodeUtils::isSinkFunction($funcName, $scan_type);
488-
if($ret[0] != null){
493+
494+
if($ret[0] != null && $ret[0] === true){
489495
//如果发现了sink调用,启动污点分析
490496
$analyser = new TaintAnalyser() ;
491497
//获取危险参数的位置
@@ -495,7 +501,6 @@ public function functionHandler($node, $block, $fileSummary){
495501
}
496502
//获取到危险参数位置的变量
497503
$argArr = NodeUtils::getFuncParamsByPos($node, $argPosition);
498-
499504
//遍历危险参数名,调用污点分析函数
500505
if(count($argArr) > 0){
501506
foreach ($argArr as $item){
@@ -511,16 +516,14 @@ public function functionHandler($node, $block, $fileSummary){
511516

512517
}
513518
}else{
514-
515519
//如果不是sink调用,启动过程间分析
516520
$context = Context::getInstance() ;
517521
$funcBody = $context->getClassMethodBody(
518522
$funcName,
519523
$this->fileSummary->getPath(),
520524
$this->fileSummary->getIncludeMap()
521525
);
522-
523-
526+
524527
//check
525528
if(!$funcBody || !is_object($funcBody)) return ;
526529

@@ -559,9 +562,10 @@ public function functionHandler($node, $block, $fileSummary){
559562
if($funcBody->getType() == "Stmt_ClassMethod"){
560563
$funcBody->stmts = $funcBody->stmts[0] ;
561564
}
562-
565+
563566
//构建相应方法体的block和summary
564567
$nextblock = $this->CFGBuilder($funcBody->stmts, NULL, NULL, NULL) ;
568+
565569
//ret危险参数的位置比如:array(0)
566570
$ret = $this->sinkFunctionHandler($funcBody, $nextblock, $block);
567571

@@ -767,8 +771,8 @@ public function CFGBuilder($nodes,$condition,$pEntryBlock,$pNextBlock){
767771
//print_r($currBlock->getBlockSummary()) ;
768772
return $currBlock ;
769773
}else{
770-
$currBlock->addNode($node);
771-
//print_r($currBlock->getBlockSummary()) ;
774+
$currBlock->addNode($node);
775+
//print_r($currBlock->getBlockSummary()) ;
772776
}
773777
}
774778

@@ -1025,10 +1029,9 @@ public function leaveNode(Node $node){
10251029
* @return array
10261030
*/
10271031
public function sinkMultiBlockTraceback($argName,$block,$flowsNum=0){
1028-
//print_r("enter sinkMultiBlockTraceback<br/>");
10291032
$mulitBlockHandlerUtils = new multiBlockHandlerUtils($block);
10301033
$blockList = $mulitBlockHandlerUtils->getPathArr();
1031-
1034+
10321035
$flows = $block->getBlockSummary()->getDataFlowMap();
10331036
//当前块flows没有遍历完
10341037
if(count($flows) != $flowsNum)
@@ -1144,34 +1147,35 @@ public function sinkTracebackBlock($argName,$block,$flowsNum){
11441147
}
11451148

11461149

1147-
//扫描漏洞类型
1148-
$scan_type = 'ALL';
1149-
echo "<pre>" ;
1150-
1150+
// //扫描漏洞类型
1151+
// $scan_type = 'ALL';
1152+
// echo "<pre>" ;
11511153

11521154
// //从用户那接受项目路径
11531155
// $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/" ;
11551158
// $allFiles = FileUtils::getPHPfile($project_path);
1159+
11561160
// //初始化
11571161
// $initModule = new InitModule() ;
11581162
// $initModule->init($project_path, $allFiles) ;
11591163

11601164

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) ;
11751179

11761180

11771181

0 commit comments

Comments
 (0)