<?
/**
* Class HtmlFormAnalizer
* @author simone cosci
* @version 1.0
*
*/
class HtmlFormAnalizer
{
/** Associative configuration array
* @access public
* @var array
*/
var $conf;
/** Associative form=>Warning array
* @access public
* @var array
*/
var $warnings;
/** Associative form=>Responses array
* @access public
* @var array
*/
var $responses;
/**
* Collection of forms of HtmlParser->forms data
* @access public
* @var array
*/
var $forms;
/** Handle to global $myHttpRequest
* @var HttpRequest class
* @access public
*/
var $request;
function HtmlFormAnalizer($forms){
$this->forms = $forms;
}
function Analize(){
$this->warnings = array();
$this->responses = array();
foreach($this->forms as $form_index=>$form){
if(!empty($form['form_data']['action'])){
$myWebResource = new WebResource($form['form_data']['action']);
$myWebResource->protocol = $this->request->protocol;
$myWebResource->host = $this->request->host;
if($myWebResource->parse()){
/* Match conf directives and ifmatch continue */
if($myWebResource->type != WST_RELATIVE_PATH)
$myWebResource->host = $myWebResource->pathinfo['host'];
$ip = gethostbyname($myWebResource->host);
if($ip == $this->request->server && strtolower($this->conf['ANALIZE_IFMATCH_IP'][0]) != 'y') continue;
if($ip != $this->request->server && strtolower($this->conf['ANALIZE_IFNOTMATCH_IP'][0]) != 'y') continue;
if($myWebResource->host == $this->request->host && strtolower($this->conf['ANALIZE_IFMATCH_HOST'][0]) != 'y') continue;
if($myWebResource->host != $this->request->host && strtolower($this->conf['ANALIZE_IFNOTMATCH_HOST'][0]) != 'y') continue;
/* Detect file extension */
$ext = explode('.',$myWebResource->pathinfo['path']);
if(count($ext)>1) $ext = array_pop($ext);
else $ext = '';
$this->responses[$form_index] = array( 'host' => $myWebResource->host,
'server' => $ip,
'scheme' => $myWebResource->pathinfo['scheme'],
'target' => $myWebResource->pathinfo['path'],
'params' => $myWebResource->params,
'files' => array()
);
}
}else
$this->responses[$form_index] = array( 'host' => $this->request->host,
'server' => $this->request->server,
'scheme' => $this->request->protocol,
'target' => $this->request->target,
'params' => array(),
'files' => array()
);
if(count($form['form_elements'])>0){
foreach($form['form_elements'] as $name=>$element){
if($element['type']=='file'){
if(isset($this->conf['FILEUPLOAD_MSG'])) $this->warnings[$form_index]['UPL'] = $this->conf['FILEUPLOAD_MSG'];
$this->responses[$form_index]['files'][$name] = '';
}
if($element['type']=='password'){
if(isset($this->conf['BRUTEFORCE_MSG'])) $this->warnings[$form_index]['BRT'] = $this->conf['BRUTEFORCE_MSG'];
}
$this->responses[$form_index]['params'][$name] = $element['value']!=null?$element['value']:'';
}
}
if(count($this->responses[$form_index]['params'])>0){
if(isset($this->conf['TRASVERSAL_MSG'])) $this->warnings[$form_index]['TRV'] = $this->conf['TRASVERSAL_MSG'];
if(isset($this->conf['CROSS_SITE_SCRIPTING_MSG'])) $this->warnings[$form_index]['XSS'] = $this->conf['CROSS_SITE_SCRIPTING_MSG'];
if(isset($this->conf['SQL_INJECTION_MSG'])) $this->warnings[$form_index]['SQL'] = $this->conf['SQL_INJECTION_MSG'];
if(isset($this->conf['REMOTECODE_EXECUTION_MSG'])) $this->warnings[$form_index]['RCX'] = $this->conf['REMOTECODE_EXECUTION_MSG'];
}
}
}
}
?>