Hsycms2.0代码审计

前言

ThinkPHP免费企业网站管理系统hsycms 带前后台是由好生意工作室开发的一款全新的企业站后台管理系统,网址URL全伪静态处理,网址简短,易于优化。

Hsycms 企业管理系统后台是作者亲者编写的一套精美蓝色响应式后台,界面简单,美观,易于操作。

sql注入审计

首先是确定路由关系,通过查看index.php文件

define('APP_PATH', __DIR__ . '/app/');

函数功能等都在/app路径下面

    public function index()
    {
		$id = input('id');
		$one  = db('article')->where('id',$id)->find();	

虽然$id = input('id');也是官方的写法,但是并没有进行过滤,还是可以进行注入,

修复方式$id = input('id/d');将其强制转换一下就OK

payload,这里使用时间盲注

/news/151) and if(1<2,sleep(2),sleep(0)) and ( 1=1

xss审计

前端在留言板直接进行注入即可,并没有任何过滤,进入后台即可弹窗

app\hsycms\view\site\book.html、

 <h2>留言列表</h2>
      <a href="javascript:history.go(0);" class="btn fr"><i class="icon-refresh"></i> 刷新</a> </div>
    <table class="table">
      <tr>
        <th width="100">ID</th>
        <th>姓名</th>
        <th>手机</th>
        <th>邮箱</th>
        <th>地址</th>
        <th width="30%">留言内容</th>
        <th>留言时间</th>
        <th width="200">操作</th>
      </tr>
      {volist name="list" id="v"}
      <tr>
        <td><input type="checkbox" name="id[]" value="{$v.id}" />{$v.id}</td>
        <td>{$v.name}</td>
        <td>{$v.phone}</td>
        <td>{$v.email}</td>
        <td>{$v.address}</td>
        <td>{$v.content}</td>
        <td>{$v.datetime|date='Y-m-d H:i:s',###}</td>       

后台模板直接拼接传入的信息

写配置文件getshell

审计过程

app/install/controller/Index.php中,首先是config方法,对传进去的db数组写进了session。之后是进入了sql方法。
在sql方法中,session中的’db_config赋值dbconfig变量,然后传进了write_config函数,跟进app/install/common.php,可以看到只是对配置模板做简单的替换,于是造成写配置文件Getshell

public function config($db = null, $admin = null) {
		if (request()->IsPost()) {
			//检测管理员信息
			if (!is_array($admin) || empty($admin[0]) || empty($admin[1]) ) {
				return $this->error('请填写完整管理员信息');
			} else if ($admin[1] != $admin[2]) {
				return $this->error('确认密码和密码不一致');
			} else {
				$info = array();
				list($info['username'], $info['password'], $info['repassword'])
				= $admin;
				//缓存管理员信息
				session('admin_info', $info);
			}

			//检测数据库配置
			if (!is_array($db) || empty($db[0]) || empty($db[1]) || empty($db[2]) || empty($db[3]) || empty($db[4]) || empty($db[5]) || empty($db[6])) {
				return $this->error('请填写完整的数据库配置');
			} else {
				$DB = array();
				list($DB['type'], $DB['hostname'], $DB['database'], $DB['username'], $DB['password'],
					$DB['hostport'], $DB['prefix']) = $db;
					
				//缓存数据库配置
				session('db_config', $DB);

				//创建数据库
				$dbname = $DB['database'];
				unset($DB['database']);
				$db  = \think\Db::connect($DB);
				$sql = "CREATE DATABASE IF NOT EXISTS `{$dbname}` DEFAULT CHARACTER SET utf8";
				if (!$db->execute($sql)) {
					return $this->error($db->getError());
				} else {
					return $this->redirect('install/index/sql');
				}
			}
		} else {
			$this->status['index']  = 'success';
			$this->status['check']  = 'success';
			$this->status['config'] = 'primary';
			$this->assign('status', $this->status);
			return $this->fetch();
		}
	}
public function sql() {
		session('error', false);
		$this->status['index']  = 'success';
		$this->status['check']  = 'success';
		$this->status['config'] = 'success';
		$this->status['sql']    = 'primary';
		$this->assign('status', $this->status);
		echo $this->fetch();
		if (session('update')) {
			$db = \think\Db::connect();
			//更新数据表
			update_tables($db, config('prefix'));
		} else {
			//连接数据库
			$dbconfig = session('db_config');			
			$db       = \think\Db::connect($dbconfig);
			
			//创建数据表
			create_tables($db, $dbconfig['prefix']);
			//注册创始人帐号
			$admin = session('admin_info');
			register_administrator($db, $dbconfig['prefix'], $admin);

			//创建配置文件
			$conf = write_config($dbconfig);
			session('config_file', $conf);
		}

		if (session('error')) {
			show_msg('失败');
		} else {
			echo '<script type="text/javascript">location.href = "'.url('install/index/complete').'";</script>';
		}
	}

	public function complete() {
		$this->status['index']    = 'success';
		$this->status['check']    = 'success';
		$this->status['config']   = 'success';
		$this->status['sql']      = 'success';
		$this->status['complete'] = 'primary';
		$this->assign('status', $this->status);
		$this->assign('status', $this->status);
		return $this->fetch();
	}
}

并没有什么过滤,直接就写入数据库和文件app\database.php中

在数据库名称这里构造一句话进行写shell。

图片[1]-Hsycms2.0代码审计-渗透云记 - 专注于网络安全与技术分享
图片[2]-Hsycms2.0代码审计-渗透云记 - 专注于网络安全与技术分享

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容