TSS切换实验

0x001 TSS的基础知识

TSS是一段内存结构

char st[10] = {0}; // st 的地址是 0042b034
TSS tss = {// tss的地址是 0x00427b40
    0x00000000,//link
    (DWORD)st,//esp0
    0x00000010,//ss0
    0x00000000,//esp1
    0x00000000,//ss1
    0x00000000,//esp2
    0x00000000,//ss2
    0x00000000,//cr3
    0x0040fad0,//eip
    0x00000000,//eflags
    0x00000000,//eax
    0x00000000,//ecx
    0x00000000,//edx
    0x00000000,//ebx
    (DWORD)st,//esp
    0x00000000,//ebp
    0x00000000,//esi
    0x00000000,//edi
    0x00000023,//es  
    0x00000008,//cs  
    0x00000010,//ss
    0x00000023,//ds
    0x00000030,//fs
    0x00000000,//gs
    0x00000000,//ldt
    0x20ac0000
};

理解TR寄存器  TSS段描述符  TSS段的关系


0x002、测试代码

// 20180322_05.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>

DWORD dwOK;
DWORD dwESP;
DWORD dwCS;

__declspec(naked)func()//00401020
{
	dwOK = 1;
	__asm{
		//int 3
		mov eax,esp
		mov dwESP,eax
		mov ax,cs
		mov word ptr [dwCS],ax

		//返回
		iret
	}
}

//eq 8003f0c0 0000e912`fdcc0068



int main(int argc, char* argv[])
{
	char bu[0x10]; //0x12ff70
	int iCr3;
	printf("input CR3:\n");
	scanf("%x",&iCr3); //!process 0 0  获取

	//0012fDCC
	DWORD iTSS[0x68]={
	0x00000000,//link
	(DWORD)bu,//esp0
	0x00000010,//ss0
	0x00000000,//esp1
	0x00000000,//ss1
	0x00000000,//esp2
	0x00000000,//ss2
	(DWORD)iCr3,//cr3
	0x00401020,//eip
	0x00000000,//eflags
	0x00000000,//eax
	0x00000000,//ecx
	0x00000000,//edx
	0x00000000,//ebx
	(DWORD)bu,//esp
	0x00000000,//ebp
	0x00000000,//esi
	0x00000000,//edi
	0x00000023,//es
	0x00000008,//cs
	0x00000010,//ss
	0x00000023,//ds
	0x00000030,//fs
	0x00000000,//gs
	0x00000000,//ldt
	0x20ac0000
	};

	char buff[6];

	*(DWORD*)&buff[0] = 0x12345678;
	*(WORD*)&buff[4] = 0x48;

	__asm
	{
		call fword ptr[buff]
	}

	printf("ok = %d ESP = %x CS = %x \n",dwOK,dwESP,dwCS);

	return 0;
}


0x003 测试环境


eq 8003f048 0000e912`fdcc0068



0x004 修改CR3


PROCESS 86311228  SessionId: 0  Cid: 059c    Peb: 7ffdf000  ParentCid: 0640
    DirBase: 06d80360  ObjectTable: e17d9ac0  HandleCount:  73.
    Image: 20180322_05.exe

对 

DirBase: 06d80360  进行设置

0x005 运行读取


总结: 难点很多,理解起来,模模糊糊的, 只是完成了实验, 很多还是不太懂!!


原文链接: TSS切换实验 版权所有,转载时请注明出处,违者必究。
注明出处格式:流沙团 ( http://gyarmy.com/post-422.html )

发表评论

1则评论给“TSS切换实验”

  1. BOB

    兄弟你这代码差了个 void 执行不过
        __declspec(naked)func()

    回复