13_平行进程

可以用来做进程保护!!!

平行得2个程序之间

1570457002031

》通过cr3的切换,导致运行的代码是另外一个程序中的代码

上面代码的缺陷:

  • 不能动态获取cr3,得程序二先运行打印出来

  • 不能很好平行的切换代码执行

注意 这里实验的时候,需要多次调整地址;使得能平行过渡到另一个程序;可以使用Nop 这些填充来控制两者之间代码过度的位置照应。

程序1:

// 6_平行进程A.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "pch.h"
#include <stdio.h>
#include<stdlib.h>
#include <Windows.h>
#define PTE(x) ( (DWORD *) (0xc000000 + ((x >> 12) << 3)))
#define PDE(x) ((DWORD *)(0xc0600000 + ((x >> 21) << 3)))
//0x403018
DWORD g_num;
//0x401000
void _declspec(naked) IdtEntry()
{
__asm
{
int 3;
}

__asm {

mov eax, cr3
mov ds : [0x8003f3f0], eax
mov eax, 0x099401a0
nop
nop
mov cr3, eax
//00401011
mov ecx, 0x12345678
mov ecx, 0x12345678
mov ecx, 0x12345678
mov ecx, 0x12345678
//00401825
nop
nop
nop
nop
nop
nop
nop
nop
mov g_num, ecx
push 0x3b
pop fs
iretd
}
}
void _declspec(nakedgo()
{
__asm {
int 0x20;
ret;
}
}
//eq 8003f500 0040ee00 00081000
void main()
{
if ((DWORD)IdtEntry != 0x401040)// code : there is not same as the past, there some crt func takes the place401000 ~401040
{
printf("WRONG ADDR");
//exit(0);
}
go();
}

程序2:

// 6_平行进程B.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "pch.h"
#include<stdio.h>
#include<stdlib.h>

#include <Windows.h>
//0x403018
DWORD g_cr3;
DWORD g_num = 0;
//0x401000
void _declspec(naked) IdtEntry()
{
__asm{
int 3;
}
__asm {
mov eax, cr3
mov g_cr3, eax
push 0x3b
pop fs;
iretd
//00401009
mov eax, 0x12345678
nop
nop
nop
mov eax, 1
mov g_num, eax
mov ecx,0xaaaaaaaa
mov eax, ds: [0x8003f3f0]
mov cr3, eax
//00401029
}
}
void _declspec(naked) go()
{
__asm{
int 0x20
ret;
}
}
void main()
{
if ((DWORD)IdtEntry != 0x401040)// code : there is not same as the past, there some crt func takes the place401000 ~401040
{
printf("WRONG ADDR");
//exit(0);
}
go();
int i = 0;
while (1)
{
i++;
if (i % 10 == 0)
{
i = 0;
system("cls");
}
printf("cr3:%p\t num%d\n", g_cr3, g_num);
Sleep(100);
}
}

扫描二维码关注公众号,回复: 7540993 查看本文章

结果: 几经修改终于平行;所以 还是得动态调整好一点。有时间再搞.

程序2 运行起来一开始得数据:

1570462554891

程序 1 运行起来之后(注意这里如果代码地址 对不齐 那么 就会 报错异常 ):

1570462158798


猜你喜欢

转载自www.cnblogs.com/leibso-cy/p/11719256.html