سؤال حول كتابة Plugin لتجاوز دالة IsDebuggerPresent
#11
(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 eaxbyte 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 [.. 1of Byte;
    BeingDebuggedByte;
    Reserved2Byte;
    Reserved3: array [.. 1of Pointer;
    LdrPointer;
    Reserved4: array [.. 102of Byte;
    Reserved5: array [.. 51of Pointer;
    PostProcessInitRoutinePointer;
    Reserved6: array [.. 127of Byte;
    Reserved7Pointer;
    SessionIdULONG;
  end;

  PROCESS_BASIC_INFORMATION record
    Reserved1
Pointer;
    PebBaseAddressPointer;
    Reserved2: array [.. 1of Pointer;
    UniqueProcessIdcardinal;
    Reserved3Pointer;
  end;

resourcestring
 PLUGIN_NAME 
'Anti IsDebuggerPresent';

var
 
g_hwndOllyHWND;  // 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(00pchar(PLUGIN_NAME));
  Result := 0;
end;

function 
ODBG_Plugindata(namePChar): integercdecl;
begin
  StrLCopy
(namePChar(PLUGIN_NAME), 32);
  Result := PLUGIN_VERSION;
end;

function 
NtQueryInformationProcess(ProcessHandleTHANDLEProcessInformationClassDWORD;
ProcessInformationPointer;ProcessInformationLengthULONGReturnLengthPULONG): LongInt;
stdcallexternal '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:Integeraction:IntegerpItem:Pointer);cdecl;
begin
  
if (origin PM_MAINthen
  begin
      Getinfo
;
    end;
end;

   exports
  ODBG_Plugininit    name 
'_ODBG_Plugininit',
  ODBG_Plugindata    name '_ODBG_Plugindata',
  ODBG_Pluginaction  name '_ODBG_Pluginaction';
begin

end

الرد
#12
سأستمر في المثال الخاص بي ، إليك شفرة مصدر كاملة Under Windows7Pro Svpack1 32bit سوف أرى مثالك أيضًا
PHP كود :
program IsDebugged;

{
$APPTYPE CONSOLE}

uses Windows;

Type
  PVOID 
Pointer;
  
NTSTATUS UINT;

Type
  TNtQueryInformationProcess 
= function(
    
ProcessHandleTHandle;
    
ProcessInformationClassULONG;
    
ProcessInformationPVOID;
    
ProcessInformationLengthULONG;
    
ReturnLengthPULONG): NTSTATUSstdcall;

  
TNtRemoveProcessDebug = function(
    
ProcessHandleTHandle;
    
DebugObjectHandleTHandle): NTSTATUSstdcall;

  
TNtSetInformationDebugObject = function(
    
DebugObjectHandleTHandle;
    
DebugObjectInformationClassULONG;
    
DebugInformationPVOID;
    
DebugInformationLengthULONG;
    
ReturnLengthPULONG
    
): NTSTATUSstdcall;

  
TNtClose = function(HandleTHandle): NTSTATUSstdcall;

var
  
NtQueryInformationProcessTNtQueryInformationProcess;
  
NtRemoveProcessDebugTNtRemoveProcessDebug;
  
NtSetInformationDebugObjectTNtSetInformationDebugObject;
  
NtCloseTNtClose;

function 
GetProcessIsBeingDebugged(ProcessHandleTHandle; var IsBeingDebuggedBoolean): Boolean;
var
  
DebugPortPVOID;
  
TargetProcessHandleTHandle;
  
SourceProcessHandleTHandle;
  
DuplicateResultBOOL;
  
DesiredAccessACCESS_MASK;
begin
  Result 
:= False;
  try
    if (@
NtQueryInformationProcess <> nilthen
    begin
      DuplicateResult 
:= False;
      
TargetProcessHandle := 0;
      
DuplicateResult := DuplicateHandle(GetCurrentProcess(), ProcessHandleGetCurrentProcess(), @TargetProcessHandle0FalseDUPLICATE_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(ProcessHandleTHandle): Boolean;
var
  
DebugObjectHandleTHandle;
  
DebugFlagsULONG;
  
TargetProcessHandleTHandle;
  
SourceProcessHandleTHandle;
  
DuplicateResultBOOL;
  
DesiredAccessACCESS_MASK;
begin
  Result 
:= False;
  try
    if (@
NtQueryInformationProcess <> nilthen
    begin
      DebugObjectHandle 
:= 0;
      if 
NtQueryInformationProcess(
        
ProcessHandle,
        
30,
        @
DebugObjectHandle,
        
SizeOf(THandle),
        
nil) = 0 then
      begin
        
try
          if (@
NtSetInformationDebugObject <> nil) and (@NtRemoveProcessDebug <> nilthen
          begin
            DebugFlags 
:= 0;
            
NtSetInformationDebugObject(
              
DebugObjectHandle,
              
2,
              @
DebugFlags,
              
SizeOf(ULONG),
              
nil);

            if 
NtRemoveProcessDebug(ProcessHandleDebugObjectHandle) = 0 then
              Result 
:= True;
          
end;
        finally
          if 
DebugObjectHandle <> 0 then
            NtClose
(DebugObjectHandle);
        
end;
      
end;
    
end;
  
except
  end
;
end;

function 
_AddCurrentProcessPrivileges(PrivilegeNameWideString): Boolean;
var
  
TokenHandleTHandle;
  
TokenPrivilegesTTokenPrivileges;
  
ReturnLengthDWORD;
begin
  Result 
:= False;
  try
    if 
OpenProcessToken(GetCurrentProcessTOKEN_ADJUST_PRIVILEGES or TOKEN_QUERYTokenHandlethen
    begin
      
try
        
LookupPrivilegeValueW(nilPWideChar(PrivilegeName), TokenPrivileges.Privileges[0].Luid);
        
TokenPrivileges.PrivilegeCount := 1;
        
TokenPrivileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
        if 
AdjustTokenPrivileges(TokenHandleFalseTokenPrivileges0nilReturnLengththen
          Result 
:= True;
      finally
        
CloseHandle(TokenHandle);
      
end;
    
end;
  
except
  end
;
end;

var
  
LibraryHandleHMODULE;
  
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_ACCESSFALSEGetCurrentProcessId);
  if 
hProcess <> INVALID_HANDLE_vALUE then
  begin
    GetProcessIsBeingDebugged
(hProcess_IsDebugged);
    if 
_isDebugged then
    begin
      WriteLn
('Process Is Debugged');
      if 
DetachProcessFromDebugger(hProcessthen WriteLn('Process Detached')
      else 
WriteLn('Process Can''t be Detached');
    
end
   
else WriteLn('Process not debugged');
  
end;
  
ReadLn

@Rever7eR
في مثالك ، أعتقد أنه يجب عليك تخصيص عنوان للكتابة ، VirtualAllocEx
في رأيي ، لا يمكننا الكتابة في PROCESS دون تحديد العنوان ADDRESS
ملحوظة: في CurrentProcess تعمل بشكل جيد عند Debugged مع دلفي
[-] كل من 1 user says قال شكرا ل Hs32-Idir على المشاركة المفيدة
  • Rever7eR
الرد
#13
توصلت الى حل أخيرا بمساعدة Kao الله يعطيه الخير  Big Grin
المشكل كان هنا في السطر الذي ذكرته سابقا , كنت احاول الكتابة في العنوان الخطأ 
 الحل كالتالي : 
PHP كود :
WriteProcessMemory(debugee,pointer(dword(ProcessBasicInfo.PebBaseAddress) + 2),@buffer,sizeof(buffer),length); 

شكرا أخي العزيز Hs32-Idir أتعبتك معي , سأراجع الكود الاخير الذي قمت بنشره بعد اخذ قسط من الراحة 
شكرا لكل من شارك بالموضوع و ابدى اهتمامه . 
المشروع مرفق لمن يريد تجربته


الملفات المرفقة
.rar   Anti-Anti-Debug.rar (الحجم : 24.2 ك ب / التحميلات : 3)
الرد
#14
المشروع مرفق Corrumped
الرد
#15
(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 [.. 1of Byte;
    BeingDebuggedByte;
    Reserved2Byte;
    Reserved3: array [.. 1of Pointer;
    LdrPointer;
    Reserved4: array [.. 102of Byte;
    Reserved5: array [.. 51of Pointer;
    PostProcessInitRoutinePointer;
    Reserved6: array [.. 127of Byte;
    Reserved7Pointer;
    SessionIdULONG;
  end;

  PROCESS_BASIC_INFORMATION record
    Reserved1
Pointer;
    PebBaseAddressPointer;
    Reserved2: array [.. 1of Pointer;
    UniqueProcessIdcardinal;
    Reserved3Pointer;
  end;

resourcestring
 PLUGIN_NAME 
'Anti IsDebuggerPresent';

var
 
g_hwndOllyHWND;  // 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(00pchar(PLUGIN_NAME));
  Result := 0;
end;

function 
ODBG_Plugindata(namePChar): integercdecl;
begin
  StrLCopy
(namePChar(PLUGIN_NAME), 32);
  Result := PLUGIN_VERSION;
end;

function 
NtQueryInformationProcess(ProcessHandleTHANDLEProcessInformationClassDWORD;
ProcessInformationPointer;ProcessInformationLengthULONGReturnLengthPULONG): LongInt;
stdcallexternal '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:Integeraction:IntegerpItem:Pointer);cdecl;
begin
  
if (origin PM_MAINthen
  begin
      Getinfo
;
    end;
end;

   exports
  ODBG_Plugininit    name 
'_ODBG_Plugininit',
  ODBG_Plugindata    name '_ODBG_Plugindata',
  ODBG_Pluginaction  name '_ODBG_Pluginaction';
begin

end

الرد
#16
شكرا عل Partage ، أعتقد أن إصدار Winrar الخاص بي قديم
[-] كل من 1 user says قال شكرا ل Hs32-Idir على المشاركة المفيدة
  • Rever7eR
الرد
#17
أخ Rever7er لماذا استخدمت TMemoryStream في الأخير؟
الرد
#18
(04-04-2020, 09:34 PM)sofiane201 كتب : أخ Rever7er لماذا استخدمت TMemoryStream في الأخير؟

ههههه اسف لم انتبه , كنت اجرب كل الطرق المتاحة 
شكرا للتنبيه  Blush
الرد


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم