13_平行進程

能夠用來作進程保護!!! web

平行得2個程序之間ide

1570457002031

》經過cr3的切換,致使運行的代碼是另一個程序中的代碼函數

上面代碼的缺陷:ui

  • 不能動態獲取cr3,得程序二先運行打印出來spa

  • 不能很好平行的切換代碼執行code

注意 這裏實驗的時候,須要屢次調整地址;使得能平行過渡到另外一個程序;能夠使用Nop 這些填充來控制二者之間代碼過分的位置照應。orm

程序1:blog

// 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);
}
}

結果: 幾經修改終於平行;因此 仍是得動態調整好一點。有時間再搞.ip

程序2 運行起來一開始得數據:

1570462554891

程序 1 運行起來以後(注意這裏若是代碼地址 對不齊 那麼 就會 報錯異常 ):

1570462158798

相關文章
相關標籤/搜索