From 387428ec5d72cea9d6f6b023e34266e12ce18891 Mon Sep 17 00:00:00 2001 From: Mathieu Tarral Date: Wed, 8 Sep 2021 09:36:15 +0200 Subject: [PATCH 1/2] elf: do not rely on lief is_pie for pie check --- checksec/elf.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/checksec/elf.py b/checksec/elf.py index 5914135..753c354 100644 --- a/checksec/elf.py +++ b/checksec/elf.py @@ -6,6 +6,7 @@ from typing import FrozenSet, List, Optional import lief +from lief.ELF import E_TYPE from .binary import BinarySecurity from .errors import ErrorParsingFailed @@ -149,7 +150,7 @@ def has_canary(self) -> bool: @property def pie(self) -> PIEType: - if self.bin.is_pie: + if self.bin.header.file_type == E_TYPE.DYNAMIC: if self.bin.has(lief.ELF.DYNAMIC_TAGS.DEBUG): return PIEType.PIE else: From b1eb586119dc8cbffde239d4876cc1adc150f6b6 Mon Sep 17 00:00:00 2001 From: Mathieu Tarral Date: Wed, 8 Sep 2021 09:50:12 +0200 Subject: [PATCH 2/2] elf: add PIEType.REL --- checksec/elf.py | 3 +++ checksec/output.py | 2 ++ tests/binaries | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/checksec/elf.py b/checksec/elf.py index 753c354..36a4026 100644 --- a/checksec/elf.py +++ b/checksec/elf.py @@ -77,6 +77,7 @@ class PIEType(Enum): No = 1 DSO = 2 PIE = 3 + REL = 4 class Libc: @@ -155,6 +156,8 @@ def pie(self) -> PIEType: return PIEType.PIE else: return PIEType.DSO + elif self.bin.header.file_type == E_TYPE.RELOCATABLE: + return PIEType.REL return PIEType.No @property diff --git a/checksec/output.py b/checksec/output.py index a51d1bb..5541c78 100644 --- a/checksec/output.py +++ b/checksec/output.py @@ -154,6 +154,8 @@ def add_checksec_result(self, filepath: Path, checksec: Union[ELFChecksecData, P pie_res = f"[red]{pie.name}" elif pie == PIEType.DSO: pie_res = f"[yellow]{pie.name}" + elif pie == PIEType.REL: + pie_res = f"[yellow]{pie.name}" else: pie_res = "[green]Yes" row_res.append(pie_res) diff --git a/tests/binaries b/tests/binaries index 8dab77c..c672a34 160000 --- a/tests/binaries +++ b/tests/binaries @@ -1 +1 @@ -Subproject commit 8dab77c4893535eef36235ae1e35ab351f76a280 +Subproject commit c672a34bd234f85071cad139852bfbae530e9ecf