<?php
if( !defined( 'DVWA_WEB_PAGE_TO_ROOT' ) ) {
define( 'DVWA System error- WEB_PAGE_TO_ROOT undefined' );
exit;
define( 'DVWA_WEB_ROOT_TO_PHPIDS', 'external/phpids/'.dvwaPhpIdsVersionGet().'/' );
// Add PHPIDS to include path
function dvwaPhpIdsVersionGet() {
return '0.6';
}
// PHPIDS Log parsing function
function dvwaReadIdsLog() { //phpids日志解析函数
$file_array = file(DVWA_WEB_PAGE_TO_PHPIDS_LOG);
$data = '';
foreach ($file_array as $line_number => $line){
$line = explode(",", $line);
$line = str_replace("\""," ",$line);
$datetime = $line[1];
$vulnerability = $line[3];
$variable = urldecode($line[4]);
$request = urldecode($line[5]);
$ip = $line[6];
$data .= "<div id=\"idslog\"><b>Date/Time:</b> " . $datetime . "<br /><b>Vulnerability:</b> " . $vulnerability . "<br /><b>Request:</b> " . htmlspecialchars($request) . "<br /><b>Variable:</b> " . htmlspecialchars($variable) . "<br /><b>IP:</b> " . $ip . "</div>";
}
return $data;
}
// Clear PHPIDS log
function dvwaClearIdsLog() { //phpids日志清理
if (isset($_GET['clear_log'])) {
$fp = fopen(DVWA_WEB_PAGE_TO_PHPIDS_LOG, w);
fclose($fp);
dvwaMessagePush( "PHPIDS log cleared" );
dvwaPageReload();
}
}
// Main PHPIDS function
function dvwaPhpIdsTrap() { //phpids主函数
try {
$request = array(
'REQUEST' => $_REQUEST,
'GET' => $_GET,
'POST' => $_POST,
'COOKIE' => $_COOKIE
);
$init = IDS_Init::init( DVWA_WEB_PAGE_TO_PHPIDS.'lib/IDS/Config/Config.ini' );
$init->config['General']['base_path'] = DVWA_WEB_PAGE_TO_PHPIDS.'lib/IDS/';
$init->config['General']['use_base_path'] = true;
$init->config['Caching']['caching'] = 'none';
// 2. Initiate the PHPIDS and fetch the results
$ids = new IDS_Monitor( $request, $init );
$result = $ids->run();
if (!$result->isEmpty()) {
require_once 'IDS/Log/File.php';
require_once 'IDS/Log/Composite.php';
$compositeLog = new IDS_Log_Composite();
$compositeLog->addLogger(IDS_Log_File::getInstance($init));
$compositeLog->execute($result);
echo 'Hacking attempt detected and logged.';
//echo $result;
exit;
}
} catch (Exception $e) {
/*
* something went terribly wrong - maybe the
* filter rules weren't found?
*/
printf(
'An error occured: %s',
$e->getMessage()
);
}
}
?>
if( !defined( 'DVWA_WEB_PAGE_TO_ROOT' ) ) {
define( 'DVWA System error- WEB_PAGE_TO_ROOT undefined' );
exit;
}
//判断是否定义常量DVWA_WEB_PAGE_TO_ROOT
define( 'DVWA_WEB_ROOT_TO_PHPIDS', 'external/phpids/'.dvwaPhpIdsVersionGet().'/' );
define( 'DVWA_WEB_PAGE_TO_PHPIDS', DVWA_WEB_PAGE_TO_ROOT.DVWA_WEB_ROOT_TO_PHPIDS );
//定义目录常量
//dvwaPhpIdsVersionGet()函数在下面定义返回版本号0.6
// Add PHPIDS to include path
set_include_path( get_include_path().PATH_SEPARATOR.DVWA_WEB_PAGE_TO_PHPIDS.'lib/' );
//set_include_path表示包含文件路径,这样做的目的是包含文件的时候可以省略文件路径,直接使用文件名加载
require_once 'IDS/Init.php';
//加载文件init.php
function dvwaPhpIdsVersionGet() {
return '0.6';
}
// PHPIDS Log parsing function
function dvwaReadIdsLog() { //phpids日志解析函数
$file_array = file(DVWA_WEB_PAGE_TO_PHPIDS_LOG);
$data = '';
foreach ($file_array as $line_number => $line){
$line = explode(",", $line);
$line = str_replace("\""," ",$line);
$datetime = $line[1];
$vulnerability = $line[3];
$variable = urldecode($line[4]);
$request = urldecode($line[5]);
$ip = $line[6];
$data .= "<div id=\"idslog\"><b>Date/Time:</b> " . $datetime . "<br /><b>Vulnerability:</b> " . $vulnerability . "<br /><b>Request:</b> " . htmlspecialchars($request) . "<br /><b>Variable:</b> " . htmlspecialchars($variable) . "<br /><b>IP:</b> " . $ip . "</div>";
}
return $data;
}
// Clear PHPIDS log
function dvwaClearIdsLog() { //phpids日志清理
if (isset($_GET['clear_log'])) {
$fp = fopen(DVWA_WEB_PAGE_TO_PHPIDS_LOG, w);
fclose($fp);
dvwaMessagePush( "PHPIDS log cleared" );
dvwaPageReload();
}
}
// Main PHPIDS function
function dvwaPhpIdsTrap() { //phpids主函数
try {
$request = array(
'REQUEST' => $_REQUEST,
'GET' => $_GET,
'POST' => $_POST,
'COOKIE' => $_COOKIE
);
$init = IDS_Init::init( DVWA_WEB_PAGE_TO_PHPIDS.'lib/IDS/Config/Config.ini' );
$init->config['General']['base_path'] = DVWA_WEB_PAGE_TO_PHPIDS.'lib/IDS/';
$init->config['General']['use_base_path'] = true;
$init->config['Caching']['caching'] = 'none';
// 2. Initiate the PHPIDS and fetch the results
$ids = new IDS_Monitor( $request, $init );
$result = $ids->run();
if (!$result->isEmpty()) {
require_once 'IDS/Log/File.php';
require_once 'IDS/Log/Composite.php';
$compositeLog = new IDS_Log_Composite();
$compositeLog->addLogger(IDS_Log_File::getInstance($init));
$compositeLog->execute($result);
echo 'Hacking attempt detected and logged.';
//echo $result;
exit;
}
} catch (Exception $e) {
/*
* something went terribly wrong - maybe the
* filter rules weren't found?
*/
printf(
'An error occured: %s',
$e->getMessage()
);
}
}
?>