Class: Msf::Exploit::Git::GitObject

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/core/exploit/git.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, content, sha1, compressed) ⇒ GitObject

Returns a new instance of GitObject.


12
13
14
15
16
17
18
# File 'lib/msf/core/exploit/git.rb', line 12

def initialize(type, content, sha1, compressed)
  @type = type
  @content = content
  @sha1 = sha1
  @compressed = compressed
  @path = "#{@sha1[0...2]}/#{@sha1[2..40]}"
end

Instance Attribute Details

#compressedObject (readonly)

Returns the value of attribute compressed.


10
11
12
# File 'lib/msf/core/exploit/git.rb', line 10

def compressed
  @compressed
end

#contentObject (readonly)

Returns the value of attribute content.


10
11
12
# File 'lib/msf/core/exploit/git.rb', line 10

def content
  @content
end

#pathObject (readonly)

Returns the value of attribute path.


10
11
12
# File 'lib/msf/core/exploit/git.rb', line 10

def path
  @path
end

#sha1Object (readonly)

Returns the value of attribute sha1.


10
11
12
# File 'lib/msf/core/exploit/git.rb', line 10

def sha1
  @sha1
end

#typeObject (readonly)

Returns the value of attribute type.


10
11
12
# File 'lib/msf/core/exploit/git.rb', line 10

def type
  @type
end

Class Method Details

.build_blob_object(content) ⇒ Object

Wrapper for `build_object()` to create a GitObject of type `blob` will represent

Parameters:

  • the (String)

    data that the object


54
55
56
57
# File 'lib/msf/core/exploit/git.rb', line 54

def self.build_blob_object(content)
  sha1, compressed = build_object('blob', content)
  GitObject.new('blob', content, sha1, compressed)
end

.build_commit_object(opts = {}) ⇒ Object

Wrapper for `build_object()` to create a GitObject of type `commit` (optional) parent sha1 and optional data such as commit message, committer name, company name, and email address

Parameters:

  • containing (Hash)

    sha1s for the tree,


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/msf/core/exploit/git.rb', line 26

def self.build_commit_object(opts = {})
  full_name = opts[:name] || Faker::Name.name
  email = opts[:email] || Faker::Internet.email(name: full_name, separators: ['-', '_'])
  company = opts[:company] || Faker::Company.name
  commit_text = opts[:message] || "Initial commit to open git repository for #{company}!"
  tree_sha1 = opts[:tree_sha1]
  parent_sha1 = opts[:parent_sha1]

  tstamp = Time.now.to_i
  author_time = rand(tstamp)
  commit_time = rand(author_time)
  tz_off = rand(10)

  commit_msg = "tree #{tree_sha1}\n"
  commit_msg << "parent #{parent_sha1}\n" unless parent_sha1.nil?
  commit_msg << "author #{full_name} <#{email}> #{author_time} -0#{tz_off}00\n"
  commit_msg << "committer #{full_name} <#{email}> #{commit_time} -0#{tz_off}00\n"
  commit_msg << "\n"
  commit_msg << "#{commit_text}\n"

  sha1, compressed = build_object('commit', commit_msg)
  GitObject.new('commit', commit_msg, sha1, compressed)
end

.build_object(type, content) ⇒ Object

Generates a git object of the specified type, ex: blob, tree, commit

object will represent Returns an Array containing the sha1 hash and Zlib-compressed data

Parameters:

  • type (String)

    of object to create

  • the (String)

    data that the resulting


90
91
92
93
94
95
# File 'lib/msf/core/exploit/git.rb', line 90

def self.build_object(type, content)
  # taken from http://schacon.github.io/gitbook/7_how_git_stores_objects.html
  header = "#{type} #{content.size}\0"
  store = header + content
  [Digest::SHA1.hexdigest(store), Rex::Text.zlib_deflate(store, Zlib::DEFAULT_COMPRESSION)]
end

.build_tree_object(tree_entries) ⇒ Object

Creates a GitObject of type `tree` the file mode, name, and sha1 from a previously-created `blob` object Ex:

mode: '100755', file_name: 'hooks',
sha1: 'a372436ad8331b380e20e8c9861f547063d76a46'

Parameters:

  • entries (Hash)

    containing


68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/msf/core/exploit/git.rb', line 68

def self.build_tree_object(tree_entries)
  tree = ''
  unless tree_entries.is_a?(Array)
    tree_entries = [ tree_entries ]
  end

  tree_entries.each do |entry|
    tree += "#{entry[:mode]} #{entry[:file_name]}\0#{[entry[:sha1]].pack('H*')}"
  end

  sha1, compressed = build_object('tree', tree)
  GitObject.new('tree', tree, sha1, compressed)
end

.find_object(sha1, objs = []) ⇒ Object

Given a sha1 and list of Git objects find the object with the matching sha1

Parameters:

  • sha1 (String)

    of the object to find

  • list (Array)

    of GitObjects to search

Returns:

  • GitObject with the matching sha1, nil otherwise


103
104
105
106
107
# File 'lib/msf/core/exploit/git.rb', line 103

def self.find_object(sha1, objs = [])
  return nil if objs.empty?

  objs.find { |obj| obj.sha1 == sha1 }
end