欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入
一. 概述
目前通用的隐藏文件方法还是hooksys_getdents64系统调用, 大致流程就是先调用原始的sys_getdents64系统调用,然后在在buf中做过滤。修改sys_call_table是比较原始的rk技术了,碰到好点的管理员, 基本上gdb一下vmlinux就能检测出来。 如何想做到更加隐蔽的话,就要寻找新的技术。 inline hook也是目前比较流行的做法,不容易检测。本文通过讲解一种利用inline hook内核中某函数, 来达到隐藏文件的方法。
二. 剖析sys_getdnts64系统调用
想隐藏文件, 还是要从sys_dents64系统调用下手。 去看下它在内核中是如何实现的。
代码在linux-2.6.26/fs/readdir.c中:
asmlinkage long sys_getdents64(unsigned int fd, struct linux_dirent64 __user * dirent, unsigned int count) { struct file * file; struct linux_dirent64 __user * lastdirent; struct getdents_callback64 buf; int error; error = -EFAULT; if (!access_ok(VERIFY_WRITE, dirent, count)) goto out; error = -EBADF; file = fget(fd); if (!file) goto out; buf.current_dir = dirent; buf.previous = NULL; buf.count = count; buf.error = 0; error = vfs_readdir(file, filldir64, &buf); if (error < 0) goto out_putf; error = buf.error; lastdirent = buf.previous; if (lastdirent) { typeof(lastdirent->d_off) d_off = file->f_pos; error = -EFAULT; if (__put_user(d_off, &lastdirent->d_off)) goto out_putf; error = count – buf.count; } out_putf: fput(file); out: return error; }
首先调用access_ok来验证是下用户空间的dirent地址是否越界,是否可写。 接着根据fd,利用fget找到对应的file结构。 接着出现了一个填充buf数据结构的操作,先不管它是干什么的,接着往下看。
vfs_readdir(file, filldir64, &buf);
函数最终还是调用vfs层的vfs_readdir来获取文件列表的。 到这,我们可以是否通过hookvfs_readdir来达到隐藏文件的效果呢。 继续跟踪vfs_readdir看看这个想法是否可行。
[1][2]
如果我们想要更多的玫瑰花,就必须种植更多的玫瑰树。