原理:
使用者提交的XSS代码被存储到服务器上的数据库里或页面或某个上传文件里,导致用户访问页面展示的内容时直接触发xss代码。
低
在name 处也可以触发xss 也是储存的 修改前端验证就可以 输出 多个字符了
把maxlength 改成 等于50 就不受限制了
在message 框 里面输入 js代码 每次刷新都会触发xss
源码分析
原
<?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() 函数移除字符串两侧的空白字符或其他预定义字符。
相关函数:
stripslashes() 函数
stripslashes() 函数删除由 addslashes() 函数添加的反斜杠。
该函数可用于清理从数据库中或者从 HTML 表单中取回的数据。
mysqli_real_escape_string(string,connection) 函数会对字符串string中的特殊符号(\x00,\n,\r,\,‘,“,\x1a)进行转义
这个没有什么说的直接把输入的js代码储存到数据库 然后再返回给用户
中
这个 在信息message 的 过滤 的很全面
addslashes 函数
addslashes() 函数返回在预定义的字符前添加反斜杠的字符串。
所有把xss 注入点放在 name 处
修改长度
使用大写的SCRIPT
因为这里过滤掉了 小写
<?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 标签
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
打cookie
这里存在存储xss
Locations
这里也存在存储xss 都是没有过滤的
XAMPP XSS
XAMPP(Apache+MySQL+PHP+PERL)是一个建XAMPP软件站集成软件包。
XAMPP存在跨站脚本漏洞。允许攻击者通过cds-fpdf.php interpret或titel参数进行xss。.
存在XSS 的页面
/xampp/cds.php?showcode=1
我这里环境好像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><script>alert("XSS")</script></b></td><td class=tabval>