python - 检查是否在python中启用了PIE
问题描述
从昨天开始,我在这里看看如何检测保护“PIE”是否被激活。为此,我分析了重定位条目的输出以查看_ITM_deregisterTMClone是否存在。有没有更好的方法来检测 PIE 而无需通过 readelf 输出?
这是我目前拥有的:
def display_pie(counter):
if (counter == 1):
print("Pie : Enable")
else:
print("Pie: No PIE")
def check_file_pie(data_file):
data = []
data2 = []
result = []
ctn = 0
check = subprocess.Popen(["readelf", "-r", data_file],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result = check.stdout.readlines()
for x in result:
data.append(list(x))
for lines in data:
data2.append("".join(map(chr, lines)))
for new_lines in data2:
if "_ITM_deregisterTMClone" in new_lines:
ctn += 1
display_pie(ctn)
谢谢,这是非常技术性的,所以如果有人可以向我解释检查可执行独立职位的更好方法,我很感兴趣!
解决方案
您可以使用pwntools,它具有操作 ELF 文件的功能。示例用法:
>>> from pwn import *
>>> e = ELF('your-elf-file')
>>> e.pie
True
如果你想知道它是如何实现的,你可以在这里找到源代码。
推荐阅读
- corda - 是否可以让一个网络运行两个版本的corda app
- javascript - Firebase 电话身份验证错误:令牌无效。在 nativeToJSError
- linux - 内核更新问题修复
- sas - 最佳实践 - 为我的 SAS ETL 生成 RUN_ID
- uber-api - 如何在沙盒环境中使用 Uber iOS SDK API?
- c# - 为什么性能计数器根本不起作用
- uwp - 在 DevicePicker 上更改标题会使文本不可见
- javascript - 如何干净地处理提取中的预期错误?
- java - 在 JFace Treeviewer 中对行进行排序
- ssas - 带过滤器的 MDX 计算成员