one_gadget 1.3.0 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cc62d276055fdb8dc5a968da82d417248f07d4b
4
- data.tar.gz: 9b102faa2884dfb094e2c8b4a1df5f32fb7f5eaf
3
+ metadata.gz: ee18c2057ce192dccd5652685097b181099130ea
4
+ data.tar.gz: 289b4547cb6ce787d3f97198ea91d90cba29f2cf
5
5
  SHA512:
6
- metadata.gz: b86e5a6ad42af54af86358385aab99a43d3f04aeb5ce8303c68d0fcb15d3c06c3d916bb477cd067bb5fb504c0c4da1479f68aa56eea7742ff4996d0362c91c0b
7
- data.tar.gz: 8a55837472e55ff34c52c74521f7c8358720055ed0aa6f7912563d4c1ad169aba3c6305c2480e43e576adb0df887f3b6fbdf9edba186b83d567b97e2fb9f8f50
6
+ metadata.gz: 75beaaf9a5a2b7c46547086ddc1642d7145eaccc1de87ba6f8ccc142e3f567ff37657650ef40a5fc86f96380738133b19952ab0996ff08f435f4d9c09302e712
7
+ data.tar.gz: 436a67c199ba743df17989749a21b203e0761357b92e22eece757b4d8c920a625097db0817dbda2fddd2b6928b44142190e5a95ca05e6327b75e23e4041fd7eb
data/README.md CHANGED
@@ -58,6 +58,11 @@ one_gadget -b 60131540dadc6796cab33388349e6e4e68692053
58
58
  # rcx == NULL || [rcx] == NULL
59
59
  # r12 == NULL || [r12] == NULL
60
60
  #
61
+ # 0xcc618 execve("/bin/sh", rax, r12)
62
+ # constraints:
63
+ # rax == NULL || [rax] == NULL
64
+ # r12 == NULL || [r12] == NULL
65
+ #
61
66
  # 0xf5b10 execve("/bin/sh", rcx, [rbp-0xf8])
62
67
  # constraints:
63
68
  # [rbp-0xf8] == NULL || [[rbp-0xf8]] == NULL
@@ -95,7 +100,7 @@ one_gadget ./spec/data/libc-2.19.so -s 'echo "offset ->"'
95
100
  ```ruby
96
101
  require 'one_gadget'
97
102
  OneGadget.gadgets(file: '/lib/x86_64-linux-gnu/libc.so.6')
98
- # => [283242, 980676, 984423, 836931, 1006352]
103
+ # => [283242, 980676, 984423, 836931, 837144, 1006352]
99
104
  ```
100
105
 
101
106
  ## Screenshots
@@ -11,6 +11,9 @@ OneGadget::Gadget.add(build_id, 0xf0567, constraints: ['[rsp+0x70] == NULL'],
11
11
  OneGadget::Gadget.add(build_id, 0xcc543, constraints: ['rcx == NULL || [rcx] == NULL',
12
12
  'r12 == NULL || [r12] == NULL'],
13
13
  effect: 'execve("/bin/sh", rcx, r12)')
14
+ OneGadget::Gadget.add(build_id, 0xcc618, constraints: ['rax == NULL || [rax] == NULL',
15
+ 'r12 == NULL || [r12] == NULL'],
16
+ effect: 'execve("/bin/sh", rax, r12)')
14
17
  OneGadget::Gadget.add(build_id, 0xf5b10, constraints: ['[rbp-0xf8] == NULL || [[rbp-0xf8]] == NULL',
15
18
  'rcx == NULL || [rcx] == NULL'],
16
19
  effect: 'execve("/bin/sh", rcx, [rbp-0xf8])')
@@ -21,10 +21,11 @@ module OneGadget
21
21
  end
22
22
 
23
23
  # Process one command.
24
+ # Will raise exceptions when encounter unhandled instruction.
24
25
  # @param [String] cmd
25
26
  # One line from result of objdump.
26
27
  # @return [void]
27
- def process(cmd)
28
+ def process!(cmd)
28
29
  inst, args = parse(cmd)
29
30
  return registers[pc] = args[0] if inst.inst == 'call'
30
31
  return if inst.inst == 'jmp' # believe the fetcher has handled jmp.
@@ -32,6 +33,16 @@ module OneGadget
32
33
  send(sym, *args)
33
34
  end
34
35
 
36
+ # Process one command, without raising any exceptions.
37
+ # @param [String] cmd
38
+ # See {#process!} for more information.
39
+ # @return [void]
40
+ def process(cmd)
41
+ process!(cmd)
42
+ rescue ArgumentError
43
+ nil
44
+ end
45
+
35
46
  # Support instruction set.
36
47
  # @return [Array<Instruction>] The support instructions.
37
48
  def instructions
@@ -28,13 +28,16 @@ module OneGadget
28
28
  end
29
29
  # find gadgets in form:
30
30
  # lea rdi, '/bin/sh'
31
+ # ...
31
32
  # jmp xxx
32
33
  # xxx:
33
34
  # ...
34
35
  # call execve
35
- cands2 = `#{objdump_cmd}|egrep 'rdi.*# #{bin_sh_hex}' -A 1`.split('--').map do |cand|
36
+ cands2 = `#{objdump_cmd}|egrep 'rdi.*# #{bin_sh_hex}' -A 3`.split('--').map do |cand|
36
37
  cand = cand.lines.map(&:strip).reject(&:empty?)
37
- next nil unless cand.last.include?('jmp')
38
+ jmp_at = cand.index { |c| c.include?('jmp') }
39
+ next nil if jmp_at.nil?
40
+ cand = cand[0..jmp_at]
38
41
  jmp_addr = cand.last.scan(/jmp\s+([\da-f]+)\s/)[0][0].to_i(16)
39
42
  dump = `#{objdump_cmd(start: jmp_addr, stop: jmp_addr + 100)}|egrep '[0-9a-f]+:'`
40
43
  remain = dump.lines.map(&:strip).reject(&:empty?)
@@ -45,6 +48,8 @@ module OneGadget
45
48
  end
46
49
 
47
50
  def resolve(processor)
51
+ # must end with execve
52
+ return unless processor.registers['rip'].to_s.include?('execve')
48
53
  # check rdi should always related to rip
49
54
  return unless processor.registers['rdi'].to_s.include?('rip')
50
55
  # rsi or [rsi] should be zero
@@ -1,3 +1,3 @@
1
1
  module OneGadget
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '1.3.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: one_gadget
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - david942j
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-20 00:00:00.000000000 Z
11
+ date: 2017-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec