首页
社区
课程
招聘
请教fly大侠,关于ESP定律的问题~!
发表于: 2004-5-18 18:29 9993

请教fly大侠,关于ESP定律的问题~!

2004-5-18 18:29
9993
ESP定律的原理能说一下吗?
还有12FFAC这个数值是固定不变的吗?如果是变的请问如何确定这个数值?
谢谢fly大侠了~!~!

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 6
支持
分享
最新回复 (6)
雪    币: 898
活跃值: (4039)
能力值: ( LV9,RANK:3410 )
在线值:
发帖
回帖
粉丝
2
当然不是固定的啦
看程序运行的堆栈情况
2004-5-18 19:58
0
雪    币: 229
活跃值: (143)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
3
我有一定的了解了,是不是查看ESP的值,然后再看堆栈中和那个ESP值相近的一个值,然后在转存查找堆栈中的值下断,是这样的吗?
2004-5-18 20:04
0
雪    币: 50161
活跃值: (20665)
能力值: (RANK:350 )
在线值:
发帖
回帖
粉丝
4
转一篇fs0文章,可能对你理解有帮助:
========================================
标 题:loader找OEP的原理 (757字)
发信人:fs0
时 间:2002-4-6 16:39:15
阅读次数:396
详细信息:

loader通过读取被加壳程序startup时的Ebp, Esp, [Esp]值跟
该程序运行到一定地址时Ebp, Esp, [Esp]的值比较,若相等则认为该地址就是OEP。

那么我们应该在哪里停下被加壳程序去读值,而该地址又不是OEP的上一或下一地址呢。
Windows 有一API VirtualProtectEx,用来设置内存空间的某些属性,在NT下可以设上
PAGE_GUARD属性,若程序读、写、执行设了PAGE_GUARD属性的内存,就会产生一
STATUS_GUARD_PAGE_VIOLATION的异常,我们就可以利用该特性,给被加密了的程序代码
空间(我只是简单的把第一个Section认为是代码段)加上PAGE_GUARD属性,要是被加壳
程序运行该保护段的代码,而且Ebp, Esp, [Esp]跟startup时的值相等则认为该地址就是OEP。

理论上该方法可以应用到其他大多数的加壳方法上,Armadillo当然是例外(:
那么为什么该loader不能用在Aspack、upx、PECompact....上?现在什么都懒了,懒啊!!

--------------------------------------------------------------------------------
标 题:“普通程序执行前ebp指向哪里”这个问题比较专业,我也不太清楚... (334字)
发信人:fs0
时 间:2002-4-7 21:23:50
阅读次数:42
详细信息:

“普通程序执行前ebp指向哪里”这个问题比较专业,我也不太清楚。
在不能十分肯定破坏被加壳程序的ebp和esp对程序有什么影响前,我想通用的加壳软件并不会贸然行事,
至少现时大多数加壳软件到达OEP时会恢复ebp, esp的值,之后的事由加壳软件的作者去想吧。
我用的是调试的方法,也初步想了一下如何反被检测到的方法,得等见到有加壳程序反调试后再加上去。

--------------------------------------------------------------------------------
2004-5-18 20:58
0
雪    币: 229
活跃值: (143)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
5
谢谢老大~!
2004-5-18 21:02
0
雪    币: 166
活跃值: (112)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
6
转一篇文章,关于win9x下程序启动时各寄存器分析

Win95 structures and secrets

by Murkry/IkX
                  
Since the start of Win95 many things that virii writers came to accept as easy to get, became harder. Things like the interrupt calls, filename paths to the system files.
Well the API calls have replaced interrupts and virii writers have used several tricks to get the address to these calls.

As for filename or path to system files, we have hard coded possible ones and also used the API's (of course this added a bit to our code). Of course back in the DOS
days if we search the PSP we could find much of this info without relying on API calls. Well as many readers of Windows95 System Programming Secrets are aware
there are several tables (or K32 objects) that are available for us but finding these tables requires API (or at least in the book they do). Well as you may have guessed by
now the pointers to these tables are readily avaiable. In win95, A and B version as well as some of the earlier version the Registers seem to startup with similiar info.

Be warned that this info does not apply to WinNT in the release of Win98 I saw it was true though. (Side note, nice check for win95 to win nt is eax != eip then your
probably not in 95 or something was playing with the registers b4 you got them. Hmm make sure your viruses restore all regs or some smart programmers may actually
write some self aware programs that check this ;)

Anyway all 95 versions I have checked Regs start out with

EAX = EIP of startup
EBX = ???
ECX = K32OBJ_MUTEX appears
EDX = K32OBJ_CRITICAL_SECTION appears
ESI = K32OBJ_PROCESS
EDI = K32OBJ_THREAD
EBP =
ESP = Strange info see below

Ok b4 all you experts yell (wait,, experts?? hell you write this):

EAX is basicaly a fact

Ebx 00530000 or similiar number never points to a in processs address though

ECX This is a Guess but it seems to point to a table and starts with 03
Read the Book to understand why 03 means something

ESI points to a table that starts with 05 and I have used this table
to get to the enviroment database which wonders of wonders
has things like Full path and file name of executing file
Paths and command line Startupinfo. Again reading the book will
explain all or if you have access to the ddk you can verify
this as I have done.

EDI Table starts up with 06 and has all sorts of info in it

EBP somewhere I have notes on what this points at, but I can't locate it
I think MarkJ may have eaten it when I last babysat for him ;)

ESP strange but if you look at a start up there are some very intersting
numbers that always show up.

now this varies depending on lenght of name, but again we find pointers to locations that when examine are tables or pointers to entries in the tables as well as SEH
pointers:

+10 = File name of file being excuted
format is strange 'Host1',0,'EXE',0
whether or not you enter the extension or not it will
be caps and the name will be caps first letter
lowercase rest
+c = ebp = Dammit what is this number
+8 = esi = obj_process database
+4 = edi = obj_thread database
EsP +0 = pnter into location in Kernel32

What does this mean to us virii/hackers of win95 lets say we want to write a virus that adds info to the end of the host but does not modify the host PE header so while
the info is there it is not loaded into memory. (A new LE\Macro infector works like this) Step one we need the file name well check out the code below which will show a
MessageBox with the file name in quotes when ran normaly but will show the file name without quotes if in td32 and I assume other debuggers (probaly not SI though) Be
warn about this feature since this means if you are running a debugger to test it will work diffrently ie if you used this pointer to try and open the file it will fail since file
"c:\filepath\foo.exe" is the file you will try to open not c:\filepath\foo.exe.

NOTE this is one way to get the info i could just use esi rather than get the info off the stack

mov edi,[esp +8] ; Get the Pointer to process Database
mov edi,[edi+040h] ; Within DataBase get pointer to the Enviroment
; DataBase
mov edi,[edi+8] ; In Enviroment DataBase get the Pnter to
; Command line
call MessageBoxA,large 0,edi, offset tile,large 1

now there are a lot of other info avaiable in the other Database but the Enviroment Table is structured as:

Offset
00h Ptr to the enviroment string
as you scan through the table you find
=C:=C:\tasm\virii\over
TEMP=C:\WINDOWS\TEMP
PROMPT=$p$g
winbootdir=C:\WINDOWS
COMSPEC=C:\WINDOWS\COMMAND.COM
PATH=C:\BTI\WIN\BIN;C:\WINDOWS;C:\WINDOWS\COMMAND;C:\UTIL;
TMP=C:\WINDOWS\TEMP
windir=C:\WINDOWS
CMDLINE=td32 host1

* While the ; is used in the path all other items are delimited by 00h

04h unknown Zero as far as I have seen
0Ch pntr to str Current directory note when in
td32
C:\TASM\VIRII\OVER\HOST1.EXE
Normal
"C:\TASM\VIRII\OVER\HOST1.EXE"
10h ptr to a copy of StartupInfo

There are other entries but these are the ones I am showing for now since they are the ones I view as nice to have for virii related, See the book or DDK for more info.

As you can see the Enviroment database is as useful as the old dos psp oh btw there is still a PSP see Process Database offset 24h of course its the linear address, But
exploring info that the stack has to offer is fun as well and as for the infamous FS:[0] seh area

this is called (in the book) Thread Information Block TIB point at by edi starting at offset 10h in that database.

Strangely this same info is also in the thread database
00 dd pointer to existing Exception handler (see 29A#2 for more info)
04 dd top of stack
08 dd stack low
0ch dw w16tdb
0eh dw StackSelector 16 byte
10h dd Selman list
14h dd User Pointer user accessable ???
18h dd pnter TIB (book says) to me points to ESI obj process database
1ch dw tibflags
1eh dw win16MutexCount
20h dd DebugContext
24h dd pntr Current Priority
28h dd Message Queue
2ch dd pntr TLS Array

Get this grab the top of stack

now sub 4 get 0
8 a pnter inside some location in Kernel32
c ?
10 0
14 looks like a copy of the PE header and a NE header of some
sort this entry may be important?? not sure

Again don't bet the house on this info, while the tables are documented I am sure a number of my fellow PE 32 bit virii friends will point out "Its not documented" when
refering to my method od using esi or stack refrence to get the Process database location. I suspect in Win95\98 stays around long enough these items will be
documented as people use them more and more. Of course just use the SEH method to protect your code and then feel free to try these ideas out if they SEH catches it
then you can exit gracefully.
2004-5-19 10:48
0
雪    币: 108
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
呵呵,,,e文哈,,安逸!!
2004-6-6 21:28
0
游客
登录 | 注册 方可回帖
返回
//