parsemerlin 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a97352111627dc256706f1a4372245227905cb0fb4133c69b711d76d11e6fa57
4
+ data.tar.gz: 449e2b2010d61b12bf153d1573c60e90c427398507d169ac92d79f1e828be7d3
5
+ SHA512:
6
+ metadata.gz: 29bf377eaa5573e4dac4597d5a1fc83c95b85bd10489abf5b25dc708ff40a537a07886f63845bb15b2c7bed2a5f5f06893bb7186a3b0e09663759776c52e10da
7
+ data.tar.gz: 0654376bff3079e25009bcae1035e6b3184c449109b196c4c96b2648d81d766cb00814f78f251b5c6d073a54d39fda7203391fc68a6968fdd77f9dbb9a157a3e
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.1
7
+ before_install: gem install bundler -v 1.17.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in parsemerlin.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 royce
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Parsemerlin
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/parsemerlin`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'parsemerlin'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install parsemerlin
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/parsemerlin.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "parsemerlin"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/parsemerlin ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require 'pry'
4
+ require 'date'
5
+ require 'json'
6
+ require 'optparse'
7
+ require 'net/https'
8
+ require 'base64'
9
+ require 'uri'
10
+ rescue LoadError => dependencieserr
11
+ puts "[ERROR] it didn't work bro! - " + dependencieserr.message.chomp
12
+ exit!
13
+ end
14
+
15
+ unless ARGV.length > 0
16
+ puts "Try parsemerlin -h \r\n\r\n"
17
+ exit!
18
+ end
19
+
20
+ COMMANDS = []
21
+ PARSED = []
22
+ opts = {}
23
+ args = OptionParser.new do |opt|
24
+ opt.banner = "parsemerlin version: 0.1 - updated: 04/26/2022\r\n\r\n"
25
+ opt.on("-f", "--file [File Path]", "\tThe agent log file you want to parse") { |file| opts[:file] = File.open(file).read.encode("UTF-8", invalid: :replace, replace: "")}
26
+ opt.on("-i", "--id [String]", "\tAgent ID") { |id| opts[:agentid] = id }
27
+ opt.on("-t", "--target [String]", "\tTarget server to POST results") { |host| opts[:host] = host }
28
+ opt.on("-e", "--endpoint [String]", "\tEndpoint on target server") { |endpoint| opts[:endpoint] = endpoint }
29
+ opt.on("-a", "--auth [String]", "\tUserame:Password for basic authenticaiton") { |auth| opts[:auth] = auth }
30
+ opt.on("-v", "--verbose", "\tEnabled verbose output\r\n\r\n") { |v| opts[:verbose] = true }
31
+ end
32
+
33
+ begin
34
+ args.parse(ARGV)
35
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
36
+ puts $!.to_s
37
+ exit!
38
+ end
39
+
40
+
41
+ def parsecommandline(line)
42
+ begin
43
+ datetime = line.split('[')[1].split(']')[0]
44
+ jobid = line.split('ID:')[1].split(',')[0]
45
+ command = line.split('Args:[')[1].split(']')[0]
46
+ return {datetime: DateTime.parse(datetime).to_time.to_s, jobid: jobid, command: command}
47
+ rescue => errr
48
+ puts "[ERROR] prasecommandline didn't work bro! - " + errr.message.chomp + "\r\n" + line if v
49
+ end
50
+ end
51
+
52
+
53
+ def parseoutput(blob, v)
54
+ begin
55
+ jobid = blob.split(': ')[1].split[0]
56
+ output = blob.split('stdout')[1].split('):')[1].split('[20')[0]
57
+ command = COMMANDS.select { |command| command[:jobid] == jobid }[0]
58
+ command[:output] = '```' + output + '```'
59
+ return command
60
+ rescue => errr
61
+ puts "[ERROR] praseoutput didn't work bro! - " + errr.message.chomp + "\r\n" + blob if v
62
+ end
63
+ end
64
+
65
+ def reportcommand(command, opts)
66
+ begin
67
+ basicauth = Base64.encode64(opts[:auth])
68
+ uri = URI.parse("https://#{opts[:host]}#{opts[:endpoint]}")
69
+ header = {"Content-Type": "application/json", "Authorization": "Basic #{basicauth}"}
70
+ command[:agentid] = opts[:agentid]
71
+
72
+ http = Net::HTTP.new(uri.host, uri.port)
73
+ http.use_ssl = true if uri.port == 443
74
+ request = Net::HTTP::Post.new(uri.request_uri, header)
75
+ request.body = command.to_json
76
+ response = http.request(request)
77
+ rescue => errr
78
+ puts "[ERROR] reportcommand didn't work bro! - " + errr.message.chomp + "\r\n" + blob if v
79
+ end
80
+ end
81
+
82
+ def doit(opts)
83
+ opts[:file].split("\n") do |line|
84
+ if line.include? "Created job"
85
+ parsed = parsecommandline(line)
86
+ COMMANDS << parsed
87
+ end
88
+ end
89
+ opts[:file].split("Results for job") do |result|
90
+ if result.split(': ')[1].split[0].size == 10
91
+ parsed = parseoutput(result, opts[:verbose])
92
+ PARSED << parsed
93
+ end
94
+ end
95
+ PARSED.each do |command|
96
+ reportcommand(command, opts)
97
+ end
98
+ end
99
+
100
+ doit(opts)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module Parsemerlin
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "parsemerlin/version"
2
+
3
+ module Parsemerlin
4
+ class Error < StandardError; end
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "parsemerlin/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "parsemerlin"
8
+ spec.version = Parsemerlin::VERSION
9
+ spec.authors = ["Royce Davis"]
10
+ spec.email = ["royce@pentestgeek.com"]
11
+
12
+ spec.summary = "Parse a merlin agent_log.txt file and send the parsed commands to a remote endpoint"
13
+ spec.description = "Parse a merlin agent_log.txt file and send the parsed commands to a remote endpoint"
14
+ spec.homepage = "https://www.pentestgeek.com"
15
+ spec.license = "MIT"
16
+ spec.executables << 'parsemerlin'
17
+
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "bin"
25
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.17"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parsemerlin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Royce Davis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Parse a merlin agent_log.txt file and send the parsed commands to a remote
56
+ endpoint
57
+ email:
58
+ - royce@pentestgeek.com
59
+ executables:
60
+ - console
61
+ - parsemerlin
62
+ - setup
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - ".gitignore"
67
+ - ".rspec"
68
+ - ".travis.yml"
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - bin/console
74
+ - bin/parsemerlin
75
+ - bin/setup
76
+ - lib/parsemerlin.rb
77
+ - lib/parsemerlin/version.rb
78
+ - parsemerlin.gemspec
79
+ homepage: https://www.pentestgeek.com
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.0.1
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Parse a merlin agent_log.txt file and send the parsed commands to a remote
102
+ endpoint
103
+ test_files: []