首页
社区
课程
招聘
关于对抗esp定律
发表于: 2004-5-15 08:00 9518

关于对抗esp定律

2004-5-15 08:00
9518
我目前能想到防止esp定律的方法是用线程,这样就分配了新的stack,堆就不清楚了.

代码我是这样写的:

; ********************************************
; *                        创建线程调用原程序入口                                *
; ********************************************
    push    0    ; 在堆栈中分配空间存放 Thread ID
    push    esp
    push    0
    push    0
    push 12345678            ; (entrypointVA)
            @entrypoint    equ dword ptr $-4
    push    0
    push    0
    call    _CreateThread[ebp]

; ********************************************
; *                        NT下利用 Native API 反跟踪                        *
; ********************************************
    mov    edi, _ZwSetInformationThread[ebp]
    .if    edi != 0
            ;push        Thread, 已经在栈中
            push    0
            push    0
            push    17
            push    eax
            call    edi
    .endif

; ********************************************
; *                                        退出当前线程                                        *
; ********************************************

    call    _GetCurrentThread[ebp]

    push    eax
    call    _ExitThread[ebp]

但是会遇到莫名其妙的错误,搞不定,请各位帮忙看看.

附一个壳,去掉了anti和很多junk供调试.(这个还没加,否则不能运行)

*** 晕...没传上,http://tlzs.our168.com/excalibur.rar

[课程]Android-CTF解题方法汇总!

收藏
免费 6
支持
分享
最新回复 (19)
雪    币: 371
活跃值: (790)
能力值: ( LV12,RANK:570 )
在线值:
发帖
回帖
粉丝
2
没这么复杂吧?测试一下就知了:
在执行正常的notepad.exe的1006ae0前push几个数,再回1006ae0运行程序是没问题的~~~~~~
2004-5-15 08:10
0
雪    币: 6075
活跃值: (2236)
能力值: (RANK:1060 )
在线值:
发帖
回帖
粉丝
3
那还需要disasm吧……这个不管,就帮忙看看Thread...:D
2004-5-15 08:29
0
雪    币: 371
活跃值: (790)
能力值: ( LV12,RANK:570 )
在线值:
发帖
回帖
粉丝
4
有没有线程同步?
2004-5-15 09:32
0
雪    币: 6075
活跃值: (2236)
能力值: (RANK:1060 )
在线值:
发帖
回帖
粉丝
5
不需要同步啊.只是为了切换堆栈并且让OD掉线.
2004-5-15 09:32
0
雪    币: 398
活跃值: (1078)
能力值: ( LV9,RANK:970 )
在线值:
发帖
回帖
粉丝
6
008700F6    6A 00           PUSH 0
008700F8    54              PUSH ESP
008700F9    6A 00           PUSH 0
008700FB    6A 00           PUSH 0
008700FD    68 88344000     PUSH 403488
00870102    6A 00           PUSH 0
00870104    6A 00           PUSH 0
00870106    FF95 D1324000   CALL DWORD PTR SS:[EBP+4032D1]  // CreateThread
0087010C    8BBD CA334000   MOV EDI,DWORD PTR SS:[EBP+4033CA]        ; ntdll.ZwSetInformationThread
00870112    0BFF            OR EDI,EDI
00870114    74 09           JE SHORT 0087011F
00870116    6A 00           PUSH 0
00870118    6A 00           PUSH 0
0087011A    6A 11           PUSH 11
0087011C    50              PUSH EAX
0087011D    FFD7            CALL EDI
0087011F    FF95 F1324000   CALL DWORD PTR SS:[EBP+4032F1]  // GetCurrentThread
00870125    50              PUSH EAX
00870126    FF95 E2324000   CALL DWORD PTR SS:[EBP+4032E2]  // ExitThread

CreateThread 后在 OD 里怎么看不到啊?
不是立刻执行的吗? 已跳过 zwSetInformationThread
2004-5-15 09:43
0
雪    币: 6075
活跃值: (2236)
能力值: (RANK:1060 )
在线值:
发帖
回帖
粉丝
7
汗~~~帖这个出来干嘛?
2004-5-15 09:49
0
雪    币: 371
活跃值: (790)
能力值: ( LV12,RANK:570 )
在线值:
发帖
回帖
粉丝
8
0101301B    FF95 3A284000   CALL DWORD PTR SS:[EBP+40283A]

XP的notepad测试:在ebp+40283a处的地址无效。
2004-5-15 10:05
0
雪    币: 6075
活跃值: (2236)
能力值: (RANK:1060 )
在线值:
发帖
回帖
粉丝
9
不会吧^
大概动态地址太高搞出火了...
2004-5-15 10:13
0
雪    币: 398
活跃值: (1078)
能力值: ( LV9,RANK:970 )
在线值:
发帖
回帖
粉丝
10
The ExitThread function ends a thread.

VOID ExitThread(
  DWORD dwExitCode   // exit code for this thread
);

Parameters
dwExitCode
Specifies the exit code for the calling thread. Use the GetExitCodeThread function to retrieve a thread's exit code.
Return Values
This function does not return a value.

Remarks
ExitThread is the preferred method of exiting a thread. When this function is called (either explicitly or by returning from a thread procedure), the current thread's stack is deallocated and the thread terminates. The entry-point function of all attached dynamic-link libraries (DLLs) is invoked with a value indicating that the thread is detaching from the DLL.

If the thread is the last thread in the process when this function is called, the thread's process is also terminated.

The state of the thread object becomes signaled, releasing any other threads that had been waiting for the thread to terminate. The thread's termination status changes from STILL_ACTIVE to the value of the dwExitCode parameter.

Terminating a thread does not necessarily remove the thread object from the operating system. A thread object is deleted when the last handle to the thread is closed.
2004-5-15 10:40
0
雪    币: 898
活跃值: (4039)
能力值: ( LV9,RANK:3410 )
在线值:
发帖
回帖
粉丝
11
各种方法都有其局限性的
ESP定律 更不是万能的  :D
2004-5-15 11:06
0
雪    币: 6075
活跃值: (2236)
能力值: (RANK:1060 )
在线值:
发帖
回帖
粉丝
12
能防一个是一个:o
2004-5-15 11:08
0
雪    币: 211
活跃值: (55)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
果然高手云集,郁闷中!!!!!~
2004-5-15 12:48
0
雪    币: 210
活跃值: (40)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
14
esp定律是什么?
2004-5-16 03:58
0
雪    币: 414
活跃值: (531)
能力值: ( LV9,RANK:170 )
在线值:
发帖
回帖
粉丝
15
之后再popad,你只要用硬件断点设断在ESP栈顶的值,在popad时将出现的,这之后就要进真正程序的OEP了。
2004-5-16 08:41
0
雪    币: 203
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
16
老兄的防止OD 的想法很不错啊,通过CreateThread 来把stack 搞的不常规。 不过通过CreateThread 的方法可能存在问题。
EntryPoint 应该是主Thread 的入口地址,这个Thread 是每一个Process 都应该有的,而且这个地址是由OS 指定给Main Thread 的,所以,当你在Create 一个Thread 指向同一个地址,这样运行的结果就是主程序是不可控的,或者说是很难控制的。所以通过这样的方法,存在问题的可能性几乎是100% 。创建的线程和Main Thread 的地址空间相同,需要你自己在程序中加入很多同步的方法,使得Main Thread 和你Create 的Thread 同步。 这样的方法应该没有通用型。 :――)
2004-5-16 12:30
0
雪    币: 6075
活跃值: (2236)
能力值: (RANK:1060 )
在线值:
发帖
回帖
粉丝
17
Oh...I see.谢谢comelysouthchin的回答。
2004-5-16 13:05
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
18
最初由 nig 发布
之后再popad,你只要用硬件断点设断在ESP栈顶的值,在popad时将出现的,这之后就要进真正程序的OEP了。

土问一下,这样不怕解压过程中,用SEH查控制寄存器么?
2004-5-16 14:53
0
雪    币: 6075
活跃值: (2236)
能力值: (RANK:1060 )
在线值:
发帖
回帖
粉丝
19
最初由 xuanqing 发布

土问一下,这样不怕解压过程中,用SEH查控制寄存器么?

那就靠人为避开了
2004-5-16 15:02
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
20
多谢版主指点
也就是说ESP只是一个
判断是否OEP的可用的线索而已
对吧
2004-5-17 17:52
0
游客
登录 | 注册 方可回帖
返回
//