• 标 题:Modify the Muad'Dib's ReverseMe1
  • 作 者:poppig
  • 时 间:2003年10月29日 11:05
  • 链 接:http://bbs.pediy.com

******************************************************************************
                      Target Muad'Dib's ReverseMe1
******************************************************************************

Author:        Muad'Dib
Protection:   None
Needs:        Hiew,WinHex,Some PE knowledge,Most important is Our Brain
Level:        ( ) Beginner (X) Intermediate ( ) Advanced ( ) Expert

点击下载(或鼠标右键另存为)

  没有限制,我们用LordPe查看信息,得到如下信息(我是用Tdump保存的结果):

#   Name      VirtSize    RVA     PhysSize  Phys off  Flags
--  --------  --------  --------  --------  --------  --------
01  .text     0000008A  00001000  00000200  00000400  60000020 [CER]
02  .rdata    000000DC  00002000  00000200  00000600  40000040 [IR]
03  .data     0000003C  00003000  00000200  00000800  C0000040 [IRW]
04  .rsrc     00000198  00004000  00000200  00000A00  C0000040 [IRW]

  我们看到.text的空间只是用了8A,我们还有0x200-0x8A=0x176可以用,That's enough.我们
可以将我们的代码写到0x400+0x8A=0x48A中!
  我们分析一下.data的空间,我们还有0x200-0x3C=0x1C4个字节可以使用,enough,我们可以
将我们的一些字符写入到0x800+0x3C=0x83C后面.什么标题啊,Text啊....
  好了现在我们就开始修改了:

1:首先是添加字符串(如下)

00000800   59 6F 75 72 20 6A 6F 62  20 69 73 20 74 6F 20 6D   Your job is to m
00000810   61 6B 65 20 6D 65 20 77  6F 72 6B 20 61 73 20 61   ake me work as a
00000820   6E 20 65 78 69 74 20 62  75 74 74 6F 6E 21 00 47   n exit button!.G
00000830   4F 41 4C 3A 00 00 00 00  00 00 00 00 00 00 00 00   OAL:............
00000840   48 69 2C 49 27 6D 20 64  65 6E 67 6B 65 6E 67 00   Hi,I'm dengkeng.
00000850   4F 4B 2C 49 27 6D 20 65  78 69 74 69 6E 67 21 00   OK,I'm exiting!.
00000860   43 72 61 63 6B 00 00 00  00 00 00 00 00 00 00 00   Crack...........

2.接下来就是添加代码,我们是让程序启动之前弹出MessageBox
  我们的Title已经有了是403060,Caption一个是403050,一个是403040
  我们需要找到在哪里Call dword ptr [xxxxxxxx],是对MessageBoxA的调用,这就需要PE 
knowledge,我们在PE头偏移0x80是Import Table信息(我们这里PE在0xC0处):

00000140   1C 20 00 00 3C 00 00 00  00 40 00 00 98 01 00 00   . ..<....@..?..
  我们找到如上位置,VRA为0000201C,大小为0000003C,Go.......到0x61C是Import Table开始
的地方.是IID结构:
                                                
00000600   82 20 00 00 74 20 00 00  00 00 00 00 B6 20 00 00   ?..t ......?..
00000610   C2 20 00 00 A4 20 00 00  00 00 00 00 (*)58 20 00 00   ?..?......X .. 
00000620   00 00 00 00 00 00 00 00  96 20 00 00 00 20 00 00   ........?... ..
00000630   64 20 00 00 00 00 00 00  00 00 00 00 D0 20 00 00   d ..........?..
00000640   0C 20 00 00 00 00 00 00  00 00 00 00 00 00 00 00   . ..............
00000650   00 00 00 00 00 00 00 00  82 20 00 00 74 20 00 00   ........?..t ..
00000660   00 00 00 00 B6 20 00 00  C2 20 00 00 A4 20 00 00   ....?..?..?..
00000670   00 00 00 00 75 00 45 78  69 74 50 72 6F 63 65 73   ....u.ExitProces
00000680   73 00 11 01 47 65 74 4D  6F 64 75 6C 65 48 61 6E   s...GetModuleHan
00000690   64 6C 65 41 00 00 4B 45  52 4E 45 4C 33 32 2E 64   dleA..KERNEL32.d
000006A0   6C 6C 00 00 92 00 44 69  61 6C 6F 67 42 6F 78 50   ll..?DialogBoxP
000006B0   61 72 61 6D 41 00 B8 00  45 6E 64 44 69 61 6C 6F   aramA.?EndDialo
000006C0   67 00 BB 01 4D 65 73 73  61 67 65 42 6F 78 41 00   g.?MessageBoxA.
000006D0   55 53 45 52 33 32 2E 64  6C 6C 00 00 00 00 00 00   USER32.dll......
  
  (*)为IID开始,一共有2个IID结构第3个为全0结构,即到0x657结束.我们看一下,第一个IID
结构所指的DllName,00002096(0x696)指向的是Kernel32.dll,里面有我们在后面所需要的API
,ExitProcess,我们在来看第二个IID我们看到它所指向的是000020D0(0x6D0),即User32.dll,
里面有我们需要的MessageBoxA,我们所关心的是FirstThunk,我们来看一下FirstThunk,第二
个IID的FirstThunk是0000200C(0x60C),在0x60C我们看到了3个API的RVA:
000020B6<======>offset 6B6 API----EndDialog
000020C2<======>offset 6C2 API----MessageBoxA
000020A4<======>offset 6A4 API----DialogBoxParamA
  我们看到它们并不是按顺序来的.所以我们看到如果要调用MessageBoxA就需要这样:
Call dword ptr [402010],这样就能够调用MessageBoxA了,我们要做的仅仅是ImageBase+RVA,
我们这里是40000+2010(610)=402010,就是610转换为RVA.
  这样我们就可以Write Code.....
  记得上面我说过什么吗?Yes,我们把代码写到0x48A处(我们写到0x490)

首先我们需要在程序运行之前弹出对话框:
0x490
push 0
push 403060 ;Title
push 403040 ;Text
push 0
call d,[402010] ;分析看上面
push 401000
ret
  当然要程序先运行我们的程序我们需要修改入口地址(PE+0x28=0xE8):
                         

000000E0   00 06 00 00 00 00 00 00  00 10 00 00 00 10 00 00   ................

Change To

000000E0   00 06 00 00 00 00 00 00  90 10 00 00 00 10 00 00   ................

入口改为00001090先运行我们的程序:
  成功了吗????Yeah,我们看到了弹出的MessageBoxA,下面我们所需要做的是让程序退出!
所以我们还要继续Write Code...
接上面的Ret后面:
push 0
push 403060 ;Title
push 403050 ;Text
push 0
call d,[402010];MessageBoxA
call d,[402004];ExitProcess,I think you can find it by youself

  OK,Code Write is over.Only We Need to do is Change The jmp after we Press The button.
Now we use W32Dasm:
:0040103E 6A00                    push 00000000

* Possible StringData Ref from Data Obj ->"GOAL:"
                                  |
:00401040 682F304000              push 0040302F

* Possible StringData Ref from Data Obj ->"Your job is to make me work as "
                                        ->"an exit button!"
                                  |
:00401045 6800304000              push 00403000
:0040104A FF7508                  push [ebp+08]

* Reference To: USER32.MessageBoxA, Ord:01BBh
                                  |
:0040104D E832000000              Call 00401084
:00401052 EB14                    jmp 00401068 ;Important,Now we change it
  
  We Change the jmp,Let it jump our Code,Now We use Hiew Change it at offset 0x452
Now we Change to "jmp 4AA",Because Our Next code after ret it start at "4AA",Press F9
to save it.
  Ok,run the programme rm1.exe,Bingo,It run as we like it to do.
  Now it's finished the article.

  Any Question Send Me E-Mail:shellc0de@sohu.com
  My QQ:28895751

  Shit,I have not pass the CET-6 this time,So I pratice My English at this article.
Excuse My Bad English!Thanks reading the article!
    

You Can Send the Article freely,please Keep complete