动态加载器的知识学习及CTFHUB动态加载器解题

理解Linux动态加载器与ELF文件
本文介绍了Linux动态加载器的工作原理,通过分析`file`和`readelf`命令展示了ELF文件的详细信息,特别是动态链接部分。在动态链接的ELF文件中,`INTERP`节指出需要`ld-linux-x86-64.so.2`加载器。通过`ldd`命令检查程序依赖,当ELF文件无执行权限时,可以利用动态库的执行权限来运行程序,如`/lib64/ld-linux-x86-64.so.2`执行`readflag`来获取CTF挑战的flag。

目录

动态加载器的了解

CTFHUB-动态加载器


动态加载器的了解

在【维基百科】中动态加载是一种机制,通过该机制,计算机程序可以在运行时将库(或其他二进制)加载到存储器中,检索包含在库中的函数和变量的地址,执行那些函数或访问那些变量,以及从存储器中卸载库。它是计算机程序使用其他软件的三种机制之一;另外两种是静态链接和动态链接。与静态链接和动态链接不同,动态加载允许计算机程序在缺少这些库的情况下启动,以发现可用的库,并潜在地获得附加功能。

为了想了解Linux系统中一个执行文件到底是怎样被执行。

写了一个简单求和C文件,进行编译后,生成了一个可执行文件。

#include<stdio.h>

int sum(int x)
{
    int sumvalue = 0;
    for(int i = 1; i <= x; i++)
    {
        sumvalue += i;
    }
    return sumvalue;
}

int main()
{
    int n = 100;
    int value;
    value = sum(n);
    printf("sum = %d\n", value);
}

在Linux中可以通过file和readelf指令来查看执行文件的大概信息以及文件的elf相关信息。

1、通过file 执行文件名 可以查看到执行文件是静态执行文件还是动态执行文件。statically linked \ dynamically linked。

$ file ./demo
./demo: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=a0c5f362e76df504e8c9f9be25369c7209a6193e, not stripped

2、readelf -h查看指令帮助

readelf: Warning: Nothing to do.
Usage: readelf <option(s)> elf-file(s)
 Display information about the contents of ELF format files
 Options are:
  -a --all               Equivalent to: -h -l -S -s -r -d -V -A -I
  -h --file-header       Display the ELF file header
  -l --program-headers   Display the program headers
     --segments          An alias for --program-headers
  -S --section-headers   Display the sections' header
     --sections          An alias for --section-headers
  -g --section-groups    Display the section groups
  -t --section-details   Display the section details
  -e --headers           Equivalent to: -h -l -S
  -s --syms              Display the symbol table
     --symbols           An alias for --syms
  --dyn-syms             Display the dynamic symbol table
  -n --notes             Display the core notes (if present)
  -r --relocs            Display the relocations (if present)
  -u --unwind            Display the unwind info (if present)
  -d --dynamic           Display the dynamic section (if present)
  -V --version-info      Display the version sections (if present)
  -A --arch-specific     Display architecture specific information (if any)
  -c --archive-index     Display the symbol/file index in an archive
  -D --use-dynamic       Use the dynamic section info when displaying symbols
  -x --hex-dump=<number|name>
                         Dump the contents of section <number|name> as bytes
  -p --string-dump=<number|name>
                         Dump the contents of section <number|name> as strings
  -R --relocated-dump=<number|name>
                         Dump the contents of section <number|name> as relocated bytes
  -z --decompress        Decompress section before dumping it
  -w[lLiaprmfFsoRtUuTgAckK] or
  --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=ma
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值