阅读DVWA系统代码之dvwaPhpIds.inc.php

<?php


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()
);
}
}


?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值