首页
社区
课程
招聘
[原创]linux 兼容内核 实现系统调用进入/退出机制 - 修改版(己更新,修正内存补丁的几处错误)
2008-1-11 23:32 7157

[原创]linux 兼容内核 实现系统调用进入/退出机制 - 修改版(己更新,修正内存补丁的几处错误)

2008-1-11 23:32
7157
原版本下载地址 :
http://linux.insigma.com.cn/download/software/unifiedkernel-2.6.13.tar.gz
原版本官方网站:
http://linux.insigma.com.cn/
修改版官方网站:
http://www.unifiedkernel.org/
修改版所做的改进,
this version don't need to compile the linux kernel 2.6.13.
just make to test it.
add sysmap.c sysmap.h config.h
modify w32entry.S w32syscall.c w32init.c
test platform fedora core 6.

原版本需要,编译 linux 2.6.13 版本的内核,还要给内核打补丁,
还限制测试了平台,总之给开发,跟测试带来了极大的不方便,
特别对一个新手入门来说,本来就不太懂,还要弄这弄那的。。
所以我才来做了修改版。
测试平台 fedora core 6,新版本的编译器,编译时有可能会
会出现重定义现象,
删除 pack_gate  write_dt_entry 就可以了

官方网站己经发布了,0.10,0.20版本了,最近应该还要发布新版。。
但这些版本都是修改,基于linux 2.6.13 内核的。

而我们所要做的工作是,要实现的是,给现有的linux 内核打内存补丁或者其它的方式,
在不修改任何linux 内核源码的前提要,要让兼容内核能够运行起来。。
适用于大部分内核版本。
0.1 跟 0.2 ,的代码量要比当前修改的要多得多。也复杂些。。。
欢迎有兴趣的朋友,积极参与加入到修改团队中来。。  
关于linux 兼容内核的介绍 请访问官方网站 :
http://linux.insigma.com.cn/
脱壳,调试程序,玩腻了,现在改玩系统内核啦!

[培训]二进制漏洞攻防(第3期);满10人开班;模糊测试与工具使用二次开发;网络协议漏洞挖掘;Linux内核漏洞挖掘与利用;AOSP漏洞挖掘与利用;代码审计。

上传的附件:
收藏
点赞0
打赏
分享
最新回复 (7)
雪    币: 3686
活跃值: (1036)
能力值: (RANK:760 )
在线值:
发帖
回帖
粉丝
cnbragon 18 2008-1-12 00:06
2
0
最近刚把工作平台移植到linux下面,f8的,学习需要研究内核,呵呵
目前yum在自动升级内核的时候,是如何解决新旧内核共存的?
雪    币: 333
活跃值: (369)
能力值: ( LV12,RANK:490 )
在线值:
发帖
回帖
粉丝
FlyToTheSpace 12 2008-1-12 08:44
3
0
你说是的linux 内核么?升级了,内核的文件的目录是不同的啊!
可以选择加载内核的不同版本,但是默认只保留两个最新两个版本。
我发的修改版,是通过System.map文件定位linux没有导出的api的。。
雪    币: 333
活跃值: (369)
能力值: ( LV12,RANK:490 )
在线值:
发帖
回帖
粉丝
FlyToTheSpace 12 2008-1-12 21:29
4
0
0.1 版本,己经修改得差不多了,还有一个模块没做好,
就是要把反汇编的模块加载到内核里,改系统原来的接口跳转到程序来身来。。要执行一段代码之后
再跳转回去,或者是取原函数的结果。保存下来备用。
通过反汇编是要计算出要复制的代码长度,再改函数头跳转。。
雪    币: 333
活跃值: (369)
能力值: ( LV12,RANK:490 )
在线值:
发帖
回帖
粉丝
FlyToTheSpace 12 2008-1-13 21:22
5
0
跳转到next 为 在原函数前面调用,next1为在原函数后面调用。

.586
.Model Flat, StdCall
Option Casemap :None

Include windows.inc
Include kernel32.inc
Include user32.inc
include masm32.inc
IncludeLib kernel32.lib
IncludeLib user32.lib

STEXT MACRO Text
  local szText
  LOCAL lbl
  LOCAL lbllbl
  call lbllbl
lbllbl:
  pop edx
  add edx,6
  jmp lbl
  szText db Text,0
  lbl:
  exitm <edx>
ENDM
PATCH_CODE STRUCT
  oldptr DWORD ?
  destptr DWORD ?
  parameter DWORD ?
  pcode db 16 ?
  code_length DWORD ?
PATCH_CODE ENDS

.data
patch  db 32
.CODE
START:
  lea edi,patch
  mov (PATCH_CODE PTR[edi]).parameter,4
  mov (PATCH_CODE PTR[edi]).destptr,MessageBox
  mov (PATCH_CODE PTR[edi]).pcode,0c3h
  push 0
  push STEXT("test")
  push STEXT("Hello world!")
  push 0
  push ExitProcess;return to
  push 0
  jmp next1
  ret
next:;//call before
  push eax
  push ebx
  push ecx
  push edx
  push edi
  push esi
  push ebp
  mov eax,[esp+28]
  shl eax,5
  lea edi,patch
  add edi,eax

  push edi;save this point
  
  mov ecx,(PATCH_CODE PTR[edi]).parameter
  and ecx,0ffh
  mov edx,ecx
  
  lea esi,[esp+40];copy parameter
  shl edx,2
  mov edi,esp
  sub edi,edx
  sub edi,4
  rep movsd
  
  mov edi,[esp]
  push ebp
  mov ebp,esp
  sub esp,edx
  mov eax,(PATCH_CODE PTR[edi]).destptr
  call eax
  mov esp,ebp
  pop ebp
  
  pop edi
  lea eax,(PATCH_CODE PTR[edi]).pcode
  mov [esp-4],eax
  pop ebp
  pop esi
  pop edi
  pop edx
  pop ecx
  pop ebx
  pop eax
  add esp,4
  jmp DWORD ptr[esp-36]
  ret
next1:
  push eax
  push ebx
  push ecx
  push edx
  push edi
  push esi
  push ebp
  
  mov eax,[esp+28]
  shl eax,5
  lea edi,patch
  add edi,eax
  
  mov ecx,(PATCH_CODE PTR[edi]).parameter
  and ecx,0ffh
  mov edx,ecx
  
  lea esi,[esp+36];copy parameter
  shl edx,2
  mov ebx,edi
  mov edi,esp
  sub edi,edx
  sub edi,8
  rep movsd
  
  call retaddr;get eip
retaddr:
  pop eax
  add eax,34h
  
  mov ecx,esp
  sub ecx,edx
  sub ecx,12
  mov DWORD ptr[ecx],eax;save ret addr.
  lea eax,(PATCH_CODE PTR[ebx]).pcode
  mov DWORD ptr[ecx-4],eax
  mov eax,esp
  sub eax,edx
  sub eax,12
  mov DWORD ptr[esp-8],eax
  mov DWORD ptr[esp-4],ebx
  pop ebp
  pop esi
  pop edi
  pop edx
  pop ecx
  pop ebx
  pop eax
  
  push ebp
  mov ebp,esp
  mov esp,[esp-32]
  
  ;lea eax,(PATCH_CODE PTR[edi]).pcode
  jmp DWORD ptr[esp-4]
  mov esp,ebp
  pop ebp
  add esp,4
  push eax
  push ebx
  push ecx
  push edx
  push edi
  push esi
  push ebp
  mov ebx,[esp-8]
  

  mov ecx,(PATCH_CODE PTR[ebx]).parameter
  shl ecx,2
  and ecx,0ffh
  mov DWORD ptr[esp-8],ecx
  mov ecx,(PATCH_CODE PTR[ebx]).destptr
  push ebp
  mov ebp,esp
  mov esp,[esp-8]
  add esp,4

  call ecx;eax,and edx may be usefully
  mov esp,ebp
  pop ebp
  pop ebp
  pop esi
  pop edi
  pop edx
  pop ecx
  mov  eax,[esp-1ch]
  mov  ebx,[esp+8]
  mov  DWORD ptr[esp+eax+8],ebx
  pop ebx
  pop eax
  add esp,[esp-24h]
  add esp,4
  jmp DWORD ptr[esp-4]
  ret
jCreateFile proc
  push 0
  jmp next
jCreateFile endp
END START

typedef struct _PATCH_CODE
{
        unsigned long oldptr;
        unsigned long destptr;
        int parameter;
        char pcode[16];
        int code_length;
}PATCH_CODE,*PPATCH_CODE;
int get_disasm_len(unsigned char * src)
{
        int len = 0;
        if((*src >= 0x50)&&(*src <=0x61)) //push EAX -> popad
                return 1;
        if((*src == 0x83)&&(src[1]==0xec))//sub esp,xx
                return 3;
        if((*src == 0x81)&&(src[1]==0xec))//sub esp,xxxxxxxx
                return 6;
        if(*src == 0x6a)//push xx
                return 2;
        if(*src == 0x68)//push xxxxxxxx
                return 5;
        if((*src == 0x89)|| (*src == 0x8b))
        {
                if((src[1]>=0xc0) && (src[1]<=0xff))//mov reg,reg
                        return 2;
        }
        return 0;
}
//this is don't support relocate
int add_patch_code(unsigned long prev,unsigned long dest,PPATCH_CODE ppc)
{
        int cplen = 0;
        int i;
        while(cplen<5)
        {
                i = get_disasm_len((unsigned char *)prev+cplen);
                if(i == 0)
                        return -1;
                cplen +=i;
        }
        memcpy(ppc->pcode,(void *)prev,cplen);
        ppc->code_length = cplen;
        ppc->pcode[cplen] = 0xe9;//jmp xxxxxxxx
        *(DWORD *)(ppc->pcode+cplen+1) = prev  - ((DWORD)ppc->pcode+cplen) - 5;
        return 0;
}
int unpatch_kernel_code()
{
        return 0;
}
int patch_kernel_code()
{
        PATCH_CODE pc;
        memset(&pc,0,sizeof(PATCH_CODE));
        add_patch_code((unsigned long)CreateFile,0,&pc);
        return 0;
}
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
泪水 2008-1-14 13:50
6
0
在虚拟机里试试
雪    币: 333
活跃值: (369)
能力值: ( LV12,RANK:490 )
在线值:
发帖
回帖
粉丝
FlyToTheSpace 12 2008-1-19 10:35
7
0
#include <linux/linkage.h>
#include <asm/thread_info.h>
#include <asm/errno.h>

#include <asm/segment.h>
#include <asm/smp.h>
#include <asm/page.h>
#include <asm/desc.h>

#define SAVE_ALL \
        pushl %eax; \
        pushl %ebx; \
        pushl %ecx; \
        pushl %edx; \
        pushl %edi; \
        pushl %esi; \
        pushl %ebp;

#define RESTORE_ALL \
        popl %ebp; \
        popl %esi; \
        popl %edi; \
        popl %edx; \
        popl %ecx; \
        popl %ebx; \
        popl %eax;

ENTRY(patch_prev)
        SAVE_ALL
        movl 28(%esp),%eax
        shll $5,%eax
        leal pach,%edi
        addl %eax,%edi

        pushl %edi//save this point
       
        movl 8(%edi),%ecx
        andl $0xff,%ecx
        movl %ecx,%edx
       
        leal 40(%esp),%esi//copy parameter
        shll $2,%edx
        movl %esp,%edi
        subl %edx,%edi
        subl $4,%edi
        rep movsd
       
        movl (%esp),%edi
        pushl %ebp
        movl %esp,%ebp
        subl %edx,%esp
        movl 4(%edi),%eax
        call *%eax
        movl %ebp,%esp
        popl %ebp
       
        popl %edi
        leal 12(%edi),%eax
        movl %eax,-4(%esp)
        RESTORE_ALL
        addl $4,%esp
        jmpl *-36(%esp)
        ret
ENTRY(patch_tail)
        pop %eax
        SAVE_ALL
       
        movl 28(%esp),%eax
        shll $5,%eax
        leal patch_code,%edi
        addl %eax,%edi
       
        movl 8(%edi),%ecx
        andl $0xff,%ecx
        movl %ecx,%edx
       
        leal 36(%esp),%esi//copy parameter
        shll $2,%edx
        movl %edi,%ebx
        movl %esp,%edi
        subl %edx,%edi
        subl $8,%edi
        rep movsd
       
        call retaddr//get eip
retaddr:
        popl %eax
        addl $0x34,%eax
       
        movl %esp,%ecx
        subl %edx,%ecx
        subl $12,%ecx
        movl %eax,(%ecx)//save ret addr.
        leal 12(%ebx),%eax//pcode
        movl %eax,-4(%ecx)
        movl %esp,%eax
        subl %edx,%eax
        subl $12,%eax
        movl %eax,-8(%esp)
        movl %ebx,-4(%esp)

        RESTORE_ALL
       
        pushl %ebp
        movl %esp,%ebp
        movl -32(%esp),%esp
       
        jmpl *-4(%esp)
        movl %ebp,%esp
        popl %ebp
       
       
        SAVE_ALL
        movl -4(%esp),%ebx

        movl 8(%ebx),%ecx//paramater
        shll $2,%ecx
        andl $0xff,%ecx
        movl %ecx,-4(%esp)
        movl 4(%ebx),%ecx//destptr

        pushl %ebp
        movl %esp,%ebp
        movl -4(%esp),%esp
        addl $4,%esp
       
        call *%ecx//eax,and edx may be usefully
        movl %ebp,%esp
        popl %ebp
       
        RESTORE_ALL
        addl $4,%esp
        ret
雪    币: 333
活跃值: (369)
能力值: ( LV12,RANK:490 )
在线值:
发帖
回帖
粉丝
FlyToTheSpace 12 2008-1-24 14:27
8
0
添加0.1版最后的修改的文件,不太稳定,明天就回家了估记20天都上不了网!
游客
登录 | 注册 方可回帖
返回