|
7 | 7 | from shellblocks.primitives.goto import ShellcodePrimitiveGoto |
8 | 8 |
|
9 | 9 |
|
| 10 | +SECTOR_SIZE = 0x2000 |
| 11 | + |
| 12 | + |
10 | 13 | @pytest.mark.parametrize('goto_page_and_address', [ |
11 | 14 | (0x81000000, 0x81000010), |
12 | 15 | (0xbc000000, 0xbc000010), |
@@ -36,11 +39,50 @@ def test_goto_sanity(temp_dir_path, goto_page_and_address): |
36 | 39 |
|
37 | 40 | mu = Uc(UC_ARCH_MIPS, UC_MODE_32 | UC_MODE_BIG_ENDIAN) |
38 | 41 | mu.mem_map(shellcode_address, 0x2000) |
39 | | - mu.mem_map(0x81000000, 0x2000) |
40 | 42 |
|
41 | 43 | # write machine code to be emulated to memory |
42 | 44 | mu.mem_write(shellcode_address, shellcode) |
43 | 45 |
|
44 | 46 | mu.emu_start(shellcode_address, goto_address) |
45 | 47 |
|
46 | 48 | assert goto_address == mu.reg_read(UC_MIPS_REG_PC) |
| 49 | + |
| 50 | + |
| 51 | +@pytest.mark.parametrize('shellcode_run_addr', [ |
| 52 | + (0x81000010), |
| 53 | + (0xbc000010), |
| 54 | + (0xbcf00010), |
| 55 | + (0x91000118), |
| 56 | +]) |
| 57 | +def test_goto_is_pic(temp_dir_path, shellcode_run_addr): |
| 58 | + # Generate shellcode |
| 59 | + # ------------------ |
| 60 | + shellcode_address = 0xbfc00000 |
| 61 | + _, goto_address = (0xbc000000, 0xbc000010) |
| 62 | + |
| 63 | + shellcode_run_sector = int(shellcode_run_addr/SECTOR_SIZE) * SECTOR_SIZE |
| 64 | + |
| 65 | + step = ShellcodeStep( |
| 66 | + "first_step", |
| 67 | + shellcode_address, |
| 68 | + [ |
| 69 | + ShellcodePrimitiveGoto("copy_next_stage", goto_address), |
| 70 | + ], |
| 71 | + 0x1000 |
| 72 | + ) |
| 73 | + |
| 74 | + out_file = step.generate(temp_dir_path / step.nickname) |
| 75 | + shellcode = out_file.read_bytes() |
| 76 | + |
| 77 | + # Try to run shellcode |
| 78 | + # -------------------- |
| 79 | + |
| 80 | + mu = Uc(UC_ARCH_MIPS, UC_MODE_32 | UC_MODE_BIG_ENDIAN) |
| 81 | + mu.mem_map(shellcode_run_sector, 0x2000) |
| 82 | + |
| 83 | + # write machine code to be emulated to memory |
| 84 | + mu.mem_write(shellcode_run_addr, shellcode) |
| 85 | + |
| 86 | + mu.emu_start(shellcode_run_addr, goto_address) |
| 87 | + |
| 88 | + assert goto_address == mu.reg_read(UC_MIPS_REG_PC) |
0 commit comments