pwntools 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'benchmark'
|
5
|
+
|
6
|
+
require 'test_helper'
|
7
|
+
|
8
|
+
require 'pwnlib/context'
|
9
|
+
require 'pwnlib/runner'
|
10
|
+
require 'pwnlib/shellcraft/shellcraft'
|
11
|
+
|
12
|
+
class SleepTest < MiniTest::Test
|
13
|
+
include ::Pwnlib::Context
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@shellcraft = ::Pwnlib::Shellcraft::Shellcraft.instance
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_amd64
|
20
|
+
context.local(arch: :amd64) do
|
21
|
+
assert_equal(<<-'EOS', @shellcraft.sleep(10))
|
22
|
+
/* push "\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" */
|
23
|
+
push 1
|
24
|
+
dec byte ptr [rsp]
|
25
|
+
push 0xb
|
26
|
+
dec byte ptr [rsp]
|
27
|
+
/* call nanosleep("rsp", 0) */
|
28
|
+
push 0x23 /* (SYS_nanosleep) */
|
29
|
+
pop rax
|
30
|
+
mov rdi, rsp
|
31
|
+
xor esi, esi /* 0 */
|
32
|
+
syscall
|
33
|
+
add rsp, 16 /* recover rsp */
|
34
|
+
EOS
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_i386
|
39
|
+
context.local(arch: :i386) do
|
40
|
+
assert_equal(<<-'EOS', @shellcraft.sleep(1 + 3e-9))
|
41
|
+
/* push "\x01\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00" */
|
42
|
+
push 1
|
43
|
+
dec byte ptr [esp]
|
44
|
+
push 3
|
45
|
+
push 1
|
46
|
+
dec byte ptr [esp]
|
47
|
+
push 1
|
48
|
+
/* call nanosleep("esp", 0) */
|
49
|
+
xor eax, eax
|
50
|
+
mov al, 0xa2 /* (SYS_nanosleep) */
|
51
|
+
mov ebx, esp
|
52
|
+
xor ecx, ecx /* 0 */
|
53
|
+
int 0x80
|
54
|
+
add esp, 16 /* recover esp */
|
55
|
+
EOS
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_run
|
60
|
+
linux_only
|
61
|
+
|
62
|
+
context.local(arch: :amd64) do
|
63
|
+
asm = @shellcraft.sleep(0.3) + @shellcraft.exit(0)
|
64
|
+
t = Benchmark.realtime { ::Pwnlib::Runner.run_assembly(asm).recvall }
|
65
|
+
assert_operator t, :>=, 0.3
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: ASCII-8BIT
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'test_helper'
|
4
5
|
|
@@ -22,12 +23,26 @@ class MemcpyTest < MiniTest::Test
|
|
22
23
|
mov cl, 0xff
|
23
24
|
rep movsb
|
24
25
|
EOS
|
25
|
-
assert_equal(<<-'EOS', @shellcraft.memcpy('rdi',
|
26
|
-
/* memcpy("rdi",
|
26
|
+
assert_equal(<<-'EOS', @shellcraft.memcpy('rdi', 0x602020, 10))
|
27
|
+
/* memcpy("rdi", 0x602020, 0xa) */
|
27
28
|
cld
|
28
|
-
mov
|
29
|
-
xor
|
30
|
-
mov
|
29
|
+
mov esi, 0x1010101
|
30
|
+
xor esi, 0x1612121 /* 0x602020 == 0x1010101 ^ 0x1612121 */
|
31
|
+
push 9 /* mov ecx, '\n' */
|
32
|
+
pop rcx
|
33
|
+
inc ecx
|
34
|
+
rep movsb
|
35
|
+
EOS
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_i386
|
40
|
+
context.local(arch: :i386) do
|
41
|
+
assert_equal(<<-'EOS', @shellcraft.memcpy('eax', 'ebx', 'ecx'))
|
42
|
+
/* memcpy("eax", "ebx", "ecx") */
|
43
|
+
cld
|
44
|
+
mov edi, eax
|
45
|
+
mov esi, ebx
|
31
46
|
rep movsb
|
32
47
|
EOS
|
33
48
|
end
|
data/test/shellcraft/mov_test.rb
CHANGED
data/test/shellcraft/nop_test.rb
CHANGED
data/test/shellcraft/ret_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: ASCII-8BIT
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'test_helper'
|
4
5
|
|
@@ -14,27 +15,27 @@ class SetregsTest < MiniTest::Test
|
|
14
15
|
|
15
16
|
def test_amd64
|
16
17
|
context.local(arch: 'amd64') do
|
17
|
-
assert_equal(<<-'EOS', @shellcraft.setregs(rax: 1, rbx: 'rax'))
|
18
|
+
assert_equal(<<-'EOS', @shellcraft.setregs({ rax: 1, rbx: 'rax' }))
|
18
19
|
mov rbx, rax
|
19
20
|
push 1
|
20
21
|
pop rax
|
21
22
|
EOS
|
22
|
-
assert_equal(<<-'EOS', @shellcraft.setregs(rax: 'SYS_write', rbx: 'rax'))
|
23
|
+
assert_equal(<<-'EOS', @shellcraft.setregs({ rax: 'SYS_write', rbx: 'rax' }))
|
23
24
|
mov rbx, rax
|
24
25
|
push 1 /* (SYS_write) */
|
25
26
|
pop rax
|
26
27
|
EOS
|
27
|
-
assert_equal(<<-'EOS', @shellcraft.setregs(rax: 'rbx', rbx: 'rax', rcx: 'rbx'))
|
28
|
+
assert_equal(<<-'EOS', @shellcraft.setregs({ rax: 'rbx', rbx: 'rax', rcx: 'rbx' }))
|
28
29
|
mov rcx, rbx
|
29
30
|
xchg rax, rbx
|
30
31
|
EOS
|
31
|
-
assert_equal(<<-'EOS', @shellcraft.setregs(rax: 1, rdx: 0))
|
32
|
+
assert_equal(<<-'EOS', @shellcraft.setregs({ rax: 1, rdx: 0 }))
|
32
33
|
push 1
|
33
34
|
pop rax
|
34
35
|
cdq /* rdx=0 */
|
35
36
|
EOS
|
36
37
|
# issue #50
|
37
|
-
assert_equal(<<-'EOS', @shellcraft.setregs(rdi: :rax, rsi: :rdi))
|
38
|
+
assert_equal(<<-'EOS', @shellcraft.setregs({ rdi: :rax, rsi: :rdi }))
|
38
39
|
mov rsi, rdi
|
39
40
|
mov rdi, rax
|
40
41
|
EOS
|
@@ -43,16 +44,16 @@ class SetregsTest < MiniTest::Test
|
|
43
44
|
|
44
45
|
def test_i386
|
45
46
|
context.local(arch: 'i386') do
|
46
|
-
assert_equal(<<-EOS, @shellcraft.setregs(eax: 1, ebx: 'eax'))
|
47
|
+
assert_equal(<<-EOS, @shellcraft.setregs({ eax: 1, ebx: 'eax' }))
|
47
48
|
mov ebx, eax
|
48
49
|
push 1
|
49
50
|
pop eax
|
50
51
|
EOS
|
51
|
-
assert_equal(<<-EOS, @shellcraft.setregs(eax: 'ebx', ebx: 'eax', ecx: 'ebx'))
|
52
|
+
assert_equal(<<-EOS, @shellcraft.setregs({ eax: 'ebx', ebx: 'eax', ecx: 'ebx' }))
|
52
53
|
mov ecx, ebx
|
53
54
|
xchg eax, ebx
|
54
55
|
EOS
|
55
|
-
assert_equal(<<-'EOS', @shellcraft.setregs(eax: 1, edx: 0))
|
56
|
+
assert_equal(<<-'EOS', @shellcraft.setregs({ eax: 1, edx: 0 }))
|
56
57
|
push 1
|
57
58
|
pop eax
|
58
59
|
cdq /* edx=0 */
|
data/test/test_helper.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rainbow'
|
2
4
|
require 'simplecov'
|
5
|
+
require 'tty/platform'
|
3
6
|
|
4
7
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
5
8
|
[SimpleCov::Formatter::HTMLFormatter]
|
@@ -20,6 +23,14 @@ module MiniTest
|
|
20
23
|
Rainbow.enabled = false
|
21
24
|
end
|
22
25
|
|
26
|
+
def linux_only(msg = 'Only tested on Linux')
|
27
|
+
skip msg unless TTY::Platform.new.linux?
|
28
|
+
end
|
29
|
+
|
30
|
+
def skip_windows(msg = 'Skip on Windows')
|
31
|
+
skip msg if TTY::Platform.new.windows?
|
32
|
+
end
|
33
|
+
|
23
34
|
# Methods for hooking logger,
|
24
35
|
# require 'pwnlib/logger' before using these methods.
|
25
36
|
|
@@ -40,5 +51,22 @@ module MiniTest
|
|
40
51
|
::Pwnlib::Logger.log.instance_variable_set(:@logdev, old)
|
41
52
|
end
|
42
53
|
end
|
54
|
+
|
55
|
+
# Hooks +$stdin+.
|
56
|
+
#
|
57
|
+
# @param [IO] io
|
58
|
+
# IO object to be used as +$stdin+.
|
59
|
+
#
|
60
|
+
# @return [Object]
|
61
|
+
# Returns what the block returned.
|
62
|
+
def hook_stdin(io)
|
63
|
+
org_stdin = $stdin
|
64
|
+
$stdin = io
|
65
|
+
begin
|
66
|
+
yield
|
67
|
+
ensure
|
68
|
+
$stdin = org_stdin
|
69
|
+
end
|
70
|
+
end
|
43
71
|
end
|
44
72
|
end
|
data/test/timer_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: ASCII-8BIT
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'test_helper'
|
4
5
|
|
@@ -34,7 +35,7 @@ class TimerTest < MiniTest::Test
|
|
34
35
|
def test_nested_countdown_false_positve_115
|
35
36
|
t = Timer.new
|
36
37
|
assert_raises(::Pwnlib::Errors::TimeoutError) do
|
37
|
-
t.countdown(0.01) { sleep(
|
38
|
+
t.countdown(0.01) { sleep(1) }
|
38
39
|
end
|
39
40
|
t.countdown(0.01) {}
|
40
41
|
end
|
data/test/tubes/buffer_test.rb
CHANGED
data/test/tubes/process_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: ASCII-8BIT
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'socket'
|
4
5
|
require 'tty-platform'
|
@@ -13,7 +14,7 @@ class ProcessTest < MiniTest::Test
|
|
13
14
|
include ::Pwnlib::Context
|
14
15
|
|
15
16
|
def setup
|
16
|
-
|
17
|
+
skip_windows
|
17
18
|
end
|
18
19
|
|
19
20
|
def test_io
|
@@ -33,7 +34,8 @@ class ProcessTest < MiniTest::Test
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def test_aslr
|
36
|
-
|
37
|
+
linux_only
|
38
|
+
|
37
39
|
map1 = ::Pwnlib::Tubes::Process.new('cat /proc/self/maps', aslr: false).read
|
38
40
|
map2 = ::Pwnlib::Tubes::Process.new(['cat', '/proc/self/maps'], aslr: false).read
|
39
41
|
assert_match('/bin/cat', map1) # make sure it read something
|
@@ -84,6 +86,10 @@ class ProcessTest < MiniTest::Test
|
|
84
86
|
# In cooked mode, tty should echo the input, so we can gets twice.
|
85
87
|
assert_equal("Hi\r\n", cat.gets)
|
86
88
|
assert_equal("Hi\r\n", cat.gets)
|
89
|
+
class << cat
|
90
|
+
# hook shutdown to silence the +cat: -: Input/output error+ message.
|
91
|
+
def shutdown; end
|
92
|
+
end
|
87
93
|
cat.close
|
88
94
|
end
|
89
95
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: ASCII-8BIT
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'open3'
|
4
5
|
|
@@ -19,10 +20,6 @@ end
|
|
19
20
|
class SerialTest < MiniTest::Test
|
20
21
|
include ::Pwnlib::Tubes
|
21
22
|
|
22
|
-
def skip_windows
|
23
|
-
skip 'Not test tube/serialtube on Windows' if TTY::Platform.new.windows?
|
24
|
-
end
|
25
|
-
|
26
23
|
def open_pair
|
27
24
|
Open3.popen3('socat -d -d pty,raw,echo=0 pty,raw,echo=0') do |_i, _o, stderr, thread|
|
28
25
|
devs = []
|
data/test/tubes/sock_test.rb
CHANGED
data/test/tubes/tube_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
# This test use UTF-8 encoding for strings since the output for hexdump contains lots of UTF-8 characters.
|
4
5
|
|
@@ -34,7 +35,7 @@ class TubeTest < MiniTest::Test
|
|
34
35
|
|
35
36
|
class << t
|
36
37
|
def buf
|
37
|
-
@buf ||= ''
|
38
|
+
@buf ||= +''
|
38
39
|
end
|
39
40
|
|
40
41
|
private
|
@@ -61,6 +62,7 @@ class TubeTest < MiniTest::Test
|
|
61
62
|
class << t
|
62
63
|
def recv_raw(_n)
|
63
64
|
raise ::Pwnlib::Errors::EndOfTubeError if io.eof?
|
65
|
+
|
64
66
|
io.read
|
65
67
|
end
|
66
68
|
|
@@ -195,6 +197,13 @@ class TubeTest < MiniTest::Test
|
|
195
197
|
5.times { assert_match(r, t.recvregex(r)) }
|
196
198
|
end
|
197
199
|
|
200
|
+
def test_recvall
|
201
|
+
t = basic_tube
|
202
|
+
t.unrecv('meow')
|
203
|
+
assert_equal('meow', t.recvall)
|
204
|
+
assert_equal('', t.recvall)
|
205
|
+
end
|
206
|
+
|
198
207
|
def test_send
|
199
208
|
t = hello_tube
|
200
209
|
assert_equal(6, t.write('DARKHH'))
|
data/test/ui_test.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
require 'test_helper'
|
7
|
+
|
8
|
+
require 'pwnlib/ui'
|
9
|
+
|
10
|
+
class UITest < MiniTest::Test
|
11
|
+
def test_pause
|
12
|
+
hook_stdin(StringIO.new("\n")) do
|
13
|
+
assert_output(<<-EOS) { log_stdout { ::Pwnlib::UI.pause } }
|
14
|
+
[INFO] Paused (press enter to continue)
|
15
|
+
EOS
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|