Files
gef/tests/commands/shellcode.py
crazy hugsyandGrazfather bcaabff1d8 Migrate tests to RPyC (#1040)
This is a major PR, but long overdue.

GEF can now use RPyC to completely control the tests which not only make
them way faster, also allow to control directly from the `pytest` tests
themselves `gdb` and `gef` (see examples). Tests are therefore smaller,
less messy, and more accurate than when using the legacy function
`gdb_run_cmd`.

The documentation in `docs/testing.md` has been updated accordingly.

This allowed to find a few missing things in gef.py itself, which were
added but nothing major.

Note that currently the PR is not perfect as I did not re-write the
tests: I've migrated most of the code to the new API to ensure coverage
stays identical. This was done because the PR is already big enough as
it is. More accurate tests can be added in following PRs.


Co-authored-by: Grazfather <[email protected]>
2024-01-09 13:02:48 -08:00

44 lines
1.3 KiB
Python

"""
Shellcode commands test module
"""
import pytest
from tests.base import RemoteGefUnitTestGeneric
from tests.utils import BIN_SH
class ShellcodeCommand(RemoteGefUnitTestGeneric):
"""`shellcode` command test module"""
def test_cmd_shellcode(self):
gdb = self._gdb
gdb.execute("start")
res = gdb.execute("shellcode", to_string=True)
self.assertIn("Missing sub-command (search|get)", res)
@pytest.mark.online
@pytest.mark.slow
def test_cmd_shellcode_search(self):
gdb = self._gdb
cmd = f"shellcode search execve {BIN_SH}"
gdb.execute("start")
res = gdb.execute(cmd, to_string=True)
self.assertIn(f"setuid(0) + execve({BIN_SH}) 49 bytes", res)
@pytest.mark.online
@pytest.mark.slow
def test_cmd_shellcode_get_ok(self):
gdb = self._gdb
gdb.execute("start")
res = gdb.execute("shellcode get 77", to_string=True)
self.assertIn("Shellcode written to ", res)
@pytest.mark.online
@pytest.mark.slow
def test_cmd_shellcode_get_nok(self):
gdb = self._gdb
n = 1111111111111
gdb.execute("start")
res = gdb.execute(f"shellcode get {n}", to_string=True)
self.assertIn(f"Failed to fetch shellcode #{n}", res)