Skip to content

Commit

Permalink
Merge pull request #111 from Wenzel/pie/add_rel_type
Browse files Browse the repository at this point in the history
ELF: add support for PIEType REL
  • Loading branch information
Wenzel authored Sep 8, 2021
2 parents 57cb7bf + b1eb586 commit 33694ef
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion checksec/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,6 +77,7 @@ class PIEType(Enum):
No = 1
DSO = 2
PIE = 3
REL = 4


class Libc:
Expand Down Expand Up @@ -149,11 +151,13 @@ 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:
return PIEType.DSO
elif self.bin.header.file_type == E_TYPE.RELOCATABLE:
return PIEType.REL
return PIEType.No

@property
Expand Down
2 changes: 2 additions & 0 deletions checksec/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/binaries
Submodule binaries updated 1 files
+ elf/pie_rel

0 comments on commit 33694ef

Please sign in to comment.