Skip to content

Commit

Permalink
added vulnerability reporter to NodeAnalyser
Browse files Browse the repository at this point in the history
  • Loading branch information
naomilwx committed Nov 18, 2014
1 parent da7ae7f commit ce064f6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Phortress/Dephenses/Taint/CodeAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Phortress\Dephenses\Taint;
use Phortress\Dephenses\Engine\SQLVulnerabilityFinder;
use Phortress\Dephenses\Engine\VulnerabilityReporter;

/**
* Description of CodeAnalyser
Expand All @@ -18,8 +19,9 @@ function __construct($tree) {
}

public function analyse(){
$vulnerabilityReporter = new VulnerabilityReporter();
$currentTaintEnv = new TaintEnvironment();
$nodeAnalyser = new NodeAnalyser();
$nodeAnalyser = new NodeAnalyser($vulnerabilityReporter);
foreach($this->parseTree as $statement){
$nodeTaintEnv = $nodeAnalyser->analyse($statement, $currentTaintEnv);
$currentTaintEnv->updateTaintEnvironment($nodeTaintEnv);
Expand Down
10 changes: 10 additions & 0 deletions lib/Phortress/Dephenses/Taint/NodeAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
* @param \PhpParser\Node $node
*/
class NodeAnalyser {
protected $vulnerabilityReporter;
public function __construct($reporter = null){
if(!empty($reporter)){
$this->vulnerabilityReporter = $reporter;
}
}

public function analyse(Node $node, TaintEnvironment $taintEnv){
$taintEnv = $taintEnv->copy();
if($node instanceof Stmt){
Expand Down Expand Up @@ -265,6 +272,9 @@ protected function resolveFuncResultTaint(Expr\FuncCall $exp){
if(SanitisingFunctions::isGeneralSanitisingFunction($func_name_str)||
SanitisingFunctions::isSanitisingReverseFunction($func_name_str)){
return $this->resolveSanitisationFuncCall($exp);
}else if(Sinks::isSinkFunction($exp) && !empty($this->vulnerabilityReporter)){
$args_with_taints = $this->getArgumentsTaintValuesForAnalysis($exp->args);
$this->vulnerabilityReporter->runVulnerabilityChecks($exp, $args_with_taints);
}else{
$func_analyser = FunctionAnalyser::getFunctionAnalyser($exp->environment, $func_name);
$args_with_taints = $this->getArgumentsTaintValuesForAnalysis($exp->args);
Expand Down
15 changes: 15 additions & 0 deletions lib/Phortress/Dephenses/Taint/Sinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,19 @@ public static function isSQLInjectionSinkFunction(Expr\FuncCall $func){
$funcName = $func->name->getLast();
return array_key_exists($funcName, self::$DATABASE_SINKS);
}

public static function isXSSSinkFunction(Expr\FuncCall $func){
$funcName = $func->name->getLast();
return array_key_exists($funcName, self::$XSS_SINKS);
}

public static function isCodeInjectionSinkFunction(Expr\FuncCall $func){
$funcName = $func->name->getLast();
return array_key_exists($funcName, self::$CODE_EXE_SINKS);
}

public static function isSinkFunction(Expr\FuncCall $func){
return self::isCodeInjectionSinkFunction($func) || self::isSQLInjectionSinkFunction
($func) || self::isXSSSinkFunction($func);
}
}

0 comments on commit ce064f6

Please sign in to comment.