pwntools 1.0.1 → 1.1.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.
Files changed (60) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +4 -3
  3. data/Rakefile +3 -1
  4. data/lib/pwnlib/asm.rb +172 -2
  5. data/lib/pwnlib/constants/constants.rb +10 -3
  6. data/lib/pwnlib/context.rb +1 -3
  7. data/lib/pwnlib/elf/elf.rb +3 -3
  8. data/lib/pwnlib/errors.rb +30 -0
  9. data/lib/pwnlib/ext/helper.rb +1 -1
  10. data/lib/pwnlib/logger.rb +140 -2
  11. data/lib/pwnlib/pwn.rb +3 -0
  12. data/lib/pwnlib/reg_sort.rb +1 -1
  13. data/lib/pwnlib/shellcraft/generators/amd64/common/infloop.rb +9 -3
  14. data/lib/pwnlib/shellcraft/generators/amd64/common/pushstr_array.rb +6 -2
  15. data/lib/pwnlib/shellcraft/generators/amd64/common/setregs.rb +6 -2
  16. data/lib/pwnlib/shellcraft/generators/amd64/linux/cat.rb +23 -0
  17. data/lib/pwnlib/shellcraft/generators/amd64/linux/execve.rb +6 -4
  18. data/lib/pwnlib/shellcraft/generators/amd64/linux/exit.rb +23 -0
  19. data/lib/pwnlib/shellcraft/generators/amd64/linux/ls.rb +6 -2
  20. data/lib/pwnlib/shellcraft/generators/amd64/linux/open.rb +23 -0
  21. data/lib/pwnlib/shellcraft/generators/amd64/linux/sh.rb +6 -2
  22. data/lib/pwnlib/shellcraft/generators/amd64/linux/syscall.rb +6 -4
  23. data/lib/pwnlib/shellcraft/generators/i386/common/infloop.rb +9 -3
  24. data/lib/pwnlib/shellcraft/generators/i386/common/pushstr_array.rb +6 -2
  25. data/lib/pwnlib/shellcraft/generators/i386/common/setregs.rb +6 -2
  26. data/lib/pwnlib/shellcraft/generators/i386/linux/cat.rb +23 -0
  27. data/lib/pwnlib/shellcraft/generators/i386/linux/execve.rb +8 -4
  28. data/lib/pwnlib/shellcraft/generators/i386/linux/exit.rb +23 -0
  29. data/lib/pwnlib/shellcraft/generators/i386/linux/ls.rb +6 -2
  30. data/lib/pwnlib/shellcraft/generators/i386/linux/open.rb +23 -0
  31. data/lib/pwnlib/shellcraft/generators/i386/linux/sh.rb +6 -2
  32. data/lib/pwnlib/shellcraft/generators/i386/linux/syscall.rb +8 -4
  33. data/lib/pwnlib/shellcraft/generators/x86/linux/cat.rb +53 -0
  34. data/lib/pwnlib/shellcraft/generators/x86/linux/exit.rb +33 -0
  35. data/lib/pwnlib/shellcraft/generators/x86/linux/open.rb +46 -0
  36. data/lib/pwnlib/shellcraft/shellcraft.rb +3 -2
  37. data/lib/pwnlib/timer.rb +5 -2
  38. data/lib/pwnlib/tubes/process.rb +153 -0
  39. data/lib/pwnlib/tubes/serialtube.rb +112 -0
  40. data/lib/pwnlib/tubes/sock.rb +24 -25
  41. data/lib/pwnlib/tubes/tube.rb +191 -39
  42. data/lib/pwnlib/util/packing.rb +3 -9
  43. data/lib/pwnlib/version.rb +1 -1
  44. data/test/asm_test.rb +85 -2
  45. data/test/constants/constants_test.rb +2 -2
  46. data/test/data/echo.rb +2 -7
  47. data/test/elf/elf_test.rb +10 -15
  48. data/test/files/use_pwn.rb +2 -6
  49. data/test/logger_test.rb +38 -0
  50. data/test/shellcraft/linux/cat_test.rb +86 -0
  51. data/test/shellcraft/linux/syscalls/exit_test.rb +56 -0
  52. data/test/shellcraft/linux/syscalls/open_test.rb +86 -0
  53. data/test/shellcraft/shellcraft_test.rb +5 -4
  54. data/test/test_helper.rb +22 -2
  55. data/test/timer_test.rb +19 -1
  56. data/test/tubes/process_test.rb +99 -0
  57. data/test/tubes/serialtube_test.rb +165 -0
  58. data/test/tubes/sock_test.rb +20 -21
  59. data/test/tubes/tube_test.rb +86 -16
  60. metadata +75 -13
@@ -8,9 +8,12 @@ require 'pwnlib/constants/constants'
8
8
  require 'pwnlib/context'
9
9
  require 'pwnlib/dynelf'
10
10
  require 'pwnlib/elf/elf'
11
+ require 'pwnlib/errors'
11
12
  require 'pwnlib/logger'
12
13
  require 'pwnlib/reg_sort'
13
14
  require 'pwnlib/shellcraft/shellcraft'
15
+ require 'pwnlib/tubes/process'
16
+ require 'pwnlib/tubes/serialtube'
14
17
  require 'pwnlib/tubes/sock'
15
18
 
16
19
  require 'pwnlib/util/cyclic'
@@ -70,7 +70,7 @@ module Pwnlib
70
70
  first_reg, val = list.shift
71
71
  # Special case for val.zero? because zeroify registers is cheaper than mov.
72
72
  next if list.empty? || all_regs.include?(val) || val.zero?
73
- list.each do |reg, _|
73
+ list.each do |(reg, _)|
74
74
  hash[reg] = first_reg
75
75
  in_out.delete(reg)
76
76
  end
@@ -1,3 +1,5 @@
1
+ # encoding: ASCII-8BIT
2
+
1
3
  require 'pwnlib/shellcraft/generators/amd64/common/common'
2
4
  require 'pwnlib/shellcraft/generators/x86/common/infloop'
3
5
 
@@ -6,9 +8,13 @@ module Pwnlib
6
8
  module Generators
7
9
  module Amd64
8
10
  module Common
9
- # See {X86::Common#infloop}.
10
- def infloop
11
- cat Generators::X86::Common.infloop
11
+ # @overload infloop
12
+ #
13
+ # @see Generators::X86::Common#infloop
14
+ def infloop(*args)
15
+ context.local(arch: :amd64) do
16
+ cat X86::Common.infloop(*args)
17
+ end
12
18
  end
13
19
  end
14
20
  end
@@ -1,3 +1,5 @@
1
+ # encoding: ASCII-8BIT
2
+
1
3
  require 'pwnlib/shellcraft/generators/amd64/common/common'
2
4
  require 'pwnlib/shellcraft/generators/x86/common/pushstr_array'
3
5
 
@@ -6,9 +8,11 @@ module Pwnlib
6
8
  module Generators
7
9
  module Amd64
8
10
  module Common
9
- # See {Pwnlib::Shellcraft::Generators::X86::Common#pushstr_array}.
11
+ # @overload pushstr_array(reg, array)
12
+ #
13
+ # @see Generators::X86::Common#pushstr_array
10
14
  def pushstr_array(*args)
11
- context.local(arch: 'amd64') do
15
+ context.local(arch: :amd64) do
12
16
  cat X86::Common.pushstr_array(*args)
13
17
  end
14
18
  end
@@ -1,3 +1,5 @@
1
+ # encoding: ASCII-8BIT
2
+
1
3
  require 'pwnlib/shellcraft/generators/amd64/common/common'
2
4
  require 'pwnlib/shellcraft/generators/x86/common/setregs'
3
5
 
@@ -6,9 +8,11 @@ module Pwnlib
6
8
  module Generators
7
9
  module Amd64
8
10
  module Common
9
- # See {Generators::X86::Common#setregs}.
11
+ # @overload setregs(reg_context, stack_allowed: true)
12
+ #
13
+ # @see Generators::X86::Common#setregs
10
14
  def setregs(*args)
11
- context.local(arch: 'amd64') do
15
+ context.local(arch: :amd64) do
12
16
  cat X86::Common.setregs(*args)
13
17
  end
14
18
  end
@@ -0,0 +1,23 @@
1
+ # encoding: ASCII-8BIT
2
+
3
+ require 'pwnlib/shellcraft/generators/amd64/linux/linux'
4
+ require 'pwnlib/shellcraft/generators/x86/linux/cat'
5
+
6
+ module Pwnlib
7
+ module Shellcraft
8
+ module Generators
9
+ module Amd64
10
+ module Linux
11
+ # @overload cat(filename, fd: 1)
12
+ #
13
+ # @see Generators::X86::Linux#cat
14
+ def cat(*args)
15
+ context.local(arch: :amd64) do
16
+ cat X86::Linux.cat(*args)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -8,10 +8,12 @@ module Pwnlib
8
8
  module Generators
9
9
  module Amd64
10
10
  module Linux
11
- # See {Generators::X86::Linux#execve}.
12
- def execve(*arguments)
13
- context.local(arch: 'amd64') do
14
- cat X86::Linux.execve(*arguments)
11
+ # @overload execve(path, argv, envp)
12
+ #
13
+ # @see Generators::X86::Linux#execve
14
+ def execve(*args)
15
+ context.local(arch: :amd64) do
16
+ cat X86::Linux.execve(*args)
15
17
  end
16
18
  end
17
19
  end
@@ -0,0 +1,23 @@
1
+ # encoding: ASCII-8BIT
2
+
3
+ require 'pwnlib/shellcraft/generators/amd64/linux/linux'
4
+ require 'pwnlib/shellcraft/generators/x86/linux/exit'
5
+
6
+ module Pwnlib
7
+ module Shellcraft
8
+ module Generators
9
+ module Amd64
10
+ module Linux
11
+ # @overload exit(status = 0)
12
+ #
13
+ # @see Generators::X86::Linux#exit
14
+ def exit(*args)
15
+ context.local(arch: :amd64) do
16
+ cat X86::Linux.exit(*args)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: ASCII-8BIT
2
+
1
3
  require 'pwnlib/shellcraft/generators/amd64/linux/linux'
2
4
  require 'pwnlib/shellcraft/generators/x86/linux/ls'
3
5
 
@@ -6,9 +8,11 @@ module Pwnlib
6
8
  module Generators
7
9
  module Amd64
8
10
  module Linux
9
- # See #{Generators::X86::Linux#ls}.
11
+ # @overload ls(dir = '.')
12
+ #
13
+ # @see Generators::X86::Linux#ls
10
14
  def ls(*args)
11
- context.local(arch: 'amd64') do
15
+ context.local(arch: :amd64) do
12
16
  cat X86::Linux.ls(*args)
13
17
  end
14
18
  end
@@ -0,0 +1,23 @@
1
+ # encoding: ASCII-8BIT
2
+
3
+ require 'pwnlib/shellcraft/generators/amd64/linux/linux'
4
+ require 'pwnlib/shellcraft/generators/x86/linux/open'
5
+
6
+ module Pwnlib
7
+ module Shellcraft
8
+ module Generators
9
+ module Amd64
10
+ module Linux
11
+ # @overload open(filename, flags = 'O_RDONLY', mode = 0)
12
+ #
13
+ # @see Generators::X86::Linux#open
14
+ def open(*args)
15
+ context.local(arch: :amd64) do
16
+ cat X86::Linux.open(*args)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: ASCII-8BIT
2
+
1
3
  require 'pwnlib/shellcraft/generators/amd64/linux/linux'
2
4
  require 'pwnlib/shellcraft/generators/x86/linux/sh'
3
5
 
@@ -6,9 +8,11 @@ module Pwnlib
6
8
  module Generators
7
9
  module Amd64
8
10
  module Linux
9
- # See #{Generators::X86::Linux#sh}.
11
+ # @overload sh(argv: false)
12
+ #
13
+ # @see Generators::X86::Linux#sh
10
14
  def sh(*args)
11
- context.local(arch: 'amd64') do
15
+ context.local(arch: :amd64) do
12
16
  cat X86::Linux.sh(*args)
13
17
  end
14
18
  end
@@ -8,10 +8,12 @@ module Pwnlib
8
8
  module Generators
9
9
  module Amd64
10
10
  module Linux
11
- # See {Generators::X86::Linux#syscall}.
12
- def syscall(*arguments)
13
- context.local(arch: 'amd64') do
14
- cat X86::Linux.syscall(*arguments)
11
+ # @overload syscall(*arguments)
12
+ #
13
+ # @see Generators::X86::Linux#syscall
14
+ def syscall(*args)
15
+ context.local(arch: :amd64) do
16
+ cat X86::Linux.syscall(*args)
15
17
  end
16
18
  end
17
19
  end
@@ -1,3 +1,5 @@
1
+ # encoding: ASCII-8BIT
2
+
1
3
  require 'pwnlib/shellcraft/generators/i386/common/common'
2
4
  require 'pwnlib/shellcraft/generators/x86/common/infloop'
3
5
 
@@ -6,9 +8,13 @@ module Pwnlib
6
8
  module Generators
7
9
  module I386
8
10
  module Common
9
- # See {X86::Common#infloop}.
10
- def infloop
11
- cat X86::Common.infloop
11
+ # @overload infloop
12
+ #
13
+ # @see Generators::X86::Common#infloop
14
+ def infloop(*args)
15
+ context.local(arch: :i386) do
16
+ cat X86::Common.infloop(*args)
17
+ end
12
18
  end
13
19
  end
14
20
  end
@@ -1,3 +1,5 @@
1
+ # encoding: ASCII-8BIT
2
+
1
3
  require 'pwnlib/shellcraft/generators/i386/common/common'
2
4
  require 'pwnlib/shellcraft/generators/x86/common/pushstr_array'
3
5
 
@@ -6,9 +8,11 @@ module Pwnlib
6
8
  module Generators
7
9
  module I386
8
10
  module Common
9
- # See {Pwnlib::Shellcraft::Generators::X86::Common#pushstr_array}.
11
+ # @overload pushstr_array(reg, array)
12
+ #
13
+ # @see Generators::X86::Common#pushstr_array
10
14
  def pushstr_array(*args)
11
- context.local(arch: 'i386') do
15
+ context.local(arch: :i386) do
12
16
  cat X86::Common.pushstr_array(*args)
13
17
  end
14
18
  end
@@ -1,3 +1,5 @@
1
+ # encoding: ASCII-8BIT
2
+
1
3
  require 'pwnlib/shellcraft/generators/i386/common/common'
2
4
  require 'pwnlib/shellcraft/generators/x86/common/setregs'
3
5
 
@@ -6,9 +8,11 @@ module Pwnlib
6
8
  module Generators
7
9
  module I386
8
10
  module Common
9
- # See {Generators::X86::Common#setregs}.
11
+ # @overload setregs(reg_context, stack_allowed: true)
12
+ #
13
+ # @see Generators::X86::Common#setregs
10
14
  def setregs(*args)
11
- context.local(arch: 'i386') do
15
+ context.local(arch: :i386) do
12
16
  cat X86::Common.setregs(*args)
13
17
  end
14
18
  end
@@ -0,0 +1,23 @@
1
+ # encoding: ASCII-8BIT
2
+
3
+ require 'pwnlib/shellcraft/generators/i386/linux/linux'
4
+ require 'pwnlib/shellcraft/generators/x86/linux/cat'
5
+
6
+ module Pwnlib
7
+ module Shellcraft
8
+ module Generators
9
+ module I386
10
+ module Linux
11
+ # @overload cat(filename, fd: 1)
12
+ #
13
+ # @see Generators::X86::Linux#cat
14
+ def cat(*args)
15
+ context.local(arch: :i386) do
16
+ cat X86::Linux.cat(*args)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: ASCII-8BIT
2
+
1
3
  require 'pwnlib/shellcraft/generators/i386/linux/linux'
2
4
  require 'pwnlib/shellcraft/generators/x86/linux/execve'
3
5
 
@@ -6,10 +8,12 @@ module Pwnlib
6
8
  module Generators
7
9
  module I386
8
10
  module Linux
9
- # See {Generators::X86::Linux#execve}.
10
- def execve(*arguments)
11
- context.local(arch: 'i386') do
12
- cat X86::Linux.execve(*arguments)
11
+ # @overload execve(path, argv, envp)
12
+ #
13
+ # @see Generators::X86::Linux#execve
14
+ def execve(*args)
15
+ context.local(arch: :i386) do
16
+ cat X86::Linux.execve(*args)
13
17
  end
14
18
  end
15
19
  end
@@ -0,0 +1,23 @@
1
+ # encoding: ASCII-8BIT
2
+
3
+ require 'pwnlib/shellcraft/generators/i386/linux/linux'
4
+ require 'pwnlib/shellcraft/generators/x86/linux/exit'
5
+
6
+ module Pwnlib
7
+ module Shellcraft
8
+ module Generators
9
+ module I386
10
+ module Linux
11
+ # @overload exit(status = 0)
12
+ #
13
+ # @see Generators::X86::Linux#exit
14
+ def exit(*args)
15
+ context.local(arch: :i386) do
16
+ cat X86::Linux.exit(*args)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: ASCII-8BIT
2
+
1
3
  require 'pwnlib/shellcraft/generators/i386/linux/linux'
2
4
  require 'pwnlib/shellcraft/generators/x86/linux/ls'
3
5
 
@@ -6,9 +8,11 @@ module Pwnlib
6
8
  module Generators
7
9
  module I386
8
10
  module Linux
9
- # See #{Generators::X86::Linux#ls}.
11
+ # @overload ls(dir = '.')
12
+ #
13
+ # @see Generators::X86::Linux#ls
10
14
  def ls(*args)
11
- context.local(arch: 'i386') do
15
+ context.local(arch: :i386) do
12
16
  cat X86::Linux.ls(*args)
13
17
  end
14
18
  end
@@ -0,0 +1,23 @@
1
+ # encoding: ASCII-8BIT
2
+
3
+ require 'pwnlib/shellcraft/generators/i386/linux/linux'
4
+ require 'pwnlib/shellcraft/generators/x86/linux/open'
5
+
6
+ module Pwnlib
7
+ module Shellcraft
8
+ module Generators
9
+ module I386
10
+ module Linux
11
+ # @overload open(filename, flags = 'O_RDONLY', mode = 0)
12
+ #
13
+ # @see Generators::X86::Linux#open
14
+ def open(*args)
15
+ context.local(arch: :i386) do
16
+ cat X86::Linux.open(*args)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: ASCII-8BIT
2
+
1
3
  require 'pwnlib/shellcraft/generators/i386/linux/linux'
2
4
  require 'pwnlib/shellcraft/generators/x86/linux/sh'
3
5
 
@@ -6,9 +8,11 @@ module Pwnlib
6
8
  module Generators
7
9
  module I386
8
10
  module Linux
9
- # See #{Generators::X86::Linux#sh}.
11
+ # @overload sh(argv: false)
12
+ #
13
+ # @see Generators::X86::Linux#sh
10
14
  def sh(*args)
11
- context.local(arch: 'i386') do
15
+ context.local(arch: :i386) do
12
16
  cat X86::Linux.sh(*args)
13
17
  end
14
18
  end
@@ -1,3 +1,5 @@
1
+ # encoding: ASCII-8BIT
2
+
1
3
  require 'pwnlib/shellcraft/generators/i386/linux/linux'
2
4
  require 'pwnlib/shellcraft/generators/x86/linux/syscall'
3
5
 
@@ -6,10 +8,12 @@ module Pwnlib
6
8
  module Generators
7
9
  module I386
8
10
  module Linux
9
- # See {Generators::X86::Linux#syscall}.
10
- def syscall(*arguments)
11
- context.local(arch: 'i386') do
12
- cat X86::Linux.syscall(*arguments)
11
+ # @overload syscall(*arguments)
12
+ #
13
+ # @see Generators::X86::Linux#syscall
14
+ def syscall(*args)
15
+ context.local(arch: :i386) do
16
+ cat X86::Linux.syscall(*args)
13
17
  end
14
18
  end
15
19
  end