简体   繁体   English

gdb 显示相同 function 的不同地址?

[英]gdb showing different address for the same function?

So I want to practice doing a ret2libc attack and I'm playing around with gdb on this simple program所以我想练习做一个 ret2libc 攻击,我在这个简单的程序上玩 gdb

// File: retlib.c

#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("system = %p\n", system);
    char c[] = "echo 123";
    system(c);

    return 0;
}

Now notice this现在注意这一点

Reading symbols from ./retlib...(no debugging symbols found)...done.
(gdb) p system
$1 = {<text variable, no debug info>} 0x4004b0 <system@plt>
(gdb) b main
Breakpoint 1 at 0x4005ea
(gdb) r
Starting program: /home/users/mickey/retlib 

Breakpoint 1, 0x00000000004005ea in main ()
(gdb) p system
$2 = {<text variable, no debug info>} 0x7ffff7a523a0 <__libc_system>
(gdb) c
Continuing.
system = 0x4004b0
123
[Inferior 1 (process 11593) exited normally]

My question is, why do I get 2 different outputs of the system function address.我的问题是,为什么我得到system function 地址的 2 个不同输出。 And even after I start running the program the gdb command says one thing, and printf says another.即使在我开始运行程序之后,gdb 命令说一件事,而 printf 说另一件事。 I notice that the tags for each address are different, but why is this happening?我注意到每个地址的标签都不一样,但是为什么会这样呢? Any help would be appreciated!任何帮助,将不胜感激!

Before running the program, gdb will give you the procedure linkage table (.plt) address, after running, the libc function address.在运行程序之前, gdb会给你过程链接表(.plt)地址,运行之后,libc function地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM