找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 3398|回复: 3

ring0使用ZwCreateThread创建用户线程

[复制链接]

30

主题

210

回帖

2778

积分

用户组: 版主

UID
1821
精华
7
威望
69 点
宅币
2159 个
贡献
206 次
宅之契约
0 份
在线时间
480 小时
注册时间
2016-7-12
发表于 2016-8-4 05:07:15 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
本帖最后由 Ayala 于 2016-10-10 10:39 编辑

  1. .386
  2. .model flat,stdcall
  3. option casemap:none




  4. include         ..\..\..\masm32\include\w2k\ntstatus.inc
  5. include         ..\..\..\masm32\include\w2k\ntddk.inc
  6. include         ..\..\..\masm32\include\w2k\w2kundoc.inc

  7. include         ..\..\..\masm32\include\w2k\hal.inc
  8. includelib         ..\..\..\masm32\lib\w2k\hal.lib

  9. include         ..\..\..\masm32\include\w2k\ntoskrnl.inc
  10. includelib         ..\..\..\masm32\lib\w2k\ntoskrnl.lib

  11. include         ..\..\..\masm32\Macros\Strings.mac


  12. KGDT_R3_DATA equ 00020H
  13. KGDT_R3_CODE equ 00018H
  14. KGDT_R3_TEB equ 00038H


  15. OBJ_KERNEL_HANDLE  equ 00000200H


  16. IFNDEF INITIAL_TEB
  17. INITIAL_TEB struc
  18.         OldStackBase                        DWORD ?
  19.         OldStackLimit                          DWORD ?
  20.         StackBase                                 DWORD ?
  21.         StackLimit                                 DWORD ?
  22.         StackAllocationBase                DWORD ?
  23. INITIAL_TEB ends
  24. ENDIF


  25. IFNDEF CLIENT_ID
  26. CLIENT_ID STRUCT        ; sizeof = 8
  27.         UniqueProcess        HANDLE        ?
  28.         UniqueThread        HANDLE        ?
  29. CLIENT_ID ENDS
  30. ENDIF

  31. IFNDEF OBJECT_ATTRIBUTES
  32. OBJECT_ATTRIBUTES STRUCT                ; sizeof = 18h
  33.         _Length                                                DWORD                        ? ; original name Length
  34.         RootDirectory                                HANDLE                        ?
  35.         ObjectName                                        PUNICODE_STRING        ?
  36.         Attributes                                        DWORD                        ?
  37.         SecurityDescriptor                        PVOID                        ? ; Points to type SECURITY_DESCRIPTOR
  38.         SecurityQualityOfService        PVOID                        ? ; Points to type SECURITY_QUALITY_OF_SERVICE
  39. OBJECT_ATTRIBUTES ENDS
  40. POBJECT_ATTRIBUTES typedef OBJECT_ATTRIBUTES
  41. ENDIF


  42.         PROTO@32 TYPEDEF PROTO STDCALL :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
  43.         PPROTO@32 TYPEDEF ptr PROTO@32
  44.        
  45.         externdef _imp__ZwCreateSymbolicLinkObject@16:DWORD
  46.        
  47. .data
  48.         ZwCreateThread PPROTO@32 0
  49.        
  50.        

  51. .code


  52. _RtlpCreateStack proc uses esi Process,MaximumStackSize,CommittedStackSize,ZeroBits,PINITIAL_TEB
  53.                                                
  54.         LOCAL Stack:DWORD
  55.        
  56.         and Stack,NULL
  57.         invoke ZwAllocateVirtualMemory,Process,\
  58.                                                                 addr Stack,\
  59.                                                                 0,\
  60.                                                                 addr CommittedStackSize,\
  61.                                                                 MEM_COMMIT,\
  62.                                                                 PAGE_READWRITE
  63.        
  64.         or eax,eax
  65.         jnz done
  66.        
  67.         mov esi,PINITIAL_TEB
  68.         assume esi:ptr INITIAL_TEB
  69.        
  70.         mov [esi].OldStackBase,0
  71.         mov [esi].OldStackLimit,0
  72.        
  73.         mov eax,Stack
  74.         mov [esi].StackLimit,eax
  75.         mov [esi].StackAllocationBase,eax
  76.        
  77.         add eax,CommittedStackSize
  78.         mov [esi].StackBase,eax
  79.        
  80.         assume esi:nothing
  81. done:
  82.         ret
  83. _RtlpCreateStack endp

  84. _RtlpFreeStack proc uses esi Process,InitialTeb
  85.         LOCAL Zero:DWORD
  86.        
  87.         and Zero,0
  88.         mov esi,InitialTeb
  89.         assume esi:ptr INITIAL_TEB
  90.         invoke ZwFreeVirtualMemory,Process,[esi].StackAllocationBase,addr Zero,MEM_RELEASE
  91.        
  92.         invoke RtlZeroMemory,esi,sizeof INITIAL_TEB
  93.         assume esi:nothing
  94.         ret
  95. _RtlpFreeStack endp

  96. _RtlInitializeContext proc uses esi process,Context,Parameter,StartAddress,StackBase
  97.        
  98.         mov esi,Context
  99.         assume esi:ptr CONTEXT
  100.        
  101.         mov [esi].ContextFlags,10007h
  102.        
  103.        
  104.         xor eax,eax
  105.         mov [esi].regEax,eax
  106.         mov [esi].regEcx,eax
  107.         mov [esi].regEdx,eax
  108.         mov [esi].regEbx,eax
  109.         mov [esi].regEsi,eax
  110.         mov [esi].regEdi,eax
  111.         mov [esi].regEbp,eax

  112.         mov [esi].regSegGs,eax
  113.         mov [esi].regSegFs,KGDT_R3_TEB
  114.         mov [esi].regSegEs,KGDT_R3_DATA
  115.         mov [esi].regSegDs,KGDT_R3_DATA
  116.         mov [esi].regSegSs,KGDT_R3_DATA
  117.         mov [esi].regSegCs,KGDT_R3_CODE
  118.        
  119.         mov [esi].regEFlags,200h
  120.        

  121.         mov eax,StartAddress
  122.         mov [esi].regEip,eax
  123.        

  124.         mov eax,StackBase
  125.         and eax,-8
  126.         mov [esi].regEsp,eax
  127.                
  128.         assume esi:nothing
  129.         ret
  130. _RtlInitializeContext endp

  131. _RtlCreateUserThread proc uses esi edi Process,\
  132.                                                                                 SecurityDescriptor,\
  133.                                                                                 CreateSuspended,\
  134.                                                                                 StackZeroBits,\
  135.                                                                                 StackReserved,\
  136.                                                                                 StackCommit,\
  137.                                                                                 StartAddress,\
  138.                                                                                 StartParameter,\
  139.                                                                                 ThreadHandle,\
  140.                                                                                 ClientID
  141.         LOCAL hThread:DWORD
  142.         LOCAL context:CONTEXT
  143.         LOCAL initteb:INITIAL_TEB
  144.         LOCAL ThreadCid:CLIENT_ID
  145.         LOCAL oa:OBJECT_ATTRIBUTES
  146.         LOCAL tBase:DWORD
  147.         LOCAL tSize:DWORD
  148.        
  149.         invoke _RtlpCreateStack,Process,StackReserved,StackCommit,StackZeroBits,addr initteb
  150.        
  151.         invoke _RtlInitializeContext,Process,addr context,StartParameter,StartAddress,initteb.StackBase
  152.        
  153.         mov oa._Length,sizeof oa
  154.         mov oa.RootDirectory,NULL
  155.         mov oa.ObjectName,NULL
  156.         mov oa.Attributes,0
  157.         mov eax,SecurityDescriptor
  158.         mov oa.SecurityDescriptor,eax
  159.         mov oa.SecurityQualityOfService,NULL
  160.         mov ax,cs
  161.         .if ax==8
  162.                 or oa.Attributes,OBJ_KERNEL_HANDLE       
  163.         .endif
  164.        
  165.         invoke ZwCreateThread,addr hThread,\
  166.                                                 THREAD_ALL_ACCESS,\
  167.                                                 addr oa,\
  168.                                                 Process,\
  169.                                                 addr ThreadCid,\
  170.                                                 addr context,\
  171.                                                 addr initteb,\
  172.                                                 CreateSuspended
  173.         mov esi,eax
  174.         .if eax<SDWORD ptr 0
  175.                 invoke _RtlpFreeStack,Process,addr initteb
  176.         .else
  177.                 mov ecx,ThreadHandle
  178.                 mov eax,hThread
  179.                 mov [ecx],eax
  180.                
  181.                 lea ecx,ThreadCid
  182.                 assume ecx:ptr CLIENT_ID
  183.                 mov edx,ClientID
  184.                 assume edx:ptr CLIENT_ID
  185.                
  186.                 mov eax,[edx].UniqueProcess
  187.                 mov [ecx].UniqueProcess,eax
  188.                
  189.                 mov eax,[edx].UniqueThread
  190.                 mov [ecx].UniqueThread,eax
  191.                
  192.                 assume edx:nothing
  193.                 assume ecx:nothing
  194.         .endif
  195.         mov eax,esi
  196.         ret
  197. _RtlCreateUserThread endp


  198. _non proc

  199.         ret
  200. _non endp


  201. thunk:
  202.         mov eax,34h
  203.         lea edx,[esp+4]
  204.         pushfd
  205.         push 8
  206.         call $
  207.         ret 10h
  208. thunk_length equ $-offset thunk       


  209. _drvmain proc uses esi edi ebx
  210.         LOCAL process:DWORD
  211.         LOCAL thread:DWORD
  212.         LOCAL ClientId:CLIENT_ID
  213.         LOCAL oa:OBJECT_ATTRIBUTES
  214.         LOCAL tBase:DWORD
  215.        
  216.         mov eax,_imp__ZwCreateSymbolicLinkObject@16
  217.         add eax,thunk_length
  218.         mov ZwCreateThread,eax
  219.        
  220.         ;
  221.         mov tBase,0b50000h
  222.        
  223.         mov ClientId.UniqueProcess,02d0h
  224.         and ClientId.UniqueThread,NULL

  225.         mov oa._Length,sizeof oa
  226.         mov oa.RootDirectory,NULL
  227.         mov oa.ObjectName,NULL
  228.         mov oa.Attributes,0
  229.         mov oa.SecurityDescriptor,NULL
  230.         mov oa.SecurityQualityOfService,NULL
  231.        
  232.         invoke ZwOpenProcess,addr process,PROCESS_ALL_ACCESS,addr oa,addr ClientId
  233.         .if eax>=SDWORD ptr 0

  234.                 invoke _RtlCreateUserThread,process,NULL,FALSE,0,0,4000h,tBase,NULL,addr thread,addr ClientId
  235.                
  236.        
  237.                
  238.                 invoke ZwClose,thread
  239.                 invoke ZwClose,process
  240.                
  241.         .endif
  242.         mov eax,1
  243.         ret
  244. _drvmain endp

  245. __DriverEntry proc pDriverObject:dword, pusRegistryPath:dword
  246.         int 3
  247.         call _drvmain
  248.         ret
  249. __DriverEntry endp
  250. end __DriverEntry
复制代码
回复

使用道具 举报

0

主题

25

回帖

52

积分

用户组: 小·技术宅

UID
1741
精华
0
威望
2 点
宅币
23 个
贡献
0 次
宅之契约
0 份
在线时间
4 小时
注册时间
2016-6-3
发表于 2018-5-3 21:11:29 | 显示全部楼层
创建完以后,这个线程有什么强大特征吗??
回复 赞! 靠!

使用道具 举报

30

主题

210

回帖

2778

积分

用户组: 版主

UID
1821
精华
7
威望
69 点
宅币
2159 个
贡献
206 次
宅之契约
0 份
在线时间
480 小时
注册时间
2016-7-12
 楼主| 发表于 2018-5-3 21:21:58 | 显示全部楼层
誓不回头 发表于 2018-5-3 21:11
创建完以后,这个线程有什么强大特征吗??

没什么强大特征 没有通知csr 权限约等同于users权限 只是相对隐蔽的一种方式
回复 赞! 靠!

使用道具 举报

0

主题

25

回帖

52

积分

用户组: 小·技术宅

UID
1741
精华
0
威望
2 点
宅币
23 个
贡献
0 次
宅之契约
0 份
在线时间
4 小时
注册时间
2016-6-3
发表于 2018-5-3 21:44:13 | 显示全部楼层
如果没有特征,如此就意义不大。。。
回复 赞! 靠!

使用道具 举报

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-4-20 04:13 , Processed in 0.039337 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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