Skip to content

Commit c82b3fb

Browse files
committed
update web UI and bugfix for sanitizationHandler
1 parent c540d8c commit c82b3fb

26 files changed

+301
-169
lines changed

CFGGenerator.php

+21-22
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private function assignHandler($node,$block,$dataFlow,$type){
257257
}else{
258258
//检查是否为sink函数
259259
$this->functionHandler($part, $block, $this->fileSummary);
260-
260+
261261
//处理净化信息和编码信息
262262
SanitizationHandler::setSanitiInfo($part,$dataFlow, $block, $this->fileSummary) ;
263263
EncodingHandler::setEncodeInfo($part, $dataFlow, $block, $this->fileSummary) ;
@@ -520,7 +520,6 @@ public function functionHandler($node, $block, $fileSummary){
520520
$this->fileSummary->getIncludeMap()
521521
);
522522

523-
524523
//check
525524
if(!$funcBody || !is_object($funcBody)) return ;
526525

@@ -1144,36 +1143,36 @@ public function sinkTracebackBlock($argName,$block,$flowsNum){
11441143
}
11451144

11461145

1147-
//扫描漏洞类型
1148-
$scan_type = 'ALL';
1149-
echo "<pre>" ;
1146+
// //扫描漏洞类型
1147+
// $scan_type = 'ALL';
1148+
// echo "<pre>" ;
11501149

11511150

11521151
// //从用户那接受项目路径
1153-
// $project_path = 'E:/School_of_software/information_security/PHPVulScanner_project/simple-log_v1.3.12/upload/';
1152+
// $project_path = 'C:/Users/xyw55/Desktop/test/74cms_3.3';
11541153
// //$project_path = "D:/MySoftware/wamp/www/code/phpvulhunter/test/test.php" ;
11551154
// $allFiles = FileUtils::getPHPfile($project_path);
11561155
// //初始化
11571156
// $initModule = new InitModule() ;
11581157
// $initModule->init($project_path, $allFiles) ;
11591158

1159+
// echo '123';
1160+
// $cfg = new CFGGenerator() ;
1161+
// $visitor = new MyVisitor() ;
1162+
// $parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative) ;
1163+
// $traverser = new PhpParser\NodeTraverser ;
1164+
// $path = CURR_PATH . '/test/test.php';
1165+
// $cfg->getFileSummary()->setPath($path);
1166+
// $code = file_get_contents($path);
1167+
// $stmts = $parser->parse($code) ;
1168+
// $traverser->addVisitor($visitor) ;
1169+
// $traverser->traverse($stmts) ;
1170+
// $nodes = $visitor->getNodes() ;
1171+
// $pEntryBlock = new BasicBlock() ;
1172+
// $pEntryBlock->is_entry = true ;
1173+
// $ret = $cfg->CFGBuilder($nodes, NULL, NULL, NULL) ;
11601174

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) ;
1175-
1176-
1175+
//echo '456';
11771176

11781177

11791178

CodeViewer.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,20 @@
2121
}
2222

2323
// $fp = htmlspecialchars($fp); js按特定的方式处理子串,不需要html编码。
24+
// $in_charset = mb_detect_encoding($sink_fp) ;
25+
// $sink_fp = iconv($in_charset, "UTF-8", $sink_fp) ;
2426

27+
// if ($arg_fp){
28+
// $in_charset = mb_detect_encoding($arg_fp) ;
29+
// $arg_fp = iconv($in_charset, "UTF-8", $arg_fp) ;
30+
// }
2531
$data = array("flag"=>true, "msg_sink"=>$sink_fp, "msg_arg"=>$arg_fp);
2632

27-
$data = json_encode($data);
33+
// echo $sink_fp;
34+
35+
//$data = json_encode($data);
36+
37+
$data = '{"flag":true,"msg_sink":"'.$sink_fp.'","msg_arg":"'.$arg_fp.'"}';
2838

2939
echo $data;
3040

analyser/TaintAnalyser.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function getPrevBlocks($currBlock){
179179
}
180180
}else{
181181
//前驱节点有多个
182-
if(!in_array($blocks,$this->pathArr)){
182+
if(!in_array($blocks,$this->pathArr,true)){
183183
array_push($this->pathArr,$blocks) ;
184184
}
185185
}
Binary file not shown.
Binary file not shown.

data/resultConetxtSerialData/C__Users_xyw55_Desktop_test_74cms_3.3_admin

Whitespace-only changes.
Binary file not shown.

data/serialdata/C__Users_xyw55_Desktop_test_74cms_3.3

+1
Large diffs are not rendered by default.

data/serialdata/C__Users_xyw55_Desktop_test_she1.1_phpshe1.1

+1
Large diffs are not rendered by default.

data/serialdata/C__Users_xyw55_Desktop_test_simple-log_v1.3.1_upload

+1
Large diffs are not rendered by default.

main.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function convertResults($resContext){
127127
$fileName = str_replace('/', '_', $scan_path);
128128
$fileName = str_replace(':', '_', $fileName);
129129
$serialPath = CURR_PATH . "/data/resultConetxtSerialData/" . $fileName;
130-
130+
sleep(10);
131131
if (!is_file($serialPath)){
132132
//创建文件
133133
$fileHandler = fopen($serialPath, 'w');

symbols/SanitizationHandler.class.php

+23-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function setSanitiInfo($node, $dataFlow, $block, $fileSummary){
1919

2020
$dataFlows = $block->getBlockSummary()->getDataFlowMap();
2121
$sanitiInfo = self::SantiniFuncHandler($node, $fileSummary);
22-
22+
$sanitiInfo=null;
2323
if($sanitiInfo){
2424
$args = NodeUtils::getFuncParamsNode($node);
2525
if (count($args) > 0){
@@ -233,7 +233,7 @@ public static function SantiniFuncHandler($node, $fileSummary){
233233

234234
$funcBody = $context->getClassMethodBody($funcName, $path, $require_array);
235235
if(!$funcBody) return null;
236-
236+
237237
$visitor = new SanitiFunctionVisitor();
238238
$parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative) ;
239239
$traverser = new PhpParser\NodeTraverser ;
@@ -374,11 +374,13 @@ public function leaveNode(Node $node){
374374
$context = Context::getInstance() ;
375375
$funcBody = $context->getFunctionBody($this->funcName);
376376
if(!$funcBody) return null;
377+
377378
$nodes = $funcBody->stmts;
378379
$cfg = new CFGGenerator() ;
379380
$block = $cfg->CFGBuilder($nodes, NULL, NULL, NULL) ;
380381

381382
$ret = $this->sanitiMultiBlockHandler($node->expr,$block);
383+
382384
if ($ret[0]){
383385
$type = array_intersect($this->sanitiInfo['type'], $ret['type']);
384386
$this->sanitiInfo = array(true,'type'=>$type);
@@ -468,47 +470,55 @@ public function sanitiMultiBlockHandler($arg, $block, $flowsNum=0){
468470

469471
$flows = $block->getBlockSummary()->getDataFlowMap();
470472
//当前块flows没有遍历完
471-
if(count($flows) != $flowsNum)
473+
if(count($flows) != $flowsNum){
472474
return $this->sanitiTracebackBlock($arg, $block, $flowsNum);
473-
475+
}else {
476+
$flowsNum = 0;
477+
}
474478
if($blockList == null || count($blockList) == 0){
475479
return ;
476480
}
477481

478482
if(!is_array($blockList[0])){
479483
//如果不是平行结构
480484
$flows = $block->getBlockSummary()->getDataFlowMap();
481-
if(count($flows) == $flowsNum){
485+
if(!$flowsNum){
482486
$block = $blockList[0];
483487
$ret = $this->sanitiTracebackBlock($arg, $block, 0);
484488
return $ret;
485489
}
486490
$ret = $this->sanitiTracebackBlock($arg, $block, $flowsNum);
487491
return $ret;
488492
}else{
493+
489494
//平行结构
490495
//分别遍历每一个平行基本块及其以上,对得到的净化信息,合并共有的,返回
491496
global $SECURES_TYPE_ALL;
492497
$retarr = $SECURES_TYPE_ALL;
498+
$isFind = false;
493499
foreach ($blockList[0] as $block){
500+
494501
$flows = $block->getBlockSummary()->getDataFlowMap();
495-
if(count($flows) == $flowsNum){
502+
if(!$flowsNum){
503+
$ret = null;
496504
$ret = $this->sanitiTracebackBlock($arg, $block, 0);
497-
if ($ret[0])
505+
if ($ret[0]){
498506
$retarr = array_intersect($ret, $retarr);
499-
else
500-
return array(false);
507+
$isFind = true;
508+
}
501509
}else{
502510
$ret = $this->sanitiTracebackBlock($arg, $block, $flowsNum);
503511
if ($ret[0]){
504512
$retarr = array_intersect($ret['type'], $retarr);
513+
$isFind = true;
505514
}
506-
else
507-
return array(false);
508515
}
509516
}
510-
return array(true,'type'=>$retarr);
511-
517+
if ($isFind){
518+
return array(true,'type'=>$retarr);
519+
}else{
520+
return array(false);
521+
}
512522
}
513523

514524
}

test/test.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?php
2-
if(1){
3-
echo 1 ;
4-
}
5-
$id=intval($_GET['id']);
6-
$info=mysql_query("select * from ".table('members')." where uid='{$id}' LIMIT 1");
2+
define('IN_QISHI', true);
3+
require_once(dirname(__FILE__).'/../data/config.php');
4+
require_once(dirname(__FILE__).'/include/admin_common.inc.php');
5+
require_once(ADMIN_ROOT_PATH.'include/admin_article_fun.php');
6+
require_once(ADMIN_ROOT_PATH.'include/upload.php');
7+
8+
$article = get_news($offset, $perpage,$joinsql.$wheresql.$oederbysql);
79

8-
if(3){
9-
echo 3 ;
10-
}
1110

1211
?>

utils/multiBlockHandlerUtils.class.php

+40-41
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,46 @@ public function __construct($block){
1616
}
1717

1818
/**
19-
* 获取当前基本块的所有前驱基本块
20-
* @param BasicBlock $block
21-
* @return Array 返回前驱基本块集合$this->pathArr
22-
* 使用该方法时,需要对类属性$this->pathArr进行初始化
23-
*/
24-
public function getPrevBlocks($currBlock){
25-
if($currBlock != null){
26-
$blocks = array() ;
27-
$edges = $currBlock->getInEdges();
28-
29-
//如果到达了第一个基本块则返回
30-
if(!$edges) return $this->pathArr;
31-
32-
foreach ($edges as $edge){
33-
array_push($blocks, $edge->getSource()) ;
34-
}
35-
36-
if(count($blocks) == 1){
37-
//前驱的节点只有一个
38-
if(!in_array($blocks[0],$this->pathArr)){
39-
array_push($this->pathArr,$blocks[0]) ;
40-
}
41-
}else{
42-
//前驱节点有多个
43-
if(!in_array($blocks,$this->pathArr)){
44-
array_push($this->pathArr,$blocks) ;
45-
}
46-
}
47-
48-
//递归
49-
foreach($blocks as $bitem){
50-
if(!is_array($bitem)){
51-
$this->getPrevBlocks($bitem);
52-
}else{
53-
$this->getPrevBlocks($bitem[0]) ;
54-
}
55-
56-
}
57-
58-
}
59-
}
19+
* 获取当前基本块的所有前驱基本块
20+
* @param BasicBlock $block
21+
* @return Array 返回前驱基本块集合$this->pathArr
22+
* 使用该方法时,需要对类属性$this->pathArr进行初始化
23+
*/
24+
public function getPrevBlocks($currBlock){
25+
if($currBlock != null){
26+
$blocks = array() ;
27+
$edges = $currBlock->getInEdges();
28+
//如果到达了第一个基本块则返回
29+
if(!$edges) return $this->pathArr;
30+
31+
foreach ($edges as $edge){
32+
array_push($blocks, $edge->getSource()) ;
33+
}
34+
35+
if(count($blocks) == 1){
36+
//前驱的节点只有一个
37+
if(!in_array($blocks[0],$this->pathArr,true)){
38+
array_push($this->pathArr,$blocks[0]) ;
39+
}
40+
}else{
41+
//前驱节点有多个
42+
if(!in_array($blocks,$this->pathArr,true)){
43+
array_push($this->pathArr,$blocks) ;
44+
}
45+
}
46+
47+
//递归
48+
foreach($blocks as $bitem){
49+
if(!is_array($bitem)){
50+
$this->getPrevBlocks($bitem);
51+
}else{
52+
$this->getPrevBlocks($bitem[0]) ;
53+
}
54+
55+
}
56+
57+
}
58+
}
6059

6160
}
6261
?>

0 commit comments

Comments
 (0)