-
Notifications
You must be signed in to change notification settings - Fork 96
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
User Agent Analysis Integration #21
Open
tmack-etg
wants to merge
10
commits into
ibmresilient:master
Choose a base branch
from
tmack-etg:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2e723a4
Adding fn_useragentanalysis function
tmack-etg b767c07
Updating config file
tmack-etg b1740f3
Creating default config
tmack-etg 00ac7c6
Fixing config to be left aligned
tmack-etg 6aaef14
* [DONE] UPDATE README
tmack-etg 6707cdf
* Fixed up config file
tmack-etg 814622c
code cleanup for app exchange submission
MarkScherfling 5154f07
setup.py changes
MarkScherfling 22bca7b
setup.py changes
MarkScherfling 96a6acf
workflow changes
MarkScherfling 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 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include README.md | ||
include fn_useragentanalysis/util/* | ||
include fn_useragentanalysis/LICENSE | ||
include fn_useragentanalysis/doc/* |
This file contains 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
### User Agent Analysis | ||
User agent analysis allows for the data enrichment on user agent strings found in web and firewall logs. These entries can provide clues as to potential attempted malicious access and what follow on steps are needed to restrict access. | ||
|
||
Updates for config file | ||
[fn_useragentanalysis] | ||
url=WHAT_IS_MY_BROWSER_API_URL | ||
api_key=WHAT_IS_MY_BROWSER_API_KEY | ||
== | ||
|
||
This template project was generated by | ||
|
||
resilient-circuits codegen -p fn_useragentanalysis [-f fn_useragentanalysis] [-w user_agent_workflow] | ||
|
||
|
||
You must edit the `setup.py` before distribution; | ||
it should contain your actual contact and license information. | ||
|
||
To install in "development mode" | ||
|
||
pip install -e ./fn_useragentanalysis/ | ||
|
||
After installation, the package will be loaded by `resilient-circuits run`. | ||
|
||
|
||
To uninstall, | ||
|
||
pip uninstall fn_useragentanalysis | ||
|
||
|
||
To package for distribution, | ||
|
||
python ./fn_useragentanalysis/setup.py sdist | ||
|
||
The resulting .tar.gz file can be installed using | ||
|
||
pip install <filename>.tar.gz | ||
|
||
|
||
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright © IBM Corporation 2010, 2018 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to | ||
deal in the Software without restriction, including without limitation the | ||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
sell copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
IN THE SOFTWARE. |
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import pkg_resources | ||
try: | ||
__version__ = pkg_resources.get_distribution(__name__).version | ||
except pkg_resources.DistributionNotFound: | ||
pass |
1 change: 1 addition & 0 deletions
1
fn_useragentanalysis/fn_useragentanalysis/components/__init__.py
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# |
64 changes: 64 additions & 0 deletions
64
fn_useragentanalysis/fn_useragentanalysis/components/fn_useragentanalysis.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
# pragma pylint: disable=unused-argument, no-self-use | ||
"""Function implementation""" | ||
|
||
import logging | ||
import requests | ||
from resilient_circuits import ResilientComponent, function, handler, StatusMessage, FunctionResult, FunctionError | ||
import fn_useragentanalysis.util.selftest as selftest | ||
|
||
|
||
class FunctionComponent(ResilientComponent): | ||
"""Component that implements Resilient function 'fn_useragentanalysis""" | ||
|
||
def __init__(self, opts): | ||
"""constructor provides access to the configuration options""" | ||
super(FunctionComponent, self).__init__(opts) | ||
self.options = opts.get("fn_useragentanalysis", {}) | ||
selftest.selftest_function(opts) | ||
|
||
@handler("reload") | ||
def _reload(self, event, opts): | ||
"""Configuration options have changed, save new values""" | ||
self.options = opts.get("fn_useragentanalysis", {}) | ||
|
||
@function("fn_useragentanalysis") | ||
def _fn_useragentanalysis_function(self, event, *args, **kwargs): | ||
"""Function: As a SOC analysis, I want to perform data enrichment on user agent strings found in web and firewall logs. These entries can provide clues as to potential attempted malicious access and what follow on steps are needed to restrict access. | ||
|
||
An integration function is required, sending an artifact string of user agent infromation to a user agent analysis website, returning detailed information as an incident note. An example workflow and rule to execute the function will be included in the packaging.""" | ||
try: | ||
# Get the function parameters: | ||
user_agent_string = kwargs.get("user_agent_string") # text | ||
|
||
log = logging.getLogger(__name__) | ||
log.info("user_agent_string: %s", user_agent_string) | ||
|
||
url = self.options.get('url', None) | ||
api_key = self.options.get('api_key', None) | ||
if not url or not api_key: | ||
raise ValueError('missing url and/or api_key from [fn_useragentanalysis] app_config') | ||
|
||
# PUT YOUR FUNCTION IMPLEMENTATION CODE HERE | ||
yield StatusMessage("starting...") | ||
data = {"user_agent": user_agent_string} | ||
headers = {'X-API-KEY': api_key} | ||
api_response = requests.post(url, headers=headers, json=data) | ||
if api_response.status_code != 200: | ||
raise Exception("Unexpected return code of {}".format(api_response.status_code)) | ||
|
||
user_agent_analysis = api_response.text | ||
|
||
results = { | ||
"user_agent_string": user_agent_string, | ||
"source_api_url": url, | ||
"user_agent_analysis": user_agent_analysis | ||
} | ||
yield StatusMessage("done...") | ||
|
||
# Produce a FunctionResult with the results | ||
yield FunctionResult(results) | ||
except Exception as e: | ||
yield FunctionError(e) | ||
|
||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# |
This file contains 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Generate a default configuration-file section for fn_useragentanalysis""" | ||
|
||
from __future__ import print_function | ||
|
||
|
||
def config_section_data(): | ||
"""Produce the default configuration section for app.config, | ||
when called by `resilient-circuits config [-c|-u]` | ||
""" | ||
config_data = u"""[fn_useragentanalysis] | ||
url=https://api.whatismybrowser.com/api/v2/user_agent_parse | ||
api_key=<<customer key>> | ||
""" | ||
return config_data |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resilient-circuits config and then further editing to add url and api_key information