RE: سؤال حول كتابة Plugin لتجاوز دالة IsDebuggerPresent - Rever7eR - 04-04-2020
(04-04-2020, 02:26 AM)Hs32-Idir كتب : في حالتي ، تتحقق الوظيفة مما إذا كانت process is Being Debugged ، لذا إذا كان صحيحًا ، فيمكنك محاولة فصلها عن Debugger
هذه ترجمة C ++ ، في دلفي PVOID = POINTER
لجعلها تعمل حاولRunAsAdmin
اجعله يعمل تحت المؤقت (Timer)
فيمكنك محاولة فصلها ب NtRemoveProcessDebug
آسف للغتي ، لدي لوحة مفاتيح ,qwerty
هل يمكنني النشر باللغة الإنجليزية أو لغات أخرى
للتحقق ما اذا كان ال Process تحت التنقيح يكفي كتابة الكود التالي و استبدال dword ptr fs:[$30] بمؤشر للبنية PEB و يمكن جلبه بالدلة NtQueryInformationProcess التي يجب ان يكون المقبض الممرر اليها هو مقبض ال Process
PHP كود : begin asm mov eax, dword ptr fs:[$30] // pointer to PEB struct movzx eax, byte ptr ds:[eax+$2] {eax + $2 holds the value of mov check,eax BeingDebugged Flag} end; if check <> 0 then showmessage('The application is under a Debugger');
حسنا أعتقد انني اوشكت على ايجاد الحل , قمت بجلب مقبض الملف الذي هو قيد التنقيح و قمت بجلب قيمة ال Flag BeingDebugged الان المشكل في استعمالي للدالة WriteProcessMemory اريد تغيير البايت 01 (BeingDebbuged) لكن لا يتم تغييره
أكرر المشكل الوحيد الان هو بالسطر :
PHP كود : writeprocessmemory(debugee,@EB.BeingDebugged,@buffer,1,length);
النموذج كاملا :
PHP كود : library AADebug;
uses SysUtils, plugin, windows, Classes;
{$R *.res}
type
PEB = record Reserved1: array [0 .. 1] of Byte; BeingDebugged: Byte; Reserved2: Byte; Reserved3: array [0 .. 1] of Pointer; Ldr: Pointer; Reserved4: array [0 .. 102] of Byte; Reserved5: array [0 .. 51] of Pointer; PostProcessInitRoutine: Pointer; Reserved6: array [0 .. 127] of Byte; Reserved7: Pointer; SessionId: ULONG; end;
PROCESS_BASIC_INFORMATION = record Reserved1: Pointer; PebBaseAddress: Pointer; Reserved2: array [0 .. 1] of Pointer; UniqueProcessId: cardinal; Reserved3: Pointer; end;
resourcestring PLUGIN_NAME = 'Anti IsDebuggerPresent';
var g_hwndOlly: HWND; // OllyDbg Window Handle ProcessBasicInfo : PROCESS_BASIC_INFORMATION; Length:cardinal; EB : PEB;
function ODBG_Plugininit(ollydbgversion:Integer;hWndOlly:HWND;features:PULONG):Integer;cdecl; begin g_hwndOlly := hWndOlly; Addtolist(0, 0, pchar(PLUGIN_NAME)); Result := 0; end;
function ODBG_Plugindata(name: PChar): integer; cdecl; begin StrLCopy(name, PChar(PLUGIN_NAME), 32); Result := PLUGIN_VERSION; end;
function NtQueryInformationProcess(ProcessHandle: THANDLE; ProcessInformationClass: DWORD; ProcessInformation: Pointer;ProcessInformationLength: ULONG; ReturnLength: PULONG): LongInt; stdcall; external 'ntdll.dll';
procedure Getinfo; var debugee,PID : THandle; buffer : Byte; begin buffer := $00; PID := PluginGetValue(VAL_PROCESSID); debugee := OpenProcess(PROCESS_ALL_ACCESS,False,PID); NtQueryInformationProcess(debugee,0,@ProcessBasicInfo,sizeof(ProcessBasicInfo),@length); readprocessmemory(debugee,ProcessBasicInfo.PebBaseAddress,@EB,sizeof(EB),length); writeprocessmemory(debugee,@EB.BeingDebugged,@buffer,1,length); messagebox(g_hwndOlly,pchar('BeingDebuggedFlag : '+ inttostr(EB.beingDebugged)),pchar('info'),MB_ICONINFORMATION); end;
procedure ODBG_Pluginaction(origin:Integer; action:Integer; pItem:Pointer);cdecl; begin if (origin = PM_MAIN) then begin Getinfo; end; end;
exports ODBG_Plugininit name '_ODBG_Plugininit', ODBG_Plugindata name '_ODBG_Plugindata', ODBG_Pluginaction name '_ODBG_Pluginaction'; begin
end.
RE: سؤال حول كتابة Plugin لتجاوز دالة IsDebuggerPresent - Hs32-Idir - 04-04-2020
سأستمر في المثال الخاص بي ، إليك شفرة مصدر كاملة Under Windows7Pro Svpack1 32bit سوف أرى مثالك أيضًا
PHP كود : program IsDebugged;
{$APPTYPE CONSOLE}
uses Windows;
Type PVOID = Pointer; NTSTATUS = UINT;
Type TNtQueryInformationProcess = function( ProcessHandle: THandle; ProcessInformationClass: ULONG; ProcessInformation: PVOID; ProcessInformationLength: ULONG; ReturnLength: PULONG): NTSTATUS; stdcall;
TNtRemoveProcessDebug = function( ProcessHandle: THandle; DebugObjectHandle: THandle): NTSTATUS; stdcall;
TNtSetInformationDebugObject = function( DebugObjectHandle: THandle; DebugObjectInformationClass: ULONG; DebugInformation: PVOID; DebugInformationLength: ULONG; ReturnLength: PULONG ): NTSTATUS; stdcall;
TNtClose = function(Handle: THandle): NTSTATUS; stdcall;
var NtQueryInformationProcess: TNtQueryInformationProcess; NtRemoveProcessDebug: TNtRemoveProcessDebug; NtSetInformationDebugObject: TNtSetInformationDebugObject; NtClose: TNtClose;
function GetProcessIsBeingDebugged(ProcessHandle: THandle; var IsBeingDebugged: Boolean): Boolean; var DebugPort: PVOID; TargetProcessHandle: THandle; SourceProcessHandle: THandle; DuplicateResult: BOOL; DesiredAccess: ACCESS_MASK; begin Result := False; try if (@NtQueryInformationProcess <> nil) then begin DuplicateResult := False; TargetProcessHandle := 0; DuplicateResult := DuplicateHandle(GetCurrentProcess(), ProcessHandle, GetCurrentProcess(), @TargetProcessHandle, 0, False, DUPLICATE_SAME_ACCESS); if DuplicateResult then begin try if NtQueryInformationProcess( TargetProcessHandle, 7, @DebugPort, SizeOf(PVOID), nil ) = 0 then Result := True; if DebugPort <> nil then IsBeingDebugged := True; finally if TargetProcessHandle <> 0 then CloseHandle(TargetProcessHandle); end; end; end; except end; end;
function DetachProcessFromDebugger(ProcessHandle: THandle): Boolean; var DebugObjectHandle: THandle; DebugFlags: ULONG; TargetProcessHandle: THandle; SourceProcessHandle: THandle; DuplicateResult: BOOL; DesiredAccess: ACCESS_MASK; begin Result := False; try if (@NtQueryInformationProcess <> nil) then begin DebugObjectHandle := 0; if NtQueryInformationProcess( ProcessHandle, 30, @DebugObjectHandle, SizeOf(THandle), nil) = 0 then begin try if (@NtSetInformationDebugObject <> nil) and (@NtRemoveProcessDebug <> nil) then begin DebugFlags := 0; NtSetInformationDebugObject( DebugObjectHandle, 2, @DebugFlags, SizeOf(ULONG), nil);
if NtRemoveProcessDebug(ProcessHandle, DebugObjectHandle) = 0 then Result := True; end; finally if DebugObjectHandle <> 0 then NtClose(DebugObjectHandle); end; end; end; except end; end;
function _AddCurrentProcessPrivileges(PrivilegeName: WideString): Boolean; var TokenHandle: THandle; TokenPrivileges: TTokenPrivileges; ReturnLength: DWORD; begin Result := False; try if OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, TokenHandle) then begin try LookupPrivilegeValueW(nil, PWideChar(PrivilegeName), TokenPrivileges.Privileges[0].Luid); TokenPrivileges.PrivilegeCount := 1; TokenPrivileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; if AdjustTokenPrivileges(TokenHandle, False, TokenPrivileges, 0, nil, ReturnLength) then Result := True; finally CloseHandle(TokenHandle); end; end; except end; end;
var LibraryHandle: HMODULE; HProcess:Thandle; _IsDebugged:Boolean; begin _AddCurrentProcessPrivileges('SeDebugPrivilege'); LibraryHandle := LoadLibrary('ntdll.dll'); if LibraryHandle <> 0 then begin try @NtQueryInformationProcess := GetProcAddress(LibraryHandle, 'NtQueryInformationProcess'); @NtRemoveProcessDebug := GetProcAddress(LibraryHandle, 'NtRemoveProcessDebug'); @NtSetInformationDebugObject := GetProcAddress(LibraryHandle, 'NtSetInformationDebugObject'); @NtClose := GetProcAddress(LibraryHandle, 'NtClose'); finally LibraryHandle := 0; FreeLibrary(LibraryHandle); end; end; hProcess := OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId); if hProcess <> INVALID_HANDLE_vALUE then begin GetProcessIsBeingDebugged(hProcess, _IsDebugged); if _isDebugged then begin WriteLn('Process Is Debugged'); if DetachProcessFromDebugger(hProcess) then WriteLn('Process Detached') else WriteLn('Process Can''t be Detached'); end else WriteLn('Process not debugged'); end; ReadLn;
@Rever7eR
في مثالك ، أعتقد أنه يجب عليك تخصيص عنوان للكتابة ، VirtualAllocEx
في رأيي ، لا يمكننا الكتابة في PROCESS دون تحديد العنوان ADDRESS
ملحوظة: في CurrentProcess تعمل بشكل جيد عند Debugged مع دلفي
RE: سؤال حول كتابة Plugin لتجاوز دالة IsDebuggerPresent - Rever7eR - 04-04-2020
توصلت الى حل أخيرا بمساعدة Kao الله يعطيه الخير 
المشكل كان هنا في السطر الذي ذكرته سابقا , كنت احاول الكتابة في العنوان الخطأ
الحل كالتالي :
PHP كود : WriteProcessMemory(debugee,pointer(dword(ProcessBasicInfo.PebBaseAddress) + 2),@buffer,sizeof(buffer),length);
شكرا أخي العزيز Hs32-Idir أتعبتك معي , سأراجع الكود الاخير الذي قمت بنشره بعد اخذ قسط من الراحة
شكرا لكل من شارك بالموضوع و ابدى اهتمامه .
المشروع مرفق لمن يريد تجربته
RE: سؤال حول كتابة Plugin لتجاوز دالة IsDebuggerPresent - Hs32-Idir - 04-04-2020
المشروع مرفق Corrumped
RE: سؤال حول كتابة Plugin لتجاوز دالة IsDebuggerPresent - Rever7eR - 04-04-2020
(04-04-2020, 07:47 PM)Hs32-Idir كتب : المشروع مرفق Corrumped
يعمل بدون مشاكل ربما الخلل بجهازك على كل حال هذا هو الكود كاملا :
PHP كود : // Author : Rever7eR // Special thanks goes to : Kao , Hs32-Idir , onexite , M.ABdelAziZ , S.FATEH library AADebug;
uses SysUtils, plugin, windows, Classes;
{$R *.res}
type
PEB = record Reserved1: array [0 .. 1] of Byte; BeingDebugged: Byte; Reserved2: Byte; Reserved3: array [0 .. 1] of Pointer; Ldr: Pointer; Reserved4: array [0 .. 102] of Byte; Reserved5: array [0 .. 51] of Pointer; PostProcessInitRoutine: Pointer; Reserved6: array [0 .. 127] of Byte; Reserved7: Pointer; SessionId: ULONG; end;
PROCESS_BASIC_INFORMATION = record Reserved1: Pointer; PebBaseAddress: Pointer; Reserved2: array [0 .. 1] of Pointer; UniqueProcessId: cardinal; Reserved3: Pointer; end;
resourcestring PLUGIN_NAME = 'Anti IsDebuggerPresent';
var g_hwndOlly: HWND; // OllyDbg Window Handle ProcessBasicInfo : PROCESS_BASIC_INFORMATION; Length:cardinal; EB : PEB;
function ODBG_Plugininit(ollydbgversion:Integer;hWndOlly:HWND;features:PULONG):Integer;cdecl; begin g_hwndOlly := hWndOlly; Addtolist(0, 0, pchar(PLUGIN_NAME)); Result := 0; end;
function ODBG_Plugindata(name: PChar): integer; cdecl; begin StrLCopy(name, PChar(PLUGIN_NAME), 32); Result := PLUGIN_VERSION; end;
function NtQueryInformationProcess(ProcessHandle: THANDLE; ProcessInformationClass: DWORD; ProcessInformation: Pointer;ProcessInformationLength: ULONG; ReturnLength: PULONG): LongInt; stdcall; external 'ntdll.dll';
procedure Getinfo; var debugee,PID : THandle; buffer : Byte; fs : TMemoryStream; begin fs := TMemoryStream.Create; buffer := $00; PID := PluginGetValue(VAL_PROCESSID); debugee := OpenProcess(PROCESS_ALL_ACCESS,False,PID); NtQueryInformationProcess(debugee,0,@ProcessBasicInfo,sizeof(ProcessBasicInfo),@length); readprocessmemory(debugee,ProcessBasicInfo.PebBaseAddress,@EB,sizeof(EB),length); WriteProcessMemory(debugee,pointer(dword(ProcessBasicInfo.PebBaseAddress) + 2),@buffer,sizeof(buffer),length); fs.Seek(EB.BeingDebugged,soBeginning); fs.Write(buffer,1); fs.Free; end;
procedure ODBG_Pluginaction(origin:Integer; action:Integer; pItem:Pointer);cdecl; begin if (origin = PM_MAIN) then begin Getinfo; end; end;
exports ODBG_Plugininit name '_ODBG_Plugininit', ODBG_Plugindata name '_ODBG_Plugindata', ODBG_Pluginaction name '_ODBG_Pluginaction'; begin
end.
RE: سؤال حول كتابة Plugin لتجاوز دالة IsDebuggerPresent - Hs32-Idir - 04-04-2020
شكرا عل Partage ، أعتقد أن إصدار Winrar الخاص بي قديم
RE: سؤال حول كتابة Plugin لتجاوز دالة IsDebuggerPresent - sofiane201 - 04-04-2020
أخ Rever7er لماذا استخدمت TMemoryStream في الأخير؟
RE: سؤال حول كتابة Plugin لتجاوز دالة IsDebuggerPresent - Rever7eR - 04-04-2020
(04-04-2020, 09:34 PM)sofiane201 كتب : أخ Rever7er لماذا استخدمت TMemoryStream في الأخير؟
ههههه اسف لم انتبه , كنت اجرب كل الطرق المتاحة
شكرا للتنبيه
|