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

more ELF OS detection techniques #1947

Merged
merged 6 commits into from
Jan 25, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Also a big thanks to the other contributors: @aaronatp, @Aayush-Goel-04, @bkojus
- binja: use `binaryninja.load` to open files @xusheng6
- binja: bump binja version to 3.5 #1789 @xusheng6
- elf: better detect ELF OS via GCC .ident directives #1928 @williballenthin
- elf: better detect ELF OS via Android dependencies #1947 @williballenthin
- fix setuptools package discovery #1886 @gmacon @mr-tz

### capa explorer IDA Pro plugin
Expand Down
13 changes: 9 additions & 4 deletions capa/features/extractors/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,8 @@ def guess_os_from_ident_directive(elf: ELF) -> Optional[OS]:
return OS.LINUX
elif "Red Hat" in comment:
return OS.LINUX
elif "Android" in comment:
return OS.ANDROID

return None

Expand Down Expand Up @@ -921,6 +923,8 @@ def guess_os_from_needed_dependencies(elf: ELF) -> Optional[OS]:
return OS.HURD
if needed.startswith("libandroid.so"):
return OS.ANDROID
if needed.startswith("liblog.so"):
return OS.ANDROID

return None

Expand Down Expand Up @@ -1023,10 +1027,6 @@ def detect_elf_os(f) -> str:
if osabi_guess:
ret = osabi_guess

elif ident_guess:
# we don't trust this too much due to non-cross-compilation assumptions
ret = ident_guess

elif ph_notes_guess:
ret = ph_notes_guess

Expand All @@ -1045,6 +1045,11 @@ def detect_elf_os(f) -> str:
elif symtab_guess:
ret = symtab_guess

elif ident_guess:
# at the bottom because we don't trust this too much
# due to potential for bugs with cross-compilation.
ret = ident_guess

return ret.value if ret is not None else "unknown"


Expand Down
Loading