加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在unix环境中拦截系统调用的可能方法有哪些?

发布时间:2020-12-15 23:00:21 所属栏目:安全 来源:网络整理
导读:在unix环境中拦截系统调用的可能方法有哪些? 我想在AIX上做. 谢谢 解决方法 不熟悉AIX,但以下适用于 Linux和Solaris.您可以使用LD_PRELOAD环境变量,它告诉ld.so在libc之前加载共享库,然后编写您自己的系统调用版本,并可选择调用原始版本. man ld.so了解更多
在unix环境中拦截系统调用的可能方法有哪些?
我想在AIX上做.

谢谢

解决方法

不熟悉AIX,但以下适用于 Linux和Solaris.您可以使用LD_PRELOAD环境变量,它告诉ld.so在libc之前加载共享库,然后编写您自己的系统调用版本,并可选择调用原始版本. man ld.so了解更多信息.有点像

#include <dlfcn.h>

typedef int (*ioctl_fn)(int,int,void*);

static 
int
my_ioctl(int      fildes,int      request,void*    argp,ioctl_fn fn_ptr)

{
    int result = 0;

    /* call original or do my stuff */
    if (request == INTERESTED)
    {
        result = 0;
    }
    else
    {
        result = (*fn_ptr)(fildes,request,argp);
    }

    return result;
}

/*
 * override ioctl() - on first call get a pointer to the "real" one
 * and then pass it onto our version of the function
 */
int
ioctl(int fildes,int request,void* argp)
{
    static ioctl_fn S_fn_ptr = 0;

    if (S_fn_ptr == 0)
    {
        S_fn_ptr = (ioctl_fn)dlsym(RTLD_NEXT,"ioctl");
    }

    return my_ioctl(fildes,argp,S_fn_ptr);
}

用我躺在身边的一些代码雕刻出来,如果我弄错了就道歉了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读