-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create initial migration, model, spec files
MSP-12172
- Loading branch information
Showing
5 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Holds the record of having launched piece of Metasploit content. | ||
# Has associations to {Mdm::User} for audit purposes, and makes polymorphic associations to things like | ||
# {Mdm::Vuln} and {Mdm::Host} for flexible record keeping about activity attacking either specific vulns or just | ||
# making mischief on specific remote targets w/out the context of a vuln or even a remote IP service. | ||
class MetasploitDataModels::ModuleRun < ActiveRecord::Base | ||
# | ||
# Constants | ||
# | ||
|
||
# Marks the module as having successfully run | ||
STATUS_EXPLOITED = 'exploited' | ||
# Marks the run as having not run successfully | ||
STATUS_FAILED = 'failed' | ||
# Marks the module as having had a runtime error | ||
STATUS_ERROR = 'error' | ||
# {ModuleRun} objects will be validated against these statuses | ||
VALID_STATUSES = [STATUS_EXPLOITED, STATUS_FAILED, STATUS_ERROR] | ||
|
||
|
||
# | ||
# Attributes | ||
# | ||
|
||
# @!attribute [rw] attempted_at | ||
# The date/time when this module was run | ||
# @return [Datetime] | ||
|
||
# @!attribute [rw] fail_detail | ||
# Arbitrary information captured by the module to give in-depth reason for failure | ||
# @return [String] | ||
|
||
# @!attribute [rw] fail_reason | ||
# One of the values of the constants in {Msf::Module::Failure} | ||
# @return [String] | ||
|
||
# @!attribute [rw] module_name | ||
# The Msf::Module#fullname of the module being run | ||
# @return [String] | ||
|
||
# @!attribute [rw] port | ||
# The port that the remote host was attacked on, if any | ||
# @return [Fixnum] | ||
|
||
# @!attribute [rw] proto | ||
# The name of the protocol that the host was attacked on, if any | ||
# @return [String] | ||
|
||
# @!attribute [rw] session_id | ||
# The {Mdm::Session} that this was run with, in the case of a post module. In exploit modules, this field will | ||
# remain null. | ||
# @return [Datetime] | ||
|
||
# @!attribute [rw] status | ||
# The result of running the module | ||
# @return [String] | ||
|
||
# @!attribute [rw] username | ||
# The name of the user running this module | ||
# @return [Datetime] | ||
|
||
|
||
|
||
# | ||
# Associations | ||
# | ||
|
||
|
||
belongs_to :trackable, polymorphic: true | ||
|
||
# The user that launched this module | ||
# @return [Mdm::User] | ||
belongs_to :user, | ||
class_name: "Mdm::User", | ||
foreign_key: "user_id", | ||
inverse_of: :module_runs | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class CreateModuleRuns < ActiveRecord::Migration | ||
def change | ||
create_table :module_runs do |t| | ||
t.string :trackable_type | ||
t.integer :trackable_id | ||
t.datetime :attempted_at | ||
t.integer :session_id | ||
t.integer :port | ||
t.string :proto | ||
t.text :fail_detail | ||
t.string :status | ||
t.string :username | ||
t.integer :user_id | ||
t.string :fail_reason | ||
t.text :module_name | ||
t.integer :module_detail_id | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'spec_helper' | ||
|
||
describe MetasploitDataModels::ModuleRun do | ||
|
||
context "associations" do | ||
it { is_expected.to belong_to(:user).class_name('Mdm::User') } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FactoryGirl.define do | ||
factory :module_run do | ||
trackable_type "MyString" | ||
trackable_id 1 | ||
attempted_at "2015-02-19 11:38:21" | ||
session_id 1 | ||
port 1 | ||
proto "MyString" | ||
fail_detail "MyText" | ||
status "MyString" | ||
username "MyString" | ||
user_id 1 | ||
module_name "exploit/windows/happy-stack-smasher" | ||
end | ||
end | ||
|