Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LibcSearcher.py 修改正则提升匹配精度,原版应对类似gets 0x0b0 这种情况完全失效 #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
  •  
  •  
  •  
18 changes: 12 additions & 6 deletions LibcSearcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def decided(self):
res = []
for name, address in self.condition.items():
addr_last12 = address & 0xfff
res.append(re.compile("^%s .*%x" % (name, addr_last12)))
# 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
files = []
Expand All @@ -43,23 +44,28 @@ def decided(self):
for i in f:
files += re.findall('^.*symbols$', i)

result = []
result = {}
for ff in files:
fd = open(db + ff, "rb")
data = fd.read().decode(errors='ignore').split("\n")
for x in res:
if any(map(lambda line: x.match(line), data)):
result.append(ff)
try:
result[ff] += 1
except KeyError:
result[ff] = 1
fd.close()

result = sorted(result.items(), key=lambda x: x[1], reverse=True)

if len(result) == 0:
print("No matched libc, please add more libc or try others")
sys.exit(0)

if len(result) > 1:
print("Multi Results:")
for x in range(len(result)):
print("%2d: %s" % (x, self.pmore(result[x])))
print("%2d:[hit %2d times] %s" % (x, result[x][1], self.pmore(result[x][0])))
print("Please supply more info using \n\tadd_condition(leaked_func, leaked_address).")
while True:
in_id = input(
Expand All @@ -68,12 +74,12 @@ def decided(self):
sys.exit(0)
try:
in_id = int(in_id)
self.db = result[in_id]
self.db = result[in_id][0]
break
except:
continue
else:
self.db = result[0]
self.db = result[0][0]
print("[+] %s be choosed." % self.pmore(self.db))

def pmore(self, result):
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Search libc function offset

[原仓库](https://github.com/lieanu/LibcSearcher),修改部分bug
## 简介

这是针对CTF比赛所做的小工具,在泄露了Libc中的某一个函数地址后,常常为不知道对方所使用的操作系统及libc的版本而苦恼,常规方法就是挨个把常见的Libc.so从系统里拿出来,与泄露的地址对比一下最后12位。
Expand Down
6 changes: 5 additions & 1 deletion libc-database/add
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ if [[ $# != 1 ]]; then
echo >&2 "Usage: $0 libc_filename"
exit 2
fi
libc="$(readlink -f "$1")"
cd "$(dirname "$0")"

. common/libc.sh

add_local $1
requirements_general || die "General requirements are not met. Please, refer to README.md for installation instructions"
requirements_local || die "Requirements for index a local libc are not met. Please, refer to README.md for installation instructions"
add_local "$libc"
1 change: 1 addition & 0 deletions libc-database/db/dietlibc_0.26-3_i386.info
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ubuntu-old-dietlibc
Binary file added libc-database/db/dietlibc_0.26-3_i386.so
Binary file not shown.
Loading