Class: Msf::Exploit::Git::GitObject
- Inherits:
-
Object
- Object
- Msf::Exploit::Git::GitObject
- Defined in:
- lib/msf/core/exploit/git.rb
Instance Attribute Summary collapse
-
#compressed ⇒ Object
readonly
Returns the value of attribute compressed.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#sha1 ⇒ Object
readonly
Returns the value of attribute sha1.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.build_blob_object(content) ⇒ Object
Wrapper for ‘build_object()` to create a GitObject of type `blob`.
-
.build_commit_object(opts = {}) ⇒ Object
Wrapper for ‘build_object()` to create a GitObject of type `commit`.
-
.build_object(type, content) ⇒ Object
Generates a git object of the specified type, ex: blob, tree, commit.
-
.build_tree_object(tree_entries) ⇒ Object
Creates a GitObject of type ‘tree` Ex: { mode: ’100755’, file_name: ‘hooks’, sha1: ‘a372436ad8331b380e20e8c9861f547063d76a46’ }.
-
.find_object(sha1, objs = []) ⇒ Object
Given a sha1 and list of Git objects find the object with the matching sha1.
Instance Method Summary collapse
-
#initialize(type, content, sha1, compressed) ⇒ GitObject
constructor
A new instance of GitObject.
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
#compressed ⇒ Object (readonly)
Returns the value of attribute compressed.
10 11 12 |
# File 'lib/msf/core/exploit/git.rb', line 10 def compressed @compressed end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
10 11 12 |
# File 'lib/msf/core/exploit/git.rb', line 10 def content @content end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/msf/core/exploit/git.rb', line 10 def path @path end |
#sha1 ⇒ Object (readonly)
Returns the value of attribute sha1.
10 11 12 |
# File 'lib/msf/core/exploit/git.rb', line 10 def sha1 @sha1 end |
#type ⇒ Object (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`
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`
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 = rand(tstamp) commit_time = rand() 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}> #{} -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
Returns an Array containing the sha1 hash and Zlib-compressed data
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` Ex:
mode: '100755', file_name: 'hooks',
sha1: 'a372436ad8331b380e20e8c9861f547063d76a46'
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
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 |