首页
社区
课程
招聘
[求助]第16章外壳编写基础汇编指令的问题
2010-4-21 15:29 8380

[求助]第16章外壳编写基础汇编指令的问题

2010-4-21 15:29
8380
ShellStart0 LABEL        DWORD
        pushad                    ; 外壳入口点
        call        next0
;**********************************************************

;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;                   以下是自构造的外壳的输入表
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportTableBegin  LABEL        DWORD
ImportTable         DD        AddressFirst-ImportTable  ;OriginalFirstThunk
                 DD        0,0                       ;TimeDataStamp,ForwardChain
AppImpRVA1         DD        DllName-ImportTable       ;Name
AppImpRVA2         DD        AddressFirst-ImportTable  ;FirstThunk
                 DD        0,0,0,0,0
AddressFirst         DD        FirstFunc-ImportTable     ;指向IMAGE_tHUNK_DATA
AddressSecond         DD        SecondFunc-ImportTable    ;指向IMAGE_tHUNK_DATA
AddressThird         DD        ThirdFunc-ImportTable     ;指向IMAGE_tHUNK_DATA
                 DD        0
DllName                 DB        'KERNEL32.dll'
                 DW        0
FirstFunc         DW        0       
                 DB        'GetProcAddress',0
SecondFunc         DW        0
                 DB        'GetModuleHandleA',0
ThirdFunc         DW        0
                 DB        'LoadLibraryA',0
ImportTableEnd  LABEL        DWORD
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;               以下是自构造的假重定位表(处理DLL时用)
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RelocBaseBegin  LABEL        DWORD
RelocBase         DD        0
                 DD        08h
                 DD        0
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;                以下是需要由加壳程序修正的变量
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SHELL_DATA_0                LABEL        DWORD
ShellBase         DD        0
ShellPackSize         DD        0
TlsTable         DB        18h dup (?)

;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;               外壳引导段使用的变量空间
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Virtualalloc         DB        'VirtualAlloc',0
VirtualallocADDR DD        0
imagebase         DD        0
ShellStep         DD        0
ShellBase2         DD        0

;**********************************************************
next0:
        pop        ebp
        sub        ebp,(ImportTable-ShellStart0)

执行到pop        ebp;时ebp里就有pop        ebp这条指令的VA地址,下面这句sub        ebp,(ImportTable-ShellStart0);求外壳入口点地址,为什么不是sub        ebp,(next0-ShellStart0);呢?

[CTF入门培训]顶尖高校博士及硕士团队亲授《30小时教你玩转CTF》,视频+靶场+题目!助力进入CTF世界

收藏
点赞6
打赏
分享
最新回复 (10)
雪    币: 485
活跃值: (12)
能力值: ( LV9,RANK:490 )
在线值:
发帖
回帖
粉丝
petnt 12 2010-4-21 16:27
2
0
pop ebp之后,ebp里似乎是 ImprotTable
雪    币: 28
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
lpfei 2010-4-21 21:13
3
0
ImportTable   DD  AddressFirst-ImportTable  ;
声明局部变量是动态分配的,相当于mov [ebp-4],0;
刚想明白,是这样的吧?
雪    币: 485
活跃值: (12)
能力值: ( LV9,RANK:490 )
在线值:
发帖
回帖
粉丝
petnt 12 2010-4-21 21:27
4
0
call 的返回地址就是ImportTable  因为紧接着call的指令是ImportTable  DD  AddressFirst-ImportTable
个人观点
雪    币: 28
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
lpfei 2010-4-21 21:57
5
0
程序运行的时候执行到ImportTable   DD  AddressFirst-ImportTable  ;这句的时候会动态分配内存,不是在编译的时候就把这句搞定了,这样call的下一地址就是ImportTable   DD  AddressFirst-ImportTable  ;把这句地址压入堆栈。可以这样理解吗?
雪    币: 485
活跃值: (12)
能力值: ( LV9,RANK:490 )
在线值:
发帖
回帖
粉丝
petnt 12 2010-4-21 22:06
6
0
程序好像执行不到那里,应该是编译的时候就搞定了
雪    币: 28
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
lpfei 2010-4-21 22:33
7
0
执行不到那里,为什么会把ImportTable   DD  AddressFirst-ImportTable  ;OriginalFirstThunk的地址压入堆栈啊,压入的地址不就是call之后要执行的代码吗?弄不明白啊。
雪    币: 485
活跃值: (12)
能力值: ( LV9,RANK:490 )
在线值:
发帖
回帖
粉丝
petnt 12 2010-4-22 07:37
8
0
call        @F
szLoadLibrary        db        'LoadLibraryA',0
szGetProcAddress   db        'GetProcAddress',0
szUser32                        db        'user32',0
szMessageBox        db        'MessageBoxA',0
szCaption                        db        '问题提示',0
szText                db        'Are you Sure?',0
@@:
pop        ebx


编译后

0040100A   > /E8 46000000   call    00401055
0040100F   . |4C            dec     esp      <-无论这句执行不执行的到,上面call之后压入的是这句的地址
00401010   . |6F            outs    dx, dword ptr es:[edi]
00401011   . |61            popad
00401012   . |64:4C         dec     esp
00401014   . |6962 72 61727>imul    esp, dword ptr [edx+72], 4179726>
0040101B   . |0047 65       add     byte ptr [edi+65], al
0040101E   . |74 50         je      short 00401070
00401020   . |72 6F         jb      short 00401091
00401022   . |6341 64       arpl    word ptr [ecx+64], ax
00401025   . |64:72 65      jb      short 0040108D
00401028   . |73 73         jnb     short 0040109D
0040102A   . |0075 73       add     byte ptr [ebp+73], dh
0040102D   . |65:72 33      jb      short 00401063
00401030   . |3200          xor     al, byte ptr [eax]
00401032   . |4D            dec     ebp
00401033   . |65:73 73      jnb     short 004010A9
00401036   . |61            popad
00401037   . |67:65:42      inc     edx
0040103A   . |6F            outs    dx, dword ptr es:[edi]
0040103B   . |78 41         js      short 0040107E
0040103D   . |00CE          add     dh, cl
0040103F   . |CA CCE2       retf    0E2CC
00401042     |CC            int3
00401043   . |E1 CA BE 00   ascii   "崾?,0
00401047   . |41 72 65 20 7>ascii   "Are you Sure?",0
00401055   $ |5B            pop     ebx <- 执行完这句ebx=0040100F


明白了吗?
雪    币: 28
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
lpfei 2010-4-22 21:19
9
0
szLoadLibrary  db  'LoadLibraryA',0
szGetProcAddress   db  'GetProcAddress',0
szUser32                  db  'user32',0
szMessageBox  db  'MessageBoxA',0
szCaption                  db  '问题提示',0
szText    db  'Are you Sure?',0
编译出来就是下面的
0040100F   . |4C            dec     esp      <-无论这句执行不执行的到,上面call之后压入的是这句的地址
00401010   . |6F            outs    dx, dword ptr es:[edi]
00401011   . |61            popad
00401012   . |64:4C         dec     esp
00401014   . |6962 72 61727>imul    esp, dword ptr [edx+72], 4179726>
0040101B   . |0047 65       add     byte ptr [edi+65], al
0040101E   . |74 50         je      short 00401070
00401020   . |72 6F         jb      short 00401091
00401022   . |6341 64       arpl    word ptr [ecx+64], ax
00401025   . |64:72 65      jb      short 0040108D
00401028   . |73 73         jnb     short 0040109D
0040102A   . |0075 73       add     byte ptr [ebp+73], dh
0040102D   . |65:72 33      jb      short 00401063
00401030   . |3200          xor     al, byte ptr [eax]
00401032   . |4D            dec     ebp
00401033   . |65:73 73      jnb     short 004010A9
00401036   . |61            popad
00401037   . |67:65:42      inc     edx
0040103A   . |6F            outs    dx, dword ptr es:[edi]
0040103B   . |78 41         js      short 0040107E
0040103D   . |00CE          add     dh, cl
0040103F   . |CA CCE2       retf    0E2CC
00401042     |CC            int3
00401043   . |E1 CA BE 00   ascii   "崾?,0
00401047   . |41 72 65 20 7>ascii   "Are you Sure?",0
当要访问这些变量就是执行这些代码吗?能大概解释下这些代码吗?
雪    币: 485
活跃值: (12)
能力值: ( LV9,RANK:490 )
在线值:
发帖
回帖
粉丝
petnt 12 2010-4-22 21:59
10
0
虽然OD认为他们是代码,但上面的是字符串,不是代码。
这些被放在代码段的变量,像访问其他变量一样,是访问这些字符串,而不是执行他们。
雪    币: 28
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
lpfei 2010-4-22 22:44
11
0
真的是字符串啊,谢谢大侠的回答。
游客
登录 | 注册 方可回帖
返回