mihari 5.4.4 → 5.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -25
  3. data/docs/alternatives.md +5 -0
  4. data/docs/analyzers/binaryedge.md +21 -0
  5. data/docs/analyzers/censys.md +23 -0
  6. data/docs/analyzers/circl.md +29 -0
  7. data/docs/analyzers/crtsh.md +25 -0
  8. data/docs/analyzers/dnstwister.md +23 -0
  9. data/docs/analyzers/feed.md +49 -0
  10. data/docs/analyzers/greynoise.md +21 -0
  11. data/docs/analyzers/hunterhow.md +25 -0
  12. data/docs/analyzers/index.md +79 -0
  13. data/docs/analyzers/onyphe.md +21 -0
  14. data/docs/analyzers/otx.md +23 -0
  15. data/docs/analyzers/passivetotal.md +36 -0
  16. data/docs/analyzers/pulsedive.md +23 -0
  17. data/docs/analyzers/securitytrails.md +32 -0
  18. data/docs/analyzers/shodan.md +21 -0
  19. data/docs/analyzers/urlscan.md +23 -0
  20. data/docs/analyzers/virustotal.md +34 -0
  21. data/docs/analyzers/virustotal_intelligence.md +22 -0
  22. data/docs/analyzers/zoomeye.md +25 -0
  23. data/docs/configuration.md +35 -0
  24. data/docs/emitters/database.md +22 -0
  25. data/docs/emitters/hive.md +18 -0
  26. data/docs/emitters/index.md +7 -0
  27. data/docs/emitters/misp.md +16 -0
  28. data/docs/emitters/slack.md +16 -0
  29. data/docs/emitters/webhook.md +63 -0
  30. data/docs/enrichers/google_public_dns.md +19 -0
  31. data/docs/enrichers/index.md +6 -0
  32. data/docs/enrichers/ipinfo.md +19 -0
  33. data/docs/enrichers/shodan.md +22 -0
  34. data/docs/enrichers/whois.md +17 -0
  35. data/docs/github_actions.md +43 -0
  36. data/docs/index.md +13 -0
  37. data/docs/installation.md +31 -0
  38. data/docs/requirements.md +20 -0
  39. data/docs/rule.md +165 -0
  40. data/docs/tags.md +3 -0
  41. data/docs/usage.md +100 -0
  42. data/frontend/package-lock.json +232 -229
  43. data/frontend/package.json +7 -7
  44. data/lib/mihari/version.rb +1 -1
  45. data/lib/mihari/web/public/assets/{index-ef33a6cd.js → index-0a5a47bf.js} +43 -41
  46. data/lib/mihari/web/public/index.html +1 -1
  47. data/mihari.gemspec +1 -1
  48. data/mkdocs.yml +35 -0
  49. data/requirements.txt +2 -0
  50. metadata +45 -4
@@ -0,0 +1,22 @@
1
+ # Database
2
+
3
+ This emitter stores data in a database. This emitter uses SQLite3 by default but you can change to use MySQL or PostgreSQL. The database is a primary database of Mihari. Each data generated by Mihari is stored in the database. You can view the data via the built-in web app.
4
+
5
+ Mihari loads a database URL via environment variable `DATABASE_URL`. Defaults to `sqlite3:///mihari.db"` (SQLite3).
6
+
7
+ If you want to use MySQL or PostgreSQL, please set a database URL for that.
8
+
9
+ - MySQL: `mysql2://username:password@host:3306/database` (+ `gem install mysql2`)
10
+ - PostgreSQL: `postgres://username:password@host:5432/database` (+ `gem install pg`)
11
+
12
+ ```yaml
13
+ emitter: database
14
+ ```
15
+
16
+ !!! note
17
+
18
+ You have to initialize the database by `mihari db migrate`.
19
+
20
+ ## ER Diagram
21
+
22
+ ![](https://imgur.com/krhoSgh.png)
@@ -0,0 +1,18 @@
1
+ # TheHive
2
+
3
+ - [https://thehive-project.org/](https://thehive-project.org/)
4
+
5
+ This emitter creates an alert on TheHive. TheHive v4 & v5 are supported.
6
+
7
+ ```yaml
8
+ emitter: the_hive
9
+ url: ...
10
+ api_key: ...
11
+ api_version: ...
12
+ ```
13
+
14
+ | Name | Type | Required? | Default | Desc. |
15
+ | ----------- | ------ | --------- | -------------------------- | ------------------- |
16
+ | url | String | No | ENV[”THEHIVE_URL”] | TheHive API URL |
17
+ | api_key | String | No | ENV[”THEHIVE_API_KEY”] | TheHive API key |
18
+ | api_version | String | No | ENV[”THEHIVE_API_VERSION”] | TheHive API version |
@@ -0,0 +1,7 @@
1
+ # Emitters
2
+
3
+ - [Database](database.md)
4
+ - [TheHive](hive.md)
5
+ - [MISP](misp.md)
6
+ - [Slack](slack.md)
7
+ - [Webhook](webhook.md)
@@ -0,0 +1,16 @@
1
+ # MISP
2
+
3
+ - [https://www.misp-project.org/](https://www.misp-project.org/)
4
+
5
+ This emitter creates an event on MISP based on an alert.
6
+
7
+ ```yaml
8
+ emitter: misp
9
+ url: ...
10
+ api_key: ...
11
+ ```
12
+
13
+ | Name | Type | Required? | Default | Desc. |
14
+ | ------- | ------ | --------- | ------------------- | ------------ |
15
+ | url | String | No | ENV[”MISP_URL”] | MISP API URL |
16
+ | api_key | String | No | ENV[”MISP_API_KEY”] | MISP API key |
@@ -0,0 +1,16 @@
1
+ # Slack
2
+
3
+ - [https://slack.com/](https://slack.com/intl/ja-jp/)
4
+
5
+ This emitter post a message to Slack via incoming webhook.
6
+
7
+ ```yaml
8
+ emitter: slack
9
+ webhook_url: ...
10
+ channel: ...
11
+ ```
12
+
13
+ | Name | Type | Required? | Default | Desc. |
14
+ | ----------- | ------ | --------- | ------------------------------- | ----------------- |
15
+ | webhook_url | String | No | ENV[SLACK_WEBHOOK_URL] | Slack webhook URL |
16
+ | channel | String | No | ENV[SLACK_CHANNEL] / `#general` | Slack channel |
@@ -0,0 +1,63 @@
1
+ # Webhook
2
+
3
+ This emitter creates an HTTP request payload based on the specified conditions.
4
+
5
+ ```yaml
6
+ emitter: webhook
7
+ url: ...
8
+ method: ...
9
+ headers: ...
10
+ template: ...
11
+ ```
12
+
13
+ | Name | Type | Required? | Default | Desc. |
14
+ | -------- | ------ | --------- | ------- | ---------------------------------------------------- |
15
+ | url | String | Yes | | URL |
16
+ | method | String | No | POST | HTTP request method (GET or POST) |
17
+ | headers | Hash | No | | HTTP request headers |
18
+ | template | String | No | | ERB template to customize the payload in JSON format |
19
+
20
+ You can customize the payload by using **template**.
21
+
22
+ A template is an ERB template. It should generate a valid JSON.
23
+
24
+ - [https://github.com/ruby/erb](https://github.com/ruby/erb)
25
+
26
+ You can use the following variables to build the JSON.
27
+
28
+ | Name | Type | Default | Desc. |
29
+ | ----------- | ----------------------- | ------- | ------------ |
30
+ | title | String | | |
31
+ | description | String | | |
32
+ | source | String | | ID of a rule |
33
+ | tags | Array<String> | [] | |
34
+ | artifacts | Array<Mihari::Artifact> | | |
35
+
36
+ ## Example
37
+
38
+ **ThreatFox**
39
+
40
+ ```yaml
41
+ - emitter: webhook
42
+ url: https://threatfox-api.abuse.ch/api/v1/
43
+ headers:
44
+ api-key: YOUR_API_KEY
45
+ template: threatfox.erb
46
+ ```
47
+
48
+ ```ruby
49
+ {
50
+ "query": "submit_ioc",
51
+ "threat_type": "payload_delivery",
52
+ "ioc_type": "ip:port",
53
+ "malware": "foobar",
54
+ "confidence_level": 100,
55
+ "anonymous": 0,
56
+ "iocs": [
57
+ <% @artifacts.select { |artifact| artifact.data_type == "ip" }.each_with_index do |artifact, idx| %>
58
+ "<%= artifact.data %>:80"
59
+ <%= ',' if idx < (@artifacts.length - 1) %>
60
+ <% end %>
61
+ ]
62
+ }
63
+ ```
@@ -0,0 +1,19 @@
1
+ ---
2
+ tags:
3
+ - DNS record
4
+ ---
5
+
6
+ # Google Public DNS
7
+
8
+ - [https://developers.google.com/speed/public-dns](https://developers.google.com/speed/public-dns)
9
+
10
+ This enricher uses Google Public DNS to enrich an URL and domain artifact.
11
+
12
+ ```yaml
13
+ enricher: google_public_dns
14
+ ```
15
+
16
+ ## Supported Artifacts
17
+
18
+ - URL
19
+ - Domain
@@ -0,0 +1,6 @@
1
+ # Enrichers
2
+
3
+ - [Google Public DNS](google_public_dns.md)
4
+ - [IPInfo](ipinfo.md)
5
+ - [Shodan](shodan.md)
6
+ - [Whois](whois.md)
@@ -0,0 +1,19 @@
1
+ ---
2
+ tags:
3
+ - Autonomous system
4
+ - Geolocation
5
+ ---
6
+
7
+ # ipinfo.io
8
+
9
+ - [https://ipinfo.io/](https://ipinfo.io/)
10
+
11
+ This enricher uses ipinfo.io API to enrich an IP artifact.
12
+
13
+ ```yaml
14
+ enricher: ipinfo
15
+ ```
16
+
17
+ ## Supported Artifacts
18
+
19
+ - IP address
@@ -0,0 +1,22 @@
1
+ ---
2
+ tags:
3
+ - Port
4
+ - CPE
5
+ - DNS record
6
+ ---
7
+
8
+ # Shodan
9
+
10
+ - [https://www.shodan.io/](https://www.shodan.io/dashboard)
11
+
12
+ This enricher uses Shodan InternetDB API to enrich an artifact.
13
+
14
+ [https://internetdb.shodan.io/](https://internetdb.shodan.io/)
15
+
16
+ ```yaml
17
+ enricher: shodan
18
+ ```
19
+
20
+ ## Supported Artifacts
21
+
22
+ - IP address
@@ -0,0 +1,17 @@
1
+ ---
2
+ tags:
3
+ - Whois
4
+ ---
5
+
6
+ # Whois
7
+
8
+ This enricher uses “whois” command to enrich an artifact.
9
+
10
+ ```yaml
11
+ enricher: whois
12
+ ```
13
+
14
+ ## Supported Artifacts
15
+
16
+ - URL
17
+ - Domain
@@ -0,0 +1,43 @@
1
+ # GitHub Actions
2
+
3
+ GitHub Actions is a good way to run Mihari searches continuously.
4
+
5
+ The following is an example of a GitHub Actions workflow to run Mihari.
6
+
7
+ ```yaml
8
+ name: Mihari searches
9
+
10
+ on:
11
+ workflow_dispatch:
12
+
13
+ jobs:
14
+ build:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - name: Install dependencies
19
+ run: sudo apt-get -yqq install sqlite3 libsqlite3-dev
20
+ - name: Set up Ruby 3.2
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: "3.2"
24
+ bundler-cache: true
25
+ - name: Run Mihari
26
+ run: |
27
+ mihari search /path/to/rule.yml
28
+ ```
29
+
30
+ !!! tip
31
+
32
+ You need to install `libpq-dev` for PostgreSQL, `libmysqlclient-dev` for MySQL.
33
+
34
+ This example assumes that you have `Gemfile` in your repository.
35
+
36
+ ```ruby
37
+ source "https://rubygems.org"
38
+
39
+ gem "pg" # if you use PostgresSQL
40
+ gem "mysql2" # if you use MySQL
41
+
42
+ gem "mihari"
43
+ ```
data/docs/index.md ADDED
@@ -0,0 +1,13 @@
1
+ # Mihari
2
+
3
+ A query aggregator for OSINT based threat hunting.
4
+
5
+ Mihari can aggregate multiple searches across multiple services in a single rule & persist findings in a database.
6
+
7
+ - [Requirements](./requirements.md)
8
+ - [Installation](./installation.md)
9
+ - [How to Write a Rule](./rule.md)
10
+ - [Usage](./usage.md)
11
+ - [Configuration](./configuration.md)
12
+ - [GitHub Actions](./github_actions.md)
13
+ - [Alternatives](./alternatives.md)
@@ -0,0 +1,31 @@
1
+ # Installation
2
+
3
+ ## Ruby Gem
4
+
5
+ Mihari is packaged as a Ruby Gem.
6
+
7
+ ```bash
8
+ gem install mihari
9
+ ```
10
+
11
+ Mihari uses SQLite3 as a primary database by default. Thus a gem for SQLite (`sqlite3`) is installed by default.
12
+
13
+ If you want to use MySQL or PostgreSQL instead of SQLite3, please install a gem for that by yourself.
14
+
15
+ **MySQL**
16
+
17
+ ```bash
18
+ gem install mysql2
19
+ ```
20
+
21
+ **PostgreSQL**
22
+
23
+ ```bash
24
+ gem install pg
25
+ ```
26
+
27
+ # Docker
28
+
29
+ You can built the Docker image by yourself.
30
+
31
+ `Dockerfile` is available at [https://github.com/ninoseki/mihari/tree/master/docker](https://github.com/ninoseki/mihari/tree/master/docker).
@@ -0,0 +1,20 @@
1
+ # Requirements
2
+
3
+ - Runtime:
4
+ - Ruby 2.7+ / 3.0+ (tested with 2.7, 3.0, 3.1 and 3.2)
5
+ - Database:
6
+ - SQLite3, PostgreSQL and MySQL
7
+ - Others:
8
+ - MISP
9
+ - TheHive
10
+
11
+ | Name | Supported versions |
12
+ | ---------- | ----------------------- |
13
+ | Ruby | v2.7, v3.0, v3.1 & v3.2 |
14
+ | PostgreSQL | v15 |
15
+ | SQLite | v3 |
16
+ | MySQL | v8 |
17
+ | MISP | v2.4 |
18
+ | TheHive | v3 & v4 |
19
+
20
+ You need to have a database to persistent the data. See [Database](./emitters/database.md) for details.
data/docs/rule.md ADDED
@@ -0,0 +1,165 @@
1
+ # How to Write a Rule
2
+
3
+ Mihari has [Sigma](https://github.com/SigmaHQ/sigma) like format to describe a set of search queries to express a rule.
4
+
5
+ Mihari has three main components to compose a rule.
6
+
7
+ ![](https://imgur.com/BBT99BG.png)
8
+
9
+ - Analyzers/Queries: a list of queries (analyzers) that builds a list of artifacts
10
+ - Enrichers: a list of enrichers that enriches a list of artifacts
11
+ - Emitters: a list of emitters that emits a list of artifacts as an alert
12
+
13
+ An artifact has five types:
14
+
15
+ - IP address (`ip`)
16
+ - Domain (`domain`)
17
+ - URL (`url`)
18
+ - Mail (`mail`)
19
+ - Hash (`hash`)
20
+
21
+ An alert can have multiple artifacts bundled by a rule.
22
+
23
+ Let's break down the following example:
24
+
25
+ ```yaml
26
+ id: c7f6968e-dbe1-4612-b0bb-8407a4fe05df
27
+ title: Example
28
+ description: Mihari rule example
29
+ created_on: "2023-01-01"
30
+ updated_on: "2023-01-02"
31
+ author: ninoseki
32
+ references:
33
+ - https://github.com/ninoseki/mihari
34
+ related:
35
+ - 6254bb74-5e5d-42ad-bc1e-231da0293b0f
36
+ tags:
37
+ - foo
38
+ - bar
39
+ queries:
40
+ - analyzer: shodan
41
+ query: ip:1.1.1.1
42
+ - analyzer: censys
43
+ query: ip:8.8.8.8
44
+ enrichers:
45
+ - enricher: whois
46
+ - enricher: ipinfo
47
+ - enricher: shodan
48
+ - enricher: google_public_dns
49
+ emitters:
50
+ - emitter: database
51
+ - emitter: misp
52
+ - emitter: slack
53
+ - emitter: the_hive
54
+ data_types:
55
+ - hash
56
+ - ip
57
+ - domain
58
+ - url
59
+ - mail
60
+ falsepositives: []
61
+ ```
62
+
63
+ ## ID
64
+
65
+ `id` is an unique ID of a rule. UUID v4 is recommended.
66
+
67
+ ## Title
68
+
69
+ `title` is a title of a rule.
70
+
71
+ ## Description
72
+
73
+ `description` is a short description of a rule.
74
+
75
+ ## Created/Updated On
76
+
77
+ `created_on` is a date of a rule creation. Optional.
78
+ Also a rule can have `updated_on` that is a date of a rule modification. Optional.
79
+
80
+ ## Tags
81
+
82
+ `tags` is a list of tags of a rule.
83
+
84
+ ## Author
85
+
86
+ `author` is an author of a rule. Optional.
87
+
88
+ ## References
89
+
90
+ `references` is a list of a references of a rule. Optional.
91
+
92
+ ## Related
93
+
94
+ `related` is a list of related rule IDs. Optional.
95
+
96
+ ## Queries
97
+
98
+ `queries` is a list of queries/analyzers.
99
+ See [Analyzers](./analyzers/index.md) to know details of each analyzer.
100
+
101
+ ## Enrichers
102
+
103
+ `enrichers` is a list of enrichers.
104
+ See [Enrichers](./enrichers/index.md) to know details of each enricher.
105
+
106
+ Defaults to:
107
+
108
+ - `google_public_dns`
109
+ - `ipinfo`
110
+ - `shodan`
111
+ - `whois`
112
+
113
+ ## Emitters
114
+
115
+ `emitters` is a list of emitters.
116
+ See [Emitters](./emitters/index.md) to know details of each emitter.
117
+
118
+ Defaults to:
119
+
120
+ - `database`
121
+ - `misp`
122
+ - `slack`
123
+ - `the_hive`
124
+
125
+ ## Data Types
126
+
127
+ `data_types` is a list of data (artifact) types to allow by a rule. Types not defined in here will be automatically rejected.
128
+
129
+ Defaults to:
130
+
131
+ - `ip`
132
+ - `domain`
133
+ - `url`
134
+ - `mail`
135
+ - `hash`
136
+
137
+ ## False positives
138
+
139
+ `falsepositives` is a list of false positive values. A string or regexp can be used in here.
140
+
141
+ ## Artifact TTL
142
+
143
+ `artifact_ttl` (alias: `artifact_lifetime`) is an integer value of artifact TTL (Time-To-Live) in seconds.
144
+
145
+ Mihari rejects a same artifact in a same rule in general.
146
+
147
+ But you may want to get a same artifact after a certain period of time. `artifact_ttl` is for that. If a rule finds a same artifact after `artifact_ttl` seconds have been passed, that artifact will be included in an alert.
148
+
149
+ ## How to Run a Rule
150
+
151
+ Once you finish writing a rule, you can run the rule by `mihari` CLI.
152
+
153
+ !!! note
154
+
155
+ You have to initialize the database by `mihari db migrate` if you haven't already done.
156
+
157
+ ```bash
158
+ mihari search /path/to/rule.yml
159
+ ```
160
+
161
+ The command outputs an alert to the standard output. Also you can confirm it with a built-in web app.
162
+
163
+ ```bash
164
+ mihari web
165
+ ```
data/docs/tags.md ADDED
@@ -0,0 +1,3 @@
1
+ # Tags
2
+
3
+ [TAGS]
data/docs/usage.md ADDED
@@ -0,0 +1,100 @@
1
+ # Usage
2
+
3
+ ```bash
4
+ $ mihari
5
+ Commands:
6
+ mihari --version, -v # Print the version
7
+ mihari alert # Sub commands for alert
8
+ mihari db # Sub commands for DB
9
+ mihari help [COMMAND] # Describe available commands or one specific command
10
+ mihari rule # Sub commands for rule
11
+ mihari search [PATH_OR_ID] # Search by a rule
12
+ mihari web # Launch the web app
13
+ ```
14
+
15
+ ## `mihari db`
16
+
17
+ This sub command is for initializing/migrating database.
18
+
19
+ ```bash
20
+ mihari db migrate
21
+ ```
22
+
23
+ See [Database](./emitters/database.md) for detailed database configuration.
24
+
25
+ ## `mihari rule`
26
+
27
+ This sub command is for validating/initializing a rule.
28
+
29
+ ```bash
30
+ mihari rule init /path/to/rule.yml
31
+ mihari rule validate /path/to/rule.yml
32
+ ```
33
+
34
+ ## `mihari search`
35
+
36
+ This is a command for running a rule.
37
+
38
+ ```bash
39
+ mihari search /path/to/rule.yml
40
+ ```
41
+
42
+ Mihari asks whether really you want to update a rule if there is a diff by default.
43
+
44
+ ```bash
45
+ $ mihari search /path/to/rule.yml
46
+ There is a diff in the rule (6254bb74-5e5d-42ad-bc1e-231da0293b0f). Are you sure you want to overwrite the rule? (y/n)
47
+ ```
48
+
49
+ It can be suppressed by providing `-f`.
50
+
51
+ ```bash
52
+ mihari search -f /path/to/rule.yml
53
+ ```
54
+
55
+ ## `mihari add`
56
+
57
+ You may want to add an alert manually. You can do that by this command.
58
+
59
+ ```bash
60
+ mihari alert /path/to/alert.yml
61
+ ```
62
+
63
+ ## `mihari web`
64
+
65
+ This command is for launching the built-in web app.
66
+
67
+ ```bash
68
+ mihari web
69
+ ```
70
+
71
+ It stars the app with `localhost:9292`. You can configure it by providing options.
72
+
73
+ ```bash
74
+ $ mihari help web
75
+ Usage:
76
+ mihari web
77
+
78
+ Options:
79
+ [--port=N] # Hostname to listen on
80
+ # Default: 9292
81
+ [--host=HOST] # Port to listen on
82
+ # Default: localhost
83
+ [--threads=THREADS] # min:max threads to use
84
+ # Default: 0:5
85
+ [--verbose], [--no-verbose] # Report each request
86
+ # Default: true
87
+ [--worker-timeout=N] # Worker timeout value (in seconds)
88
+ # Default: 60
89
+ [--hide-config-values], [--no-hide-config-values] # Whether to hide config values or not
90
+ # Default: true
91
+ [--open], [--no-open] # Whether to open the app in browser or not
92
+ # Default: true
93
+ [--rack-env=RACK_ENV] # Rack environment
94
+ # Default: production
95
+ ```
96
+
97
+ !!! tip
98
+
99
+ The built-in web app offers API to interact with Mihari.
100
+ The API docs are available on `/redoc-static.html`