存储XSS实验

原理:
使用者提交的XSS代码被存储到服务器上的数据库里或页面或某个上传文件里,导致用户访问页面展示的内容时直接触发xss代码。

image.png
在name 处也可以触发xss 也是储存的 修改前端验证就可以 输出 多个字符了
把maxlength 改成 等于50 就不受限制了
image.png

在message 框 里面输入 js代码 每次刷新都会触发xss
image.png

image.png

源码分析

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

?>

注释

<?php

if( isset( $_POST[ 'btnSign' ] ) ) {   //POST方法
    // Get input
    $message = trim( $_POST[ 'mtxMessage' ] );    // POST 传参方法 ,trim 函数把传进来的字符串移除两侧的字符 
    $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();
}

?>

trim 用法 :
trim() 函数移除字符串两侧的空白字符或其他预定义字符。
相关函数:

  • ltrim() - 移除字符串左侧的空白字符或其他预定义字符。
  • rtrim() - 移除字符串右侧的空白字符或其他预定义字符。

stripslashes() 函数
stripslashes() 函数删除由 addslashes() 函数添加的反斜杠。
该函数可用于清理从数据库中或者从 HTML 表单中取回的数据。

mysqli_real_escape_string(string,connection) 函数会对字符串string中的特殊符号(\x00,\n,\r,\,‘,“,\x1a)进行转义

这个没有什么说的直接把输入的js代码储存到数据库 然后再返回给用户

image.png
这个 在信息message 的 过滤 的很全面
addslashes 函数
addslashes() 函数返回在预定义的字符前添加反斜杠的字符串。

所有把xss 注入点放在 name 处
修改长度
image.png

使用大写的SCRIPT
因为这里过滤掉了 小写
image.png
image.png

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

addslashes 函数
addslashes() 函数返回在预定义的字符前添加反斜杠的字符串。

htmlspecialchars
进行了html 实体化

str_replace( ‘

Stored XSS Source
vulnerabilities/xss_s/source/high.php
<?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
$name = preg_replace( ‘/<(.)s(.)c(.)r(.)i(.)p(.)t/i’, ‘’, $name );

可以使用其他标签 进行xss
svg 标签

img 标签

image.png

WordPress 储存XSS

描述: WordPress是WordPress软件基金会的一套使用PHP语言开发的博客平台,该平台支持在PHP和MySQL的服务器上架设个人博客网站。 WordPress 的事件管理器插件 5.9.4 通过 wp-admin/edit.php?post_type=event&page=events-manager-options URI 的 dbem_event_reapproved_email_body 参数具有 XSS。
Add New Event
这里事件标题存在存储xss
image.png
打cookie

image.png
这里存在存储xss
Locations
这里也存在存储xss 都是没有过滤的
image.png

image.png

XAMPP XSS

XAMPP(Apache+MySQL+PHP+PERL)是一个建XAMPP软件站集成软件包。
XAMPP存在跨站脚本漏洞。允许攻击者通过cds-fpdf.php interpret或titel参数进行xss。.
image.png

存在XSS 的页面
/xampp/cds.php?showcode=1
image.png
image.png
我这里环境好像G 了 不得行 还是我太菜了没有复现成功
cds.php 文件和 cds.fpdf.php 文件 存在XSS

http://X.X.X.X/xampp/cds.php?interpret= <script>alert("XSS")</script>&titel=XSS&jahr=1984 
Request: http://localhost/xampp/cds.php?interpret=XSS&titel= <script>alert("XSS")</script>&jahr=1984 
Second Request (to xss attack): http://X.X.X.X/xampp/cds-fpdf.php
http://localhost/xampp/cds-fpdf.php?interpret=XSS&titel= <script>alert("XSS")</script>&jahr=1984 
http://localhost/xampp/cds-fpdf.php?interpret= <script>alert("XSS")</script>&titel=XSS&jahr=1984 
When cds-fpdf.php is loaded not filter the characters: <b><script>alert("XSS")</script></b></td><td class=tabval> cds.php filter it: <td class=tabval><b>&lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;</b></td><td class=tabval>
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值