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

}

?>

trim用于移除字符串两侧空白字符和其他预定义字符

mysql_real_escape_string对字符串中特殊符号转义

stripslashes删除字符串中的反斜杠

但是对过滤XSS没用,还存到数据库里了。直接在message中输入<script>alert(/xss/)</script>就会弹框

Name对输入有长度限制,抓包改包传

一返回这个界面就弹框,是为存储型XSS

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

}

?>

strip_tags清理了HTML\XML\PHP 的标签,但保留<b>标签的使用权限

addslashes在预定义字符前加反斜杠转义

htmlspecialchars把预定义字符转为HTML实体

还把name 的<script>过滤了

message惨遭毒手,可以从name下手

抓包改包加绕过

<sc<script>ript>alert(/xss/)</script>

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

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

}

?>

把name的<script>彻底过滤了

可以换别的标签

<img src=1 onerror=alert(1)>

Impossible:

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

?>

这回厉害了,升到impossible级别,之前打进数据库的语句,打开页面都不弹框了

就全员htmlspecialchars呗

但要注意htmlspecialchars使用位置,不要被绕过了

DVWA靶场之XSS(Stored)通关的更多相关文章

  1. DVWA XSS (Stored) 通关教程

    Stored Cross Site Scripting 存储型XSS,持久化,代码是存储在服务器中的,如在个人信息或发表文章等地方,加入代码,如果没有过滤或过滤不严,那么这些代码将储存到服务器中,用户 ...

  2. DVWA靶场之XSS(Reflected)通关

    反射型xss Low: <?php header ("X-XSS-Protection: 0"); // Is there any input? if( array_key_ ...

  3. DVWA靶场之SQL Injection通关

    SQL注入,一个大概的手工流程: 判断是否有注入,什么类型 破解SQL语句中查询的字段数是多少 确定回显位置 破库 破表 破字段 获得内容 Low: <?php if( isset( $_REQ ...

  4. DVWA XSS (Reflected) 通关教程

    XSS 介绍XSS,全称Cross Site Scripting,即跨站脚本攻击,某种意义上也是一种注入攻击,是指攻击者在页面中注入恶意的脚本代码,当受害者访问该页面时,恶意代码会在其浏览器上执行,需 ...

  5. 1.4 DVWA亲测XSS漏洞

    首先需要有配置好的DVWA环境,像下图这样   其中: XSS (DOM) :  DOM型XSS漏洞 XSS (Reflected) : 反射性XSS漏洞  XSS (Stored) :  存储型XS ...

  6. DVWA之Reflected XSS(反射型XSS)

    目录 Low Medium High Impossible Low 源代码: <?php header ("X-XSS-Protection: 0"); // Is ther ...

  7. DVWA之DOM XSS(DOM型跨站脚本攻击)

    目录 Low Medium High Impossible Low 源代码: <?php # No protections, anything goes ?> 从源代码可以看出,这里low ...

  8. XSS Stored 测试

    dvwa存储型XSS 存储型XSS:会把用户输入的数据“存储”在服务器端,一般出现在需要用户可以输入数据的地方,比如网站的留言板.评论等地方,当网站这些地方过滤不严格的时候,就会被黑客注入恶意攻击代码 ...

  9. DVWA靶场之Brute Force(暴破)通关

    DVWA最经典PHP/MySQL老靶场,简单回顾一下通关流程吧 DVWA十大金刚,也是最常见的十种漏洞利用:Brute Force(暴破).Command Injection(命令行注入).CSRF( ...

随机推荐

  1. 修改myeclipse 项目中用的jdk版本

    修改myeclipse 项目中用的jdk版本 首先, 打开MyEclipse,如下图所示 打开之后,找到我们的java项目 右键--"Build Path--->Confirgure ...

  2. MySQL中的字段拼接 concat() concat_ws() group_concat()函数

    1.concat()函数 2.concat_ws()函数 3.group_concat()函数 操作的table select * from test_concat order by id limit ...

  3. 「AGC034E」 Complete Compress

    「AGC034E」 Complete Compress 显然可以枚举根. 然后把某两棵棋子同时往深度浅的方向提,即对不存在祖先关系的两个棋子进行操作. 如果能到达那么就更新答案. 问题转化为如何判定能 ...

  4. 00JAVA语法基础_四则运算 01

    自动生成30道四则运算的数学题,当前只是简单符合出题,答题和判断的代码,还没做要求,所以现在只是能随机生成三十道100以内的加减法和九九乘法表的乘除法 package Sizeyunsuan; /** ...

  5. IDEA 生成类注释和方法注释

    目录 一.生成类注释-01 1.1.生成类注解模板 1.2.把模板设置到IDEA中 1.3.效果图 二.生成类注释-02 2.1.生成类注释模板 2.2.把模板设置到IDEA中 2.3.效果图 2.4 ...

  6. 微信小程序云开发-云存储-使用云开发控制台存储文件

    一.存储 进入[云开发控制台]>点击[存储].将需要存储的文件通过[上传文件]方式上传上去.或者通过拖拽的方式上传文件.  二.存储文件的类型 可以存储的文件有很多,常见的文件类型包括:word ...

  7. Leetcode春季活动打卡第三天:面试题 10.01. 合并排序的数组

    Leetcode春季活动打卡第三天:面试题 10.01. 合并排序的数组 Leetcode春季活动打卡第三天:面试题 10.01. 合并排序的数组 思路 这道题,两个数组原本就有序.于是我们采用双指针 ...

  8. P4293 [WC2010]能量场

    P4293 [WC2010]能量场 题意 给你 \(n\) 个粒子,每个粒子有两个权值 \(m_i,c_i\) 每个相邻有序对 \((a,b)\) 会产生 \(m_am_b(c_a-c_b)\) 的贡 ...

  9. hash表/哈希表

    https://blog.csdn.net/duan19920101/article/details/51579136 简单理解就是一个通过映射直接查找的表(散列表),用哈希函数将数据按照其存储特点进 ...

  10. 记一次Vue跨导航栏问题解决方案

    简述 这篇文章是我项目中,遇到的一个issue,我将解决过程和方法记录下来. 本篇文章基于Vue.js进行的前端页面构建,由于仅涉及前端,将不做数据来源及其他部分的叙述.使用的CSS框架是 Boots ...