contrib: use LIEF 0.12.0 for symbol and security checks
This commit is contained in:
3 files changed
+9
-21
No files matched your search
@@ -12,10 +12,6 @@ from typing import List
|
|||||||
|
|
||||||
import lief #type:ignore
|
import lief #type:ignore
|
||||||
|
|
||||||
# temporary constant, to be replaced with lief.ELF.ARCH.RISCV
|
|
||||||
# https://github.com/lief-project/LIEF/pull/562
|
|
||||||
LIEF_ELF_ARCH_RISCV = lief.ELF.ARCH(243)
|
|
||||||
|
|
||||||
def check_ELF_RELRO(binary) -> bool:
|
def check_ELF_RELRO(binary) -> bool:
|
||||||
'''
|
'''
|
||||||
Check for read-only relocations.
|
Check for read-only relocations.
|
||||||
@@ -101,7 +97,6 @@ def check_ELF_separate_code(binary):
|
|||||||
for segment in binary.segments:
|
for segment in binary.segments:
|
||||||
if segment.type == lief.ELF.SEGMENT_TYPES.LOAD:
|
if segment.type == lief.ELF.SEGMENT_TYPES.LOAD:
|
||||||
for section in segment.sections:
|
for section in segment.sections:
|
||||||
assert(section.name not in flags_per_section)
|
|
||||||
flags_per_section[section.name] = segment.flags
|
flags_per_section[section.name] = segment.flags
|
||||||
# Spot-check ELF LOAD program header flags per section
|
# Spot-check ELF LOAD program header flags per section
|
||||||
# If these sections exist, check them against the expected R/W/E flags
|
# If these sections exist, check them against the expected R/W/E flags
|
||||||
@@ -222,7 +217,7 @@ CHECKS = {
|
|||||||
lief.ARCHITECTURES.ARM: BASE_ELF,
|
lief.ARCHITECTURES.ARM: BASE_ELF,
|
||||||
lief.ARCHITECTURES.ARM64: BASE_ELF,
|
lief.ARCHITECTURES.ARM64: BASE_ELF,
|
||||||
lief.ARCHITECTURES.PPC: BASE_ELF,
|
lief.ARCHITECTURES.PPC: BASE_ELF,
|
||||||
LIEF_ELF_ARCH_RISCV: BASE_ELF,
|
lief.ARCHITECTURES.RISCV: BASE_ELF,
|
||||||
},
|
},
|
||||||
lief.EXE_FORMATS.PE: {
|
lief.EXE_FORMATS.PE: {
|
||||||
lief.ARCHITECTURES.X86: BASE_PE,
|
lief.ARCHITECTURES.X86: BASE_PE,
|
||||||
@@ -250,12 +245,9 @@ if __name__ == '__main__':
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if arch == lief.ARCHITECTURES.NONE:
|
if arch == lief.ARCHITECTURES.NONE:
|
||||||
if binary.header.machine_type == LIEF_ELF_ARCH_RISCV:
|
print(f'{filename}: unknown architecture')
|
||||||
arch = LIEF_ELF_ARCH_RISCV
|
retval = 1
|
||||||
else:
|
continue
|
||||||
print(f'{filename}: unknown architecture')
|
|
||||||
retval = 1
|
|
||||||
continue
|
|
||||||
|
|
||||||
failed: List[str] = []
|
failed: List[str] = []
|
||||||
for (name, func) in CHECKS[etype][arch]:
|
for (name, func) in CHECKS[etype][arch]:
|
||||||
|
|||||||
@@ -15,10 +15,6 @@ from typing import List, Dict
|
|||||||
|
|
||||||
import lief #type:ignore
|
import lief #type:ignore
|
||||||
|
|
||||||
# temporary constant, to be replaced with lief.ELF.ARCH.RISCV
|
|
||||||
# https://github.com/lief-project/LIEF/pull/562
|
|
||||||
LIEF_ELF_ARCH_RISCV = lief.ELF.ARCH(243)
|
|
||||||
|
|
||||||
# Debian 9 (Stretch) EOL: 2022. https://wiki.debian.org/DebianReleases#Production_Releases
|
# Debian 9 (Stretch) EOL: 2022. https://wiki.debian.org/DebianReleases#Production_Releases
|
||||||
#
|
#
|
||||||
# - g++ version 6.3.0 (https://packages.debian.org/search?suite=stretch&arch=any&searchon=names&keywords=g%2B%2B)
|
# - g++ version 6.3.0 (https://packages.debian.org/search?suite=stretch&arch=any&searchon=names&keywords=g%2B%2B)
|
||||||
@@ -44,7 +40,7 @@ MAX_VERSIONS = {
|
|||||||
lief.ELF.ARCH.ARM: (2,18),
|
lief.ELF.ARCH.ARM: (2,18),
|
||||||
lief.ELF.ARCH.AARCH64:(2,18),
|
lief.ELF.ARCH.AARCH64:(2,18),
|
||||||
lief.ELF.ARCH.PPC64: (2,18),
|
lief.ELF.ARCH.PPC64: (2,18),
|
||||||
LIEF_ELF_ARCH_RISCV: (2,27),
|
lief.ELF.ARCH.RISCV: (2,27),
|
||||||
},
|
},
|
||||||
'LIBATOMIC': (1,0),
|
'LIBATOMIC': (1,0),
|
||||||
'V': (0,5,0), # xkb (bitcoin-qt only)
|
'V': (0,5,0), # xkb (bitcoin-qt only)
|
||||||
@@ -78,7 +74,7 @@ ELF_INTERPRETER_NAMES: Dict[lief.ELF.ARCH, Dict[lief.ENDIANNESS, str]] = {
|
|||||||
lief.ENDIANNESS.BIG: "/lib64/ld64.so.1",
|
lief.ENDIANNESS.BIG: "/lib64/ld64.so.1",
|
||||||
lief.ENDIANNESS.LITTLE: "/lib64/ld64.so.2",
|
lief.ENDIANNESS.LITTLE: "/lib64/ld64.so.2",
|
||||||
},
|
},
|
||||||
LIEF_ELF_ARCH_RISCV: {
|
lief.ELF.ARCH.RISCV: {
|
||||||
lief.ENDIANNESS.LITTLE: "/lib/ld-linux-riscv64-lp64d.so.1",
|
lief.ENDIANNESS.LITTLE: "/lib/ld-linux-riscv64-lp64d.so.1",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -200,7 +196,7 @@ def check_exported_symbols(binary) -> bool:
|
|||||||
if not symbol.exported:
|
if not symbol.exported:
|
||||||
continue
|
continue
|
||||||
name = symbol.name
|
name = symbol.name
|
||||||
if binary.header.machine_type == LIEF_ELF_ARCH_RISCV or name in IGNORE_EXPORTS:
|
if binary.header.machine_type == lief.ELF.ARCH.RISCV or name in IGNORE_EXPORTS:
|
||||||
continue
|
continue
|
||||||
print(f'{binary.name}: export of symbol {name} not allowed!')
|
print(f'{binary.name}: export of symbol {name} not allowed!')
|
||||||
ok = False
|
ok = False
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ chain for " target " development."))
|
|||||||
(define-public lief
|
(define-public lief
|
||||||
(package
|
(package
|
||||||
(name "python-lief")
|
(name "python-lief")
|
||||||
(version "0.11.5")
|
(version "0.12.0")
|
||||||
(source
|
(source
|
||||||
(origin
|
(origin
|
||||||
(method git-fetch)
|
(method git-fetch)
|
||||||
@@ -207,7 +207,7 @@ chain for " target " development."))
|
|||||||
(file-name (git-file-name name version))
|
(file-name (git-file-name name version))
|
||||||
(sha256
|
(sha256
|
||||||
(base32
|
(base32
|
||||||
"0qahjfg1n0x76ps2mbyljvws1l3qhkqvmxqbahps4qgywl2hbdkj"))))
|
"026jchj56q25v6gc0754dj9cj5hz5zaza8ij93y5ga94w20kzm9q"))))
|
||||||
(build-system python-build-system)
|
(build-system python-build-system)
|
||||||
(native-inputs
|
(native-inputs
|
||||||
`(("cmake" ,cmake)))
|
`(("cmake" ,cmake)))
|
||||||
|
|||||||
Reference in new issue
Block a user