设为主页 | 加入收藏 | 繁體中文

无驱动执行Ring0代码

  //指导指导指导指导指导指导指导指导指导指导指导指导
  // Ring0Demo.c v1.0 by zzzEVAzzz
  // 目标:演示无驱动执行Ring0代码。
  // 原理:通过\Device\PhysicalMemory修改NtVdmControl入口,跳转到Ring0Code
  //指导指导指导指导指导指导指导指导指导指导指导指导
  #include
  #include
  #include
  #pragma comment (lib,"ntdll.lib")       // Copy From DDK
  #pragma comment (lib,"Kernel32.lib")
  #pragma comment (lib,"Advapi32.lib")
  //------------------ 数据范例声明开端 --------------------//
  typedef struct _SYSTEM_MODULE_INFORMATION {
  ULONG Reserved[2];
  PVOID Base;
  ULONG Size;
  ULONG Flags;
  USHORT Index;
  USHORT Unknown;
  USHORT LoadCount;
  USHORT ModuleNameOffset;
  CHAR ImageName[256];
  } SYSTEM_MODULE_INFORMATION, *PSYSTEM_MODULE_INFORMATION;
  typedef struct _OBJECT_ATTRIBUTES {
  ULONG Length;
  HANDLE RootDirectory;
  PUNICODE_STRING ObjectName;
  ULONG Attributes;
  PVOID SecurityDescriptor;
  PVOID SecurityQualityOfService;
  } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;
  typedef enum _SECTION_INHERIT {
  ViewShare = 1,
  ViewUnmap = 2
  } SECTION_INHERIT;
  typedef struct _MY_PROCESS_INFO {
  ULONG PID;
  ULONG KPEB;
  ULONG CR3;
  CHAR Name[16];
  ULONG Reserved;
  } MY_PROCESS_INFO, *PMY_PROCESS_INFO;
  typedef long NTSTATUS;
  //------------------ 数据范例声明结束 --------------------//
  //--------------------- 预界说开端 -----------------------//
  #define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
  #define STATUS_SUCCESS              0x00000000
  #define STATUS_UNSUCCESSFUL         0xC0000001
  #define STATUS_NOT_IMPLEMENTED      0xC0000002
  #define STATUS_INFO_LENGTH_MISMATCH 0xC0000004
  #define STATUS_INVALID_PARAMETER    0xC000000D
  #define STATUS_ACCESS_DENIED        0xC0000022
  #define STATUS_BUFFER_TOO_SMALL     0xC0000023
  #define OBJ_KERNEL_HANDLE           0x00000200
  #define SystemModuleInformation     11
  #define InitializeObjectAttributes( p, n, a, r, s ) { \    /* 注意,由于php标签过滤,以下6行缺少续行符\ */
  (p)->Length = sizeof( OBJECT_ATTRIBUTES );        
  (p)->RootDirectory = r;                           
  (p)->Attributes = a;                              
  (p)->ObjectName = n;                              
  (p)->SecurityDescriptor = s;                      
  (p)->SecurityQualityOfService = NULL;             
  }
  //--------------------- 预界说结束 -----------------------//
  //------------------ Native API声明开端 ------------------//
  NTSYSAPI
  VOID
  NTAPI
  RtlInitUnicodeString(
  PUNICODE_STRING DestinationString,
  PCWSTR SourceString
  );
  NTSYSAPI
  NTSTATUS
  NTAPI
  ZwQuerySystemInformation(
  ULONG SystemInformationClass,
  PVOID SystemInformation,
  ULONG SystemInformationLength,
  PULONG ReturnLength
  );
  NTSYSAPI
  NTSTATUS
  NTAPI
  ZwOpenSection(
  OUT PHANDLE SectionHandle,
  IN ACCESS_MASK DesiredAccess,
  IN POBJECT_ATTRIBUTES ObjectAttributes
  );
  NTSYSAPI
  NTSTATUS
  NTAPI
  ZwMapViewOfSection(
  IN HANDLE SectionHandle,
  IN HANDLE ProcessHandle,
  IN OUT PVOID *BaseAddress,
  IN ULONG ZeroBits,
  IN ULONG CommitSize,
  IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
  IN OUT PULONG ViewSize,
  IN SECTION_INHERIT InheritDisposition,
  IN ULONG AllocationType,
  IN ULONG Protect
  );
  NTSYSAPI
  NTSTATUS
  NTAPI
  ZwUnmapViewOfSection(
  IN HANDLE ProcessHandle,
  IN PVOID BaseAddress
  );
  NTSYSAPI
  NTSTATUS
  NTAPI
  ZwClose(
  IN HANDLE Handle
  );
  NTSYSAPI
  NTSTATUS
  NTAPI
  NtVdmControl(
  IN ULONG ControlCode,
  IN PVOID ControlData
  );
  //------------------ Native API声明结束 ------------------//
  //------------------ 全局变量界说开端 --------------------//
  NTSTATUS
  (NTAPI *pfnNtVdmControl)(
  IN ULONG ControlCode,
  IN PVOID ControlData
  );
  BOOLEAN
  (NTAPI *pfnPsGetVersion)(
  PULONG MajorVersion OPTIONAL,
  PULONG MinorVersion OPTIONAL,
  PULONG BuildNumber OPTIONAL,
  PUNICODE_STRING CSDVersion OPTIONAL
  );
  HANDLE
  (NTAPI *pfnPsGetCurrentProcessId)(
  );
  PVOID
  (NTAPI *pfnMemcpy)(
  IN VOID UNALIGNED *Destination,
  IN CONST VOID UNALIGNED *Source,
  IN SIZE_T Length
  );
  ULONG
  (_cdecl *pfnDbgPrint)(
  IN PCHAR Format,
  ...
  );
  ULONG *pPsInitialSystemProcess;
  //------------------ 全局变量界说结束 --------------------// 


    文章作者: 福州军威计算机技术有限公司
    军威网络是福州最专业的电脑维修公司,专业承接福州电脑维修、上门维修、IT外包、企业电脑包年维护、局域网网络布线、网吧承包等相关维修服务。
    版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出处 、作者信息和声明。否则将追究法律责任。

TAG:
评论加载中...
内容:
评论者: 验证码: