active_attack 0.1.14

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.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +50 -0
  4. data/Rakefile +32 -0
  5. data/app/assets/config/active_attack_manifest.js +2 -0
  6. data/app/assets/images/active_attack/logo.png +0 -0
  7. data/app/assets/javascripts/active_attack/application.js +8 -0
  8. data/app/assets/javascripts/active_attack/controllers/campaign_controller.es6 +23 -0
  9. data/app/assets/javascripts/active_attack/controllers/matrix_controller.es6 +23 -0
  10. data/app/assets/javascripts/active_attack/controllers/playbooks_controller.es6 +28 -0
  11. data/app/assets/javascripts/active_attack/initializers/stimulus.coffee +2 -0
  12. data/app/assets/stylesheets/active_attack/application.css +15 -0
  13. data/app/assets/stylesheets/active_attack/data_sources.css +4 -0
  14. data/app/assets/stylesheets/active_attack/detections.css +4 -0
  15. data/app/assets/stylesheets/active_attack/difficulty_for_adversaries.css +4 -0
  16. data/app/assets/stylesheets/active_attack/matrices.css +4 -0
  17. data/app/assets/stylesheets/active_attack/permissions_requireds.css +4 -0
  18. data/app/assets/stylesheets/active_attack/platforms.css +4 -0
  19. data/app/assets/stylesheets/active_attack/playbooks.css +400 -0
  20. data/app/assets/stylesheets/active_attack/tactics.css +4 -0
  21. data/app/assets/stylesheets/active_attack/versions.css +4 -0
  22. data/app/controllers/active_attack/application_controller.rb +5 -0
  23. data/app/controllers/active_attack/matrices_controller.rb +82 -0
  24. data/app/controllers/active_attack/playbooks_controller.rb +89 -0
  25. data/app/controllers/active_attack/tactics_controller.rb +62 -0
  26. data/app/helpers/active_attack/application_helper.rb +4 -0
  27. data/app/helpers/active_attack/playbooks_helper.rb +21 -0
  28. data/app/helpers/active_attack/tactics_helper.rb +4 -0
  29. data/app/jobs/active_attack/application_job.rb +4 -0
  30. data/app/mailers/active_attack/application_mailer.rb +6 -0
  31. data/app/models/active_attack/active_attack.rb +7 -0
  32. data/app/models/active_attack/application_record.rb +5 -0
  33. data/app/models/active_attack/build.rb +6 -0
  34. data/app/models/active_attack/data_source.rb +15 -0
  35. data/app/models/active_attack/detection.rb +14 -0
  36. data/app/models/active_attack/difficulty_for_adversary.rb +10 -0
  37. data/app/models/active_attack/matrix.rb +82 -0
  38. data/app/models/active_attack/permissions_required.rb +14 -0
  39. data/app/models/active_attack/platform.rb +16 -0
  40. data/app/models/active_attack/playbook.rb +177 -0
  41. data/app/models/active_attack/tactic.rb +61 -0
  42. data/app/models/active_attack/version.rb +14 -0
  43. data/app/overrides/models/active_stix/active_stix_override.rb +7 -0
  44. data/app/overrides/models/active_stix/attack_pattern_override.rb +75 -0
  45. data/app/overrides/models/active_stix/bundle_override.rb +18 -0
  46. data/app/overrides/models/active_stix/malware_override.rb +40 -0
  47. data/app/overrides/models/active_stix/report_override.rb +18 -0
  48. data/app/overrides/models/active_stix/tool_override.rb +36 -0
  49. data/app/views/active_attack/matrices/_form.html.erb +27 -0
  50. data/app/views/active_attack/matrices/_stix_attack_matrix.json.jbuilder +2 -0
  51. data/app/views/active_attack/matrices/edit.html.erb +6 -0
  52. data/app/views/active_attack/matrices/index.html.erb +16 -0
  53. data/app/views/active_attack/matrices/index.json.jbuilder +1 -0
  54. data/app/views/active_attack/matrices/new.html.erb +5 -0
  55. data/app/views/active_attack/matrices/show.html.erb +33 -0
  56. data/app/views/active_attack/matrices/show.json.jbuilder +1 -0
  57. data/app/views/active_attack/playbooks/_attack_playbook.json.jbuilder +2 -0
  58. data/app/views/active_attack/playbooks/_form.html.erb +32 -0
  59. data/app/views/active_attack/playbooks/edit.html.erb +6 -0
  60. data/app/views/active_attack/playbooks/index.html.erb +38 -0
  61. data/app/views/active_attack/playbooks/index.json.jbuilder +1 -0
  62. data/app/views/active_attack/playbooks/new.html.erb +5 -0
  63. data/app/views/active_attack/playbooks/show.html.erb +70 -0
  64. data/app/views/active_attack/playbooks/show.json.jbuilder +1 -0
  65. data/app/views/active_attack/tactics/_form.html.erb +42 -0
  66. data/app/views/active_attack/tactics/edit.html.erb +6 -0
  67. data/app/views/active_attack/tactics/index.html.erb +35 -0
  68. data/app/views/active_attack/tactics/new.html.erb +5 -0
  69. data/app/views/active_attack/tactics/show.html.erb +29 -0
  70. data/app/views/layouts/active_attack/application.html.erb +15 -0
  71. data/config/routes.rb +11 -0
  72. data/db/migrate/20191211202017_create_active_attack_data_sources.rb +10 -0
  73. data/db/migrate/20191211202101_create_active_attack_detections.rb +10 -0
  74. data/db/migrate/20191211202127_create_active_attack_difficulty_for_adversaries.rb +10 -0
  75. data/db/migrate/20191211202210_create_active_attack_matrices.rb +10 -0
  76. data/db/migrate/20191211202241_create_active_attack_permissions_requireds.rb +9 -0
  77. data/db/migrate/20191211202303_create_active_attack_platforms.rb +10 -0
  78. data/db/migrate/20191211202358_create_active_attack_playbooks.rb +11 -0
  79. data/db/migrate/20191211202448_create_active_attack_versions.rb +10 -0
  80. data/db/migrate/20191212205423_create_active_attack_tactics.rb +14 -0
  81. data/db/migrate/20200405004308_create_active_attack_builds.rb +10 -0
  82. data/db/migrate/20200405005101_add_buildable_type_to_builds.rb +5 -0
  83. data/db/migrate/20200405040306_add_stix_id_to_active_attack_matrices.rb +5 -0
  84. data/db/migrate/20200405040455_add_attributes_to_active_attack_matrices.rb +6 -0
  85. data/db/migrate/20200405041534_add_matrix_ref_to_active_attack_tactics.rb +5 -0
  86. data/db/migrate/20200405041824_add_created_by_ref_to_active_attack_matrices.rb +5 -0
  87. data/db/migrate/20200410170440_add_threat_actor_to_active_attack_playbooks.rb +5 -0
  88. data/lib/active_attack.rb +6 -0
  89. data/lib/active_attack/engine.rb +25 -0
  90. data/lib/active_attack/version.rb +3 -0
  91. data/lib/enterprise-attack.json +145354 -0
  92. data/lib/tasks/active_attack_tasks.rake +4 -0
  93. metadata +238 -0
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,5 @@
1
+ module ActiveAttack
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,82 @@
1
+ class ActiveAttack::MatricesController < ApplicationController
2
+ before_action :set_matrix, only: [:show, :edit, :update, :destroy, :data]
3
+
4
+ # GET /attack/matrices
5
+ # GET /attack/matrices.json
6
+ def index
7
+ @attack_matrices = ActiveAttack::Matrix.all
8
+ end
9
+
10
+ # GET /attack/matrices/1
11
+ # GET /attack/matrices/1.json
12
+ def show
13
+ @attack_matrix = ActiveAttack::Matrix.find(params[:id])
14
+ end
15
+
16
+
17
+ # GET /attack/matrices/new
18
+ def new
19
+ @attack_matrix = ActiveAttack::Matrix.new
20
+ end
21
+
22
+ # GET /attack/matrices/1/edit
23
+ def edit
24
+ end
25
+
26
+ def data
27
+ end
28
+
29
+ # POST /attack/matrices
30
+ # POST /attack/matrices.json
31
+ def create
32
+ @attack_matrix = ActiveAttack::Matrix.new(attack_matrix_params)
33
+
34
+ respond_to do |format|
35
+ if @attack_matrix.save
36
+ bundle = @attack_matrix.ingest_bundle(params[:attack_matrix][:uploaded_file].path)
37
+ @attack_matrix.update(:stix_bundle_id => bundle.stix_id)
38
+ format.html { redirect_to @attack_matrix, notice: 'Attack matrix was successfully created.' }
39
+ format.json { render :show, status: :created, location: @attack_matrix }
40
+ else
41
+ format.html { render :new }
42
+ format.json { render json: @attack_matrix.errors, status: :unprocessable_entity }
43
+ end
44
+ end
45
+ end
46
+
47
+ # PATCH/PUT /stix/matrices/1
48
+ # PATCH/PUT /stix/matrices/1.json
49
+ def update
50
+ respond_to do |format|
51
+ if @attack_matrix.update(attack_attack_matrix_params)
52
+ format.html { redirect_to @attack_matrix, notice: 'Attack matrix was successfully updated.' }
53
+ format.json { render :show, status: :ok, location: @attack_matrix }
54
+ else
55
+ format.html { render :edit }
56
+ format.json { render json: @attack_matrix.errors, status: :unprocessable_entity }
57
+ end
58
+ end
59
+ end
60
+
61
+ # DELETE /attack/matrices/1
62
+ # DELETE /attack/matrices/1.json
63
+ def destroy
64
+ @attack_matrix.destroy
65
+ respond_to do |format|
66
+ format.html { redirect_to attack_attack_matrices_url, notice: 'Attack matrix was successfully destroyed.' }
67
+ format.json { head :no_content }
68
+ end
69
+ end
70
+
71
+ private
72
+ # Use callbacks to share common setup or constraints between actions.
73
+ def set_matrix
74
+ #@attack_pattern = ActiveStix::AttackPattern.find(params[:id])
75
+ @matrix = ActiveAttack::Matrix.find(params[:id])
76
+ end
77
+
78
+ # Never trust parameters from the scary internet, only allow the white list through.
79
+ def attack_matrix_params
80
+ params.require(:attack_matrix).permit(:stix_bundle_id, :name)
81
+ end
82
+ end
@@ -0,0 +1,89 @@
1
+ class ActiveAttack::PlaybooksController < ApplicationController
2
+ before_action :set_attack_playbook, only: [:edit, :update, :destroy]
3
+
4
+ # GET /attack/playbooks
5
+ # GET /attack/playbooks.json
6
+ def index
7
+ @playbooks = ActiveAttack::Playbook.all
8
+ end
9
+
10
+ # GET /attack/playbooks/1
11
+ # GET /attack/playbooks/1.json
12
+ def show
13
+ # @attack_playbook.stix_bundle.bundled_objects.each do | x |
14
+ # render :json => @attack_playbook.stix_bundle
15
+ # end
16
+ @playbooks = ActiveAttack::Playbook.all
17
+ @playbook = @playbooks.find(params[:id])
18
+ @threat_actor = @playbook.threat_actor
19
+ @report = @playbook.bundle
20
+
21
+ respond_to do |format|
22
+ format.html
23
+ format.json {render json: @playbook.as_stix}
24
+ end
25
+ end
26
+
27
+ # GET /attack/playbooks/new
28
+ def new
29
+ @attack_playbook = ActiveAttack::Playbook.new
30
+ end
31
+
32
+ # GET /attack/playbooks/1/edit
33
+ def edit
34
+ end
35
+
36
+ # POST /attack/playbooks
37
+ # POST /attack/playbooks.json
38
+ def create
39
+ @attack_playbook = ActiveAttack::Playbook.new(attack_playbook_params)
40
+
41
+ respond_to do |format|
42
+ if @attack_playbook.save
43
+ bundle = @attack_playbook.ingest_bundle(params[:attack_playbook][:uploaded_file].path)
44
+ @attack_playbook.update(:stix_bundle_id => bundle.stix_id)
45
+ format.html { redirect_to @attack_playbook, notice: 'Playbook was successfully created.' }
46
+ format.json { render :show, status: :created, location: @attack_playbook }
47
+ else
48
+ format.html { render :new }
49
+ format.json { render json: @attack_playbook.errors, status: :unprocessable_entity }
50
+ end
51
+ end
52
+ end
53
+
54
+ # PATCH/PUT /attack/playbooks/1
55
+ # PATCH/PUT /attack/playbooks/1.json
56
+ def update
57
+ respond_to do |format|
58
+ if @attack_playbook.update(attack_playbook_params)
59
+ format.html { redirect_to @attack_playbook, notice: 'Playbook was successfully updated.' }
60
+ format.json { render :show, status: :ok, location: @attack_playbook }
61
+ else
62
+ format.html { render :edit }
63
+ format.json { render json: @attack_playbook.errors, status: :unprocessable_entity }
64
+ end
65
+ end
66
+ end
67
+
68
+ # DELETE /attack/playbooks/1
69
+ # DELETE /attack/playbooks/1.json
70
+ def destroy
71
+ @attack_playbook.destroy
72
+ respond_to do |format|
73
+ format.html { redirect_to attack_playbooks_url, notice: 'Playbook was successfully destroyed.' }
74
+ format.json { head :no_content }
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ # Use callbacks to share common setup or constraints between actions.
81
+ def set_attack_playbook
82
+ @attack_playbook = ActiveAttack::Playbook.find(params[:id])
83
+ end
84
+
85
+ # Never trust parameters from the scary internet, only allow the white list through.
86
+ def attack_playbook_params
87
+ params.require(:attack_playbook).permit(:name, :stix_bundle_id, :id)
88
+ end
89
+ end
@@ -0,0 +1,62 @@
1
+ require_dependency "active_attack/application_controller"
2
+
3
+ module ActiveAttack
4
+ class TacticsController < ApplicationController
5
+ before_action :set_tactic, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /tactics
8
+ def index
9
+ @tactics = Tactic.all
10
+ end
11
+
12
+ # GET /tactics/1
13
+ def show
14
+ end
15
+
16
+ # GET /tactics/new
17
+ def new
18
+ @tactic = Tactic.new
19
+ end
20
+
21
+ # GET /tactics/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /tactics
26
+ def create
27
+ @tactic = Tactic.new(tactic_params)
28
+
29
+ if @tactic.save
30
+ redirect_to @tactic, notice: 'Tactic was successfully created.'
31
+ else
32
+ render :new
33
+ end
34
+ end
35
+
36
+ # PATCH/PUT /tactics/1
37
+ def update
38
+ if @tactic.update(tactic_params)
39
+ redirect_to @tactic, notice: 'Tactic was successfully updated.'
40
+ else
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ # DELETE /tactics/1
46
+ def destroy
47
+ @tactic.destroy
48
+ redirect_to tactics_url, notice: 'Tactic was successfully destroyed.'
49
+ end
50
+
51
+ private
52
+ # Use callbacks to share common setup or constraints between actions.
53
+ def set_tactic
54
+ @tactic = Tactic.find(params[:id])
55
+ end
56
+
57
+ # Only allow a trusted parameter "white list" through.
58
+ def tactic_params
59
+ params.require(:tactic).permit(:stix_id, :name, :description, :shortname, :created_by_ref)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,4 @@
1
+ module ActiveAttack
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,21 @@
1
+ module ActiveAttack
2
+ module PlaybooksHelper
3
+ def attack_pattern_class(phase, row)
4
+ if @playbook.attack_patterns.collect(&:name).include? @playbook.attack_pattern_matrix(phase.name, row)
5
+ "used"
6
+ end
7
+ end
8
+
9
+ def campaign_list(phase, row)
10
+ @playbook.attack_pattern_campaign_list(phase,row)
11
+ end
12
+
13
+ def attack_pattern_target(phase, row)
14
+ if @playbook.attack_patterns.collect(&:name).include? @playbook.attack_pattern_matrix(phase.name, row)
15
+ "matrix.used"
16
+ else
17
+ "matrix.notused"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ module ActiveAttack
2
+ module TacticsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ActiveAttack
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module ActiveAttack
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module ActiveAttack
2
+ module ActiveAttack
3
+ def self.table_name_prefix
4
+ 'active_attack_active_attack_'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveAttack
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module ActiveAttack
2
+ class Build < ApplicationRecord
3
+ belongs_to :buildable, polymorphic: true
4
+ belongs_to :platform
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ module ActiveAttack
2
+ class DataSource < ApplicationRecord
3
+ has_many :attack_patterns, :class_name => 'ActiveStix::AttackPattern', through: :data_source_attack_pattern
4
+
5
+ def self.create_source(src)
6
+ xmd = find_or_create_by(source:src)
7
+ xmd
8
+ end
9
+
10
+ def convert_to_json
11
+ source
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module ActiveAttack
2
+ class Detection < ApplicationRecord
3
+ has_many :attack_patterns, :class_name => 'ActiveStix::AttackPattern', through: :detection_attack_pattern
4
+
5
+ def self.create_descr(descr)
6
+ xmd = find_or_create_by(description:descr)
7
+ xmd
8
+ end
9
+
10
+ def convert_to_json
11
+ description
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module ActiveAttack
2
+ class DifficultyForAdversary < ApplicationRecord
3
+ has_many :attack_patterns, :class_name => 'ActiveStix::AttackPattern', through: :difficulty_for_adversary_attack_pattern
4
+
5
+ def self.create_difficulty(diff)
6
+ isDiff = find_or_create_by(difficulty:diff)
7
+ isDiff
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,82 @@
1
+ module ActiveAttack
2
+ class Matrix < ApplicationRecord
3
+ belongs_to :bundle, :class_name => 'ActiveStix::Bundle', optional: true
4
+
5
+ has_many :reference_items, class_name: "ActiveStix::ReferenceItem", as: :referrer
6
+ has_many :external_references, class_name: "ActiveStix::ExternalReference", through: :reference_items
7
+ has_many :tactics, primary_key: 'stix_id', foreign_key: 'matrix_ref'
8
+
9
+ def ingest_bundle(path)
10
+ bundle = ActiveStix::Bundle.ingest(path)
11
+ self.bundle = bundle
12
+ save
13
+ bundle
14
+ end
15
+
16
+
17
+ def self.ingest_json(obj)
18
+ binding.pry
19
+ xmx = find_or_create_by(stix_id:obj['id'], name:obj['name'])
20
+
21
+ if obj.has_key?('description')
22
+ xmx.description = obj['description']
23
+ end
24
+
25
+ if obj.has_key?('created_by_ref')
26
+ xmx.created_by_ref = obj['created_by_ref']
27
+ end
28
+
29
+ if obj.has_key?('external_references')
30
+ obj['external_references'].each do |er|
31
+ external_reference = ActiveStix::ExternalReference.ingest_json(er, obj['id'])
32
+ xmx.external_references << external_reference unless ActiveStix::ReferenceItem.find_by(external_reference_id:external_reference.id, referrer_id:xmx.id, referrer_type: "ActiveAttack::Matrix")
33
+ end
34
+ end
35
+
36
+ if obj.has_key?('object_marking_refs')
37
+ # todo
38
+ end
39
+
40
+ if obj.has_key?('tactic_refs')
41
+ obj['tactic_refs'].each do |tr|
42
+ tactic_ref = ActiveAttack::Tactic.find_or_create_by(stix_id: tr)
43
+ xmx.tactics << tactic_ref
44
+ end
45
+ end
46
+
47
+ xmx.save
48
+ xmx
49
+ end
50
+
51
+ def convert_to_json
52
+ external_refs_arr = []
53
+ external_references.each do | x |
54
+ external_refs_arr << x.convert_to_json
55
+ end
56
+
57
+ marking_def_arr = []
58
+ marking_definitions.each do | x |
59
+ marking_def_arr << x.convert_to_json
60
+ end
61
+
62
+
63
+ tactic_refs_arr = []
64
+ x_mitre_tactic_refs.each do | x |
65
+ tactic_refs_arr << x.convert_to_json
66
+ end
67
+
68
+ {
69
+ :external_references => external_refs_arr,
70
+ :object_marking_refs => marking_def_arr,
71
+ :id => stix_id,
72
+ :name => name,
73
+ :created => created_at.to_s,
74
+ :modified => updated_at.to_s,
75
+ :type => "x-mitre-matrix",
76
+ :created_by_ref => created_by_ref,
77
+ :description => description,
78
+ :tactic_refs => tactic_refs_arr
79
+ }
80
+ end
81
+ end
82
+ end