代码审计-zzzphp代码执行漏洞getshell

\inc\zzz_template.php

public
	function parserIfLabel( $zcontent ) {
		$pattern = '/\{if:([\s\S]+?)}([\s\S]*?){end\s+if}/';    //{if:xxxx}xxx{end if}
		if ( preg_match_all( $pattern, $zcontent, $matches ) ) {
			$count = count( $matches[ 0 ] );
			for ( $i = 0; $i < $count; $i++ ) {
				$flag = '';
				$out_html = '';
				$ifstr = $matches[ 1 ][ $i ];
				$ifstr = str_replace( '<>', '!=', $ifstr ); // < >
				$ifstr = str_replace( 'mod', '%', $ifstr ); //
				$ifstr1 = cleft( $ifstr, 0, 1 ); // \s   from trim()
				switch ( $ifstr1 ) {
					case '=':
						$ifstr = '0' . $ifstr;
						break;
					case '{':
					case '[':
						$ifstr = "'" . str_replace( "=", "'=", $ifstr );
						break;
				}
				$ifstr = str_replace( '=', '==', $ifstr ); // =
				$ifstr = str_replace( '===', '==', $ifstr );  // ===
				@eval( 'if(' . $ifstr . '){$flag="if";}else{$flag="else";}' );
				if ( preg_match( '/([\s\S]*)?\{else\}([\s\S]*)?/', $matches[ 2 ][ $i ], $matches2 ) ) { // 判断是否存在else				
					switch ( $flag ) {
						case 'if': // 条件为真
							if ( isset( $matches2[ 1 ] ) ) {
								$out_html .= $matches2[ 1 ];
							}
							break;
						case 'else': // 条件为假
							if ( isset( $matches2[ 2 ] ) ) {
								$out_html .= $matches2[ 2 ];

							}
							break;
					}
				} elseif ( $flag == 'if' ) {
					$out_html .= $matches[ 2 ][ $i ];
				}

				// 无限极嵌套解析
				$pattern2 = '/\{if([0-9]):/';
				if ( preg_match( $pattern2, $out_html, $matches3 ) ) {
					$out_html = str_replace( '{if' . $matches3[ 1 ], '{if', $out_html );
					$out_html = str_replace( '{else' . $matches3[ 1 ] . '}', '{else}', $out_html );
					$out_html = str_replace( '{end if' . $matches3[ 1 ] . '}', '{end if}', $out_html );
					$out_html = $this->parserIfLabel( $out_html );
				}

				// 执行替换
				$zcontent = str_replace( $matches[ 0 ][ $i ], $out_html, $zcontent );
			}
		}
		return $zcontent;
	}

解析模块是通过ParsetTemplate来解析的
ParserTemplate类的php文件在zzz_template.php

其中一些替换图中做了备注:

而在search模板中进行了调用:
\zzzphp\search\index.php

<?php
define('LOCATION', 'search');
require dirname(dirname(__FILE__)). '/inc/zzz_client.php';

zzzphp\inc\zzz_client.php:

传入模板if标签

代码执行:

posted @ 2019-09-16 18:29  卿先生  阅读(630)  评论(0编辑  收藏  举报