mihari 3.9.0 → 3.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +6 -7
  3. data/config.ru +1 -1
  4. data/lib/mihari/errors.rb +2 -0
  5. data/lib/mihari/mixins/configuration.rb +12 -2
  6. data/lib/mihari/models/alert.rb +1 -8
  7. data/lib/mihari/models/artifact.rb +3 -0
  8. data/lib/mihari/structs/ipinfo.rb +3 -4
  9. data/lib/mihari/version.rb +1 -1
  10. data/lib/mihari/web/api.rb +43 -0
  11. data/lib/mihari/web/app.rb +47 -29
  12. data/lib/mihari/web/endpoints/alerts.rb +74 -0
  13. data/lib/mihari/web/endpoints/artifacts.rb +92 -0
  14. data/lib/mihari/web/endpoints/command.rb +32 -0
  15. data/lib/mihari/web/endpoints/configs.rb +22 -0
  16. data/lib/mihari/web/endpoints/ip_addresses.rb +27 -0
  17. data/lib/mihari/web/endpoints/sources.rb +18 -0
  18. data/lib/mihari/web/endpoints/tags.rb +38 -0
  19. data/lib/mihari/web/entities/alert.rb +23 -0
  20. data/lib/mihari/web/entities/artifact.rb +24 -0
  21. data/lib/mihari/web/entities/autonomous_system.rb +9 -0
  22. data/lib/mihari/web/entities/command.rb +14 -0
  23. data/lib/mihari/web/entities/config.rb +16 -0
  24. data/lib/mihari/web/entities/dns.rb +10 -0
  25. data/lib/mihari/web/entities/geolocation.rb +10 -0
  26. data/lib/mihari/web/entities/ip_address.rb +13 -0
  27. data/lib/mihari/web/entities/message.rb +9 -0
  28. data/lib/mihari/web/entities/reverse_dns.rb +9 -0
  29. data/lib/mihari/web/entities/source.rb +9 -0
  30. data/lib/mihari/web/entities/tag.rb +13 -0
  31. data/lib/mihari/web/entities/whois.rb +16 -0
  32. data/lib/mihari/web/public/grape.rb +73 -0
  33. data/lib/mihari/web/public/index.html +1 -1
  34. data/lib/mihari/web/public/redoc-static.html +53 -27
  35. data/lib/mihari/web/public/static/js/app.6b636b62.js +50 -0
  36. data/lib/mihari/web/public/static/js/app.6b636b62.js.map +1 -0
  37. data/lib/mihari.rb +2 -12
  38. data/mihari.gemspec +7 -5
  39. data/sig/lib/mihari/web/app.rbs +1 -1
  40. metadata +108 -74
  41. data/lib/mihari/serializers/alert.rb +0 -14
  42. data/lib/mihari/serializers/artifact.rb +0 -18
  43. data/lib/mihari/serializers/autonomous_system.rb +0 -9
  44. data/lib/mihari/serializers/dns.rb +0 -11
  45. data/lib/mihari/serializers/geolocation.rb +0 -11
  46. data/lib/mihari/serializers/reverse_dns.rb +0 -11
  47. data/lib/mihari/serializers/tag.rb +0 -11
  48. data/lib/mihari/serializers/whois.rb +0 -11
  49. data/lib/mihari/web/controllers/alerts_controller.rb +0 -67
  50. data/lib/mihari/web/controllers/analyzers_controller.rb +0 -38
  51. data/lib/mihari/web/controllers/artifacts_controller.rb +0 -94
  52. data/lib/mihari/web/controllers/base_controller.rb +0 -22
  53. data/lib/mihari/web/controllers/command_controller.rb +0 -26
  54. data/lib/mihari/web/controllers/config_controller.rb +0 -13
  55. data/lib/mihari/web/controllers/ip_address_controller.rb +0 -21
  56. data/lib/mihari/web/controllers/sources_controller.rb +0 -12
  57. data/lib/mihari/web/controllers/tags_controller.rb +0 -30
  58. data/lib/mihari/web/helpers/json.rb +0 -53
data/lib/mihari.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "awrence"
3
4
  require "colorize"
4
5
  require "dry/configurable"
5
6
  require "dry/files"
6
7
  require "mem"
8
+ require "plissken"
7
9
  require "yaml"
8
10
 
9
11
  # Load .env
@@ -135,18 +137,6 @@ require "mihari/models/tag"
135
137
  require "mihari/models/tagging"
136
138
  require "mihari/models/whois"
137
139
 
138
- # Serializers
139
- require "mihari/serializers/autonomous_system"
140
- require "mihari/serializers/dns"
141
- require "mihari/serializers/geolocation"
142
- require "mihari/serializers/reverse_dns"
143
- require "mihari/serializers/tag"
144
- require "mihari/serializers/whois"
145
-
146
- require "mihari/serializers/artifact"
147
-
148
- require "mihari/serializers/alert"
149
-
150
140
  # Analyzers
151
141
  require "mihari/analyzers/base"
152
142
  require "mihari/analyzers/basic"
data/mihari.gemspec CHANGED
@@ -42,7 +42,6 @@ Gem::Specification.new do |spec|
42
42
  spec.add_development_dependency "vcr", "~> 6.0"
43
43
  spec.add_development_dependency "webmock", "~> 3.14"
44
44
 
45
- spec.add_dependency "active_model_serializers", "~> 0.10"
46
45
  spec.add_dependency "activerecord", "~> 6.1"
47
46
  spec.add_dependency "activerecord-filter", "~> 6.1"
48
47
  spec.add_dependency "addressable", "~> 2.8"
@@ -61,6 +60,10 @@ Gem::Specification.new do |spec|
61
60
  spec.add_dependency "dry-struct", "~> 1.4"
62
61
  spec.add_dependency "dry-validation", "~> 1.7"
63
62
  spec.add_dependency "email_address", "~> 0.2"
63
+ spec.add_dependency "grape", "~> 1.5"
64
+ spec.add_dependency "grape-entity", "~> 0.10"
65
+ spec.add_dependency "grape-swagger", "~> 1.4"
66
+ spec.add_dependency "grape-swagger-entity", "~> 0.5"
64
67
  spec.add_dependency "hachi", "~> 1.0"
65
68
  spec.add_dependency "http", "~> 5.0"
66
69
  spec.add_dependency "launchy", "~> 2.5"
@@ -71,20 +74,19 @@ Gem::Specification.new do |spec|
71
74
  spec.add_dependency "normalize_country", "0.3"
72
75
  spec.add_dependency "onyphe", "~> 2.0"
73
76
  spec.add_dependency "otx_ruby", "~> 0.9"
74
- spec.add_dependency "parallel", "~> 1.20"
77
+ spec.add_dependency "parallel", "~> 1.21"
75
78
  spec.add_dependency "passive_circl", "~> 0.1"
76
79
  spec.add_dependency "passivetotalx", "~> 0.1"
80
+ spec.add_dependency "plissken", "~> 1.4"
77
81
  spec.add_dependency "public_suffix", "~> 4.0"
78
82
  spec.add_dependency "pulsedive", "~> 0.1"
79
83
  spec.add_dependency "puma", "~> 5.5"
80
84
  spec.add_dependency "rack", "~> 2.2"
81
85
  spec.add_dependency "rack-contrib", "~> 2.3"
86
+ spec.add_dependency "rack-cors", "~> 1.1"
82
87
  spec.add_dependency "safe_shell", "~> 1.1"
83
88
  spec.add_dependency "securitytrails", "~> 1.0"
84
89
  spec.add_dependency "shodanx", "~> 0.2"
85
- spec.add_dependency "sinatra", "~> 2.1"
86
- spec.add_dependency "sinatra-contrib", "~> 2.1"
87
- spec.add_dependency "sinatra-param", "~> 1.6"
88
90
  spec.add_dependency "slack-notifier", "~> 2.4"
89
91
  spec.add_dependency "spysex", "~> 0.2"
90
92
  spec.add_dependency "sqlite3", "~> 1.4"
@@ -1,5 +1,5 @@
1
1
  module Mihari
2
- class App # < Sinatra::Base
2
+ class App
3
3
  def self.run!: (?port: ::Integer port, ?host: ::String host, ?threads: ::String threads, ?verbose: bool verbose) -> void
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mihari
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.0
4
+ version: 3.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manabu Niseki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-23 00:00:00.000000000 Z
11
+ date: 2021-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -234,20 +234,6 @@ dependencies:
234
234
  - - "~>"
235
235
  - !ruby/object:Gem::Version
236
236
  version: '3.14'
237
- - !ruby/object:Gem::Dependency
238
- name: active_model_serializers
239
- requirement: !ruby/object:Gem::Requirement
240
- requirements:
241
- - - "~>"
242
- - !ruby/object:Gem::Version
243
- version: '0.10'
244
- type: :runtime
245
- prerelease: false
246
- version_requirements: !ruby/object:Gem::Requirement
247
- requirements:
248
- - - "~>"
249
- - !ruby/object:Gem::Version
250
- version: '0.10'
251
237
  - !ruby/object:Gem::Dependency
252
238
  name: activerecord
253
239
  requirement: !ruby/object:Gem::Requirement
@@ -500,6 +486,62 @@ dependencies:
500
486
  - - "~>"
501
487
  - !ruby/object:Gem::Version
502
488
  version: '0.2'
489
+ - !ruby/object:Gem::Dependency
490
+ name: grape
491
+ requirement: !ruby/object:Gem::Requirement
492
+ requirements:
493
+ - - "~>"
494
+ - !ruby/object:Gem::Version
495
+ version: '1.5'
496
+ type: :runtime
497
+ prerelease: false
498
+ version_requirements: !ruby/object:Gem::Requirement
499
+ requirements:
500
+ - - "~>"
501
+ - !ruby/object:Gem::Version
502
+ version: '1.5'
503
+ - !ruby/object:Gem::Dependency
504
+ name: grape-entity
505
+ requirement: !ruby/object:Gem::Requirement
506
+ requirements:
507
+ - - "~>"
508
+ - !ruby/object:Gem::Version
509
+ version: '0.10'
510
+ type: :runtime
511
+ prerelease: false
512
+ version_requirements: !ruby/object:Gem::Requirement
513
+ requirements:
514
+ - - "~>"
515
+ - !ruby/object:Gem::Version
516
+ version: '0.10'
517
+ - !ruby/object:Gem::Dependency
518
+ name: grape-swagger
519
+ requirement: !ruby/object:Gem::Requirement
520
+ requirements:
521
+ - - "~>"
522
+ - !ruby/object:Gem::Version
523
+ version: '1.4'
524
+ type: :runtime
525
+ prerelease: false
526
+ version_requirements: !ruby/object:Gem::Requirement
527
+ requirements:
528
+ - - "~>"
529
+ - !ruby/object:Gem::Version
530
+ version: '1.4'
531
+ - !ruby/object:Gem::Dependency
532
+ name: grape-swagger-entity
533
+ requirement: !ruby/object:Gem::Requirement
534
+ requirements:
535
+ - - "~>"
536
+ - !ruby/object:Gem::Version
537
+ version: '0.5'
538
+ type: :runtime
539
+ prerelease: false
540
+ version_requirements: !ruby/object:Gem::Requirement
541
+ requirements:
542
+ - - "~>"
543
+ - !ruby/object:Gem::Version
544
+ version: '0.5'
503
545
  - !ruby/object:Gem::Dependency
504
546
  name: hachi
505
547
  requirement: !ruby/object:Gem::Requirement
@@ -646,14 +688,14 @@ dependencies:
646
688
  requirements:
647
689
  - - "~>"
648
690
  - !ruby/object:Gem::Version
649
- version: '1.20'
691
+ version: '1.21'
650
692
  type: :runtime
651
693
  prerelease: false
652
694
  version_requirements: !ruby/object:Gem::Requirement
653
695
  requirements:
654
696
  - - "~>"
655
697
  - !ruby/object:Gem::Version
656
- version: '1.20'
698
+ version: '1.21'
657
699
  - !ruby/object:Gem::Dependency
658
700
  name: passive_circl
659
701
  requirement: !ruby/object:Gem::Requirement
@@ -682,6 +724,20 @@ dependencies:
682
724
  - - "~>"
683
725
  - !ruby/object:Gem::Version
684
726
  version: '0.1'
727
+ - !ruby/object:Gem::Dependency
728
+ name: plissken
729
+ requirement: !ruby/object:Gem::Requirement
730
+ requirements:
731
+ - - "~>"
732
+ - !ruby/object:Gem::Version
733
+ version: '1.4'
734
+ type: :runtime
735
+ prerelease: false
736
+ version_requirements: !ruby/object:Gem::Requirement
737
+ requirements:
738
+ - - "~>"
739
+ - !ruby/object:Gem::Version
740
+ version: '1.4'
685
741
  - !ruby/object:Gem::Dependency
686
742
  name: public_suffix
687
743
  requirement: !ruby/object:Gem::Requirement
@@ -753,7 +809,7 @@ dependencies:
753
809
  - !ruby/object:Gem::Version
754
810
  version: '2.3'
755
811
  - !ruby/object:Gem::Dependency
756
- name: safe_shell
812
+ name: rack-cors
757
813
  requirement: !ruby/object:Gem::Requirement
758
814
  requirements:
759
815
  - - "~>"
@@ -767,75 +823,47 @@ dependencies:
767
823
  - !ruby/object:Gem::Version
768
824
  version: '1.1'
769
825
  - !ruby/object:Gem::Dependency
770
- name: securitytrails
771
- requirement: !ruby/object:Gem::Requirement
772
- requirements:
773
- - - "~>"
774
- - !ruby/object:Gem::Version
775
- version: '1.0'
776
- type: :runtime
777
- prerelease: false
778
- version_requirements: !ruby/object:Gem::Requirement
779
- requirements:
780
- - - "~>"
781
- - !ruby/object:Gem::Version
782
- version: '1.0'
783
- - !ruby/object:Gem::Dependency
784
- name: shodanx
785
- requirement: !ruby/object:Gem::Requirement
786
- requirements:
787
- - - "~>"
788
- - !ruby/object:Gem::Version
789
- version: '0.2'
790
- type: :runtime
791
- prerelease: false
792
- version_requirements: !ruby/object:Gem::Requirement
793
- requirements:
794
- - - "~>"
795
- - !ruby/object:Gem::Version
796
- version: '0.2'
797
- - !ruby/object:Gem::Dependency
798
- name: sinatra
826
+ name: safe_shell
799
827
  requirement: !ruby/object:Gem::Requirement
800
828
  requirements:
801
829
  - - "~>"
802
830
  - !ruby/object:Gem::Version
803
- version: '2.1'
831
+ version: '1.1'
804
832
  type: :runtime
805
833
  prerelease: false
806
834
  version_requirements: !ruby/object:Gem::Requirement
807
835
  requirements:
808
836
  - - "~>"
809
837
  - !ruby/object:Gem::Version
810
- version: '2.1'
838
+ version: '1.1'
811
839
  - !ruby/object:Gem::Dependency
812
- name: sinatra-contrib
840
+ name: securitytrails
813
841
  requirement: !ruby/object:Gem::Requirement
814
842
  requirements:
815
843
  - - "~>"
816
844
  - !ruby/object:Gem::Version
817
- version: '2.1'
845
+ version: '1.0'
818
846
  type: :runtime
819
847
  prerelease: false
820
848
  version_requirements: !ruby/object:Gem::Requirement
821
849
  requirements:
822
850
  - - "~>"
823
851
  - !ruby/object:Gem::Version
824
- version: '2.1'
852
+ version: '1.0'
825
853
  - !ruby/object:Gem::Dependency
826
- name: sinatra-param
854
+ name: shodanx
827
855
  requirement: !ruby/object:Gem::Requirement
828
856
  requirements:
829
857
  - - "~>"
830
858
  - !ruby/object:Gem::Version
831
- version: '1.6'
859
+ version: '0.2'
832
860
  type: :runtime
833
861
  prerelease: false
834
862
  version_requirements: !ruby/object:Gem::Requirement
835
863
  requirements:
836
864
  - - "~>"
837
865
  - !ruby/object:Gem::Version
838
- version: '1.6'
866
+ version: '0.2'
839
867
  - !ruby/object:Gem::Dependency
840
868
  name: slack-notifier
841
869
  requirement: !ruby/object:Gem::Requirement
@@ -1112,14 +1140,6 @@ files:
1112
1140
  - lib/mihari/schemas/configuration.rb
1113
1141
  - lib/mihari/schemas/macros.rb
1114
1142
  - lib/mihari/schemas/rule.rb
1115
- - lib/mihari/serializers/alert.rb
1116
- - lib/mihari/serializers/artifact.rb
1117
- - lib/mihari/serializers/autonomous_system.rb
1118
- - lib/mihari/serializers/dns.rb
1119
- - lib/mihari/serializers/geolocation.rb
1120
- - lib/mihari/serializers/reverse_dns.rb
1121
- - lib/mihari/serializers/tag.rb
1122
- - lib/mihari/serializers/whois.rb
1123
1143
  - lib/mihari/status.rb
1124
1144
  - lib/mihari/structs/alert.rb
1125
1145
  - lib/mihari/structs/censys.rb
@@ -1131,17 +1151,29 @@ files:
1131
1151
  - lib/mihari/type_checker.rb
1132
1152
  - lib/mihari/types.rb
1133
1153
  - lib/mihari/version.rb
1154
+ - lib/mihari/web/api.rb
1134
1155
  - lib/mihari/web/app.rb
1135
- - lib/mihari/web/controllers/alerts_controller.rb
1136
- - lib/mihari/web/controllers/analyzers_controller.rb
1137
- - lib/mihari/web/controllers/artifacts_controller.rb
1138
- - lib/mihari/web/controllers/base_controller.rb
1139
- - lib/mihari/web/controllers/command_controller.rb
1140
- - lib/mihari/web/controllers/config_controller.rb
1141
- - lib/mihari/web/controllers/ip_address_controller.rb
1142
- - lib/mihari/web/controllers/sources_controller.rb
1143
- - lib/mihari/web/controllers/tags_controller.rb
1144
- - lib/mihari/web/helpers/json.rb
1156
+ - lib/mihari/web/endpoints/alerts.rb
1157
+ - lib/mihari/web/endpoints/artifacts.rb
1158
+ - lib/mihari/web/endpoints/command.rb
1159
+ - lib/mihari/web/endpoints/configs.rb
1160
+ - lib/mihari/web/endpoints/ip_addresses.rb
1161
+ - lib/mihari/web/endpoints/sources.rb
1162
+ - lib/mihari/web/endpoints/tags.rb
1163
+ - lib/mihari/web/entities/alert.rb
1164
+ - lib/mihari/web/entities/artifact.rb
1165
+ - lib/mihari/web/entities/autonomous_system.rb
1166
+ - lib/mihari/web/entities/command.rb
1167
+ - lib/mihari/web/entities/config.rb
1168
+ - lib/mihari/web/entities/dns.rb
1169
+ - lib/mihari/web/entities/geolocation.rb
1170
+ - lib/mihari/web/entities/ip_address.rb
1171
+ - lib/mihari/web/entities/message.rb
1172
+ - lib/mihari/web/entities/reverse_dns.rb
1173
+ - lib/mihari/web/entities/source.rb
1174
+ - lib/mihari/web/entities/tag.rb
1175
+ - lib/mihari/web/entities/whois.rb
1176
+ - lib/mihari/web/public/grape.rb
1145
1177
  - lib/mihari/web/public/index.html
1146
1178
  - lib/mihari/web/public/redoc-static.html
1147
1179
  - lib/mihari/web/public/static/favicon.ico
@@ -1181,6 +1213,8 @@ files:
1181
1213
  - lib/mihari/web/public/static/js/app.365f1907.js.map
1182
1214
  - lib/mihari/web/public/static/js/app.378da3dc.js
1183
1215
  - lib/mihari/web/public/static/js/app.378da3dc.js.map
1216
+ - lib/mihari/web/public/static/js/app.6b636b62.js
1217
+ - lib/mihari/web/public/static/js/app.6b636b62.js.map
1184
1218
  - lib/mihari/web/public/static/js/app.8e3e5150.js
1185
1219
  - lib/mihari/web/public/static/js/app.8e3e5150.js.map
1186
1220
  - lib/mihari/web/public/static/js/app.a862ebca.js
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_model_serializers"
4
-
5
- module Mihari
6
- module Serializers
7
- class AlertSerializer < ActiveModel::Serializer
8
- attributes :id, :title, :description, :source, :created_at
9
-
10
- has_many :artifacts, serializer: ArtifactSerializer
11
- has_many :tags, through: :taggings, serializer: TagSerializer
12
- end
13
- end
14
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_model_serializers"
4
-
5
- module Mihari
6
- module Serializers
7
- class ArtifactSerializer < ActiveModel::Serializer
8
- attributes :id, :data, :data_type, :source
9
-
10
- has_one :autonomous_system, serializer: AutonomousSystemSerializer
11
- has_one :geolocation, serializer: GeolocationSerializer
12
- has_one :whois_record, serializer: WhoisRecordSerializer
13
-
14
- has_many :dns_records, serializer: DnsRecordSerializer
15
- has_many :reverse_dns_names, serializer: ReverseDnsNameSerializer
16
- end
17
- end
18
- end
@@ -1,9 +0,0 @@
1
- require "active_model_serializers"
2
-
3
- module Mihari
4
- module Serializers
5
- class AutonomousSystemSerializer < ActiveModel::Serializer
6
- attributes :asn
7
- end
8
- end
9
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_model_serializers"
4
-
5
- module Mihari
6
- module Serializers
7
- class DnsRecordSerializer < ActiveModel::Serializer
8
- attributes :resource, :value
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_model_serializers"
4
-
5
- module Mihari
6
- module Serializers
7
- class GeolocationSerializer < ActiveModel::Serializer
8
- attributes :country, :country_code
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_model_serializers"
4
-
5
- module Mihari
6
- module Serializers
7
- class ReverseDnsNameSerializer < ActiveModel::Serializer
8
- attributes :name
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_model_serializers"
4
-
5
- module Mihari
6
- module Serializers
7
- class TagSerializer < ActiveModel::Serializer
8
- attributes :id, :name
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_model_serializers"
4
-
5
- module Mihari
6
- module Serializers
7
- class WhoisRecordSerializer < ActiveModel::Serializer
8
- attributes :domain, :created_on, :updated_on, :expires_on, :registrar, :contacts
9
- end
10
- end
11
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mihari
4
- module Controllers
5
- class AlertsController < BaseController
6
- get "/api/alerts" do
7
- param :page, Integer
8
- param :artifact, String
9
- param :description, String
10
- param :source, String
11
- param :tag, String
12
-
13
- param :from_at, DateTime
14
- param :fromAt, DateTime
15
- param :to_at, DateTime
16
- param :toAt, DateTime
17
-
18
- param :asn, Integer
19
- param :dns_record, String
20
- param :dnsRecord, String
21
- param :reverse_dns_name, String
22
- param :reverseDnsName, String
23
-
24
- # set page & limit
25
- page = params["page"] || 1
26
- params["page"] = page.to_i
27
-
28
- limit = 10
29
- params["limit"] = 10
30
-
31
- # normalize keys
32
- params["artifact_data"] = params["artifact"]
33
- params["from_at"] = params["from_at"] || params["fromAt"]
34
- params["to_at"] = params["to_at"] || params["toAt"]
35
- params["dns_record"] = params["dns_record"] || params["dnsRecord"]
36
- params["reverse_dns_name"] = params["reverse_dns_name"] || params["reverseDnsName"]
37
-
38
- # symbolize hash keys
39
- filter = params.to_h.transform_keys(&:to_sym)
40
-
41
- search_filter_with_pagenation = Structs::Alert::SearchFilterWithPagination.new(**filter)
42
- alerts = Mihari::Alert.search(search_filter_with_pagenation)
43
- total = Mihari::Alert.count(search_filter_with_pagenation.without_pagination)
44
-
45
- json({ alerts: alerts, total: total, current_page: page, page_size: limit })
46
- end
47
-
48
- delete "/api/alerts/:id" do
49
- param :id, Integer, required: true
50
-
51
- id = params["id"].to_i
52
-
53
- begin
54
- alert = Mihari::Alert.find(id)
55
- alert.destroy
56
-
57
- status 204
58
- body ""
59
- rescue ActiveRecord::RecordNotFound
60
- status 404
61
-
62
- json({ message: "ID:#{id} is not found" })
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mihari
4
- module Controllers
5
- class AnalyzersController < BaseController
6
- post "/api/analyzer" do
7
- contract = Mihari::Schemas::AnalyzerRunContract.new
8
- result = contract.call(params)
9
-
10
- unless result.errors.empty?
11
- status 400
12
-
13
- return json(result.errors.to_h)
14
- end
15
-
16
- args = result.to_h
17
-
18
- ignore_old_artifacts = args[:ignoreOldArtifacts]
19
- ignore_threshold = args[:ignoreThreshold]
20
-
21
- analyzer = Mihari::Analyzers::Basic.new(
22
- title: args[:title],
23
- description: args[:description],
24
- source: args[:source],
25
- artifacts: args[:artifacts],
26
- tags: args[:tags]
27
- )
28
- analyzer.ignore_old_artifacts = ignore_old_artifacts
29
- analyzer.ignore_threshold = ignore_threshold
30
-
31
- analyzer.run
32
-
33
- status 201
34
- body ""
35
- end
36
- end
37
- end
38
- end
@@ -1,94 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mihari
4
- module Controllers
5
- class ArtifactsController < BaseController
6
- get "/api/artifacts/:id" do
7
- param :id, Integer, required: true
8
-
9
- id = params["id"].to_i
10
-
11
- begin
12
- artifact = Mihari::Artifact.includes(
13
- :autonomous_system,
14
- :geolocation,
15
- :whois_record,
16
- :dns_records,
17
- :reverse_dns_names
18
- ).find(id)
19
- rescue ActiveRecord::RecordNotFound
20
- status 404
21
-
22
- return json({ message: "ID:#{id} is not found" })
23
- end
24
-
25
- # TODO: improve queries
26
- alert_ids = Mihari::Artifact.where(data: artifact.data).pluck(:alert_id)
27
- tag_ids = Mihari::Tagging.where(alert_id: alert_ids).pluck(:tag_id)
28
- tag_names = Mihari::Tag.where(id: tag_ids).distinct.pluck(:name)
29
-
30
- artifact_json = Serializers::ArtifactSerializer.new(artifact).as_json
31
-
32
- # convert reverse DNS names into an array of string
33
- # also change it as nil if it is empty
34
- reverse_dns_names = (artifact_json[:reverse_dns_names] || []).filter_map { |v| v[:name] }
35
- reverse_dns_names = nil if reverse_dns_names.empty?
36
- artifact_json[:reverse_dns_names] = reverse_dns_names
37
-
38
- # change DNS records as nil if it is empty
39
- dns_records = artifact_json[:dns_records] || []
40
- dns_records = nil if dns_records.empty?
41
- artifact_json[:dns_records] = dns_records
42
-
43
- # set tags
44
- artifact_json[:tags] = tag_names
45
-
46
- json artifact_json
47
- end
48
-
49
- get "/api/artifacts/:id/enrich" do
50
- param :id, Integer, required: true
51
-
52
- id = params["id"].to_i
53
-
54
- begin
55
- artifact = Mihari::Artifact.includes(
56
- :autonomous_system,
57
- :geolocation,
58
- :whois_record,
59
- :dns_records,
60
- :reverse_dns_names
61
- ).find(id)
62
- rescue ActiveRecord::RecordNotFound
63
- status 404
64
-
65
- return json({ message: "ID:#{id} is not found" })
66
- end
67
-
68
- artifact.enrich_all
69
- artifact.save
70
-
71
- status 201
72
- body ""
73
- end
74
-
75
- delete "/api/artifacts/:id" do
76
- param :id, Integer, required: true
77
-
78
- id = params["id"].to_i
79
-
80
- begin
81
- alert = Mihari::Artifact.find(id)
82
- alert.destroy
83
-
84
- status 204
85
- body ""
86
- rescue ActiveRecord::RecordNotFound
87
- status 404
88
-
89
- json({ message: "ID:#{id} is not found" })
90
- end
91
- end
92
- end
93
- end
94
- end