反调试技术(以OD为例附核心原代码)【delphi】
(2011-09-11 00:11:52)
转帖:
曾几何时,我徘徊在了调试与反调试的地平线上。
调试与反调试、反反调试是永远存在的问题,现在的大多数软件也加了反调试功能(尤其是网游),保护其不被调试破解。
调试大家都知道有很多这方面的工具,如OD、CE、ICE...,反调试大家也知道有很多种方法,如自己加代码实现、加壳等,反反调试...
今天做了一个小程序,采用了19种方式来检测自己是否被调试、下断等,这只是一个小测试,没有加入驱动和hook等乱七八糟的东西,纯以代码实现。有兴趣的朋友可以帮忙测试下。好了,废话到此为止,我们来看代码:(代码随便写的,如有BUG请勿取笑)
unit Unit1;
interface
uses
JwaNative, Debug,
Windows, Messages, SysUtils,
Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
function FD_IsDebuggerPresent(): Boolean;
function
PD_PEB_BeingDebuggedFlag(): Boolean;
function
FD_PEB_NtGlobalFlags(): Boolean;
function FD_Heap_HeapFlags():
Boolean;
function FD_Heap_ForceFlags():
Boolean;
function
FD_CheckRemoteDebuggerPresent(): Boolean;
function
FD_NtQueryInfoProc_DbgPort(): Boolean;
function
FD_NtQueryInfoProc_DbgObjHandle(): Boolean;
function
FD_NtQueryInfoProc_DbgFlags(): Boolean;
function
FD_SeDebugPrivilege(csrssPid: THandle): Boolean;
function
FD_Find_Debugger_Window(): Boolean;
function
FD_Exception_Closehandle(): Boolean;
function FD_Exception_Int3():
Boolean;
function
FD_OutputDebugString(): boolean;
function
FD_Check_StartupInfo(): Boolean;
function FD_INT_2d():
Boolean;
function FS_OD_Int3_Pushfd():
Boolean;
function
FS_SI_Exception_Int1(): Boolean;
function FB_HWBP_Exception():
Boolean;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
ExitProcess(0);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
isdebugged: DWORD;
retLen: PULONG;
ProcessHandle: DWORD;
tmp: PChar;
label
IsDebug;
begin
try
//反调试检测
isdebugged := 0;
if FB_HWBP_Exception then isdebugged := isdebugged + 1;
label4.Caption := IntToStr(isdebugged);
if FS_SI_Exception_Int1 then isdebugged := isdebugged + 1;
label4.Caption := IntToStr(isdebugged);
if FD_Find_Debugger_Window then isdebugged := isdebugged + 1;
if FD_IsDebuggerPresent then isdebugged := isdebugged + 1;
if PD_PEB_BeingDebuggedFlag then isdebugged := isdebugged +
1;
if FD_PEB_NtGlobalFlags then isdebugged := isdebugged + 1;
if FD_Heap_HeapFlags then isdebugged := isdebugged + 1;
if FD_CheckRemoteDebuggerPresent then isdebugged := isdebugged +
1;
if FD_NtQueryInfoProc_DbgPort then isdebugged := isdebugged +
1;
if FD_NtQueryInfoProc_DbgObjHandle then isdebugged := isdebugged +
1;
if FD_NtQueryInfoProc_DbgFlags then isdebugged := isdebugged +
1;