one_gadget 2.0.0 → 2.1.1

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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +215 -65
  3. data/README.md +96 -22
  4. data/lib/one_gadget/abi.rb +41 -5
  5. data/lib/one_gadget/builds/libc-2.31-93b46e0027747153e336c3fd9431ce9a5d82ad00.rb +563 -0
  6. data/lib/one_gadget/builds/libc-2.35-891c1403437a4e30e684e0c8e34b87a09e4298e5.rb +434 -0
  7. data/lib/one_gadget/builds/libc-2.39-a1d1cf4badf1f5dfe57ff1d17bd692ccc6fcd5c5.rb +531 -0
  8. data/lib/one_gadget/builds/libc-2.39-cd8f5a207dd67aea370d2b471a54c3e56f44ab18.rb +531 -0
  9. data/lib/one_gadget/builds/libc-2.43-b50ceafbd17dc6bceee344a66671c7eaa152bef4.rb +15 -0
  10. data/lib/one_gadget/emulators/aarch64.rb +5 -2
  11. data/lib/one_gadget/emulators/amd64.rb +1 -0
  12. data/lib/one_gadget/emulators/arm.rb +27 -18
  13. data/lib/one_gadget/emulators/arm_family.rb +35 -160
  14. data/lib/one_gadget/emulators/conditional.rb +28 -22
  15. data/lib/one_gadget/emulators/constraints.rb +269 -0
  16. data/lib/one_gadget/emulators/data_processing.rb +167 -0
  17. data/lib/one_gadget/emulators/i386.rb +4 -6
  18. data/lib/one_gadget/emulators/instruction.rb +24 -1
  19. data/lib/one_gadget/emulators/lambda.rb +6 -4
  20. data/lib/one_gadget/emulators/mips.rb +289 -0
  21. data/lib/one_gadget/emulators/processor.rb +33 -455
  22. data/lib/one_gadget/emulators/register_file.rb +19 -10
  23. data/lib/one_gadget/emulators/riscv64.rb +265 -0
  24. data/lib/one_gadget/emulators/safe_calls.rb +9 -3
  25. data/lib/one_gadget/emulators/tracked_memory.rb +209 -0
  26. data/lib/one_gadget/emulators/x86.rb +32 -22
  27. data/lib/one_gadget/fetchers/aarch64.rb +0 -27
  28. data/lib/one_gadget/fetchers/amd64.rb +0 -24
  29. data/lib/one_gadget/fetchers/argument_resolution.rb +340 -0
  30. data/lib/one_gadget/fetchers/arm.rb +99 -44
  31. data/lib/one_gadget/fetchers/base.rb +142 -640
  32. data/lib/one_gadget/fetchers/candidate_walk.rb +150 -0
  33. data/lib/one_gadget/fetchers/disassembly.rb +252 -0
  34. data/lib/one_gadget/fetchers/dynamic_symbols.rb +104 -0
  35. data/lib/one_gadget/fetchers/i386.rb +5 -8
  36. data/lib/one_gadget/fetchers/mips.rb +478 -0
  37. data/lib/one_gadget/fetchers/objdump.rb +25 -3
  38. data/lib/one_gadget/fetchers/riscv64.rb +78 -0
  39. data/lib/one_gadget/fetchers/x86.rb +19 -0
  40. data/lib/one_gadget/fetchers.rb +22 -6
  41. data/lib/one_gadget/gadget.rb +27 -37
  42. data/lib/one_gadget/helper.rb +19 -5
  43. data/lib/one_gadget/one_gadget.rb +6 -0
  44. data/lib/one_gadget/version.rb +1 -1
  45. data/lib/one_gadget.rb +1 -1
  46. metadata +18 -6
  47. data/lib/one_gadget/builds/libc-2.26-2104f3d4ad5cf68603afbe7ba1a17f5ac99c5988.rb +0 -227
  48. data/lib/one_gadget/builds/libc-2.26-ddcc13122ddbfe5e5ef77d4ebe66d124ae5762c2.rb +0 -300
  49. data/lib/one_gadget/builds/libc-2.26-f65648a832414f2144ce795d75b6045a1ec2e252.rb +0 -199
@@ -14,6 +14,17 @@ module OneGadget
14
14
  # Registers of AArch64.
15
15
  AARCH64 = %w[xzr wzr sp] + 0.upto(30).map { |i| ["x#{i}", "w#{i}"] }.flatten
16
16
 
17
+ # Registers of RISC-V (RV64), by the ABI names objdump prints: it emits neither
18
+ # the numbered +x0+-+x15+ names nor +fp+ for +s0+, so neither is listed.
19
+ RISCV64 = %w[zero ra sp gp tp] + 0.upto(6).map { |i| "t#{i}" } +
20
+ 0.upto(11).map { |i| "s#{i}" } + 0.upto(7).map { |i| "a#{i}" }
21
+
22
+ # Registers of MIPS (32-bit), by the names objdump prints: it emits the ABI
23
+ # names rather than the numbered +$0+-+$31+, and +fp+ rather than +s8+.
24
+ MIPS = %w[zero at v0 v1 gp sp fp ra] +
25
+ 0.upto(3).map { |i| "a#{i}" } + 0.upto(9).map { |i| "t#{i}" } +
26
+ 0.upto(7).map { |i| "s#{i}" } + 0.upto(1).map { |i| "k#{i}" }
27
+
17
28
  # Registers of ARM (32-bit).
18
29
  # objdump never prints the numbered name of a register that has a role name:
19
30
  # +r10+-+r15+ always appear as +sl+/+fp+/+ip+/+sp+/+lr+/+pc+, so those are
@@ -31,7 +42,12 @@ module OneGadget
31
42
  8.upto(15).map { |i| ["r#{i}d", "r#{i}"] }).to_h,
32
43
  i386: {},
33
44
  aarch64: 0.upto(30).to_h { |i| ["w#{i}", "x#{i}"] }.merge('wzr' => 'xzr'),
34
- arm: {}
45
+ arm: {},
46
+ # RISC-V names no part of a register: its 32-bit operations are instructions
47
+ # of their own (+addiw+, +sext.w+), each writing the whole register.
48
+ riscv64: {},
49
+ # MIPS names no part of a register either.
50
+ mips: {}
35
51
  }.freeze
36
52
 
37
53
  # Registers a call may destroy, per each ABI's calling convention: the return
@@ -49,11 +65,19 @@ module OneGadget
49
65
  aarch64: (0.upto(7).to_a + 9.upto(18).to_a).map { |i| "x#{i}" },
50
66
  # AAPCS: r0-r3 arguments and return, ip (r12) the intra-procedure scratch,
51
67
  # and lr, which the call itself overwrites with the return address.
52
- arm: %w[r0 r1 r2 r3 ip lr]
68
+ arm: %w[r0 r1 r2 r3 ip lr],
69
+ # RISC-V LP64: a0-a7 arguments (a0/a1 also the return), t0-t6 temporaries,
70
+ # and ra, which the call itself overwrites with the return address.
71
+ riscv64: %w[ra] + 0.upto(7).map { |i| "a#{i}" } + 0.upto(6).map { |i| "t#{i}" },
72
+ # o32: v0/v1 the return, a0-a3 arguments, t0-t9 temporaries, at the
73
+ # assembler's scratch, and ra, which the call itself overwrites. gp goes
74
+ # with them: PIC code reloads it from the stack after every call, because
75
+ # the callee establishes its own.
76
+ mips: %w[at v0 v1 gp ra] + 0.upto(3).map { |i| "a#{i}" } + 0.upto(9).map { |i| "t#{i}" }
53
77
  }.freeze
54
78
 
55
79
  # The register each ABI leaves an integer return value in.
56
- RETURN_REGISTER = { amd64: 'rax', i386: 'eax', aarch64: 'x0', arm: 'r0' }.freeze
80
+ RETURN_REGISTER = { amd64: 'rax', i386: 'eax', aarch64: 'x0', arm: 'r0', riscv64: 'a0' }.freeze
57
81
 
58
82
  module_function
59
83
 
@@ -81,10 +105,22 @@ module OneGadget
81
105
  ARM
82
106
  end
83
107
 
108
+ # Registers' name of RISC-V (RV64).
109
+ # @return [Array<String>] List of registers.
110
+ def riscv64
111
+ RISCV64
112
+ end
113
+
114
+ # Registers' name of MIPS (32-bit).
115
+ # @return [Array<String>] List of registers.
116
+ def mips
117
+ MIPS
118
+ end
119
+
84
120
  # Returns all names of registers.
85
121
  # @return [Array<String>] List of registers.
86
122
  def all
87
- amd64 + aarch64 + arm
123
+ amd64 + aarch64 + arm + riscv64 + mips
88
124
  end
89
125
 
90
126
  # Checks if the register is a stack-related pointer.
@@ -92,7 +128,7 @@ module OneGadget
92
128
  # Register's name.
93
129
  # @return [Boolean] +true+ if +reg+ is a stack or frame pointer (e.g. +rsp+, +rbp+, +sp+).
94
130
  def stack_register?(reg)
95
- %w[esp ebp rsp rbp sp x29].include?(reg)
131
+ %w[esp ebp rsp rbp sp x29 s0].include?(reg)
96
132
  end
97
133
  end
98
134
  end