Skip to content

Commit

Permalink
pre-commit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ishans-crest committed Sep 24, 2024
1 parent cda79b4 commit fb1209e
Show file tree
Hide file tree
Showing 12 changed files with 529 additions and 470 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
repos:
- repo: https://github.com/phantomcyber/dev-cicd-tools
rev: v1.16
rev: v1.19
hooks:
- id: org-hook
- id: package-app-dependencies
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
rev: v1.5.0
hooks:
- id: detect-secrets
args: ['--no-verify', '--exclude-files', '^phantom.json$']
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
18 changes: 1 addition & 17 deletions phantom.json
Original file line number Diff line number Diff line change
Expand Up @@ -2489,34 +2489,18 @@
],
"pip_dependencies": {
"wheel": [
{
"module": "beautifulsoup4",
"input_file": "wheels/py3/beautifulsoup4-4.9.1-py3-none-any.whl"
},
{
"module": "python_magic",
"input_file": "wheels/shared/python_magic-0.4.18-py2.py3-none-any.whl"
},
{
"module": "soupsieve",
"input_file": "wheels/py3/soupsieve-2.3.2.post1-py3-none-any.whl"
}
]
},
"pip39_dependencies": {
"wheel": [
{
"module": "beautifulsoup4",
"input_file": "wheels/py3/beautifulsoup4-4.9.1-py3-none-any.whl"
},
{
"module": "python_magic",
"input_file": "wheels/shared/python_magic-0.4.18-py2.py3-none-any.whl"
},
{
"module": "soupsieve",
"input_file": "wheels/py3/soupsieve-2.5-py3-none-any.whl"
}
]
}
}
}
882 changes: 475 additions & 407 deletions phantom_connector.py

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions phantom_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# either express or implied. See the License for the specific language governing permissions
# and limitations under the License.
TIMEOUT = 120
INVALID_RESPONSE = 'Server did not return a valid JSON response.'
INVALID_RESPONSE = "Server did not return a valid JSON response."

OPEN_XML_FORMATS = [
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
Expand All @@ -24,7 +24,7 @@
]

# list of file types supported for deflation
SUPPORTED_FILES = ['application/zip', 'application/x-gzip', 'application/x-tar', 'application/x-bzip2', 'application/gzip']
SUPPORTED_FILES = ["application/zip", "application/x-gzip", "application/x-tar", "application/x-bzip2", "application/gzip"]

# Consts for error messages
PHANTOM_ERR_INVALID_INT = "Please provide a valid {msg} integer value in the '{param}' action parameter"
Expand All @@ -41,8 +41,9 @@
PHANTOM_ERR_UNABLE_RETRIEVE_ID = "Unable to retrieve ID of newly created container"
PHANTOM_ERR_ACTION_RESULT_NOT_FOUND = "No action results found matching given criteria"
PHANTOM_ERR_NON_EMPTY_PARAM_VALUE = "Please provide row_values_as_list parameter as a non-empty JSON formatted list"
PHANTOM_ERR_SPECIFY_IP_HOSTNAME = ("Accessing 127.0.0.1 is not allowed."
" Please specify the actual IP or hostname used by the Phantom instance in the Asset config")
PHANTOM_ERR_SPECIFY_IP_HOSTNAME = (
"Accessing 127.0.0.1 is not allowed." " Please specify the actual IP or hostname used by the Phantom instance in the Asset config"
)
PHANTOM_ERR_GET_VAULT_INFO = "Failed to get the vault info: {}"

ARTIFACT_DEFAULT_MAX_RESULTS = 10
Expand Down
74 changes: 37 additions & 37 deletions phantom_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,59 @@

def find_artifacts(provides, all_results, context):

headers = ['Container ID', 'Container', 'Artifact ID', 'Artifact Name', 'Found in field', 'Matched Value']
headers = ["Container ID", "Container", "Artifact ID", "Artifact Name", "Found in field", "Matched Value"]

context['results'] = results = []
context['headers'] = headers
context["results"] = results = []
context["headers"] = headers

for summary, action_results in all_results:
for result in action_results:
table = {}
table['data'] = table_data = []
base = result.get_summary().get('server')
table["data"] = table_data = []
base = result.get_summary().get("server")
data = result.get_data()
for item in data:
row = []

c_link = base + '/mission/{}'.format(item.get('container'))
c_link_artifact = c_link + '/analyst/artifacts'
row.append({ 'value': c_link, 'link': item.get('container') })
row.append({ 'value': c_link, 'link': item.get('container_name') })
row.append({ 'value': c_link_artifact, 'link': item.get('id') })
row.append({ 'value': c_link_artifact, 'link': item.get('name') })
row.append({ 'value': item.get('found in') })
row.append({ 'value': item.get('matched') })
c_link = base + "/mission/{}".format(item.get("container"))
c_link_artifact = c_link + "/analyst/artifacts"
row.append({"value": c_link, "link": item.get("container")})
row.append({"value": c_link, "link": item.get("container_name")})
row.append({"value": c_link_artifact, "link": item.get("id")})
row.append({"value": c_link_artifact, "link": item.get("name")})
row.append({"value": item.get("found in")})
row.append({"value": item.get("matched")})
table_data.append(row)
results.append(table)

return 'phantom_multiple_actions.html'
return "phantom_multiple_actions.html"


def add_artifact(provides, all_results, context):

headers = ['Artifact ID', 'Container ID']
headers = ["Artifact ID", "Container ID"]

context['results'] = results = []
context['headers'] = headers
context["results"] = results = []
context["headers"] = headers

for summary, action_results in all_results:
for result in action_results:
table = {}
table['data'] = table_data = []
table["data"] = table_data = []
summary = result.get_summary()
base = summary.get('server')
base = summary.get("server")
data = result.get_data()
for item in data:
row = []

c_link = base + '/mission/{}'.format(summary.get('container_id'))
c_link_artifact = c_link + '/analyst/artifacts'
row.append({ 'value': c_link_artifact, 'link': summary.get('artifact_id') })
row.append({ 'value': c_link, 'link': summary.get('container_id') })
c_link = base + "/mission/{}".format(summary.get("container_id"))
c_link_artifact = c_link + "/analyst/artifacts"
row.append({"value": c_link_artifact, "link": summary.get("artifact_id")})
row.append({"value": c_link, "link": summary.get("container_id")})
table_data.append(row)
results.append(table)

return 'phantom_multiple_actions.html'
return "phantom_multiple_actions.html"


def find_listitem(provides, all_results, context):
Expand All @@ -83,38 +83,38 @@ def find_listitem(provides, all_results, context):
except:
python_version = 2

headers = ['List Name', 'Matched Row', 'Found at']
headers = ["List Name", "Matched Row", "Found at"]

context['results'] = results = []
context['headers'] = headers
context["results"] = results = []
context["headers"] = headers

for summary, action_results in all_results:
for result in action_results:
table = {}
table['data'] = table_data = []
table["data"] = table_data = []
summary = result.get_summary()
param = result.get_param()
data = result.get_data()
locations = summary.get('locations')
locations = summary.get("locations")
if not locations:
locations = 'Not Found'
locations = "Not Found"
for idx, item in enumerate(data):
row = []
item_str = ""
for i in item:
if i:
i = UnicodeDammit(i).unicode_markup.encode('utf-8') if python_version == 2 else i
i = UnicodeDammit(i).unicode_markup.encode("utf-8") if python_version == 2 else i
item_str = '{0}"{1}",'.format(item_str, i)
item_str = item_str[:-1]

row.append({ 'value': param.get('list') })
row.append({ 'value': item_str })
len_of_list = len(locations) > idx and locations[idx] or 'Missing Data'
row.append({"value": param.get("list")})
row.append({"value": item_str})
len_of_list = len(locations) > idx and locations[idx] or "Missing Data"
if isinstance(len_of_list, str):
row.append({ 'value': len_of_list})
row.append({"value": len_of_list})
else:
row.append({ 'value': 'Row {}, Column {}'.format(len_of_list[0], len_of_list[1])})
row.append({"value": "Row {}, Column {}".format(len_of_list[0], len_of_list[1])})
table_data.append(row)
results.append(table)

return 'phantom_multiple_actions.html'
return "phantom_multiple_actions.html"
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[tool.black]
line-length = 145
target-version = ['py39']
verbose = true

[tool.isort]
line_length = 145
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
beautifulsoup4==4.9.1
python-magic==0.4.18
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[flake8]
max-line-length = 145
max-complexity = 28
extend-ignore = F403,E128,E126,E111,E121,E127,E731,E201,E202,F405,E722,D,W292
extend-ignore = F403,E128,E126,E121,E127,E731,E201,E202,F405,E722,D

[isort]
line_length = 145
Binary file removed wheels/py3/beautifulsoup4-4.9.1-py3-none-any.whl
Binary file not shown.
Binary file removed wheels/py3/soupsieve-2.3.2.post1-py3-none-any.whl
Binary file not shown.
Binary file removed wheels/py3/soupsieve-2.5-py3-none-any.whl
Binary file not shown.

0 comments on commit fb1209e

Please sign in to comment.