zoukankan      html  css  js  c++  java
  • dvwa 源码分析(四) --- dvwaPhpIds.inc.php分析

    根据文件名就知道是IDS相关的

     1 <?php
     2 
     3 if( !defined( 'DVWA_WEB_PAGE_TO_ROOT' ) ) {
     4     define( 'DVWA System error- WEB_PAGE_TO_ROOT undefined' );
     5     exit;
     6 }
     7 
     8 define( 'DVWA_WEB_ROOT_TO_PHPIDS', 'external/phpids/'.dvwaPhpIdsVersionGet().'/' );
     9 define( 'DVWA_WEB_PAGE_TO_PHPIDS', DVWA_WEB_PAGE_TO_ROOT.DVWA_WEB_ROOT_TO_PHPIDS );
    10 
    11 // Add PHPIDS to include path
    12 set_include_path( get_include_path().PATH_SEPARATOR.DVWA_WEB_PAGE_TO_PHPIDS.'lib/' );
    13 
    14 require_once 'IDS/Init.php';
    15 
    16 function dvwaPhpIdsVersionGet() {
    17     return '0.6';
    18 }

    我们先分析前面的18行

    3-6行就是一个是否已定义的判断,在前面我们已经分析过了,这里不再复述。

    8-9行定义一个新目录变量,这样就可以更方面的包含目录或文件了。

    第8行的dvwaPhpIdsVersionGet()函数在16行定义,返回PhpIds的版本号。

    第12行的set_include_path表示包含文件路径,这样做的目的是包含文件的时候可以省略文件路径,直接使用文件名。

    第14行又包含一个新的文件,这个文件是在set_include_path的基础上包含的。这里我就不继续分析下去了,因为越分析文件会更多。

    下面是几个函数

    我们来第一个函数

     1 // PHPIDS Log parsing function 
     2 function dvwaReadIdsLog() {
     3 
     4     $file_array = file(DVWA_WEB_PAGE_TO_PHPIDS_LOG);
     5     
     6     $data = '';
     7 
     8     foreach ($file_array as $line_number => $line){
     9         $line = explode(",", $line);
    10         $line = str_replace("""," ",$line);
    11         
    12         $datetime = $line[1];
    13         $vulnerability = $line[3];
    14         $variable = urldecode($line[4]);
    15         $request = urldecode($line[5]);
    16         $ip = $line[6];
    17         
    18         $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>";
    19     }
    20 
    21 return $data;
    22 }
    PHPIDS 日志解析函数

     第二个函数

    1 // Clear PHPIDS log
    2 function dvwaClearIdsLog()    {
    3     if (isset($_GET['clear_log'])) { 
    4         $fp = fopen(DVWA_WEB_PAGE_TO_PHPIDS_LOG, w);
    5         fclose($fp);
    6         dvwaMessagePush( "PHPIDS log cleared" );
    7         dvwaPageReload();
    8     }
    9 }
    PHPIDS 日志清理

    第三个函数

     1 // Main PHPIDS function
     2 function dvwaPhpIdsTrap() {
     3     try {
     4         $request = array(
     5             'REQUEST' => $_REQUEST,
     6             'GET' => $_GET,
     7             'POST' => $_POST,
     8             'COOKIE' => $_COOKIE
     9         );
    10 
    11         $init = IDS_Init::init( DVWA_WEB_PAGE_TO_PHPIDS.'lib/IDS/Config/Config.ini' );
    12 
    13         $init->config['General']['base_path'] = DVWA_WEB_PAGE_TO_PHPIDS.'lib/IDS/';
    14         $init->config['General']['use_base_path'] = true;
    15         $init->config['Caching']['caching'] = 'none';
    16 
    17         // 2. Initiate the PHPIDS and fetch the results
    18         $ids = new IDS_Monitor( $request, $init );
    19         $result = $ids->run();
    20 
    21         if (!$result->isEmpty()) {
    22             require_once 'IDS/Log/File.php';
    23             require_once 'IDS/Log/Composite.php';
    24 
    25             $compositeLog = new IDS_Log_Composite();
    26             $compositeLog->addLogger(IDS_Log_File::getInstance($init));
    27             
    28             $compositeLog->execute($result);
    29             
    30             echo 'Hacking attempt detected and logged.';
    31 
    32             //echo $result;
    33             exit;
    34         }
    35     } catch (Exception $e) {
    36         /*
    37         * something went terribly wrong - maybe the
    38         * filter rules weren't found?
    39         */
    40         printf(
    41             'An error occured: %s',
    42             $e->getMessage()
    43         );
    44     }
    45 }
    PHPIDS 主函数

    这个文件就分析完了,我们回到dvwaPage.inc.php。

  • 相关阅读:
    Java反射机制的简单应用
    UI组件之AdapterView及其子类关系,Adapter接口及事实上现类关系
    CSDN日报20170406 ——《代码非常烂,所以离职。》
    Swift环境下实现UILabel居上 居中 居下对齐
    在EA中将画出的ER图转换成SQL脚本
    hdu2236
    glm编译错误问题解决 formal parameter with __declspec(align(&#39;16&#39;)) won&#39;t be aligned
    CSS中的相关概念
    javascript jquery 推断对象为空的方式
    swift 给导航添加item,实现界面的跳转
  • 原文地址:https://www.cnblogs.com/tk091/p/3220009.html
Copyright © 2011-2022 走看看