Skip to content

Commit 7321025

Browse files
author
exploit
committed
Updated for the type of symbol
处理赋值时,当使用强制类型转换时,直接将type设置为int, 在污点分析中,如果type != string 或者valueInt,则视为安全。
1 parent 93b2392 commit 7321025

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

CFGGenerator.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,11 @@ private function assignHandler($node,$block,$dataFlow,$type){
246246
$dataFlow->setValue($concat) ;
247247
}
248248
}else{
249-
//不属于已有的任何一个symbol类型,如函数调用
249+
//不属于已有的任何一个symbol类型,如函数调用,类型转换
250250
if($part && ($part->getType() == "Expr_FuncCall" ||
251251
$part->getType() == "Expr_MethodCall" ||
252-
$part->getType() == "Expr_StaticCall") ){
252+
$part->getType() == "Expr_StaticCall" ) ){
253+
253254
//处理 id = urlencode($_GET['id']) ;
254255
if(!SymbolUtils::isValue($part)){
255256
$funcName = NodeUtils::getNodeFunctionName($part) ;
@@ -280,18 +281,24 @@ private function assignHandler($node,$block,$dataFlow,$type){
280281
EncodingHandler::setEncodeInfo($part, $dataFlow, $block, $this->fileSummary) ;
281282
}
282283
}
283-
284-
285-
286-
//处理内置函数
287-
284+
285+
}
286+
287+
//处理类型强制转换
288+
if($part
289+
&& ($part->getType() == "Expr_Cast_Int" || $part->getType() == "Expr_Cast_Double")
290+
&& $type == "right"){
291+
$dataFlow->getLocation()->setType("int") ;
292+
$symbol = SymbolUtils::getSymbolByNode($part->expr) ;
293+
$dataFlow->setValue($symbol) ;
288294
}
289295

290296
//处理三元表达式
291297
if($part && $part->getType() == "Expr_Ternary"){
292298
BIFuncUtils::ternaryHandler($type, $part, $dataFlow) ;
293299
}
294-
}
300+
301+
}//else
295302

296303
//处理完一条赋值语句,加入DataFlowMap
297304
if($type == "right"){

analyser/SqliAnalyser.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private function check_sanitization($var,$saniArr){
5151
}
5252

5353
//数值型注入,转义无效
54-
if($var->getType() == "int" && in_array("addslashes", $saniArr)){
54+
if($var->getType() == "valueInt" && in_array("addslashes", $saniArr)){
5555
return false ;
5656
}
5757

analyser/TaintAnalyser.class.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,16 @@ public function addTypeByVars(&$vars){
112112
continue ;
113113
}
114114
//判断是否被单引号包裹
115-
116115
$is_start_with = $this->startWith($vars[$i-1]->getValue(), "'");
117116
$is_end_with = $this->endsWith($vars[$i+1]->getValue(), "'") ;
118117

119118
if($is_start_with != -1 && $is_end_with != -1){
120-
$vars[$i]->setType("int") ;
119+
$vars[$i]->setType("valueInt") ;
121120
}
122121
}else{
123122
//如果没有前驱和后继 ,即为开头和结尾,且为var类型,直接设为int
124123
if($vars[$i] instanceof VariableSymbol){
125-
$vars[$i]->setType("int") ;
124+
$vars[$i]->setType("valueInt") ;
126125
}
127126
}
128127
}
@@ -514,11 +513,19 @@ public function multiFileHandler($block, $argName, $node, $fileSummary){
514513
* (2)false =>没有净化
515514
* 'XSS','SQLI','HTTP','CODE','EXEC','LDAP','INCLUDE','FILE','XPATH','FILEAFFECT'
516515
* @param string $type 漏洞的类型,使用TypeUtils可以获取
516+
* @param Symbol $var 危险参数
517517
* @param array $saniArr 危险参数的净化信息栈
518518
* @param array $encodingArr 危险参数的编码信息栈
519519
*/
520520
public function isSanitization($type,$var,$saniArr,$encodingArr){
521-
$is_clean = null ;
521+
$is_clean = null ;
522+
523+
//如果symbol类型为int,直接返回安全true
524+
if(!in_array($var->getType(), array('string','valueInt'))){
525+
return true ;
526+
}
527+
528+
//根据不同的漏洞类型进行判断
522529
switch ($type){
523530
case 'SQLI':
524531
$sql_analyser = new SqliAnalyser() ;

symbols/SanitizationHandler.class.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ class SanitizationHandler {
1818
public static function setSanitiInfo($node, $dataFlow, $block, $fileSummary){
1919
$dataFlows = $block->getBlockSummary()->getDataFlowMap();
2020
$sanitiInfo = self::SantiniFuncHandler($node, $fileSummary);
21-
//print_r($sanitiInfo);
2221
if($sanitiInfo){
23-
2422
//向上追踪变量,相同变量的净化信息,全部添加
2523
$funcParams = NodeUtils::getNodeFuncParams($node);
2624

test/test.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
$id = $_GET['id'] ;
3-
$id.="xxxx";
4-
echo $id ;
2+
3+
$id = (float)$_GET['id'];
4+
mysql_query($id) ;
5+
56
?>

0 commit comments

Comments
 (0)