Znn3bq.jpeg
ÉÇÍ·´óѧº£Ñó¿ÆÑ§½ÓÊܵ÷¼Á
²é¿´: 380  |  »Ø¸´: 0
µ±Ç°Ö÷ÌâÒѾ­´æµµ¡£

sdlj8051

½ð³æ (ÖøÃûдÊÖ)

[½»Á÷] [תÌù]Ó¦ÓÃÄÚ´æ¶ÏµãµÄLoader

program Loader;
(***********************************)
(*                                 *)
(* Memory Access Breakpoint Loader *)
(*            by tt.t              *)
(*                                 *)
(*                                 *)
(***********************************)

{
Ä¿±ê£ºÀ¹½Ø¶ÔÖ¸¶¨µØÖ·µÄд²Ù×÷£¬nopµôдµØÖ·µÄÖ¸Áî¡£
Äѵ㣺ÔÚÒª²¹¶¡µØÖ·ÉèMemory Write Breakpoint£¬²éÁ˰ëÌìûÕÒµ½ÏֳɵĶ«Î÷£¬Ö»ºÃ×Ô¼ºÐ´¡£
˼·£º½«Òª²¹¶¡µÄµØÖ·ÉèΪ²»¿Éд£¬µ±Ð´Ê±»á·¢ÉúAV´íÎó£¬È»ºó½øÐÐPatch¡£µ«VirtualProtectEx»á½«Õû

¸öPageÉèΪ²»¿ÉдÊôÐÔ£¬ËùÓÐдPageµÄ²Ù×÷¶¼»á²úÉúAccess violation£¬ÎÞ·¨Ö±½ÓÕÒµ½ÒªPatchµÄ´úÂë¡£
½â¾ö·½·¨£ºÒª±£´æµØÖ·ËùÔÚPageµÄµØÖ··¶Î§£¬·¢ÉúAV´íÎóʱÅжÏÊÇ·ñÒòΪVirtualProtect²úÉúµÄExceptio

n£¬Èç²»Êǽ«PageµÄÊôÐÔÉèΪ¿Éд£¬Í¬Ê±ÉèÖõ¥²½±êÖ¾£¬Ð´²Ù×÷Íê³Éºó»Ö¸´PageΪ²»¿ÉдÊôÐÔ£¬¼ÌÐøÖ´

ÐУ¬Ö±ÖÁÕÒµ½ÐèPatch´úÂë¡£
²»ÖªµÀÓÐûÓиüºÃµÄ·½·¨¡£
}

uses
  JwaWinType,
  JwaWinNt,
  JwaWinBase,
  JwaWinUser;

{$R *.res}

var
  si: STARTUPINFO;
  pi: PROCESS_INFORMATION;

function MyExtractFilePath(f: String): String;
var
  i, l: integer;
begin
  l := Length(f);
  for i := l downto 1 do
    if f = '' then Break;
  result := copy(f, 0, i);
end;

procedure CreateVictimProcess(Path: String);
const
  Nop: PChar = Chr($90) + Chr($90) + Chr($90);
var
  DbgEvent: TDebugEvent;
  DbgParam: DWORD;
  OldPrt, NewPrt: DWORD;
  pPatch: PByte;
  PgMin, PgMax: DWORD;
  MemInfo: TMemoryBasicInformation;
  WExpAddr: DWORD;
  DbgContext: TContext;
  rm: Boolean;
  hThread: DWORD;
begin   
  ZeroMemory(@si, sizeof(STARTUPINFO));
  si.cb := sizeof(STARTUPINFO);
  if not CreateProcess(PChar(Path), nil, nil, nil, False, CREATE_SUSPENDED or

CREATE_DEFAULT_ERROR_MODE, nil,
                       PChar(MyExtractFilePath(Path)), si, pi) then
  begin
    MessageBox(0, 'CreateProcess failed! ', 'Error!', 0);
    exit;
  end;
  ResumeThread(pi.hThread);
  if WaitForInputIdle(pi.hProcess, INFINITE) <> 0 then
  begin
    MessageBox(0, 'WaitForInputIdle failed! ', 'Error!', 0);
    exit;
  end;
  if not DebugActiveProcess(pi.dwProcessId) then
  begin
    MessageBox(0, 'DebugActiveProcess failed! ', 'Error!', 0);
    exit;
  end;
  if VirtualQueryEx(pi.hProcess, Pointer($9c66BC), MemInfo, SizeOf(MemInfo)) = 0 then
  begin
    MessageBox(0, 'VirtualQueryEx failed! ', 'Error!', 0);
    exit;
  end;
  PgMin := DWORD(MemInfo.BaseAddress);
  pgMax := PgMin + MemInfo.RegionSize;
  {VirtualProtect»á½«Õû¸öPageÉèΪ²»¿ÉдÊôÐÔ£¬ËùÓÐдPageµÄ²Ù×÷¶¼»á²úÉúAccess violation£¬Òª±£´æ

Õû¸öPageµÄµØÖ··¶Î§£¬
   ºóÃæ¿ÉÒÔÅжÏÊÇ·ñÒòΪVirtualProtect²úÉúµÄException}      
  if not VirtualProtectEx(pi.hProcess, Pointer($9c66BC), 1, PAGE_EXECUTE_READ, @OldPrt) then
  begin
    MessageBox(0, 'VirtualProtectEx failed! ', 'Error!', 0);
    exit;
  end;
  {¸ÄдPageÊôÐÔΪ²»¿Éд}
  rm := false;
  while WaitForDebugEvent(DbgEvent, INFINITE) do
  begin
    DbgParam := DBG_CONTINUE;
    case DbgEvent.dwDebugEventCode of
      EXCEPTION_DEBUG_EVENT:
      begin
        if DbgEvent.Exception.ExceptionRecord.ExceptionCode <> EXCEPTION_BREAKPOINT then
          case DbgEvent.Exception.ExceptionRecord.ExceptionCode of
            EXCEPTION_SINGLE_STEP: {µ¥²½ÖжÏ}
            begin
              if rm then {ÓÉÓÚEXCEPTION_ACCESS_VIOLATION²úÉúµÄµ¥²½Öжϣ¬»Ö¸´PageΪ²»¿ÉдÊôÐÔ}
              begin
                rm := false;
                VirtualProtectEx(pi.hProcess, Pointer($9c66BC), 1, PAGE_EXECUTE_READ, @NewPrt);
              end;
            end;
            EXCEPTION_ACCESS_VIOLATION: {AVÖжÏ}
            begin
              DbgParam := DBG_EXCEPTION_NOT_HANDLED;
              if DbgEvent.Exception.ExceptionRecord.ExceptionInformation[0] = 1 then {д²Ù×÷}
              begin
                WExpAddr := DbgEvent.Exception.ExceptionRecord.ExceptionInformation[1]; {д²Ù×÷µÄÄ¿±êµØ

Ö·}
                if (WExpAddr >= PgMin) and (WExpAddr <= PgMax) then {Ä¿±êµØÖ·ÔÚPage·¶Î§}
                begin
                  DbgParam := DBG_CONTINUE;
                  if(WExpAddr <> $9c66BC) then {²»ÊÇдָ¶¨µØÖ·}
                  begin
                    VirtualProtectEx(pi.hProcess, Pointer($9c66BC), 1, OldPrt, @NewPrt);
                    DbgContext.ContextFlags := CONTEXT_CONTROL;
                    hThread := OpenThread(THREAD_ALL_ACCESS, false, DbgEvent.dwThreadId);
                    GetThreadContext(hThread, DbgContext);
                    DbgContext.EFlags := DbgContext.EFlags or $100;

{Éèµ¥²½±êÖ¾£¬»á´¥·¢EXCEPTION_SINGLE_STEP}
                    SetThreadContext(hThread, DbgContext);
                    rm := true; {±êÖ¾£¬±íÃ÷ÊÇEXCEPTION_ACCESS_VIOLATION²úÉúµÄµ¥²½ÖжÏ}
                  end
                  else
                  begin {Patch}
                    pPatch := DbgEvent.Exception.ExceptionRecord.ExceptionAddress;
                    VirtualProtectEx(pi.hProcess, pPatch, 3, PAGE_READWRITE, @NewPrt);
                    WriteProcessMemory(pi.hProcess, pPatch, Nop, 3, nil);
                    VirtualProtectEx(pi.hProcess, pPatch, 3, NewPrt, @NewPrt);
                  end;
                end;
              end;
            end;
            else
              DbgParam := DBG_EXCEPTION_NOT_HANDLED;
          end;
      end;
      EXIT_PROCESS_DEBUG_EVENT:
      begin
        ContinueDebugEvent(DbgEvent.dwProcessId, DbgEvent.dwThreadId, DbgParam);
        Break;
      end;
    end;
    ContinueDebugEvent(DbgEvent.dwProcessId, DbgEvent.dwThreadId, DbgParam);
  end;
end;

var
  Victim: string;
begin
  Victim := MyExtractFilePath(ParamStr(0)) + 'Wise***.exe'; //Êܺ¦³ÌÐò
  CreateVictimProcess(Victim);
  halt;
end.


--------------------------------------------------------------------------------

±ê Ìâ: ´ð¸´
·¢ÌûÈË:ttui
ʱ ¼ä: 2005-10-28 10:09
ÏêϸÐÅÏ¢:


ft£¬¼ÈÈ»¿´²»¶®ÄǾÍÄǾÍÏêϸעÊÍÏ¡£
¼ÇµÃÒª´óÌåÁ˽âÏÂdeubg apiµÄÓ÷¨ºÍʹÓÃÁ÷³ÌÏÈ.

procedure CreateVictimProcess(Path: String);
const
  Nop: PChar = Chr($90) + Chr($90) + Chr($90);
var
  DbgEvent: TDebugEvent;
  DbgParam: DWORD;  //ContinueDebugEventÓÃ,±êÖ¾ÈçºÎ´¦Àíµ÷ÊÔÏûÏ¢
  OldPrt, NewPrt: DWORD;
  pPatch: PByte;
  PgMin, PgMax: DWORD;
  MemInfo: TMemoryBasicInformation;
  WExpAddr: DWORD;
  DbgContext: TContext;
  rm: Boolean;
  hThread: DWORD;
begin   
  ZeroMemory(@si, sizeof(STARTUPINFO));
  si.cb := sizeof(STARTUPINFO);
  if not CreateProcess(PChar(Path), nil, nil, nil, False, CREATE_SUSPENDED or CREATE_DEFAULT_ERROR_MODE, nil,
                       PChar(MyExtractFilePath(Path)), si, pi) then
  begin
    MessageBox(0, 'CreateProcess failed! ', 'Error!', 0);
    exit;
  end;
  //½¨Á¢Ä¿±ê½ø³Ì
  ResumeThread(pi.hThread);
  //»Ö¸´½ø³ÌÖ´ÐÐ.ÆäʵCreateProcessʱ²»¼ÓCREATE_SUSPENDED±êÖ¾¾Í¿ÉÒÔÊ¡µôÕâ¾ä
  if WaitForInputIdle(pi.hProcess, INFINITE) <> 0 then
  begin
    MessageBox(0, 'WaitForInputIdle failed! ', 'Error!', 0);
    exit;
  end;
  //µÈ´ýÄ¿±ê½ø³ÌÍêÈ«ÔËÐÐÖÁÆä¿ªÊ¼µÈ´ýÓû§ÊäÈë.
  //ÒòΪĿ±ê³ÌÐòÊǼӹý¿ÇµÄ,¿ÇµÄ²¿·Ö»á¼ì²éµ÷ÊÔÆ÷,ËùÒԵȵ½¿ÇÔËÐнáÊøÔÚÈ¥debugËü.
  if not DebugActiveProcess(pi.dwProcessId) then
  begin
    MessageBox(0, 'DebugActiveProcess failed! ', 'Error!', 0);
    exit;
  end;
  //¹ÒÉÏÄ¿±ê³ÌÐò
  if VirtualQueryEx(pi.hProcess, Pointer($9c66BC), MemInfo, SizeOf(MemInfo)) = 0 then
  begin
    MessageBox(0, 'VirtualQueryEx failed! ', 'Error!', 0);
    exit;
  end;
  //²éѯÐèÒªÉèÄÚ´æ¶ÏµãµÄµØÖ·($9c66BC,Ò²¾ÍÊÇ0x9c66BC,ºóÃæ¼ò³Æaddr)ËùÔÚpageµÄÇé¿ö
  PgMin := DWORD(MemInfo.BaseAddress);
  pgMax := PgMin + MemInfo.RegionSize;
  //µÃµ½addrËùÔÚµÄpageµÄʼĩµØÖ·.
  {ÒòΪVirtualProtect»á½«addrËùÔÚÕû¸öPageÉèΪ²»¿ÉдÊôÐÔ(¼ûVirtualProtectµÄAPI˵Ã÷)£¬ËùÓÐдPageµÄ²Ù×÷,¼´Ê¹²»ÊÇдÎÒÃǸÐÐËȤ(µ«Î»ÓÚÄǸöpageÉÏ)µÄµØÖ·µÄ²Ù×÷,¶¼»áÒòΪ½«addrÉèΪ²»¿ÉдÊôÐÔ¶ø²úÉúAccess violation.ËùÒÔÕâÀïÒª±£´æÕû¸öPageµÄµØÖ··¶Î§£¬ÒÔ±ãºóÃæÅжÏAVÊDz»ÊÇÒòдaddr¶ø²úÉúµÄ}  
  if not VirtualProtectEx(pi.hProcess, Pointer($9c66BC), 1, PAGE_EXECUTE_READ, @OldPrt) then
  begin
    MessageBox(0, 'VirtualProtectEx failed! ', 'Error!', 0);
    exit;
  end;
  {¸ÄдaddrÊôÐÔΪ²»¿Éд.ÕâÀï»á½«addrËùÔÚµÄÕû¸öPageÉèΪ²»¿ÉдÊôÐÔ}
  rm := false;  {±êÖ¾ÊDz»ÊÇÒò´¦ÀíAVÉèÖõĵ¥²½ÖжϲúÉúµÄÖжÏ}
  while WaitForDebugEvent(DbgEvent, INFINITE) do  //µÈ´ýµ÷ÊÔÏûÏ¢
  begin
    DbgParam := DBG_CONTINUE;  //ĬÈÏ´¦Àíµ÷ÊÔÏûÏ¢
    case DbgEvent.dwDebugEventCode of
      EXCEPTION_DEBUG_EVENT:
      begin
        if DbgEvent.Exception.ExceptionRecord.ExceptionCode <> EXCEPTION_BREAKPOINT then
        //ÅжÏÊDz»ÊÇint 3²úÉúµÄÖжÏ.ÒòΪDebugActiveProcess¹ÒÉϳÌÐòºó»áÏòdebuger·¢³öÒ»¸öEXCEPTION_BREAKPOINTµ÷ÊÔÏûÏ¢,ÕâÀïºöÂÔËü
          case DbgEvent.Exception.ExceptionRecord.ExceptionCode of  //ÅжÏÒì³£ÀàÐÍ
            EXCEPTION_ACCESS_VIOLATION: {AVÒì³£}
            begin
              DbgParam := DBG_EXCEPTION_NOT_HANDLED; //±íʾÓÉÄ¿±ê³ÌÐòµÄSEH´¦ÀíÒì³£
              if DbgEvent.Exception.ExceptionRecord.ExceptionInformation[0] = 1 then
              begin  {ÊÇд²Ù×÷²úÉúµÄAV}
                WExpAddr := DbgEvent.Exception.ExceptionRecord.ExceptionInformation[1]; {WExpAddr =д²Ù×÷µÄÄ¿±êµØÖ·}
                if (WExpAddr >= PgMin) and (WExpAddr <= PgMax) then {WExpAddrÔÚaddrËùÔÚPageÉÏ}
                begin
                  DbgParam := DBG_CONTINUE;//±íʾÎÒÃÇÀ´´¦ÀíÒì³£,ÈÃÄ¿±ê³ÌÐò´Ó·¢ÉúÒì³£´¦¼ÌÐøÖ´ÐÐ.
                  if(WExpAddr <> $9c66BC) then {WExpAddr²»ÊÇдaddr,ÒªÔÊÐíÄ¿±ê³ÌÐòд²Ù×÷}
                  begin
                    VirtualProtectEx(pi.hProcess, Pointer($9c66BC), 1, OldPrt, @NewPrt);//»Ö¸´addrËùÔÚpageΪԭÀ´µÄÊôÐÔ(¿Éд)

                    DbgContext.ContextFlags := CONTEXT_CONTROL;
                    hThread := OpenThread(THREAD_ALL_ACCESS, false, DbgEvent.dwThreadId);
                    //ÓÉThread IdµÃµ½Thread handle
                    GetThreadContext(hThread, DbgContext);
                    //µÃµ½threadµÄContext,ÉèÖõ¥²½Ö´ÐбêÖ¾,ÈÃд²Ù×÷Íê³Éºó·¢Éúµ¥²½ÖжÏ,ÒԱ㽫addrÖØÐÂÉèΪ²»¿Éд,À¹½ØÏÂÒ»´Îд²Ù×÷.
                    DbgContext.EFlags := DbgContext.EFlags or $100; {Éèµ¥²½±êÖ¾}
                    SetThreadContext(hThread, DbgContext);
                    //ÉèÖÃthreadµÄContext

                    rm := true; {±êÖ¾£¬±íÃ÷ÊÇÎÒÃÇ´¦ÀíAV¶ø²úÉúµÄµ¥²½ÖжÏ}
                  end
                  else  //{WExpAddrÊÇдaddr,½øÐÐPatch}
                  begin
                    pPatch := DbgEvent.Exception.ExceptionRecord.ExceptionAddress;
                    //дµØÖ·²Ù×÷Óï¾äµØÖ·
                    VirtualProtectEx(pi.hProcess, pPatch, 3, PAGE_READWRITE, @NewPrt);
                    //Éè²Ù×÷Óï¾äµØÖ·Îª¿Éд
                    WriteProcessMemory(pi.hProcess, pPatch, Nop, 3, nil);
                    //nopµôдµØÖ·Óï¾ä
                    VirtualProtectEx(pi.hProcess, pPatch, 3, NewPrt, @NewPrt);
                    //»Ö¸´Óï¾äµØÖ·ÊôÐÔ
                  end;
                end;
              end;
            end;{AVÒì³£´¦ÀíÍê±Ï}
            EXCEPTION_SINGLE_STEP: {·¢Éúµ¥²½ÖжÏ}
            begin
              if rm then {ÓÉÓÚ´¦ÀíAV²úÉúµÄµ¥²½ÖжÏ.}
              begin
                rm := false;
               //ÖØÖñêÖ¾
                VirtualProtectEx(pi.hProcess, Pointer($9c66BC), 1, PAGE_EXECUTE_READ, @NewPrt);
               //»Ö¸´PageΪ²»¿ÉдÊôÐÔ,ÒÔ±ãÀ¹½ØÏ´Îд²Ù×÷
              end;
            end;
            else//²»ÊÇAVÖжϻòµ¥²½ÖжÏ,ÓÉÄ¿±ê³ÌÐòµÄSEH´¦ÀíÒì³£
              DbgParam := DBG_EXCEPTION_NOT_HANDLED;
          end;
      end;
      EXIT_PROCESS_DEBUG_EVENT:
      begin
        ContinueDebugEvent(DbgEvent.dwProcessId, DbgEvent.dwThreadId, DbgParam);
        //Ä¿±ê³ÌÐòÍÆ³ö,loaderʹÃü½áÊø,Í˳ö
        Break;
      end;
    end;
    ContinueDebugEvent(DbgEvent.dwProcessId, DbgEvent.dwThreadId, DbgParam);
  end;
end;

[ Last edited by sdlj8051 on 2006-10-6 at 11:31 ]
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ sdlj8051 µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[²ÄÁϹ¤³Ì] ²ÄÁϵ÷¼ÁÍÆ¼ö +9 µ°¸âx2 2026-04-07 9/450 2026-04-13 09:07 by lhj2009
[¿¼ÑÐ] 295·ÖÇóµ÷¼Á +13 ?ÒªÉϰ¶? 2026-04-10 13/650 2026-04-12 15:37 by laoshidan
[¿¼ÑÐ] 305Çóµ÷¼Á +7 Â꿨°Í¿¨boom 2026-04-11 7/350 2026-04-12 07:35 by zhouxiaoyu
[¿¼ÑÐ] 296Çóµ÷¼Á +8 Íô£¡£¿£¡ 2026-04-09 8/400 2026-04-11 21:02 by ÄæË®³Ë·ç
[¿¼ÑÐ] 343Çóµ÷¼Á +9 Íõ¹ú˧ 2026-04-10 9/450 2026-04-11 20:31 by dongdian1
[¿¼ÑÐ] 086003µ÷¼ÁÇóÖú +21 ËÕß®Íò 2026-04-09 22/1100 2026-04-11 20:25 by dongdian1
[¿¼ÑÐ] µ÷¼Á +5 ÎĵÀÐÇ̨ 2026-04-11 5/250 2026-04-11 15:01 by ¿­¿­Òª±ä˧
[¿¼ÑÐ] 085410 273·Öµ÷¼Á +4 X1999 2026-04-09 4/200 2026-04-11 13:05 by pies112
[¿¼ÑÐ] 346£¬¹¤¿Æ0854Çóµ÷¼Á£¬×¨Ë¶ +7 moser233 2026-04-10 8/400 2026-04-11 08:52 by Öí»á·É
[¿¼ÑÐ] ÉúÎïѧ308Çóµ÷¼Á£¨Ò»Ö¾Ô¸»ª¶«Ê¦´ó£© +6 ÏàÐűػá¹ââÍòÕ 2026-04-10 6/300 2026-04-11 05:23 by zhuwenxu
[¿¼ÑÐ] ²ÄÁÏÓ뻯¹¤µ÷¼Á +12 ·ñ¼«Ì©À´2026 2026-04-10 13/650 2026-04-11 00:28 by wangjihu
[¿¼ÑÐ] ½­ËÕ´óѧ ¹¤¿Æµ÷¼Á ¼ñ© +3 Evan_Liu 2026-04-09 5/250 2026-04-10 10:22 by Evan_Liu
[¿¼ÑÐ] ³õÊÔ·Ö332£¬Ò»Ö¾Ô¸±¨¿¼Î÷±±¹¤Òµ´óѧ£¬ +11 ¹ÊÈË?? 2026-04-09 11/550 2026-04-09 21:54 by JineShine
[¿¼ÑÐ] 070300»¯Ñ§ Çóµ÷¼Á +13 73372112 2026-04-08 13/650 2026-04-09 20:22 by maddjdld
[¿¼ÑÐ] ¿¼Ñе÷¼Á-²ÄÁÏÀà-284 +28 Ïë»»ÊÖ»ú²»Ïë½âÊ 2026-04-08 28/1400 2026-04-09 20:08 by µ¹Êý321?
[¿¼ÑÐ] 286Çóµ÷¼Á +19 Faune 2026-04-08 20/1000 2026-04-09 08:36 by ŶŶ123
[¿¼ÑÐ] 085404£¬334·Ö£¬Çóµ÷¼Á +5 sunjie8888 2026-04-08 8/400 2026-04-09 07:26 by sunjie8888
[¿¼ÑÐ] Èí¼þ¹¤³ÌÇóµ÷¼Á22Èí¹¤296·ÖÇóµ÷¼Á£¬½ÓÊÜ¿çµ÷ +4 yangchen2017 2026-04-08 5/250 2026-04-08 21:56 by ÍÁľ˶ʿÕÐÉú
[¿¼ÑÐ] 316Çóµ÷¼Á +4 15318418673 2026-04-07 4/200 2026-04-07 22:12 by hemengdong
[¿¼ÑÐ] 333Çóµ÷¼Á +6 ºÏ³ËÑîϰϦ 2026-04-06 6/300 2026-04-07 09:44 by Öí»á·É
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û