首页
社区
课程
招聘
[旧帖] jmp dword ptr[esp]的问题 0.00雪花
发表于: 2007-1-15 21:59 5242

[旧帖] jmp dword ptr[esp]的问题 0.00雪花

2007-1-15 21:59
5242
//我写了些代码,打算写SHELLCODE,可惜技术不到家,
//这段代码,有很多疑问,为什么Hello world会显示两次?
//高手可否指点一下!!感激!同时也希望其他初学者也可以学到点东西.

// testjmp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>

void test()
{
        __asm
        {
                pop edi
                pop esi
                pop ebx
                pop ebp
                jmp DWORD ptr[esp]
        }
}
int main(int argc, char* argv[])
{
        test();
        printf("Hello World!\n");
        return 0;
}

/////////////////////////
// 输出
/*
Hello World!
Hello World!
Press any key to continue
*/
/* 反汇编内容

00401000   $  55            push    ebp
00401001   .  8BEC          mov     ebp, esp
00401003   .  53            push    ebx
00401004   .  56            push    esi
00401005   .  57            push    edi
00401006   .  8BE5          mov     esp, ebp
00401008   .  5D            pop     ebp
00401009   .  FF2424        jmp     dword ptr [esp]
0040100C   .  5F            pop     edi
0040100D   .  5E            pop     esi
0040100E   .  5B            pop     ebx
0040100F   .  5D            pop     ebp
00401010   .  C3            retn

00401020  /$  E8 DBFFFFFF   call    00401000
00401025  |.  68 30604000   push    00406030                         ;  ASCII "Hello World!",LF
0040102A  |.  E8 11000000   call    00401040
0040102F  |.  83C4 04       add     esp, 4
00401032  |.  33C0          xor     eax, eax
00401034  \.  C3            retn

*/

[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
最初由 zhenqiucai 发布
//我写了些代码,打算写SHELLCODE,可惜技术不到家,
//这段代码,有很多疑问,为什么Hello world会显示两次?
//高手可否指点一下!!感激!同时也希望其他初学者也可以学到点东西.

// testjmp.cpp : Defines the entry point for the console application.
........


//经过调试,发现是main ret前 esp要加04h
//这样就OK了,但不知道为什么!!!
//继续调试!!!!1
// testjmp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>

void test()
{
        __asm
        {
                mov esp, ebp
                pop ebp
                jmp DWORD ptr[esp]
        }
}
void aaa()
{
        int k=0;
}
int main(int argc, char* argv[])
{
        aaa();
        int k;
        test();
        printf("Hello World!\n");
        __asm
        {
                add esp, 4
        }
        return 0;
}
2007-1-15 22:19
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
//Oh!!No!!!
//明白了!!可以删了!!!
//不好意思,好在没麻烦高手指点!!!
//如果有比我更菜的人,你可以看看!1!
// 代码入下:
// testjmp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>

void test()
{
        __asm
        {
                mov esp, ebp
                pop ebp
                add esp, 4
                jmp DWORD ptr[esp-04h]
        }
}

int main(int argc, char* argv[])
{
        test();
        printf("Hello World!\n");
        return 0;
}
2007-1-15 22:24
0
雪    币: 101
活跃值: (12)
能力值: ( LV12,RANK:210 )
在线值:
发帖
回帖
粉丝
4
add esp, 4
    jmp DWORD ptr[esp-04h]

就是一个ret而已, 没什么奇怪的
不过, 有些壳到是把ret变形成这样。
2007-1-16 13:03
0
游客
登录 | 注册 方可回帖
返回
//