目标
目标 TibiaBot NG 3.4
主页 http://www.TibiaBot.com
PEiD Armadillo 2.51 - 3.xx DLL Stub -> Silicon Realms Toolworks
Introduction
In this tutorial we are going to have a go at unpacking an Armadillo 3.xx DLL.
Usually this is quite an easy task, but this program seems to mess up the relocation table...
SO LETS FIX IT
Then press Shift+F9 to run until it breaks.
It will break 5 or 6 times and will look like this:
然后按 Shift+F9 直到程序中断
她将中断 5 或 6 次然后看到堆栈如下提示:
We are looking for a call to VirtualProtect from a Dynamicly Allocated area, this is called from 00A2C892
Which is in .text so this isnt the one we want.
After we have passed all the VirtualProtect's we dont want you will see the Armadillo NAG Screen:
After pressing OK we should break on another VirtualProtect:
当按下 OK 后我们会中断在另一个 VirtualProtect:
Notice this is called from a Dynamic Area? So This is the call we were looking for!
Press Ctrl+F9 (NOT SHIFT) then Shift+F7 to step out of the call back into the code.
Then goto the top of the section and search for "Push 100", search until you find this:
In order for the IAT to be clean and useable you must change the PUSH EBP into RETN
Now remove the Breakpoint on VirtualProtect and place one on CreateThread
When it breaks open the memory map (Alt+M) and place Break-On-Access for CODE section:
The OEP is 009E1D7C and the Imagebase is 00870000
Due to the limitations of Imprec we have to fiddle this part...
Subtract 00400000 NOT 00870000 from the OEP and we get the OEP Imprec needs.(005E1D7C)
(Do Not Press Get imports yet)
Now we need the RVA and Size of the IAT, to do this leave Imprec open then return to ollydbg and goto the top of the section (Press Home) then press Ctrl+B and enter the hex FF 25 and search, You should land on this line:
00871250 -FF25 70D29E00 JMP DWORD PTR DS:[9ED270] ; kernel32.CloseHandle
Now Right Click > Follow In Dump > Memory Address
To make it easier to view Right click in the dump and select Long > Address.
Now scroll up until you can see what looks to be the start of the IAT:
(Note down the address next to the pointer (009ED1B0 for us) as we need it later)
Now Scroll the opposite way until you find what looks like the end of the IAT:
记下 009ED1B0 ,一会我们会用到
现在向相反方向滚动直到找到 IAT 的结束地址:
(Note down the address next to the pointer (009EDA44 for us) as we need it later)
So the RVA for the IAT is 009ED1B8 minus 00400000 = 005ED1B8
The Size of the IAT is 009ED1B8 - 009EDA44 = 884
Now enter this information into Imprec and click Get Imports (Not IAT AutoSearch):
Click Show Invalid, then right click and Invalid pointer and choose Cut Thunks
点显示"无效函数",然后在无效指针上点右键选择”剪切指针“
NOW WAIT! Before you go clicking Fix Dump we have a vital task left.
We need the real RVA for the OEP and IAT Start
So the real OEP RVA is 009E1D7C minus 00870000 = 00171D7C
The real RVA for the IAT is 009ED1B8 minus 00870000 = 0017D1B8
So place those values into Imprec:
Now click Fix Dump and select the file you dumped with LordPE earlier.
Now lets just tidy up the DLL by loading the PE Editor in LordPE
Change the Imagebase to 00870000 and the BaseOfCode to 1000 then save it
Usually this would be the end of unpacking the file (besides removing the unused sections).
But this app has some tricks which damage/invalidate the Relocation Table in some way.
Usually you simply change the address+size of the Relocation Table in Directory Information from .reloc1 to match .reloc
This doesnt work for this app so we must rebuild the Relocation table.
We now need to have 2 almost identical dumps (Same OEP, Header, Good IAT) but with different imagebases at the time of dumping.
We already have one from above, but that was made using LoadDLL.
We need a dump from the actual target program aswell, in this case TibiaBot uses a loader to inject hook.dll into the active process Tibia.exe (The Game this was designed for).
So we much load Tibia.exe into OllyDBG and run it, then goto Debugging Options and Select Break on New Module
Once this is done run Loader.exe (The program that injects the DLL into the process) and now OllyDBG should break showing the DLL being loaded.
Next to it there is a column called Entry, this shows the entrypoint of the DLL > Go to it
Once there place a breakpoint on it and then remove Break on new modules.
Once it has broken at the entry point of the dll then you must follow all the steps from the beginning again until you have the 2 working dumps.
Remember to change the imagebase on the 2nd dumped dll to what it was in memory.
PLEASE NOTE that Armadillo can ignore breakpoints on some targets if the option was enabled, if this is the case then Press Ctrl+G and type the API name (i.e VirtualProtect) and place a normal breakpoint on the retn of that function instead of BP FUNCTION_NAME
请注意如果选项是钩选的 Armadillo 可以在一些目标上忽略断点,
如果发生这种情况可以按 Ctrl+G 并输入 API 名 (如:VirtualProtect),并在函数的 retn 处下一个普通的断点来代替 BP 函数名这种方式.
Once you have your 2 dll's then we need to use a wonderful tool called ReloX by Mackt.
Load both Dll's into the program: