【问题标题】:Is it possible to dump inode information from the inotify subsystem?是否可以从 inotify 子系统中转储 inode 信息?
【发布时间】:2020-03-08 04:33:21
【问题描述】:

我想弄清楚我的编辑正在观看哪些文件。 我了解到 count the number of inotify fds from /proc/${PID}/fd 是可能的,我的问题是:是否可以通过一个进程转储监视的 inode 列表?

更新: 我更新了一个可行的解决方案,感谢您提供有用的参考 here。

更新 2:好吧,最近我发现 kallsyms_lookup_name(和更多符号)自 Linux Kernel v5.7 以来没有导出,所以如果其他人关心,我决定更新我自己的解决方案。

【问题讨论】:

  • 用户空间实现请参考CRIU中的inotify node inverse map:criu.org/Irmap

标签: hook inotify inode rootkit


【解决方案1】:

解决了。 在khook中使用的kprobe机制的帮助下,我只需简单地钩住__x64_sys_inotify_add_watch并使用user_path_at窃取dentry。

下面列出了代码sn-p,并提供了我的工作解决方案here。

#define IN_ONLYDIR          0x01000000  /* only watch the path if it is a directory */
#define IN_DONT_FOLLOW      0x02000000  /* don't follow a sym link */


//regs->(di, si, dx, r10), reference: arch/x86/include/asm/syscall_wrapper.h#L125
//SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname, u32, mask)
KHOOK_EXT(long, __x64_sys_inotify_add_watch, const struct pt_regs *);
static long khook___x64_sysinotify_add_watch(const struct pt_regs *regs)
{
    int wd;
    struct path path;
    unsigned int flags = 0;
    char buf[PATH_MAX];
    char *pname;
    // decode the registers
    int fd = (int) regs->di;
    const char __user *pathname = (char __user *) regs->si;
    u32 mask = (u32) regs->dx;

    // do the original syscall
    wd = KHOOK_ORIGIN(__x64_sys_inotify_add_watch, regs);
    // get the pathname
    if (!(mask & IN_DONT_FOLLOW))
        flags |= LOOKUP_FOLLOW;
    if (mask & IN_ONLYDIR)
        flags |= LOOKUP_DIRECTORY;
    if ( wd>=0 && (user_path_at(AT_FDCWD, pathname, flags, &path)==0) )
    {
        pname = dentry_path_raw(path.dentry, buf, PATH_MAX); //"pname" points to "buf[PATH_MAX]"
        path_put(&path);
        printk("%s, PID %d add (%d,%d): %s\n", current->comm, task_pid_nr(current), fd, wd, pname);
    }
    return wd;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 2010-09-29
    • 1970-01-01
    • 2017-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多