-
Notifications
You must be signed in to change notification settings - Fork 1
Workspace adaptation #62
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8646b09
Adding data to workspace and change a log to debug mode
ipmach 6bf881d
update logs.json
ipmach 6e627c1
add data.json in documentation
ipmach 56c5297
add basic usage - parser tutorial
ipmach 968661f
add random detector in basic usage
ipmach 9646242
minor change
ipmach f3c4860
minor change
ipmach 063b5a2
change relative paths
ipmach 9359c82
correct small bug in method name
ipmach 20666c0
correct unittest and update readme
ipmach 33f7983
Add links to official documentations
ipmach ff7f1d8
update docs and remove a print statement
ipmach e77c7aa
Update docs/basic_usage.md
viktorbeck98 d207fbb
Update docs/basic_usage.md
viktorbeck98 4406442
Update docs/basic_usage.md
viktorbeck98 8876fc8
Update src/tools/workspace/utils.py
viktorbeck98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,9 +1,155 @@ | ||
|
|
||
| # Getting started: Basic usage | ||
|
|
||
| Basic usage of the DetectMate Library. | ||
| In this section, we will show different examples of the basic usage of the DetectMate Library. | ||
|
|
||
| ## Parser | ||
|
|
||
| In this example, we will use the [`MatcherParser`](parsers/template_matcher.md) to parse audit data from the [AIT Log Data Set V2.0](https://zenodo.org/records/5789064). The code loads the logs, parse them and save the input and output in json files using [`from_to`](helper/from_to.md) module. | ||
|
|
||
| ```python | ||
| from detectmatelibrary.parsers.template_matcher import MatcherParser | ||
| from detectmatelibrary.helper.from_to import From, To | ||
|
|
||
|
|
||
| config_dict = { | ||
| "parsers": { | ||
| "MatcherParser": { | ||
| "auto_config": True, | ||
| "method_type": "matcher_parser", | ||
| "path_templates": "ait_audit.txt", | ||
| "log_format": r'type=<Type> msg=audit\(<Time>:<Serial>\): <Content>' | ||
| } | ||
| } | ||
| } | ||
| parser = MatcherParser(name="MatcherParser", config=config_dict) | ||
|
|
||
|
|
||
| for i, log in enumerate(From.log(parser, "audit.log", do_process=False)): | ||
| To.json(log, "logs.json") | ||
|
|
||
| parsed_log = parser.process(log) | ||
| To.json(parsed_log, "parsed_log.json") | ||
|
|
||
| ``` | ||
|
|
||
| The logs will be saved in `logs.json` in this format: | ||
|
|
||
| ```json | ||
| { | ||
| "0": { | ||
| "log": "type=USER_ACCT msg=audit(1642723741.072:375): pid=10125 uid=0 auid=4294967295 ses=4294967295 msg='op=PAM:accounting acct=\"root\" exe=\"/usr/sbin/cron\" hostname=? addr=? terminal=cron res=success'", | ||
| "__version__": "1.0.0", | ||
| "hostname": "", | ||
| "logSource": "", | ||
| "logID": "0" | ||
| }, | ||
| ... | ||
| } | ||
| ``` | ||
| And the `parsed_log.json`: | ||
|
|
||
| ```json | ||
| { | ||
| "0": { | ||
| "parserID": "MatcherParser", | ||
| "parsedLogID": "10", | ||
| "logID": "0", | ||
| "parsedTimestamp": 1772027171, | ||
| "logFormatVariables": { | ||
| "Type": "USER_ACCT", | ||
| "Serial": "375", | ||
| "Time": "1642723741.072", | ||
| "Content": "pid=10125 uid=0 auid=4294967295 ses=4294967295 msg='op=PAM:accounting acct=\"root\" exe=\"/usr/sbin/cron\" hostname=? addr=? terminal=cron res=success'" | ||
| }, | ||
| "__version__": "1.0.0", | ||
| "receivedTimestamp": 1772027171, | ||
| "variables": [ | ||
| "10125", | ||
| "0", | ||
| "4294967295", | ||
| "4294967295", | ||
| "PAM:accounting", | ||
| "\"root\"", | ||
| "\"/usr/sbin/cron\"", | ||
| "?", | ||
| "?", | ||
| "cron", | ||
| "success" | ||
| ], | ||
| "log": "type=USER_ACCT msg=audit(1642723741.072:375): pid=10125 uid=0 auid=4294967295 ses=4294967295 msg='op=PAM:accounting acct=\"root\" exe=\"/usr/sbin/cron\" hostname=? addr=? terminal=cron res=success'", | ||
| "parserType": "matcher_parser", | ||
| "EventID": 0, | ||
| "template": "pid=<*> uid=<*> auid=<*> ses=<*> msg='op=<*> acct=<*> exe=<*> hostname=<*> addr=<*> terminal=<*> res=<*>'" | ||
| }, | ||
| ... | ||
| } | ||
| ``` | ||
|
|
||
| ## Detector | ||
|
|
||
| In this example, we will use the [`RandomDetector`](detectors/random_detector.md) with the parsed logs from the previous example. | ||
|
|
||
| ```python | ||
| from detectmatelibrary.parsers.template_matcher import MatcherParser | ||
| from detectmatelibrary.helper.from_to import From, To, FromTo | ||
|
|
||
| config_dict = { | ||
| "detectors": { | ||
| "RandomDetector": { | ||
| "auto_config": False, | ||
| "method_type": "random_detector", | ||
| "params": {}, | ||
| "events": { | ||
| 1: { | ||
| "test": { | ||
| "params": {}, | ||
| "variables": [{ | ||
| "pos": 0, | ||
| "name": "process", | ||
| "params": { | ||
| "threshold": 0. | ||
| } | ||
| }] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| detector = RandomDetector(name="RandomDetector", config=config_dict) | ||
|
|
||
| for alert in FromTo.json2json(detector, "parsed_log.json", "alerts.json"): | ||
| if alert is not None: | ||
| print("Anomaly detected!") | ||
| ``` | ||
|
|
||
| The alerts will be saved in `alerts.json` in this format: | ||
|
|
||
| ```json | ||
| { | ||
| "0": { | ||
| "extractedTimestamps": [ | ||
| 1642723752 | ||
| ], | ||
| "receivedTimestamp": 1772032073, | ||
| "score": 1.0, | ||
| "detectionTimestamp": 1772032073, | ||
| "alertID": "10", | ||
| "detectorType": "random_detector", | ||
| "detectorID": "RandomDetector", | ||
| "description": "", | ||
| "__version__": "1.0.0", | ||
| "logIDs": [ | ||
| "6" | ||
| ], | ||
| "alertsObtain": { | ||
| "process": "1.0" | ||
| } | ||
| }, | ||
| ... | ||
| } | ||
| ``` | ||
|
|
||
|
|
||
| Go back to [Index](index.md), to previous step: [Installation](installation.md) or to next step: [Create new component](create_components.md). |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.