首页
社区
课程
招聘
HooK GetModuleHandleA 脱壳辅助工具
发表于: 2005-6-22 16:31 10132

HooK GetModuleHandleA 脱壳辅助工具

2005-6-22 16:31
10132
我们都知道标准delphi程序一开始肯定会调用到GetModuleHandleA这个涵数,很多壳都把OEP处理了,也就是运行过后清楚什么的,代码偷取什么的,我们只要Hook这个函数,然后让程序暂停下来,那么是不是壳就还没有完成代码的清楚什么的,我们dump出来的代码就是完整的或者是可分析的.当然这个工具很容易就可以改来Hook其他函数.我给出代码,大家自己研究好了.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    lbl1: TLabel;
    lbl2: TLabel;
    StringGrid1: TStringGrid;
    btn1: TButton;
    procedure btn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  _kernel32hwnd:cardinal;
  _oldPage:Cardinal;
  _hgetadr:cardinal;
  _modulehwnd:Cardinal;
  __modulehwnd:Cardinal;
  __kernel32hwnd:cardinal;
  _esp,_ebp:Cardinal;
  _msgnum:Cardinal;
procedure Hook;
implementation

{$R *.dfm}
procedure Transact;
var
  _tsetp:Cardinal;
  _tvalue:Cardinal;
  _tesp:Cardinal;
begin
  Form1.StringGrid1.Cells[0,0]:='Address';
  Form1.StringGrid1.Cells[1,0]:='Value';
  for _tsetp :=0  to 100 do
  begin
    _tesp:=_esp+(_tsetp*4)+36;
    Form1.StringGrid1.Cells[0,_tsetp+1]:=IntToHex(_tesp,8);
    asm
      push eax;
      push ebx;
      mov  eax,_Tesp;
      Mov  ebx,[eax];
      Mov  _tvalue,ebx;
      pop ebx;
      pop   eax;
    end;
    Form1.StringGrid1.Cells[1,_tsetp+1]:=IntToHex(_tvalue,8);
  end;
  MessageBox(0, PChar(inttohex(_msgnum,8)), '警告', MB_OK + MB_ICONINFORMATION);
  _msgnum:=_msgnum+1;
end;
procedure HGetmoduleHandleA;
label _label1;
begin
  asm
    pushad;
    pushfd;
    mov _esp,esp;
    mov _ebp,ebp;
    pushad;
    pushad;
    pushad;
    pushad;
    call transact;
    mov ebp,_ebp;
    mov esp,_esp;
    popfd;
    popad;
    jmp __modulehwnd;
  end;
end;
procedure Hook;
begin
  _kernel32hwnd:=LoadLibrary('kernel32.dll');
  __kernel32hwnd:=LoadLibrary('C:\HooKDLLs\_kernel32.dll');
  __modulehwnd:=Cardinal(GetProcAddress(__kernel32hwnd,'GetModuleHandleA'));
  _kernel32hwnd:=Cardinal(GetProcAddress(_kernel32hwnd,'GetModuleHandleA'));
  VirtualProtect(Pointer(_kernel32hwnd),100,PAGE_READWRITE,_oldPage);
  _hgetadr:=Cardinal(@HGetmoduleHandleA);
  asm
    push eax;
    push ebx;
    mov eax,_kernel32hwnd;
    mov bl,$B8;
    mov Byte[eax],bl;
    add eax,1;
    mov ebx,_hgetadr;
    mov dword[eax],ebx;
    add eax,4;
    mov bl,$FF;
    mov Byte[eax],bl;
    add eax,1;
    mov bl,$E0;
    mov Byte[eax],bl;
    pop ebx;
    pop eax;
  end;
  VirtualProtect(Pointer(_kernel32hwnd),100,_oldPage,_oldPage);
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
  Hook;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  hook;
end;

end.

/////////////////////////////
library hying7xUpK;

uses
  Windows,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

exports HooK;
begin
  Form1:=TForm1.Create(form1);
  form1.Show;
end.
/////////////////////////////

object Form1: TForm1
  Left = 525
  Top = 164
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'Form1'
  ClientHeight = 533
  ClientWidth = 664
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object lbl1: TLabel
    Left = 456
    Top = 24
    Width = 30
    Height = 12
    Caption = 'ESP->'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -12
    Font.Name = #23435#20307
    Font.Style = []
    ParentFont = False
  end
  object lbl2: TLabel
    Left = 456
    Top = 224
    Width = 30
    Height = 12
    Caption = 'EBP->'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -12
    Font.Name = #23435#20307
    Font.Style = []
    ParentFont = False
  end
  object StringGrid1: TStringGrid
    Left = 493
    Top = 0
    Width = 171
    Height = 241
    ColCount = 2
    Ctl3D = True
    DefaultRowHeight = 16
    FixedCols = 0
    RowCount = 50
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -12
    Font.Name = #23435#20307
    Font.Style = []
    Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goDrawFocusSelected, goRowSizing, goColSizing, goEditing, goTabs]
    ParentCtl3D = False
    ParentFont = False
    ScrollBars = ssVertical
    TabOrder = 0
    ColWidths = (
      74
      77)
  end
  object btn1: TButton
    Left = 16
    Top = 16
    Width = 121
    Height = 33
    Caption = 'HoOk'
    TabOrder = 1
    OnClick = btn1Click
  end
end
/////////////////////
注入自己想办法,

要在被注入的程序目录下拷贝一个kernel32.dll为_kernel32.dll
大家其实一看代码就知道。我也不废话拉哈。希望对大家有用.让脱壳越来越简单,也是从另外一种思路去理解壳,不一定要去分析壳的代码才能脱壳.

这个程序是我写来dump xx2.53用的.自己也没什么用处拉.所以放出来.
当然修改一下就可以HooK整个IAT.或者什么的.


BTW:好好利用返回的堆栈,那样可以找到很多有用的东西.

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 0
支持
分享
最新回复 (13)
雪    币: 236
活跃值: (59)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
不知怎么样用,说一说用法吧。
对DLL文件有用吗?
2005-6-23 11:35
0
雪    币: 13606
活跃值: (4398)
能力值: ( LV7,RANK:100 )
在线值:
发帖
回帖
粉丝
3
提供一下编译好的,不想安装DELPHI的说~
2005-6-23 22:14
0
雪    币: 236
活跃值: (59)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
最初由 LOCKLOSE 发布
提供一下编译好的,不想安装DELPHI的说~

给你,你能说一下怎么用吗?附件:hookapi.zip
2005-6-24 08:32
0
雪    币: 342
活跃值: (323)
能力值: ( LV9,RANK:450 )
在线值:
发帖
回帖
粉丝
5
最初由 ijia 发布

给你,你能说一下怎么用吗?附件:hookapi.zip

使用方法:
拷贝kernel32.dll到需要注入的程序的目录下.
首先我们需要用工具把dll注入到目标进程,注入后dll会自动hook getmodulehandlea这个函数,并且弹出一个窗口,暂停主线程,当点确定后程序继续,当程序再次调用到这个函数的时候,程序又弹出窗口并且暂停,弹出的窗口显示的数字就是调用次数,说明一下,当这个窗口弹出时,也会调用getmodulehandlea这个函数.当然当程序暂停的时候和合适时间也就是调用次数时,dump程序,
2005-6-24 11:10
0
雪    币: 236
活跃值: (59)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
最初由 netsowell 发布

使用方法:
拷贝kernel32.dll到需要注入的程序的目录下.
首先我们需要用工具把dll注入到目标进程,注入后dll会自动hook getmodulehandlea这个函数,并且弹出一个窗口,暂停主线程,当点确定后程序继续,当程序再次调用到这个函数的时候,程序又弹出窗口并且暂停,弹出的窗口显示的数字就是调用次数,说明一下,当这个窗口弹出时,也会调用getmodulehandlea这个函数.当然当程序暂停的时候和合适时间也就是调用次数时,dump程序,


不好意思,再问一下,是在被注入程序启动后再注入?那样的话getmodulehandlea不已经被加载了吗?还是用CreateRemoteTh.../CreateProcess?
2005-6-25 09:36
0
雪    币: 13606
活跃值: (4398)
能力值: ( LV7,RANK:100 )
在线值:
发帖
回帖
粉丝
7
用netsowell版主的东东注入就可以了~
2005-6-25 09:50
0
雪    币: 342
活跃值: (323)
能力值: ( LV9,RANK:450 )
在线值:
发帖
回帖
粉丝
8
最初由 ijia 发布


不好意思,再问一下,是在被注入程序启动后再注入?那样的话getmodulehandlea不已经被加载了吗?还是用CreateRemoteTh.../CreateProcess?

看你的需要,不过如过壳的话,很多CreateRemoteTh.../CreateProcess注入不进去。
2005-6-25 14:03
0
雪    币: 236
活跃值: (59)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
谢谢两位热心解答,终于明白了。
2005-6-25 16:07
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
我的程序目前可以根据用户需要HOOK所需的函数,同时输出调用列表,还可以HOOK多个DLL中的指定函数,不过最多也就是用来辅助脱壳,想重建IAT还总是出错。
2005-6-28 09:32
0
雪    币: 342
活跃值: (323)
能力值: ( LV9,RANK:450 )
在线值:
发帖
回帖
粉丝
11
最初由 cleverboy 发布
我的程序目前可以根据用户需要HOOK所需的函数,同时输出调用列表,还可以HOOK多个DLL中的指定函数,不过最多也就是用来辅助脱壳,想重建IAT还总是出错。

过不了多久就放一个强大的Hook模块.
2005-7-1 02:15
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
最初由 netsowell 发布

过不了多久就放一个强大的Hook模块.

期待ing!!!不知netsowell同志的程序有多少行?我的只有300多一点点!
2005-7-4 09:38
0
雪    币: 342
活跃值: (323)
能力值: ( LV9,RANK:450 )
在线值:
发帖
回帖
粉丝
13
最初由 cleverboy 发布

期待ing!!!不知netsowell同志的程序有多少行?我的只有300多一点点!

我的是一个dll模块.是用于我开发apidebugger 1.0(我写的一个专门注入调试api的软件)的模块,里面现在已经有5种注入方式,代码大小就不知道拉.这个无法估计,因为还有写什么其他函数在里面.
2005-7-4 15:49
0
雪    币: 8090
活跃值: (3278)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
14
cleverboy 我的程序目前可以根据用户需要HOOK所需的函数,同时输出调用列表,还可以HOOK多个DLL中的指定函数,不过最多也就是用来辅助脱壳,想重建IAT还总是出错。
你好,你的程序有demo不
2017-5-5 11:22
0
游客
登录 | 注册 方可回帖
返回
//