Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

17 changes: 8 additions & 9 deletions LibcSearcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
import re
import sys

import config

if config.libcs_path == "path/to/libc-database/db/":
print("Please edit the config.py to set the path to your libc-database.")
sys.exit(0)

class LibcSearcher(object):
def __init__(self, func=None, address=None):
self.condition = {}
if func is not None and address is not None:
self.add_condition(func, address)
self.libc_database_path = os.path.join(
os.path.realpath(os.path.dirname(__file__)), "libc-database/db/")
os.path.realpath(os.path.dirname(__file__)), config.libcs_path)
self.db = ""

def add_condition(self, func, address):
Expand All @@ -24,7 +29,7 @@ def add_condition(self, func, address):
sys.exit()
self.condition[func] = address

#Wrapper for libc-database's find shell script.
# Wrapper for libc-database's find shell script.
def decided(self):
if len(self.condition) == 0:
print("No leaked info provided.")
Expand All @@ -34,7 +39,7 @@ def decided(self):
res = []
for name, address in self.condition.items():
addr_last12 = address & 0xfff
# res.append(re.compile("^%s .*%x" % (name, addr_last12))) #后3位以0开头将丢失第一位,匹配精度下降,将出现大量结果;还可能匹配上地址中间部分,所以改为加%03x$
# res.append(re.compile("^%s .*%x" % (name, addr_last12))) # 后3位以0开头将丢失第一位,匹配精度下降,将出现大量结果;还可能匹配上地址中间部分,所以改为加%03x$
res.append(re.compile("^%s .*%03x$" % (name, addr_last12)))

db = self.libc_database_path
Expand Down Expand Up @@ -120,9 +125,3 @@ def dump(self, func=None):

print("No matched, Make sure you supply a valid function name or just add more libc.")
return 0


if __name__ == "__main__":
obj = LibcSearcher("fgets", 0x7ff39014bd90)
print("[+]system offset: ", hex(obj.dump("system")))
print("[+]/bin/sh offset: ", hex(obj.dump("str_bin_sh")))
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
# Search libc function offset
[原仓库](https://github.com/lieanu/LibcSearcher),修改部分bug



## 来源

这是[原仓库](https://github.com/lieanu/LibcSearcher)的一个 fork;LibcSearcher 是一个好用的工具,可惜原仓库已经数年没有更新了,而原作者也已数年在 GitHub 没有任何活动,似乎已经放弃维护了。

## 简介

这是针对CTF比赛所做的小工具,在泄露了Libc中的某一个函数地址后,常常为不知道对方所使用的操作系统及libc的版本而苦恼,常规方法就是挨个把常见的Libc.so从系统里拿出来,与泄露的地址对比一下最后12位
这是针对 CTF 比赛所做的小工具

为了不在这一块浪费太多生命,写了几行代码,方便以后重用
在泄露了目标系统 libc 中的某一个函数地址后,往往需要通过手动对比来判断目标系统使用的 libc 版本,并进一步计算出其它函数的地址;该工具实现了这一麻烦过程的脚本化

这里用了[libc-database](https://github.com/niklasb/libc-database)的数据库。
推荐 [libc-database](https://github.com/niklasb/libc-database) 的数据库。

## 安装

```shell
git clone https://github.com/lieanu/LibcSearcher.git
```bash
git clone https://github.com/runshell/LibcSearcher.git
cd LibcSearcher
python setup.py develop
```

在此之后,请修改 LibcSearcher 目录下的 `config.py`,将变量 `libcs_path` 改为你存放各版本 libc 的目录;如果你使用的是 [libc-database](https://github.com/niklasb/libc-database),应当改为 libc-database 目录下子目录 db 的路径。**注意,路径请以`/`结尾。**

## 示例

```python
from LibcSearcher import *

#第二个参数,为已泄露的实际地址,或最后12位(比如:d90),int类型
obj = LibcSearcher("fgets", 0X7ff39014bd90)
# 第 2 个参数为已泄露的实际地址或最后 12 位(比如 0xd90)
libc = LibcSearcher("fgets", 0X7ff39014bd90)

obj.dump("system") #system 偏移
obj.dump("str_bin_sh") #/bin/sh 偏移
obj.dump("__libc_start_main_ret")
libc.dump("system") # 函数 system 的偏移
libc.dump("str_bin_sh") # 字符串 /bin/sh 的偏移
libc.dump("__libc_start_main_ret")
```

如果遇到返回多个libc版本库的情况,可以通过`add_condition(leaked_func, leaked_address)`来添加限制条件,也可以手工选择其中一个libc版本(如果你确定的话)。

## 其它

水平一般,代码很烂,如有bug,欢迎吐槽。
如果遇到返回多个libc版本库的情况,可以通过 `add_condition(leaked_func, leaked_address)` 来添加限制条件,也可以手动选择其中一个libc版本(如果你确定的话)。

欢迎贡献不同linux发行版的libc信息。
3 changes: 3 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python

libcs_path = 'path/to/libc-database/db/' # 根据需要修改
42 changes: 0 additions & 42 deletions libc-database/README.md

This file was deleted.

13 changes: 0 additions & 13 deletions libc-database/add

This file was deleted.

117 changes: 0 additions & 117 deletions libc-database/common/libc.sh

This file was deleted.

1 change: 0 additions & 1 deletion libc-database/db/dietlibc_0.26-3_i386.info

This file was deleted.

Binary file removed libc-database/db/dietlibc_0.26-3_i386.so
Binary file not shown.
Loading