Delphi_OD_代码_调试_Delphi反调试技术(以OD为例附核心原代码)
1.程序窗口[chuang kou]句柄[ju bing]检测
原理:用FindWindow函数[han shu]查找[cha zhao]具有相同窗口[chuang kou]类名和标题的窗口[chuang kou],如果找到就说明[shuo ming]有OD在运行[yun hang]
//********************************************
//通过查找[cha zhao]窗口[chuang kou]类名来实现检测OllyDBG
//********************************************
function AntiLoader():Boolean;
const
OllyName='OLLYDBG';
var
Hwnd:Thandle;
begin
Hwnd:=FindWindow(OllyName,nil);
if Hwnd<>0 then
Result:=True
else
Result:=False;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if AntiLoader then
MessageBox(Handle,'找到调试[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION)
else
MessageBox(Handle,'未找到调试[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION)
end;
2.用线程[xian cheng]环境块检测
原理:用ring3级下的调试[tiao shi]器对可执行[zhi hang]程序[zhi hang cheng xu][ke zhi hang cheng xu]进行调试[tiao shi]时,调试[tiao shi]器会把被调试[tiao shi]的可执行[zhi hang]程序[zhi hang cheng xu][ke zhi hang cheng xu]作为一个子线程[xian cheng]进行跟踪[gen zong].这时被调试[tiao shi]的可执行[zhi hang]程序[zhi hang cheng xu][ke zhi hang cheng xu]的PEB结构[jie gou]偏移0x02处的BeingDebugged的值为1,如果可执行[zhi hang]程序[zhi hang cheng xu][ke zhi hang cheng xu]未被调试[tiao shi],则值为0,所以可以利用这个值来检测程序是否被ring3级下的调试[tiao shi]器调试[tiao shi]
//***************************************
//使用PEB结构[jie gou]检测OllyDBG
//***************************************
function AntiLoader():Boolean; //检测调试[tiao shi]器;
var
YInt,NInt:Integer;
begin
asm
mov eax,fs:[$30]
//获取PEB偏移2h处BeingDebugged的值
movzx eax,byte ptr[eax+$2]
or al,al
jz @No
jnz @Yes
@No:
mov NInt,1
@Yes:
Mov YInt,1
end;
if YInt=1 then
Result:=True;
if NInt=1 then
Result:=False;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if AntiLoader then
MessageBox(Handle,'发现调试[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION)
else
MessageBox(Handle,'未发现调试[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION);
end;
3.用API函数[han shu]IsDebuggerPresent检测
原理:操作系统[xi tong][cao zuo xi tong]将调试[tiao shi]对象[dui xiang]设置[she zhi]为在特殊环境中运行[yun hang],而kernel32.dll中的API函数[han shu]IsDebuggerPresent的功能是用于[yong yu]判断进程[jin cheng]是否处于调试[tiao shi]环境中,这样就可以利用这个API函数[han shu]来查看进程[jin cheng]是否在调试[tiao shi]器中执行[zhi hang]
//****************************************
//利用IsDebuggerPresent函数[han shu]检测OllyDBG
//****************************************
function AntiLoader():Boolean;
var
isDebuggerPresent: function:Boolean;
Addr: THandle;
begin
Addr := LoadLibrary('kernel32.dll');
isDebuggerPresent := GetProcAddress(Addr, 'IsDebuggerPresent');
if isDebuggerPresent then
Result:=True
else
Result:=False;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if AntiLoader then
MessageBox(Handle,'发现调试[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION)
else
MessageBox(Handle,'未发现提示[ti shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION);
end;
4.检查程序[jian cha cheng xu]的父进程[jin cheng]
原理:Windows操作系统[xi tong][cao zuo xi tong]下的GUI可执行[zhi hang]程序[zhi hang cheng xu][ke zhi hang cheng xu]的父进程[jin cheng]都是explorer.exe(CUI可执行[zhi hang]程序[zhi hang cheng xu][ke zhi hang cheng xu]的父进程[jin cheng]是 CMD.exe,系统[xi tong]服务[xi tong fu wu]的父进程[jin cheng]是Service.exe,在实际使用的时候需要根据自己的程序类型[lei xing]来选择[xuan ze]父进程[jin cheng]实现反跟踪[gen zong]),而正被调试[tiao shi]器OD调试[tiao shi]的程序的父进程[jin cheng]是调试[tiao shi]器的执行[zhi hang]程序[zhi hang cheng xu]ollydbg.exe而不是别的.所以可以利用检查父进程[jin cheng]是否为explorer.exe的方法[fang fa]来检测OD.
//***************************************************
//检查父进程[jin cheng]来检测OllyDBG
//***************************************************
function AntiLoader():Boolean;
const
ParentName='\EXPLORER.EXE';
var
hSnap,hProcess:THandle;
szBuffer:array[0..MAX_PATH] of char;
FileName:array[0..MAX_PATH] of char;
Process32:PROCESSENTRY32;
LoopFlag:BOOL;
begin
////得到所有进程[jin cheng]的列表[lie biao]快照[kuai zhao]
hSnap:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if hSnap=INVALID_HANDLE_VALUE then
begin
Result:=False;
Exit;
end;
Process32.dwSize:=sizeof(PROCESSENTRY32);
//查找[cha zhao]进程[jin cheng]
LoopFlag:=Process32First(hSnap,Process32);
if LoopFlag=False then
begin
CloseHandle(hSnap);
Result:=False;
Exit;
end;
while Integer(LoopFlag)<>0 do
begin
if Process32.th32ProcessID=GetCurrentProcessId() then
begin
hProcess:=OpenProcess(PROCESS_ALL_ACCESS,FALSE,Process32.th32ParentProcessID);
if hProcess<>0 then
begin
if GetModuleFileNameEx(hProcess,0,FileName,MAX_PATH)<>0 then
begin
//取得系统[xi tong]目录[xi tong mu lu]
GetWindowsDirectory(szBuffer,MAX_PATH);
//合并系统[xi tong]目录[xi tong mu lu]和\EXPLORER.EXE
StrCat(szBuffer,ParentName);
//转换[zhuan huan]成大写以后比较当前调试[tiao shi]程序[tiao shi cheng xu]的进程[jin cheng]是否为父进程[jin cheng]
if UpperCase(String(FileName))<>UpperCase(String(szBuffer)) then
Result:=True
else
Result:=False;
end;
end
else
Result:=False;
end;
LoopFlag:=Process32Next(hSnap,Process32);
end;
CloseHandle(hSnap);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if AntiLoader then
MessageBox(Handle,'发现调试[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION)
else
MessageBox(Handle,'未发现调试[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION)
end;
5.检查STARTUPINFO结构[jie gou]
原理:Windows操作系统[xi tong][cao zuo xi tong]中的explorer.exe创建进程[jin cheng]的时候会把STARTUPINFO结构[jie gou]中的值设为0,而非explorer.exe创建进程[jin cheng]的时候会忽略这个结构[jie gou]中的值,也就是结构[jie gou]中的值不为0,所以可以利用这个来判断OD是否在调试[tiao shi]程序[tiao shi cheng xu].
/************************************************
//通过检测STARTUPINFO结构[jie gou]来检测OllyDbg
//************************************************
function AntiLoader():Boolean;
var
Info:STARTUPINFO;
begin
GetStartupInfo(Info);
if (Info.dwX<>0) or (Info.dwY<>0) or (Info.dwXCountChars<>0) or (Info.dwYCountChars<>0) or
(Info.dwFillAttribute<>0) or (Info.dwXSize<>0) or (Info.dwYSize<>0) then
Result:=True
else
Result:=False;
end;
procedure TMainFrm.FormCreate(Sender: TObject);
begin
if AntiLoader then
MessageBox(Handle,'发现调试[tiao shi]器!','提示[ti shi]',MB_OK)
else
MessageBox(Handle,'未发现调试[tiao shi]器!','提示[ti shi]',MB_OK);
end;
参考:http://www.cnblogs.com/key-ok/p/4594685.html
Delphi_OD_代码_调试_Delphi反调试技术(以OD为例附核心原代码)的更多相关文章
- Delphi_OD_代码_调试_Delphi反调试技术(以OD为例附核心原代码) (转)
1.程序窗口[chuang kou]句柄[ju bing]检测原理:用FindWindow函数[han shu]查找[cha zhao]具有相同窗口[chuang kou]类名和标题的窗口[chuan ...
- Windows 32位-调试与反调试
1.加载调试符号链接文件并放入d:/symbols目录下. 0:000> .sympath srv*d:\symbols*http://msdl.microsoft.com/download/s ...
- 华为手机内核代码的编译及刷入教程【通过魔改华为P9 Android Kernel 对抗反调试机制】
0x00 写在前面 攻防对立.程序调试与反调试之间的对抗是一个永恒的主题.在安卓逆向工程实践中,通过修改和编译安卓内核源码来对抗反调试是一种常见的方法.但网上关于此类的资料比较少,且都是基于AOSP ...
- C/C++ 程序反调试的方法
C/C++ 要实现程序反调试有多种方法,BeingDebugged,NtGlobalFlag,ProcessHeap,CheckRemoteDebuggerPresent,STARTUPINFO,Is ...
- 浅谈android反调试之 签名校验
反调试原理 很多时候,我们都需要进行修改修改应用程序的指令,然后重打包运行,重新打包就需要充签名. 利用签名的变化我们用于反调试.反调试实现代码如下: 为了更加隐藏,比较函数可能在SO层进行实现,如下 ...
- 修改Android手机内核,绕过反调试
本文博客链接:http://blog.csdn.net/qq1084283172/article/details/57086486 0x1.手机设备环境 Model number: Nexus 5 O ...
- 手动绕过百度加固Debug.isDebuggerConnected反调试的方法
本文博客地址:http://blog.csdn.net/qq1084283172/article/details/78237571 1.调用Debug.isDebuggerConnected函数这种反 ...
- 反调试技术常用API,用来对付检测od和自动退出程序
在调试一些病毒程序的时候,可能会碰到一些反调试技术,也就是说,被调试的程序可以检测到自己是否被调试器附加了,如果探知自己正在被调试,肯定是有人试图反汇编啦之类的方法破解自己.为了了解如何破解反调试技术 ...
- Linux下的反调试技术
Linux下的反调试技术 2014年01月30日 ⁄ 综合 ⁄ 共 2669字 ⁄ 字号 小 中 大 ⁄ 评论关闭 转自 http://wangcong.org/blog/archives/310 ...
随机推荐
- 怎样查看MySql数据库物理文件存放位置
想导出mysql中的数据库文件,死活找不到,网上说在配置文件中有路径,可是我打开我的配置文件,里边的代码全都是注释掉的,没有一句有用的.后来在某一论坛上找到解决方法了,记录下来. 使用如下命令: my ...
- git 删除配置的远程地址
删除(origin 名称需根据你本地查询出来的想删除的名字, 查询命令为 git remote -v) git remote rm origin 添加(origin 名称可根据需要添加) git re ...
- 过滤器(filter)实现用户登录拦截
过滤器(filter)实现用户登录拦截 >>>>>>>>>>>>>>>>>>>> ...
- python np.linspace
该函数的形式为: linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None) 作用为:在规定的时间内,返回固定间隔的 ...
- Java SE (1)之 JFrame 组件 FlowLayout 布局
package com.sunzhiyan; import java.awt.*; import java.awt.event.*; import javax.swing.*; public clas ...
- 手势识别=读取手机联系人=ContentResolver-Day3
手势识别=读取手机联系人=ContentResolverDay32 mobile3.0 手机设置向导页面完成 选择器没有做完成 样式提取完成 自定义控件的优化继续 抽取父类Activity 完成 手机 ...
- Sql Xml
/* sql xml 入门: --by jinjazz --http://blog.csdn.net/jinjazz 1.xml: 能认识元素.属性和值 2.xpath: 寻址语言,类似windows ...
- css-a:visited
如下代码: <a href="#">链接地址</a> 如果属性 href的设置为'#',则鼠标滑过(即使没有点击',也算成'visited'.而对于 hre ...
- mvc5 + ef6 + autofac搭建项目(repository+uow)(二)
续上篇: DBContext 在上篇 图一类库根目录创建的 DbContextBase /// <summary> /// 数据库上下文基类 /// </summary> // ...
- 深入理解shared pool共享池之library cache的library cache lock系列四
本文了解下等待事件library cache lock,进一步理解library cache,之前的文章请见: 深入理解shared pool共享池之library cache的library ca ...