Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: alert-elastic command #951

Open
YamatoSecurity opened this issue Mar 3, 2023 · 7 comments
Open

New feature: alert-elastic command #951

YamatoSecurity opened this issue Mar 3, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@YamatoSecurity
Copy link
Collaborator

New alert-elastic (sub)command:

Usage:
hayabusa.exe alert <INPUT> --sent-alerts <FILE> --host <HOST> --index <INDEX_NAME> --password <PASSWORD> [OPTIONS]

Help:
Input:
  -d, --directory <DIR>  Directory of multiple .evtx files
  -f, --file <FILE>      File path to one .evtx file
  -l, --live-analysis    Analyze the local C:\Windows\System32\winevt\Logs folder

Output:
  -s, --sent-alerts <FILE>       Save a log of sent alerts in order to not resend them (ex: sent-alerts.csv)
  -p, --profile <PROFILE>       Specify output profile

Display Settings:
      --no-color            Disable color output
  -q, --quiet               Quiet mode: do not display the launch banner
  -v, --verbose             Output verbose information

Elastic Settings:
      --strict               strict mode: do not only warn, but abort if an error occurs
  -i, --index <INDEX_NAME>   name of the elasticsearch index
  -H, --host <HOST>          server name or IP address of elasticsearch server
  -P, --port <PORT>          API port number of elasticsearch server [default: 9200]
      --proto <PROTOCOL>     protocol to be used to connect to elasticsearch [default: https] [possible values: http, https]
  -k, --insecure             omit certificate validation
  -U, --username <USERNAME>  username for elasticsearch server [default: elastic]
  -W, --password <PASSWORD>  password for authenticating at elasticsearch 

Filtering:
  -E, --EID-filter                Scan only common EIDs for faster speed (./rules/config/target_event_IDs.txt)
      --enable-deprecated-rules   Enable rules marked as deprecated
  -n, --enable-noisy-rules        Enable rules marked as noisy (./rules/config/noisy_rules.txt)
      --enable-unsupported-rules  Enable rules marked as unsupported
  -e, --exact-level <LEVEL>       Scan for only specific levels (informational, low, medium, high, critical)
      --exclude-status <STATUS>   Ignore rules according to status (ex: experimental) (ex: stable,test)
  -m, --min-level <LEVEL>         Minimum level for rules (default: informational)
      --timeline-end <DATE>       End time of the event logs to load (ex: "2022-02-22 23:59:59 +09:00")
      --timeline-start <DATE>     Start time of the event logs to load (ex: "2020-02-22 00:00:00 +09:00")

General Options:
  -Q, --quiet-errors                     Quiet errors mode: do not save error logs
  -r, --rules <DIR/FILE>                 Specify a custom rule directory or file (default: ./rules)
  -c, --rules-config <DIR>               Specify custom rule config directory (default: ./rules/config)
  -t, --threads <NUMBER>                 Number of threads (default: optimal number for performance)

Time Format:
      --European-time     Output timestamp in European time format (ex: 22-02-2022 22:00:00.123 +02:00)
      --ISO-8601          Output timestamp in ISO-8601 format (ex: 2022-02-22T10:10:10.1234567Z) (Always UTC)
      --RFC-2822          Output timestamp in RFC 2822 format (ex: Fri, 22 Feb 2022 22:00:00 -0600)
      --RFC-3339          Output timestamp in RFC 3339 format (ex: 2022-02-22 22:00:00.123456-06:00)
      --US-military-time  Output timestamp in US military time format (ex: 02-22-2022 22:00:00.123 -06:00)
      --US-time           Output timestamp in US time format (ex: 02-22-2022 10:00:00.123 PM -06:00)
  -U, --UTC               Output time in UTC format (default: local time)

When using alert-xxxx, hayabusa will not display alerts to the screen like with csv-timeline. Instead, it will display messages about sending the logs. Example:

Sending 300 new alerts to https://www.elastic.co/hogehoge:4040
Error: could not connect
0 alerts were already sent.
Sending 300 new alerts to https://www.elastic.co/hogehoge:4040
Alerts sent successfully
200 alerts were already sent.
Sending 100 new alerts to https://www.elastic.co/hogehoge:4040
Alerts sent successfully

etc...

If the alerts are sent successfully then the following information is written to the sent-alerts.csv file. (If the file already exists, then the file is updated)
Timestamp (Original ISO-8601 timestamp), Rule ID, Rule Title
Before Hayabusa sends the alerts, it checks the Timestamp and Rule ID in this file. If the timestamp and rule ID match, then we assume that the alert was previously sent and the alert does not get sent again.
The Rule Title is not needed for checking as the title may be changed over time, however, I want to save it to help out when debugging.

The following rust crates look good to use:

@hitenkoku Do you think you can do this issue?

@YamatoSecurity YamatoSecurity added the enhancement New feature or request label Mar 3, 2023
@hitenkoku
Copy link
Collaborator

@YamatoSecurity Thank you for raising the issue.
I basically don't see the problem, but I am concerned that the size of the csv file is getting bigger and bigger each time I do it.

For example, how about writing only the latest timestamp in the File and deeming anything before that time to have been sent?

@YamatoSecurity
Copy link
Collaborator Author

@hitenkoku Thank you for your comment! Indeed, the CSV file will get bigger and bigger over time but should not double the log size.
What about keeping the file compressed? That will reduce the file by 10x or more. Maybe we can use something like rust-brotli or brotlic ?

The problem with just writing the latest timestamp and scanning recent logs is that Hayabusa won't be able to find past incidents (perform threat hunting) which is the main goal. It would just become an inferior host IDS which I couldn't really recommend to use.

@YamatoSecurity
Copy link
Collaborator Author

How about we also not include the Rule Title in the CSV file which will save space. I thought it might be useful for debugging but now that I think about it we probably do not need it. If it is just timestamps and rule IDs, the file should not get too big. And if we compress it, it should become pretty small.

@YamatoSecurity YamatoSecurity added this to the v2.3.0 milestone Mar 4, 2023
@hitenkoku
Copy link
Collaborator

Thanks for the comment.

I think Timestamp and Rule ID are sufficient for the contents of the csv.

I will try to create one.

@hitenkoku hitenkoku self-assigned this Mar 4, 2023
@hitenkoku
Copy link
Collaborator

@YamatoSecurity Would it be correct to sort the following config in alphabetical order of the long option?

Elastic Settings:
      --strict               strict mode: do not only warn, but abort if an error occurs
  -i, --index <INDEX_NAME>   name of the elasticsearch index
  -H, --host <HOST>          server name or IP address of elasticsearch server
  -P, --port <PORT>          API port number of elasticsearch server [default: 9200]
      --proto <PROTOCOL>     protocol to be used to connect to elasticsearch [default: https] [possible values: http, https]
  -k, --insecure             omit certificate validation
  -U, --username <USERNAME>  username for elasticsearch server [default: elastic]
  -W, --password <PASSWORD>  password for authenticating at elasticsearch 

@YamatoSecurity
Copy link
Collaborator Author

@hitenkoku
Yes, let's organize this in alphabetical order of the long options:

Elastic Settings:
  -H, --host <HOST>          server name or IP address of elasticsearch server
  -i, --index <INDEX_NAME>   name of the elasticsearch index
  -k, --insecure             omit certificate validation
  -W, --password <PASSWORD>  password for authenticating at elasticsearch 
  -P, --port <PORT>          API port number of elasticsearch server [default: 9200]
      --proto <PROTOCOL>     protocol to be used to connect to elasticsearch [default: https] [possible values: http, https]
      --strict               strict mode: do not only warn, but abort if an error occurs
  -U, --username <USERNAME>  username for elasticsearch server [default: elastic]

@YamatoSecurity YamatoSecurity modified the milestones: v2.3.0, v2.4.0 Mar 15, 2023
@YamatoSecurity
Copy link
Collaborator Author

This is going to take a while to test so I changed the milestone to 2.4.0. Maybe release next month in April?

@hitenkoku hitenkoku added this to In progress in hayabusa development board Apr 2, 2023
@YamatoSecurity YamatoSecurity modified the milestones: v2.4.0, v2.5.0 Apr 8, 2023
@YamatoSecurity YamatoSecurity modified the milestones: v2.5.0, v2.6., v2.6.0 May 3, 2023
@YamatoSecurity YamatoSecurity modified the milestones: v2.6.0, v2.7.0 May 30, 2023
@hitenkoku hitenkoku modified the milestones: v2.7.0, v2.8.0 Jul 2, 2023
@YamatoSecurity YamatoSecurity modified the milestones: v2.8.0, v2.9.0 Aug 15, 2023
@YamatoSecurity YamatoSecurity modified the milestones: v2.9.0, v2.10.0 Sep 14, 2023
@YamatoSecurity YamatoSecurity removed this from the v2.10.0 milestone Sep 29, 2023
@YamatoSecurity YamatoSecurity added this to the v2.11.0 milestone Sep 29, 2023
@YamatoSecurity YamatoSecurity modified the milestones: v2.11.0, v2.13.0 Dec 13, 2023
@YamatoSecurity YamatoSecurity modified the milestones: v2.13.0, v2.14.0 Jan 23, 2024
@YamatoSecurity YamatoSecurity modified the milestones: v2.14.0, v2.15.0 Mar 4, 2024
@YamatoSecurity YamatoSecurity modified the milestones: v2.15.0, v2.16.0 Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants