pwntools 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/lib/pwn.rb +1 -0
- data/lib/pwnlib/abi.rb +1 -0
- data/lib/pwnlib/asm.rb +83 -42
- data/lib/pwnlib/constants/constant.rb +4 -1
- data/lib/pwnlib/constants/constants.rb +3 -0
- data/lib/pwnlib/constants/linux/amd64.rb +2 -0
- data/lib/pwnlib/constants/linux/i386.rb +2 -0
- data/lib/pwnlib/context.rb +10 -1
- data/lib/pwnlib/dynelf.rb +7 -2
- data/lib/pwnlib/elf/elf.rb +79 -6
- data/lib/pwnlib/errors.rb +3 -2
- data/lib/pwnlib/ext/array.rb +2 -1
- data/lib/pwnlib/ext/helper.rb +3 -2
- data/lib/pwnlib/ext/integer.rb +2 -1
- data/lib/pwnlib/ext/string.rb +3 -2
- data/lib/pwnlib/logger.rb +21 -1
- data/lib/pwnlib/memleak.rb +1 -0
- data/lib/pwnlib/pwn.rb +5 -1
- data/lib/pwnlib/reg_sort.rb +5 -0
- data/lib/pwnlib/runner.rb +53 -0
- data/lib/pwnlib/shellcraft/generators/amd64/common/common.rb +2 -0
- data/lib/pwnlib/shellcraft/generators/amd64/common/infloop.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/amd64/common/memcpy.rb +5 -1
- data/lib/pwnlib/shellcraft/generators/amd64/common/mov.rb +4 -0
- data/lib/pwnlib/shellcraft/generators/amd64/common/nop.rb +2 -0
- data/lib/pwnlib/shellcraft/generators/amd64/common/popad.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/amd64/common/pushstr.rb +3 -1
- data/lib/pwnlib/shellcraft/generators/amd64/common/pushstr_array.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/amd64/common/ret.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/amd64/common/setregs.rb +3 -2
- data/lib/pwnlib/shellcraft/generators/amd64/linux/cat.rb +3 -2
- data/lib/pwnlib/shellcraft/generators/amd64/linux/execve.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/amd64/linux/exit.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/amd64/linux/linux.rb +2 -0
- data/lib/pwnlib/shellcraft/generators/amd64/linux/ls.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/amd64/linux/open.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/amd64/linux/sh.rb +3 -2
- data/lib/pwnlib/shellcraft/generators/amd64/linux/sleep.rb +24 -0
- data/lib/pwnlib/shellcraft/generators/amd64/linux/syscall.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/helper.rb +11 -2
- data/lib/pwnlib/shellcraft/generators/i386/common/common.rb +2 -0
- data/lib/pwnlib/shellcraft/generators/i386/common/infloop.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/i386/common/memcpy.rb +34 -0
- data/lib/pwnlib/shellcraft/generators/i386/common/mov.rb +3 -0
- data/lib/pwnlib/shellcraft/generators/i386/common/nop.rb +2 -0
- data/lib/pwnlib/shellcraft/generators/i386/common/pushstr.rb +2 -0
- data/lib/pwnlib/shellcraft/generators/i386/common/pushstr_array.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/i386/common/setregs.rb +3 -2
- data/lib/pwnlib/shellcraft/generators/i386/linux/cat.rb +3 -2
- data/lib/pwnlib/shellcraft/generators/i386/linux/execve.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/i386/linux/exit.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/i386/linux/linux.rb +2 -0
- data/lib/pwnlib/shellcraft/generators/i386/linux/ls.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/i386/linux/open.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/i386/linux/sh.rb +3 -2
- data/lib/pwnlib/shellcraft/generators/i386/linux/sleep.rb +24 -0
- data/lib/pwnlib/shellcraft/generators/i386/linux/syscall.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/x86/common/common.rb +5 -3
- data/lib/pwnlib/shellcraft/generators/x86/common/infloop.rb +2 -0
- data/lib/pwnlib/shellcraft/generators/x86/common/memcpy.rb +17 -0
- data/lib/pwnlib/shellcraft/generators/x86/common/mov.rb +2 -0
- data/lib/pwnlib/shellcraft/generators/x86/common/pushstr.rb +2 -0
- data/lib/pwnlib/shellcraft/generators/x86/common/pushstr_array.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/x86/common/setregs.rb +8 -6
- data/lib/pwnlib/shellcraft/generators/x86/linux/cat.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/x86/linux/execve.rb +3 -0
- data/lib/pwnlib/shellcraft/generators/x86/linux/exit.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/x86/linux/linux.rb +2 -0
- data/lib/pwnlib/shellcraft/generators/x86/linux/ls.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/x86/linux/open.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/x86/linux/sh.rb +1 -0
- data/lib/pwnlib/shellcraft/generators/x86/linux/sleep.rb +52 -0
- data/lib/pwnlib/shellcraft/generators/x86/linux/syscall.rb +10 -10
- data/lib/pwnlib/shellcraft/registers.rb +5 -1
- data/lib/pwnlib/shellcraft/shellcraft.rb +8 -3
- data/lib/pwnlib/timer.rb +6 -2
- data/lib/pwnlib/tubes/buffer.rb +4 -1
- data/lib/pwnlib/tubes/process.rb +2 -0
- data/lib/pwnlib/tubes/serialtube.rb +3 -1
- data/lib/pwnlib/tubes/sock.rb +7 -1
- data/lib/pwnlib/tubes/tube.rb +23 -3
- data/lib/pwnlib/ui.rb +21 -0
- data/lib/pwnlib/util/cyclic.rb +2 -0
- data/lib/pwnlib/util/fiddling.rb +37 -5
- data/lib/pwnlib/util/getdents.rb +1 -0
- data/lib/pwnlib/util/hexdump.rb +8 -5
- data/lib/pwnlib/util/lists.rb +3 -0
- data/lib/pwnlib/util/packing.rb +5 -2
- data/lib/pwnlib/util/ruby.rb +1 -0
- data/lib/pwnlib/version.rb +2 -1
- data/test/abi_test.rb +1 -0
- data/test/asm_test.rb +75 -85
- data/test/constants/constant_test.rb +1 -0
- data/test/constants/constants_test.rb +1 -0
- data/test/context_test.rb +1 -0
- data/test/data/assembly/aarch64.s +19 -0
- data/test/data/assembly/amd64.s +21 -0
- data/test/data/assembly/arm.s +9 -0
- data/test/data/assembly/i386.s +21 -0
- data/test/data/assembly/mips.s +16 -0
- data/test/data/assembly/mips64.s +6 -0
- data/test/data/assembly/powerpc.s +18 -0
- data/test/data/assembly/powerpc64.s +36 -0
- data/test/data/assembly/sparc.s +33 -0
- data/test/data/assembly/sparc64.s +5 -0
- data/test/data/assembly/thumb.s +37 -0
- data/test/data/echo.rb +1 -0
- data/test/dynelf_test.rb +3 -1
- data/test/elf/elf_test.rb +18 -0
- data/test/ext_test.rb +1 -0
- data/test/files/use_pwn.rb +1 -0
- data/test/files/use_pwnlib.rb +1 -0
- data/test/full_file_test.rb +6 -0
- data/test/logger_test.rb +24 -3
- data/test/memleak_test.rb +1 -0
- data/test/reg_sort_test.rb +1 -0
- data/test/runner_test.rb +32 -0
- data/test/shellcraft/infloop_test.rb +1 -0
- data/test/shellcraft/linux/cat_test.rb +1 -0
- data/test/shellcraft/linux/ls_test.rb +1 -0
- data/test/shellcraft/linux/sh_test.rb +1 -0
- data/test/shellcraft/linux/sleep_test.rb +68 -0
- data/test/shellcraft/linux/syscalls/execve_test.rb +1 -0
- data/test/shellcraft/linux/syscalls/exit_test.rb +1 -0
- data/test/shellcraft/linux/syscalls/open_test.rb +1 -0
- data/test/shellcraft/linux/syscalls/syscall_test.rb +1 -0
- data/test/shellcraft/memcpy_test.rb +20 -5
- data/test/shellcraft/mov_test.rb +1 -0
- data/test/shellcraft/nop_test.rb +1 -0
- data/test/shellcraft/popad_test.rb +1 -0
- data/test/shellcraft/pushstr_array_test.rb +1 -0
- data/test/shellcraft/pushstr_test.rb +1 -0
- data/test/shellcraft/registers_test.rb +1 -0
- data/test/shellcraft/ret_test.rb +1 -0
- data/test/shellcraft/setregs_test.rb +9 -8
- data/test/shellcraft/shellcraft_test.rb +1 -0
- data/test/test_helper.rb +28 -0
- data/test/timer_test.rb +2 -1
- data/test/tubes/buffer_test.rb +1 -0
- data/test/tubes/process_test.rb +8 -2
- data/test/tubes/serialtube_test.rb +1 -4
- data/test/tubes/sock_test.rb +1 -0
- data/test/tubes/tube_test.rb +10 -1
- data/test/ui_test.rb +18 -0
- data/test/util/cyclic_test.rb +1 -0
- data/test/util/fiddling_test.rb +8 -0
- data/test/util/getdents_test.rb +1 -0
- data/test/util/hexdump_test.rb +2 -1
- data/test/util/lists_test.rb +1 -0
- data/test/util/packing_test.rb +3 -2
- metadata +119 -59
data/test/context_test.rb
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# These tests are fetched from Capstone's test_arm64.c
|
|
2
|
+
# ARM-64
|
|
3
|
+
2c: 09 00 38 d5 mrs x9, midr_el1
|
|
4
|
+
30: bf 40 00 d5 msr spsel, #0
|
|
5
|
+
34: 0c 05 13 d5 msr dbgdtrtx_el0, x12
|
|
6
|
+
38: 20 50 02 0e tbx v0.8b, {v1.16b, v2.16b, v3.16b}, v2.8b
|
|
7
|
+
3c: 20 e4 3d 0f scvtf v0.2s, v1.2s, #3
|
|
8
|
+
40: 00 18 a0 5f fmla s0, s0, v0.s[3]
|
|
9
|
+
44: a2 00 ae 9e fmov x2, v5.d[1]
|
|
10
|
+
48: 9f 37 03 d5 dsb nsh
|
|
11
|
+
4c: bf 33 03 d5 dmb osh
|
|
12
|
+
50: df 3f 03 d5 isb
|
|
13
|
+
54: 21 7c 02 9b mul x1, x1, x2
|
|
14
|
+
58: 21 7c 00 53 lsr w1, w1, #0
|
|
15
|
+
5c: 00 40 21 4b sub w0, w0, w1, uxtw
|
|
16
|
+
60: e1 0b 40 b9 ldr w1, [sp, #8]
|
|
17
|
+
64: 20 04 81 da cneg x0, x1, ne
|
|
18
|
+
68: 20 08 02 8b add x0, x1, x2, lsl #2
|
|
19
|
+
6c: 10 5b e8 3c ldr q16, [x24, w8, uxtw #4]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# simple move
|
|
2
|
+
0: b8 17 00 00 00 mov eax, 0x17
|
|
3
|
+
|
|
4
|
+
# pwntools-python's shellcraft.sh()
|
|
5
|
+
0: 6a 68 push 0x68
|
|
6
|
+
2: 48 b8 2f 62 69 6e 2f 2f 2f 73 movabs rax, 0x732f2f2f6e69622f
|
|
7
|
+
c: 50 push rax
|
|
8
|
+
d: 48 89 e7 mov rdi, rsp
|
|
9
|
+
10: 68 72 69 01 01 push 0x1016972
|
|
10
|
+
15: 81 34 24 01 01 01 01 xor dword ptr [rsp], 0x1010101
|
|
11
|
+
1c: 31 f6 xor esi, esi
|
|
12
|
+
1e: 56 push rsi
|
|
13
|
+
1f: 6a 08 push 8
|
|
14
|
+
21: 5e pop rsi
|
|
15
|
+
22: 48 01 e6 add rsi, rsp
|
|
16
|
+
25: 56 push rsi
|
|
17
|
+
26: 48 89 e6 mov rsi, rsp
|
|
18
|
+
29: 31 d2 xor edx, edx
|
|
19
|
+
2b: 6a 3b push 0x3b
|
|
20
|
+
2d: 58 pop rax
|
|
21
|
+
2e: 0f 05 syscall
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# These tests are fetched from Capstone's test_arm.c
|
|
2
|
+
1000: ed ff ff eb bl #0xfbc
|
|
3
|
+
1004: 04 e0 2d e5 str lr, [sp, #-4]!
|
|
4
|
+
1008: 00 00 00 00 andeq r0, r0, r0
|
|
5
|
+
100c: e0 83 22 e5 str r8, [r2, #-0x3e0]!
|
|
6
|
+
1010: f1 02 03 0e mcreq p2, #0, r0, c3, c1, #7
|
|
7
|
+
1014: 00 00 a0 e3 mov r0, #0
|
|
8
|
+
1018: 02 30 c1 e7 strb r3, [r1, r2]
|
|
9
|
+
101c: 00 00 53 e3 cmp r3, #0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# simple move
|
|
2
|
+
0: b8 5d 00 00 00 mov eax, 0x5d
|
|
3
|
+
|
|
4
|
+
# pwntools-python's shellcraft.sh()
|
|
5
|
+
0: 6a 68 push 0x68
|
|
6
|
+
2: 68 2f 2f 2f 73 push 0x732f2f2f
|
|
7
|
+
7: 68 2f 62 69 6e push 0x6e69622f
|
|
8
|
+
c: 89 e3 mov ebx, esp
|
|
9
|
+
e: 68 01 01 01 01 push 0x1010101
|
|
10
|
+
13: 81 34 24 72 69 01 01 xor dword ptr [esp], 0x1016972
|
|
11
|
+
1a: 31 c9 xor ecx, ecx
|
|
12
|
+
1c: 51 push ecx
|
|
13
|
+
1d: 6a 04 push 4
|
|
14
|
+
1f: 59 pop ecx
|
|
15
|
+
20: 01 e1 add ecx, esp
|
|
16
|
+
22: 51 push ecx
|
|
17
|
+
23: 89 e1 mov ecx, esp
|
|
18
|
+
25: 31 d2 xor edx, edx
|
|
19
|
+
27: 6a 0b push 0xb
|
|
20
|
+
29: 58 pop eax
|
|
21
|
+
2a: cd 80 int 0x80
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# These tests are fetched from Capstone's test_mips.c
|
|
2
|
+
|
|
3
|
+
# context: endian: big
|
|
4
|
+
# !skip asm # because of keystone-engine/keystone#405
|
|
5
|
+
# MIPS-32 (Big-endian)
|
|
6
|
+
1000: 0c 10 00 97 jal 0x40025c
|
|
7
|
+
1004: 00 00 00 00 nop
|
|
8
|
+
1008: 24 02 00 0c addiu $v0, $zero, 0xc
|
|
9
|
+
100c: 8f a2 00 00 lw $v0, ($sp)
|
|
10
|
+
1010: 34 21 34 56 ori $at, $at, 0x3456
|
|
11
|
+
|
|
12
|
+
# context: endian: big
|
|
13
|
+
# Copied from above, ignored branch instructions
|
|
14
|
+
1008: 24 02 00 0c addiu $v0, $zero, 0xc
|
|
15
|
+
100c: 8f a2 00 00 lw $v0, ($sp)
|
|
16
|
+
1010: 34 21 34 56 ori $at, $at, 0x3456
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# context: endian: big
|
|
2
|
+
# This test is (almost) same as powerpc64.s
|
|
3
|
+
1000: 43 20 0c 07 bdnzla+ 0xc04
|
|
4
|
+
1004: 41 56 ff 17 bdztla 4*cr5+eq, 0xffffffffffffff14
|
|
5
|
+
1008: 80 20 00 00 lwz 1, 0(0)
|
|
6
|
+
1010: 80 3f 00 00 lwz 1, 0(31)
|
|
7
|
+
1014: 10 43 23 0e vpkpx 2, 3, 4
|
|
8
|
+
1018: d0 44 00 80 stfs 2, 0x80(4)
|
|
9
|
+
101c: 4c 43 22 02 crand 2, 3, 4
|
|
10
|
+
1020: 2d 03 00 80 cmpwi cr2, 3, 0x80
|
|
11
|
+
1024: 7c 43 20 14 addc 2, 3, 4
|
|
12
|
+
1028: 7c 43 20 93 mulhd. 2, 3, 4
|
|
13
|
+
102c: 4f 20 00 21 bdnzlrl+
|
|
14
|
+
1030: 4c c8 00 21 bgelrl- cr2
|
|
15
|
+
1034: 40 82 00 14 bne 0x1044
|
|
16
|
+
|
|
17
|
+
# This instruction in ppc32 only
|
|
18
|
+
0: 7c 21 04 a6 mfsr 1, 1
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# These tests are fetched from Capstone's test_ppc.c
|
|
2
|
+
|
|
3
|
+
# context: endian: big
|
|
4
|
+
# !skip asm
|
|
5
|
+
# PPC-64
|
|
6
|
+
1000: 43 20 0c 07 bdnzla+ 0xc04
|
|
7
|
+
1004: 41 56 7f 17 bdztla 4*cr5+eq, 0x7f14
|
|
8
|
+
# Inconsistent output between capstone3 and later versions, skip
|
|
9
|
+
; 1008: 80 20 00 00 lwz r1, 0(0)
|
|
10
|
+
; 100c: 80 3f 00 00 lwz r1, 0(r31)
|
|
11
|
+
1008: 10 43 23 0e vpkpx v2, v3, v4
|
|
12
|
+
100c: d0 44 00 80 stfs f2, 0x80(r4)
|
|
13
|
+
1010: 4c 43 22 02 crand 2, 3, 4
|
|
14
|
+
1014: 2d 03 00 80 cmpwi cr2, r3, 0x80
|
|
15
|
+
1018: 7c 43 20 14 addc r2, r3, r4
|
|
16
|
+
101c: 7c 43 20 93 mulhd. r2, r3, r4
|
|
17
|
+
1020: 4f 20 00 21 bdnzlrl+
|
|
18
|
+
1024: 4c c8 00 21 bgelrl- cr2
|
|
19
|
+
1028: 40 82 00 14 bne 0x103c
|
|
20
|
+
|
|
21
|
+
# context: endian: big
|
|
22
|
+
# !skip disasm
|
|
23
|
+
# PPC-64
|
|
24
|
+
1000: 43 20 0c 07 bdnzla+ 0xc04
|
|
25
|
+
1004: 41 56 7f 17 bdztla 4*cr5+eq, 0x7f14
|
|
26
|
+
1008: 80 20 00 00 lwz 1, 0(0)
|
|
27
|
+
1010: 80 3f 00 00 lwz 1, 0(31)
|
|
28
|
+
1014: 10 43 23 0e vpkpx 2, 3, 4
|
|
29
|
+
1018: d0 44 00 80 stfs 2, 0x80(4)
|
|
30
|
+
101c: 4c 43 22 02 crand 2, 3, 4
|
|
31
|
+
1020: 2d 03 00 80 cmpwi cr2, 3, 0x80
|
|
32
|
+
1024: 7c 43 20 14 addc 2, 3, 4
|
|
33
|
+
1028: 7c 43 20 93 mulhd. 2, 3, 4
|
|
34
|
+
102c: 4f 20 00 21 bdnzlrl+
|
|
35
|
+
1030: 4c c8 00 21 bgelrl- cr2
|
|
36
|
+
1034: 40 82 00 14 bne 0x1044
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# These tests are fetched from Capstone's test_sparc.c
|
|
2
|
+
|
|
3
|
+
# !skip asm # because of keystone-engine/keystone#405
|
|
4
|
+
1000: 80 a0 40 02 cmp %g1, %g2
|
|
5
|
+
1004: 85 c2 60 08 jmpl %o1+8, %g2
|
|
6
|
+
1008: 85 e8 20 01 restore %g0, 1, %g2
|
|
7
|
+
100c: 81 e8 00 00 restore
|
|
8
|
+
1010: 90 10 20 01 mov 1, %o0
|
|
9
|
+
1014: d5 f6 10 16 casx [%i0], %l6, %o2
|
|
10
|
+
1018: 21 00 00 0a sethi 0xa, %l0
|
|
11
|
+
101c: 86 00 40 02 add %g1, %g2, %g3
|
|
12
|
+
1020: 01 00 00 00 nop
|
|
13
|
+
1024: 12 bf ff ff bne 0x1020
|
|
14
|
+
1028: 10 bf ff ff ba 0x1024
|
|
15
|
+
102c: a0 02 00 09 add %o0, %o1, %l0
|
|
16
|
+
1030: 0d bf ff ff fbg 0x102c
|
|
17
|
+
1034: d4 20 40 00 st %o2, [%g1]
|
|
18
|
+
1038: d4 4e 00 16 ldsb [%i0+%l6], %o2
|
|
19
|
+
# The output between objdump/llvm/capstone is inconsistent
|
|
20
|
+
; 103c: 2a c2 80 03 brnz,a,pn %o2, 0x1048
|
|
21
|
+
|
|
22
|
+
# Copied from above, ignored branch instructions
|
|
23
|
+
1000: 80 a0 40 02 cmp %g1, %g2
|
|
24
|
+
1004: 85 e8 20 01 restore %g0, 1, %g2
|
|
25
|
+
1008: 81 e8 00 00 restore
|
|
26
|
+
100c: 90 10 20 01 mov 1, %o0
|
|
27
|
+
1010: d5 f6 10 16 casx [%i0], %l6, %o2
|
|
28
|
+
1014: 21 00 00 0a sethi 0xa, %l0
|
|
29
|
+
1018: 86 00 40 02 add %g1, %g2, %g3
|
|
30
|
+
101c: 01 00 00 00 nop
|
|
31
|
+
1020: a0 02 00 09 add %o0, %o1, %l0
|
|
32
|
+
1024: d4 20 40 00 st %o2, [%g1]
|
|
33
|
+
1028: d4 4e 00 16 ldsb [%i0+%l6], %o2
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# These tests are fetched from Capstone's test_arm.c
|
|
2
|
+
# Thumb
|
|
3
|
+
# PC-relative instructions are buggy in Capstone3, two lines are commented.
|
|
4
|
+
80001000: 60 f9 1f 04 vld3.8 {d16, d17, d18}, [r0:0x40]
|
|
5
|
+
80001004: e0 f9 4f 07 vld4.16 {d16[1], d17[1], d18[1], d19[1]}, [r0]
|
|
6
|
+
80001008: 70 47 bx lr
|
|
7
|
+
; 8000100a: 00 f0 10 e8 blx #0x8000102c
|
|
8
|
+
8000100a: eb 46 mov fp, sp
|
|
9
|
+
8000100c: 83 b0 sub sp, #0xc
|
|
10
|
+
8000100e: c9 68 ldr r1, [r1, #0xc]
|
|
11
|
+
; 80001010: 1f b1 cbz r7, #0x8000101e
|
|
12
|
+
80001010: 30 bf wfi
|
|
13
|
+
80001012: af f3 20 84 cpsie.w f
|
|
14
|
+
80001016: 52 f8 23 f0 ldr.w pc, [r2, r3, lsl #2]
|
|
15
|
+
|
|
16
|
+
# Thumb-mixed
|
|
17
|
+
80001000: d1 e8 00 f0 tbb [r1, r0]
|
|
18
|
+
80001004: f0 24 movs r4, #0xf0
|
|
19
|
+
80001006: 04 07 lsls r4, r0, #0x1c
|
|
20
|
+
80001008: 1f 3c subs r4, #0x1f
|
|
21
|
+
8000100a: f2 c0 stm r0!, {r1, r4, r5, r6, r7}
|
|
22
|
+
8000100c: 00 00 movs r0, r0
|
|
23
|
+
8000100e: 4f f0 00 01 mov.w r1, #0
|
|
24
|
+
80001012: 46 6c ldr r6, [r0, #0x44]
|
|
25
|
+
|
|
26
|
+
# Thumb-2 & register named with numbers
|
|
27
|
+
# An `iteet` instruction is removed to make the `it` instruction valid
|
|
28
|
+
80001000: 4f f0 00 01 mov.w r1, #0
|
|
29
|
+
80001004: bd e8 00 88 pop.w {fp, pc}
|
|
30
|
+
80001008: d1 e8 00 f0 tbb [r1, r0]
|
|
31
|
+
8000100c: 18 bf it ne
|
|
32
|
+
; 8000100e: ad bf iteet ge
|
|
33
|
+
8000100e: f3 ff 0b 0c vdupne.8 d16, d11[1]
|
|
34
|
+
80001012: 86 f3 00 89 msr cpsr_fc, r6
|
|
35
|
+
80001016: 80 f3 00 8c msr apsr_nzcvqg, r0
|
|
36
|
+
8000101a: 4f fa 99 f6 sxtb.w r6, sb, ror #8
|
|
37
|
+
8000101e: d0 ff a2 01 vaddw.u16 q8, q8, d18
|
data/test/data/echo.rb
CHANGED
data/test/dynelf_test.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# encoding: ASCII-8BIT
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require 'open3'
|
|
4
5
|
|
|
@@ -16,7 +17,7 @@ class DynELFTest < MiniTest::Test
|
|
|
16
17
|
include ::Pwnlib::ELF
|
|
17
18
|
|
|
18
19
|
def setup
|
|
19
|
-
|
|
20
|
+
linux_only
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
# popen victim with specific libc.so.6
|
|
@@ -49,6 +50,7 @@ class DynELFTest < MiniTest::Test
|
|
|
49
50
|
IO.readlines("/proc/#{options[:pid]}/maps").map(&:split).each do |s|
|
|
50
51
|
st, ed = s[0].split('-').map { |x| x.to_i(16) }
|
|
51
52
|
next unless main_ra.between?(st, ed)
|
|
53
|
+
|
|
52
54
|
realbase = st
|
|
53
55
|
break
|
|
54
56
|
end
|
data/test/elf/elf_test.rb
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
# encoding: ASCII-8BIT
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require 'test_helper'
|
|
4
5
|
|
|
6
|
+
require 'pwnlib/context'
|
|
5
7
|
require 'pwnlib/elf/elf'
|
|
6
8
|
require 'pwnlib/logger'
|
|
7
9
|
|
|
8
10
|
class ELFTest < MiniTest::Test
|
|
11
|
+
include ::Pwnlib::Context
|
|
12
|
+
|
|
9
13
|
def setup
|
|
10
14
|
@path_of = ->(file) { File.join(__dir__, '..', 'data', 'elfs', file) }
|
|
11
15
|
@elf = to_elf_silent('i386.prelro.elf')
|
|
@@ -126,4 +130,18 @@ PIE: No PIE (0x400000)
|
|
|
126
130
|
assert_equal([0x1234001, 0x1392613], elf.search('ELF').to_a)
|
|
127
131
|
assert_equal(0x138d00b, elf.find('/bin/sh').next)
|
|
128
132
|
end
|
|
133
|
+
|
|
134
|
+
def test_one_gadgets
|
|
135
|
+
libc = ::Pwnlib::ELF::ELF.new(File.join(__dir__, '..', 'data', 'lib64', 'libc.so.6'), checksec: false)
|
|
136
|
+
# Well.. one_gadget(s) may change in the future, so we just check the return type
|
|
137
|
+
val = libc.one_gadgets.first
|
|
138
|
+
assert(val.is_a?(Integer))
|
|
139
|
+
assert_equal(libc.one_gadgets[0], val)
|
|
140
|
+
assert_equal(libc.one_gadgets[-1], libc.one_gadgets.last)
|
|
141
|
+
|
|
142
|
+
libc.address = 0xdeadf000
|
|
143
|
+
assert_equal(0xdeadf000 + val, libc.one_gadgets[0])
|
|
144
|
+
|
|
145
|
+
assert_output(/execve/) { log_stdout { context.local(log_level: :debug) { libc.one_gadgets[0] } } }
|
|
146
|
+
end
|
|
129
147
|
end
|
data/test/ext_test.rb
CHANGED
data/test/files/use_pwn.rb
CHANGED
data/test/files/use_pwnlib.rb
CHANGED
data/test/full_file_test.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# encoding: ASCII-8BIT
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require 'open3'
|
|
4
5
|
|
|
@@ -13,4 +14,9 @@ class FullFileTest < MiniTest::Test
|
|
|
13
14
|
assert(status.success?, stderr)
|
|
14
15
|
end
|
|
15
16
|
end
|
|
17
|
+
|
|
18
|
+
def test_ruby_cli
|
|
19
|
+
_, stderr, status = Open3.capture3('ruby', '-e', 'require "pwn"', binmode: true)
|
|
20
|
+
assert(status.success?, stderr)
|
|
21
|
+
end
|
|
16
22
|
end
|
data/test/logger_test.rb
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
# encoding: ASCII-8BIT
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'open3'
|
|
5
|
+
require 'tempfile'
|
|
2
6
|
|
|
3
7
|
require 'test_helper'
|
|
4
8
|
|
|
@@ -12,15 +16,15 @@ class LoggerTest < MiniTest::Test
|
|
|
12
16
|
def setup
|
|
13
17
|
@logger = ::Pwnlib::Logger::LoggerType.new
|
|
14
18
|
class << @logger
|
|
15
|
-
def add(*
|
|
19
|
+
def add(*)
|
|
16
20
|
clear
|
|
17
21
|
super
|
|
18
22
|
@logdev.string
|
|
19
23
|
end
|
|
20
24
|
|
|
21
|
-
def indented(
|
|
25
|
+
def indented(*, **)
|
|
22
26
|
clear
|
|
23
|
-
super
|
|
27
|
+
super
|
|
24
28
|
@logdev.string
|
|
25
29
|
end
|
|
26
30
|
|
|
@@ -95,5 +99,22 @@ class LoggerTest < MiniTest::Test
|
|
|
95
99
|
libc.to_s
|
|
96
100
|
libc.to_s(16) = "bc614e000"
|
|
97
101
|
EOS
|
|
102
|
+
|
|
103
|
+
lib_path = File.expand_path(File.join(__dir__, '..', 'lib'))
|
|
104
|
+
f = Tempfile.new(['dump', '.rb'])
|
|
105
|
+
begin
|
|
106
|
+
f.write <<~EOS
|
|
107
|
+
$LOAD_PATH.unshift #{lib_path.inspect}
|
|
108
|
+
require 'pwn'
|
|
109
|
+
FileUtils.remove(__FILE__)
|
|
110
|
+
log.dump 1337
|
|
111
|
+
EOS
|
|
112
|
+
f.close
|
|
113
|
+
_, stderr, status = Open3.capture3('ruby', f.path, binmode: true)
|
|
114
|
+
assert(status.success?, stderr)
|
|
115
|
+
ensure
|
|
116
|
+
f.close
|
|
117
|
+
f.unlink
|
|
118
|
+
end
|
|
98
119
|
end
|
|
99
120
|
end
|
data/test/memleak_test.rb
CHANGED
data/test/reg_sort_test.rb
CHANGED
data/test/runner_test.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# encoding: ASCII-8BIT
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'test_helper'
|
|
5
|
+
|
|
6
|
+
require 'pwnlib/runner'
|
|
7
|
+
require 'pwnlib/shellcraft/shellcraft'
|
|
8
|
+
|
|
9
|
+
class RunnerTest < MiniTest::Test
|
|
10
|
+
include ::Pwnlib::Context
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
linux_only 'Runner can only be used on Linux'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def shellcraft
|
|
17
|
+
::Pwnlib::Shellcraft::Shellcraft.instance
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_i386_run_assembly
|
|
21
|
+
context.local(arch: 'i386') do
|
|
22
|
+
r = ::Pwnlib::Runner.run_assembly(
|
|
23
|
+
shellcraft.pushstr('run_assembly') +
|
|
24
|
+
shellcraft.syscall('SYS_write', 1, 'esp', 12) +
|
|
25
|
+
shellcraft.exit(0)
|
|
26
|
+
)
|
|
27
|
+
assert_equal('run_assembly', r.recvn(12))
|
|
28
|
+
# Test if reach EOF
|
|
29
|
+
assert_raises(::Pwnlib::Errors::EndOfTubeError) { r.recv }
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|