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

Add config to override libc version. #1027

Merged
merged 8 commits into from
Dec 22, 2023
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
8 changes: 8 additions & 0 deletions docs/commands/heap.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ gef➤ gef config gef.bruteforce_main_arena True
Note that this might take a few seconds to complete. If GEF does find the symbol you can then
calculate the offset to the libc base address and save it in the config.

Sometimes, the dump might not contain proper info to help GEF find the libc version, which results in
failure to parse the arena information. In this case, you can try to provide GEF a specific libc
version to use with the following command:

```text
gef➤ gef config gef.libc_version 2.31
```

### `heap chunks` command

Displays all the chunks from the `heap` section of the current arena.
Expand Down
7 changes: 7 additions & 0 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -9587,6 +9587,7 @@ def __init__(self) -> None:
gef.config["gef.show_deprecation_warnings"] = GefSetting(True, bool, "Toggle the display of the `deprecated` warnings")
gef.config["gef.buffer"] = GefSetting(True, bool, "Internally buffer command output until completion")
gef.config["gef.bruteforce_main_arena"] = GefSetting(False, bool, "Allow bruteforcing main_arena symbol if everything else fails")
gef.config["gef.libc_version"] = GefSetting("", str, "Specify libc version when auto-detection fails")
gef.config["gef.main_arena_offset"] = GefSetting("", str, "Offset from libc base address to main_arena symbol (int or hex). Set to empty string to disable.")

self.commands : Dict[str, GenericCommand] = collections.OrderedDict()
Expand Down Expand Up @@ -11166,8 +11167,14 @@ def __str__(self) -> str:
def version(self) -> Optional[Tuple[int, int]]:
if not is_alive():
return None

if not self._version:
self._version = GefLibcManager.find_libc_version()

# Whenever auto-detection fails, we use the user-provided version.
if self._version == (0, 0) and gef.config["gef.libc_version"] != "":
return tuple([int(v) for v in gef.config["gef.libc_version"].split(".")])

return self._version

@staticmethod
Expand Down
22 changes: 21 additions & 1 deletion tests/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test GEF configuration parameters.
"""

from tests.utils import gdb_run_cmd
from tests.utils import gdb_run_cmd, gdb_start_silent_cmd
from tests.utils import GefUnitTestGeneric


Expand Down Expand Up @@ -49,3 +49,23 @@ def test_config_type_validator(self):
res = gdb_run_cmd("gef config gef.debug 0")
self.assertNoException(res)
self.assertNotIn("[!]", res)

def test_config_libc_version(self):
"""Check setting libc version."""
res = gdb_run_cmd("gef config gef.libc_version")
self.assertNoException(res)
self.assertNotIn("[!]", res)

res = gdb_run_cmd("gef config gef.libc_version", before=["gef config gef.libc_version 2.31"])
self.assertNoException(res)
self.assertNotIn("[!]", res)
self.assertIn('gef.libc_version (str) = "2.31"', res)

res = gdb_run_cmd("gef config gef.libc_version", before=["gef config gef.libc_version 2.31", "gef config gef.libc_version ''"])
self.assertNoException(res)
self.assertNotIn("[!]", res)
self.assertIn('gef.libc_version (str) = ""', res)

res = gdb_start_silent_cmd("python print(gef.libc.version)", before=["gef config gef.libc_version 2.31"])
self.assertNoException(res)
self.assertNotIn("[!]", res)
Loading