首页 > 其他分享 >DVWA靶机-全级别测试-XSS(Stored)

DVWA靶机-全级别测试-XSS(Stored)

时间:2023-02-12 13:05:18浏览次数:48  
标签:XSS name DVWA ston Stored mysqli ___ GLOBALS message


存储型的XSS


存储型XSS又称持久型XSS,攻击脚本将被永久地存放在目标服务器的数据库或文件中,具有很高的隐蔽性



低难度


设置如下:


DVWA靶机-全级别测试-XSS(Stored)_mysql


源代码:


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

?>


过滤了某些sql注入,但是对用户的输入没有做编码处理


DVWA靶机-全级别测试-XSS(Stored)_mysql_02


测试,发现是个留言板


<script>alert('xss')</script>


结果


DVWA靶机-全级别测试-XSS(Stored)_php_03


存在xss漏洞


DVWA靶机-全级别测试-XSS(Stored)_mysql_04


留言版信息如上


DVWA靶机-全级别测试-XSS(Stored)_mysql_05


有个特点

每次用户访问这个页面都会执行xss攻击


中难度


设置如下:


DVWA靶机-全级别测试-XSS(Stored)_html_06


源代码:


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

?>


先测试


DVWA靶机-全级别测试-XSS(Stored)_html_07


第一个是长度有限制

第二个是script标签被过滤掉

猜测是使用了黑名单策略


DVWA靶机-全级别测试-XSS(Stored)_html_08


前端代码


DVWA靶机-全级别测试-XSS(Stored)_mysql_09


后台代码


于是我们构造payload


<scriPt>alert('XSS')</scriPt>    大写的P


DVWA靶机-全级别测试-XSS(Stored)_mysql_10


结果成功触发


DVWA靶机-全级别测试-XSS(Stored)_php_11


刷新页面,仍然存在xss弹窗


DVWA靶机-全级别测试-XSS(Stored)_html_12


保存在服务端了


高难度


设置如下:


DVWA靶机-全级别测试-XSS(Stored)_html_13


源代码:


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

?>


使用正则表达式过滤了<script>标签

但是可以使用其他标签,如svg


<svg onl oad=alert(/xss/)>


DVWA靶机-全级别测试-XSS(Stored)_html_14


这个难度,我们使用beef工具来测试

我们使用kali,生成一个hook的js脚本


systemctl start beef-xss.service 开启


systemctl stop beef-xss.service 关闭


systemctl restart beef-xss.service  重启


点击beef start


DVWA靶机-全级别测试-XSS(Stored)_html_15


发现错误,排查原因


DVWA靶机-全级别测试-XSS(Stored)_mysql_16


成功启动


DVWA靶机-全级别测试-XSS(Stored)_mysql_17


这次我们使用的是本地的实验环境


DVWA靶机-全级别测试-XSS(Stored)_mysql_18


我们将hook的js文件放进入


DVWA靶机-全级别测试-XSS(Stored)_php_19


下次我们来讲讲beef的使用吧

这次跳过


不可能难度


设置如下


DVWA靶机-全级别测试-XSS(Stored)_mysql_20


源代码:


<?php

if( isset( $_POST[ 'btnSign' ] ) ) {
// Check Anti-CSRF token
checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );

// 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)) ? "" : ""));
$message = htmlspecialchars( $message );

// Sanitize name input
$name = stripslashes( $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)) ? "" : ""));
$name = htmlspecialchars( $name );

// Update database
$data = $db->prepare( 'INSERT INTO guestbook ( comment, name ) VALUES ( :message, :name );' );
$data->bindParam( ':message', $message, PDO::PARAM_STR );
$data->bindParam( ':name', $name, PDO::PARAM_STR );
$data->execute();
}

// Generate Anti-CSRF token
generateSessionToken();

?>


此处用htmlspecialchars函数过滤了name和message,不存在注入

都进行了严格的过滤


防御措施


对用户输入的信息进行严格的过滤。

标签:XSS,name,DVWA,ston,Stored,mysqli,___,GLOBALS,message
From: https://blog.51cto.com/apple0/6052021

相关文章

  • DVWA靶场实战(十三)——CSP Bypass
    DVWA靶场实战(十三)十三、CSPBypass:1.漏洞原理:CSPBypass全称是Content-Security-Policy,中文叫做绕过内容安全策略。Content-Security-Policy是一个HTTP响应头的名称......
  • CSharp: donet 7 Stored procedure mapping with Entity Framework core 7
    sql:IFEXISTS(select*fromsysobjectswhereid=object_id(N'[dbo].People')andOBJECTPROPERTY(id,N'IsUserTable')=1)DROPTABLEPeopleGOCREATETABLE......
  • CSharp: donet Stored procedure mapping with Entity Framework 6
    sql:IFEXISTS(select*fromsysobjectswhereid=object_id(N'[dbo].DepartmentMaster')andOBJECTPROPERTY(id,N'IsUserTable')=1)DROPTABLEDepartmentMas......
  • XSS Challenges
    XSS挑战(由yamagata21)-阶段#1(int21h.jp)题目要求注入JavaScript命令:alert(document.domain);Stage#1输入321来定位代码的位置,发现是处于<b></b>标签之内,没有......
  • phpstudy后台管理页面存在XSS
    一、下载小皮面板官方下载地址:https://www.xp.cn/二、漏洞复现安装完成后来到登录页面,复制好相关后台连接和用户名密码后进行正常登录。在用户名处插入xss语句,验证码......
  • DVWA通关笔记(一)
    DVWA通关笔记SQL注入LOW1.寻找注入点?uid=1'----------------页面报错?uid=1’--+------------------页面正常则为单引号闭合2.判断列数?uid=1'orderby3-......
  • DVWA靶场实战(十二)——XSS(Stored)
    DVWA靶场实战(十二)五、XSS(Stored):1.漏洞原理:XSS的Stored被称作存储型XSS漏洞,漏洞的原理为语句被保存到服务器上,显示到HTML页面中,经常出现在用户评论的页面,攻击者将XS......
  • Google XSS Game
    XSSgame(xss-game.appspot.com)这是一款谷歌的XSS游戏,总共有6个级别Level1无需转义,直接编辑URL栏或者搜索框中都可以执行<script>alert(1)</script>Leve......
  • 分享两个好用的XSS漏扫工具(工具)
    =================免责声明:希望大家以遵守《网络安全法》相关法律,本团队发表此文章仅用于研究学习,切勿用于非法犯罪活动,对于恶意使用该工具造成的损失,和本团队无关。=======......
  • DVWA系列3:CSRF
    DVWA系列3:CSRF前言CSRF(Cross-siterequestforgery),即跨站请求伪造,是一种挟制用户在当前已登录的Web应用程序上执行非本意的操作的攻击方法。比如说,用户之前登录了网银网......