-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from InQuest/develop
v1.0.0-beta9
- Loading branch information
Showing
11 changed files
with
210 additions
and
37 deletions.
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,23 @@ | ||
name: threatingestor-workflow | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.6", "3.7"] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
pip install -r requirements.txt | ||
pip install -r requirements-testing.txt | ||
- name: Test scripts | ||
run: nosetests --with-coverage --cover-package=threatingestor --cover-xml |
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,14 @@ | ||
# Comes with Python 3.6.9 installed by default | ||
FROM ubuntu:18.04 | ||
|
||
RUN apt-get update | ||
RUN apt-get install python3-pip -y | ||
RUN apt-get install sqlite3 | ||
|
||
RUN pip3 install threatingestor \ | ||
twitter \ | ||
feedparser | ||
COPY config.yml . | ||
|
||
# Run the ThreatIngestor without accessing /bin/bash container | ||
CMD ["threatingestor", "config.yml"] |
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
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
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
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,44 @@ | ||
.. _github-gist-source: | ||
|
||
GitHub Gist Username Search | ||
------------------------ | ||
|
||
The **GitHub Gist** source plugin uses GitHub's `gist API`_ to find new gists created by a user, and create a :ref:`Task artifact <task-artifact>` for each. | ||
|
||
Configuration Options | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
* ``module`` (required): ``github_gist`` | ||
* ``user`` (required): Username of the gist owner. | ||
* ``username`` (optional): Username for authentication. | ||
* ``token`` (optional): Token or password for authentication. | ||
|
||
Example Configuration | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The following examples all assume GitHub credentials have already been | ||
configured in the ``credentials`` section of the config, like this: | ||
|
||
.. code-block:: yaml | ||
credentials: | ||
- name: github-auth | ||
username: myuser | ||
token: MYTOKEN | ||
.. note:: | ||
|
||
GitHub credentials are optional, but increase the rate limit for API | ||
requests *significantly*. If you are doing more than one or two low- | ||
volume searches, you should set up the credentials. | ||
|
||
Inside the ``sources`` section of your configuration file: | ||
|
||
.. code-block:: yaml | ||
- name: github-gist-search | ||
credentials: github-auth | ||
module: github_gist | ||
user: InQuest | ||
.. _github gist user API: https://docs.github.com/en/rest/gists/gists#list-gists-for-a-user |
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
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
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
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,52 @@ | ||
import datetime, requests | ||
|
||
from threatingestor.sources import Source | ||
import threatingestor.artifacts | ||
|
||
def user_set(user): | ||
GIST_SEARCH_URL = "https://api.github.com/users/{0}/gists".format(user) | ||
return GIST_SEARCH_URL | ||
|
||
class Plugin(Source): | ||
"""Github Gist Source Plugin""" | ||
def __init__(self, name, user="", username="", token=""): | ||
self.name = name | ||
self.user = user | ||
|
||
if username and token: | ||
self.auth = (username, token) | ||
else: | ||
self.auth = None | ||
|
||
def _gist_search(self, params): | ||
"""Returns a list of gist results.""" | ||
|
||
# Iterates through pages of results from query. | ||
response = requests.get(user_set(self.user), params=params, auth=self.auth) | ||
|
||
gist_list = [] | ||
|
||
for gist in response.json(): | ||
gist_list.append(gist) | ||
|
||
return gist_list | ||
|
||
def run(self, saved_state): | ||
"""Returns a list of artifacts and the saved state""" | ||
|
||
params = { "per_page": "100" } | ||
|
||
saved_state = datetime.datetime.utcnow().isoformat()[:-7] + 'Z' | ||
gist_list = self._gist_search(params) | ||
|
||
artifact_list = [] | ||
|
||
for gist in gist_list: | ||
title = "Gist Owner: {0}".format(self.user) | ||
description = 'URL: {u}\nTask autogenerated by ThreatIngestor from source: {s}' | ||
description = description.format(s=self.name, u=gist['html_url']) | ||
artifact = threatingestor.artifacts.Task(title, self.name, reference_link=gist['html_url'], reference_text=description) | ||
|
||
artifact_list.append(artifact) | ||
|
||
return saved_state, artifact_list |
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