heapinfo 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e90a4db825f5e6b53989edc82441a0800d13aaa7
4
- data.tar.gz: f638662fb165a7c884c5427b378cfac091ebe83a
3
+ metadata.gz: 3afc942b75cd48a72f4d699b68423d2b6e23ff01
4
+ data.tar.gz: 69bbf96563700cdf3275b680229f65c6ba20e8e5
5
5
  SHA512:
6
- metadata.gz: f2356a124a5a9480e2e170f6abb2ee782f671734d4e7edbe2f15f47f690609a40580ac1d3d8f027342d03a82901c996b32d9dc21dccb4473105f027814149503
7
- data.tar.gz: 3e3df55aca650bf6c8277185afdf56bb3f9c4e3ded9ec444af64f6159302aa9eb5d001da0f3f7dac82d174348c5e8af5b4340abfa1a5cca6f205a7936fa640b0
6
+ metadata.gz: c3cceb98b2e06f7c02a6ce16c9d9322de0a554742a213aeb26e8e7dce945fb35f9e425cf2e316e9317128df0ef061317c57fbcf449842888c9a35886c6549783
7
+ data.tar.gz: b1285f36856258f0834707b54252cc2989050fc72f99a9ebead0fadc565ab10e0e090fe03bbd42bb1c3ebd6e52c293ea1ef49e237451dcc81f33d43d9f5f30ac
@@ -35,7 +35,10 @@ module HeapInfo
35
35
  return self if top_ptr == 0 # arena not init yet
36
36
  @top_chunk = Chunk.new size_t, top_ptr, @dumper
37
37
  @last_remainder = Chunk.new size_t, top_ptr_offset + 8, @dumper
38
- @system_mem = Helper.unpack(size_t, @dumper.call(top_ptr_offset + 258 * size_t + 16, size_t))
38
+ # this offset diff after 2.23
39
+ @system_mem = 2.times.map do |off|
40
+ Helper.unpack(size_t, @dumper.call(top_ptr_offset + 258 * size_t + 16 + off * size_t, size_t))
41
+ end.find { |val| val >= 0x21000 and (val & 0xfff) == 0 }
39
42
  @fastbin = Array.new(7) do |idx|
40
43
  f = Fastbin.new(size_t, @base + 8 - size_t * 2 + size_t * idx, @dumper, head: true)
41
44
  f.index = idx
@@ -1,3 +1,3 @@
1
1
  module HeapInfo
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.4'.freeze
3
3
  end
@@ -1,17 +1,31 @@
1
1
  # encoding: ascii-8bit
2
2
  require 'heapinfo'
3
3
  describe HeapInfo::Dumper do
4
+ before(:all) do
5
+ @self_maps = IO.binread('/proc/self/maps').lines.map do |seg|
6
+ s = seg.split(/\s/)
7
+ s[0] = s[0].split('-').map { |addr| addr.to_i(16) }
8
+ [s[0][0], s[0][1], s[1], s[-1]] # start, end, perm, name
9
+ end
10
+
11
+ @get_elf_base = ->() do
12
+ exe = File.readlink('/proc/self/exe')
13
+ @self_maps.find { |arr| arr[3] == exe }[0]
14
+ end
15
+ end
16
+
4
17
  describe 'dump' do
5
18
  before(:each) do
6
19
  @mem_filename = '/proc/self/mem'
20
+ @elf_base = @get_elf_base.call
7
21
  end
8
22
  it 'simple' do
9
23
  dumper = HeapInfo::Dumper.new(nil, @mem_filename)
10
- expect(dumper.dump(0x400000, 4)).to eq "\x7fELF"
24
+ expect(dumper.dump(@elf_base, 4)).to eq "\x7fELF"
11
25
  end
12
26
  it 'segment' do
13
- class S;def elf; HeapInfo::Segment.new(0x400000, 'elf'); end; end
14
- dumper = HeapInfo::Dumper.new(S.new, @mem_filename)
27
+ class S;def initialize(base);@base = base;end; def elf; HeapInfo::Segment.new(@base, 'elf'); end; end
28
+ dumper = HeapInfo::Dumper.new(S.new(@elf_base), @mem_filename)
15
29
  expect(dumper.dump(:elf, 4)).to eq "\x7fELF"
16
30
  end
17
31
  it 'invalid' do
@@ -34,26 +48,33 @@ describe HeapInfo::Dumper do
34
48
 
35
49
  describe 'find' do
36
50
  before(:all) do
37
- class S;def elf; HeapInfo::Segment.new(0x400000, ''); end; def bits; 64; end; end
38
- @dumper = HeapInfo::Dumper.new(S.new, '/proc/self/mem')
51
+ @elf_base = @get_elf_base.call
52
+ class S; def bits; 64; end; end
53
+ @dumper = HeapInfo::Dumper.new(S.new(@elf_base), '/proc/self/mem')
54
+ @end_of_maps = ->() do
55
+ @self_maps.find.with_index do |seg, i|
56
+ seg[2].include?('r') and seg[1] != @self_maps[i][0] # incontinuously segment
57
+ end[1]
58
+ end
39
59
  end
40
60
  it 'simple' do
41
- expect(@dumper.find("ELF", :elf, 4)).to eq 0x400001
61
+ expect(@dumper.find("ELF", :elf, 4)).to eq @elf_base + 1
42
62
  expect(@dumper.find("ELF", :elf, 3)).to be nil
43
63
  end
44
64
  it 'regexp' do
45
- addr = @dumper.find(/ru.y/, :elf, 0x1000)
46
- expect(@dumper.dump(addr, 4) =~ /ru.y/).to eq 0
65
+ addr = @dumper.find(/lin.x/, :elf, 0x1000)
66
+ expect(@dumper.dump(addr, 5) =~ /lin.x/).to eq 0
47
67
  end
48
68
  it 'invalid' do
49
69
  expect(@dumper.find(nil, :elf, 1)).to be nil
50
70
  end
51
71
  it 'parser' do
52
- expect(@dumper.find("ELF", ':elf + 1', 3)).to eq 0x400001
72
+ expect(@dumper.find("ELF", ':elf + 1', 3)).to eq @elf_base + 1
53
73
  end
54
74
  it 'reach end' do
75
+ mem = @end_of_maps.call
55
76
  # check dumper won't return nil when remain readable memory less than one page
56
- expect(@dumper.find("\x00", 0x601010, 0x1000).nil?).to be false
77
+ expect(@dumper.find("\x00", mem - 0xff0, 0x1000).nil?).to be false
57
78
  end
58
79
  end
59
80
 
@@ -28,5 +28,6 @@ int main(int argc, char **argv) {
28
28
  v = malloc(152); // let 136 put into smallbin
29
29
  malloc(200); // to prevent merge with top_chunk
30
30
  free(v); // put into unsorted bin
31
- scanf("%*c");
31
+ char dummy;
32
+ read(0, &dummy, 1); // function which not use heap
32
33
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heapinfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - david942j
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-20 00:00:00.000000000 Z
11
+ date: 2016-12-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: create an interactive memory info interface while pwn / exploiting
14
14
  email: