Exemplo n.º 1
0
    def test_command_xinfo(self):
        self.assertFailIfInactiveSession(gdb_run_command("xinfo $sp"))
        res = gdb_start_silent_command("xinfo")
        self.assertTrue(b"At least one valid address must be specified" in res)

        res = gdb_start_silent_command("xinfo $sp")
        self.assertNoException(res)
        self.assertTrue(len(res.splitlines()) >= 7)
        return
Exemplo n.º 2
0
    def test_command_xinfo(self):
        self.assertFailIfInactiveSession(gdb_run_command("xinfo $sp"))
        res = gdb_start_silent_command("xinfo")
        self.assertTrue(b"At least one valid address must be specified" in res)

        res = gdb_start_silent_command("xinfo $sp")
        self.assertNoException(res)
        self.assertTrue(len(res.splitlines()) >= 7)
        return
Exemplo n.º 3
0
    def test_command_vmmap(self):
        self.assertFailIfInactiveSession(gdb_run_command("vmmap"))
        res = gdb_start_silent_command("vmmap")
        self.assertNoException(res)
        self.assertTrue(len(res.splitlines()) > 1)

        res = gdb_start_silent_command("vmmap stack")
        self.assertNoException(res)
        self.assertTrue(len(res.splitlines()) > 1)
        return
Exemplo n.º 4
0
    def test_command_vmmap(self):
        self.assertFailIfInactiveSession(gdb_run_command("vmmap"))
        res = gdb_start_silent_command("vmmap")
        self.assertNoException(res)
        self.assertTrue(len(res.splitlines()) > 1)

        res = gdb_start_silent_command("vmmap stack")
        self.assertNoException(res)
        self.assertTrue(len(res.splitlines()) > 1)
        return
Exemplo n.º 5
0
 def test_command_hexdump(self):
     self.assertFailIfInactiveSession(gdb_run_command("hexdump $pc"))
     res = gdb_start_silent_command("hexdump qword $pc")
     self.assertNoException(res)
     res = gdb_start_silent_command("hexdump dword $pc l1")
     self.assertNoException(res)
     res = gdb_start_silent_command("hexdump word $pc l5 down")
     self.assertNoException(res)
     res = gdb_start_silent_command("hexdump byte $sp l32")
     self.assertNoException(res)
     return
Exemplo n.º 6
0
 def test_command_hexdump(self):
     self.assertFailIfInactiveSession(gdb_run_command("hexdump $pc"))
     res = gdb_start_silent_command("hexdump qword $pc")
     self.assertNoException(res)
     res = gdb_start_silent_command("hexdump dword $pc l1")
     self.assertNoException(res)
     res = gdb_start_silent_command("hexdump word $pc l5 down")
     self.assertNoException(res)
     res = gdb_start_silent_command("hexdump byte $sp l32")
     self.assertNoException(res)
     return
Exemplo n.º 7
0
 def test_command_print_format(self):
     self.assertFailIfInactiveSession(gdb_run_command("print-format"))
     res = gdb_start_silent_command("print-format $rsp")
     self.assertNoException(res)
     self.assertTrue(b"buf = [" in res)
     res = gdb_start_silent_command("print-format -f js $rsp")
     self.assertNoException(res)
     self.assertTrue(b"var buf = [" in res)
     res = gdb_start_silent_command("print-format -f iDontExist $rsp")
     self.assertNoException(res)
     self.assertTrue(b"Language must be :" in res)
     return
Exemplo n.º 8
0
    def test_command_dereference(self):
        self.assertFailIfInactiveSession(gdb_run_command("dereference"))

        res = gdb_start_silent_command("dereference $sp")
        self.assertNoException(res)
        self.assertTrue(len(res.splitlines()) > 2)
        self.assertTrue(b"$rsp" in res)

        res = gdb_start_silent_command("dereference 0")
        self.assertNoException(res)
        self.assertTrue(b"Unmapped address" in res)
        return
Exemplo n.º 9
0
    def test_command_dereference(self):
        self.assertFailIfInactiveSession(gdb_run_command("dereference"))

        res = gdb_start_silent_command("dereference $sp")
        self.assertNoException(res)
        self.assertTrue(len(res.splitlines()) > 2)
        self.assertTrue(b"$rsp" in res)

        res = gdb_start_silent_command("dereference 0")
        self.assertNoException(res)
        self.assertTrue(b"Unmapped address" in res)
        return
Exemplo n.º 10
0
    def test_command_xor_memory(self):
        cmd = "xor-memory display $sp 0x10 0x41"
        self.assertFailIfInactiveSession(gdb_run_command(cmd))
        res = gdb_start_silent_command(cmd)
        self.assertNoException(res)
        self.assertTrue(b"Original block" in res)
        self.assertTrue(b"XOR-ed block" in res)

        cmd = "xor-memory patch $sp 0x10 0x41"
        res = gdb_start_silent_command(cmd)
        self.assertNoException(res)
        self.assertTrue(b"Patching XOR-ing ")
        return
Exemplo n.º 11
0
    def test_command_xor_memory(self):
        cmd = "xor-memory display $sp 0x10 0x41"
        self.assertFailIfInactiveSession(gdb_run_command(cmd))
        res = gdb_start_silent_command(cmd)
        self.assertNoException(res)
        self.assertTrue(b"Original block" in res)
        self.assertTrue(b"XOR-ed block" in res)

        cmd = "xor-memory patch $sp 0x10 0x41"
        res = gdb_start_silent_command(cmd)
        self.assertNoException(res)
        self.assertTrue(b"Patching XOR-ing ")
        return
Exemplo n.º 12
0
    def test_command_retdec(self):
        cmd = "retdec -s main"
        target = "tests/binaries/retdec.out"
        res = gdb_start_silent_command(cmd, target=target)
        if b"No RetDec API key provided" in res:
            api_key = os.getenv("GEF_RETDEC_API_KEY")
            if api_key is None:
                return
            before = ["gef config retdec.key {}".format(api_key),]
            res = gdb_start_silent_command(cmd, before=before, target=target)

        self.assertNoException(res)
        self.assertTrue(b"Saved as" in res)
        return
Exemplo n.º 13
0
    def test_command_retdec(self):
        cmd = "retdec -s main"
        target = "tests/binaries/retdec.out"
        res = gdb_start_silent_command(cmd, target=target)
        if b"No RetDec API key provided" in res:
            api_key = os.getenv("GEF_RETDEC_API_KEY")
            if api_key is None:
                return
            before = ["gef config retdec.key {}".format(api_key),]
            res = gdb_start_silent_command(cmd, before=before, target=target)

        self.assertNoException(res)
        self.assertTrue(b"Saved as" in res)
        return
Exemplo n.º 14
0
 def test_command_capstone_disassemble(self):
     self.assertFailIfInactiveSession(
         gdb_run_command("capstone-disassemble"))
     res = gdb_start_silent_command("capstone-disassemble")
     self.assertNoException(res)
     self.assertTrue(len(res.splitlines()) > 1)
     return
Exemplo n.º 15
0
 def test_command_registers(self):
     self.assertFailIfInactiveSession(gdb_run_command("registers"))
     res = gdb_start_silent_command("registers")
     self.assertNoException(res)
     self.assertTrue(b"$rax" in res)
     self.assertTrue(b"$eflags" in res)
     return
Exemplo n.º 16
0
 def test_command_canary(self):
     self.assertFailIfInactiveSession(gdb_run_command("canary"))
     res = gdb_start_silent_command("canary", target="tests/binaries/canary.out")
     self.assertNoException(res)
     self.assertTrue(b"Found AT_RANDOM at" in res)
     self.assertTrue(b"The canary of process " in res)
     return
Exemplo n.º 17
0
 def test_command_canary(self):
     self.assertFailIfInactiveSession(gdb_run_command("canary"))
     res = gdb_start_silent_command("canary", target="tests/binaries/canary.out")
     self.assertNoException(res)
     self.assertTrue(b"Found AT_RANDOM at" in res)
     self.assertTrue(b"The canary of process " in res)
     return
Exemplo n.º 18
0
 def test_command_registers(self):
     self.assertFailIfInactiveSession(gdb_run_command("registers"))
     res = gdb_start_silent_command("registers")
     self.assertNoException(res)
     self.assertTrue(b"$rax" in res)
     self.assertTrue(b"$eflags" in res)
     return
Exemplo n.º 19
0
 def test_command_heap_arenas(self):
     cmd = "heap arenas"
     target = "tests/binaries/heap.out"
     self.assertFailIfInactiveSession(gdb_run_command(cmd, target=target))
     res = gdb_start_silent_command(cmd, target=target)
     self.assertNoException(res)
     self.assertTrue(b"Arena (base=" in res)
     return
Exemplo n.º 20
0
 def test_command_process_status(self):
     self.assertFailIfInactiveSession(gdb_run_command("process-status"))
     res = gdb_start_silent_command("process-status")
     self.assertNoException(res)
     self.assertTrue(b"Process Information" in res \
                     and b"No child process" in res \
                     and b"No open connections" in res)
     return
Exemplo n.º 21
0
 def test_command_heap_arenas(self):
     cmd = "heap arenas"
     target = "tests/binaries/heap.out"
     self.assertFailIfInactiveSession(gdb_run_command(cmd, target=target))
     res = gdb_start_silent_command(cmd, target=target)
     self.assertNoException(res)
     self.assertTrue(b"Arena (base=" in res)
     return
Exemplo n.º 22
0
 def test_command_process_status(self):
     self.assertFailIfInactiveSession(gdb_run_command("process-status"))
     res = gdb_start_silent_command("process-status")
     self.assertNoException(res)
     self.assertTrue(b"Process Information" in res \
                     and b"No child process" in res \
                     and b"No open connections" in res)
     return
Exemplo n.º 23
0
    def test_command_unicorn_emulate(self):
        cmd = "emu -n 1"
        res = gdb_run_command(cmd)
        self.assertFailIfInactiveSession(res)

        res = gdb_start_silent_command(cmd)
        self.assertNoException(res)
        self.assertTrue(b"Final registers" in res)
        return
Exemplo n.º 24
0
    def test_command_unicorn_emulate(self):
        cmd = "emu -n 1"
        res = gdb_run_command(cmd)
        self.assertFailIfInactiveSession(res)

        res = gdb_start_silent_command(cmd)
        self.assertNoException(res)
        self.assertTrue(b"Final registers" in res)
        return
Exemplo n.º 25
0
    def test_command_trace_run(self):
        cmd = "trace-run"
        res = gdb_run_command(cmd)
        self.assertFailIfInactiveSession(res)

        cmd = "trace-run $pc+1"
        res = gdb_start_silent_command(cmd,
                                       before=["gef config trace-run.tracefile_prefix /tmp/gef-trace-"])
        self.assertNoException(res)
        self.assertTrue(b"Tracing from" in res)
        return
Exemplo n.º 26
0
    def test_command_trace_run(self):
        cmd = "trace-run"
        res = gdb_run_command(cmd)
        self.assertFailIfInactiveSession(res)

        cmd = "trace-run $pc+1"
        res = gdb_start_silent_command(cmd,
                                       before=["gef config trace-run.tracefile_prefix /tmp/gef-trace-"])
        self.assertNoException(res)
        self.assertTrue(b"Tracing from" in res)
        return
Exemplo n.º 27
0
 def test_command_keystone_assemble(self):
     valid_cmds = [
         "assemble nop; xor eax, eax; int 0x80",
         "assemble -a arm -m arm add r0, r1, r2",
         "assemble -a mips -m mips32 add $v0, 1",
         "assemble -a sparc -m sparc32  set 0, %o0",
         "assemble -a arm64 -m little_endian add x29, sp, 0; mov  w0, 0; ret"
     ]
     for cmd in valid_cmds:
         res = gdb_start_silent_command(cmd)
         self.assertNoException(res)
         self.assertTrue(len(res.splitlines()) > 1)
     return
Exemplo n.º 28
0
 def test_command_keystone_assemble(self):
     valid_cmds = [
         "assemble nop; xor eax, eax; int 0x80",
         "assemble -a arm -m arm add r0, r1, r2",
         "assemble -a mips -m mips32 add $v0, 1",
         "assemble -a sparc -m sparc32  set 0, %o0",
         "assemble -a arm64 -m little_endian add x29, sp, 0; mov  w0, 0; ret"
     ]
     for cmd in valid_cmds:
         res = gdb_start_silent_command(cmd)
         self.assertNoException(res)
         self.assertTrue(len(res.splitlines()) > 1)
     return
Exemplo n.º 29
0
 def test_command_xfiles(self):
     self.assertFailIfInactiveSession(gdb_run_command("xfiles"))
     res = gdb_start_silent_command("xfiles")
     self.assertNoException(res)
     self.assertTrue(len(res.splitlines()) >= 3)
     return
Exemplo n.º 30
0
 def test_command_reset_cache(self):
     res = gdb_start_silent_command("reset-cache")
     self.assertNoException(res)
     return
Exemplo n.º 31
0
 def test_command_shellcode_get(self):
     res = gdb_start_silent_command("shellcode get 77")
     self.assertNoException(res)
     self.assertTrue(b"Shellcode written to " in res)
     return
Exemplo n.º 32
0
 def test_command_heap_analysis(self):
     cmd = "heap-analysis-helper"
     self.assertFailIfInactiveSession(gdb_run_command(cmd))
     res = gdb_start_silent_command(cmd)
     self.assertNoException(res)
     return
Exemplo n.º 33
0
 def test_command_shellcode_get(self):
     res = gdb_start_silent_command("shellcode get 77")
     self.assertNoException(res)
     self.assertTrue(b"Shellcode written to " in res)
     return
Exemplo n.º 34
0
 def test_command_stub(self):
     cmd = "stub printf"
     self.assertFailIfInactiveSession(gdb_run_command(cmd))
     res = gdb_start_silent_command(cmd)
     self.assertNoException(res)
     return
Exemplo n.º 35
0
 def test_command_shellcode(self):
     res = gdb_start_silent_command("shellcode")
     self.assertNoException(res)
     self.assertTrue(b"Missing sub-command <search|get>" in res)
     return
Exemplo n.º 36
0
 def test_command_shellcode_search(self):
     cmd = "shellcode search execve /bin/sh"
     res = gdb_start_silent_command(cmd)
     self.assertNoException(res)
     self.assertTrue(b"setuid(0) + execve(/bin/sh) 49 bytes" in res)
     return
Exemplo n.º 37
0
 def test_command_capstone_disassemble(self):
     self.assertFailIfInactiveSession(gdb_run_command("capstone-disassemble"))
     res = gdb_start_silent_command("capstone-disassemble")
     self.assertNoException(res)
     self.assertTrue(len(res.splitlines()) > 1)
     return
Exemplo n.º 38
0
 def test_command_shellcode_search(self):
     cmd = "shellcode search execve /bin/sh"
     res = gdb_start_silent_command(cmd)
     self.assertNoException(res)
     self.assertTrue(b"setuid(0) + execve(/bin/sh) 49 bytes" in res)
     return
Exemplo n.º 39
0
 def test_command_xfiles(self):
     self.assertFailIfInactiveSession(gdb_run_command("xfiles"))
     res = gdb_start_silent_command("xfiles")
     self.assertNoException(res)
     self.assertTrue(len(res.splitlines()) >= 3)
     return
Exemplo n.º 40
0
 def test_command_heap_analysis(self):
     cmd = "heap-analysis-helper"
     self.assertFailIfInactiveSession(gdb_run_command(cmd))
     res = gdb_start_silent_command(cmd)
     self.assertNoException(res)
     return
Exemplo n.º 41
0
 def test_command_shellcode(self):
     res = gdb_start_silent_command("shellcode")
     self.assertNoException(res)
     self.assertTrue(b"Missing sub-command <search|get>" in res)
     return
Exemplo n.º 42
0
 def test_command_stub(self):
     cmd = "stub printf"
     self.assertFailIfInactiveSession(gdb_run_command(cmd))
     res = gdb_start_silent_command(cmd)
     self.assertNoException(res)
     return
Exemplo n.º 43
0
 def test_command_search_pattern(self):
     self.assertFailIfInactiveSession(gdb_run_command("grep /bin/sh"))
     res = gdb_start_silent_command("grep /bin/sh")
     self.assertNoException(res)
     self.assertTrue(b"0x" in res)
     return
Exemplo n.º 44
0
 def test_command_search_pattern(self):
     self.assertFailIfInactiveSession(gdb_run_command("grep /bin/sh"))
     res = gdb_start_silent_command("grep /bin/sh")
     self.assertNoException(res)
     self.assertTrue(b"0x" in res)
     return
Exemplo n.º 45
0
 def test_command_reset_cache(self):
     res = gdb_start_silent_command("reset-cache")
     self.assertNoException(res)
     return