Skip to content

Commit 8ca6aa1

Browse files
authored
Merge pull request #13 from rohitcoder/feat/added-severity
Added Severity logic and severity query feature
2 parents dbff0e7 + 3941156 commit 8ca6aa1

File tree

5 files changed

+71
-5
lines changed

5 files changed

+71
-5
lines changed

connection.yml.sample

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,34 @@ notify:
33
suppress_duplicates: True
44
slack:
55
webhook_url: https://hooks.slack.com/services/T0XXXXXXXXXXX/BXXXXXXXX/1CIyXXXXXXXXXXXXXXX
6-
6+
jira:
7+
username: "[email protected]"
8+
server_url: "https://amce.atlassian.net"
9+
api_token: "JIRA_API_TOKEN_HERE"
10+
project: "SEC"
11+
issue_type: "Task"
12+
labels:
13+
- "hawk-eye"
14+
assignee: "[email protected]"
15+
issue_fields:
16+
summary_prefix: "[Hawk-eye] PII Exposed - "
17+
description_template: |
18+
A Data Security issue has been identified:
19+
20+
{details}
21+
severity_rules:
22+
critical:
23+
- query: "length(matches) > `10` && contains(['EMAIL', 'PAN'], pattern_name)"
24+
description: "Detected more than 10 Email or Pan exposed"
25+
high:
26+
- query: "length(matches) > `10` && contains(['EMAIL', 'PAN'], pattern_name) && data_source == 'slack'"
27+
description: "Detected more than 10 Email or Pan exposed in Slack"
28+
medium:
29+
- query: "length(matches) > `5` && length(matches) <= `10` && contains(['EMAIL', 'PAN'], pattern_name) && data_source == 'slack' && profile == 'customer_support'"
30+
description: "Detected more than 5 and less than 10 Email or Pan exposed in Customer support Slack workspace"
31+
low:
32+
- query: "length(matches) <= `5`"
33+
description: "Detected less than 5 PII or Secrets"
734
sources:
835
redis:
936
redis_example:

hawk_scanner/internals/system.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import jmespath
12
from rich.console import Console
23
from rich.table import Table
34
import json, requests, argparse, yaml, re, datetime, os, subprocess, platform, hashlib
@@ -541,6 +542,40 @@ def SlackNotify(msg, args):
541542
except Exception as e:
542543
print_error(args, f"An error occurred: {str(e)}")
543544

545+
def evaluate_severity(json_data, rules):
546+
if 'severity_rules' not in rules:
547+
rules = {
548+
'severity_rules': {
549+
'critical': [
550+
{'query': "length(matches) > `20`", 'description': "Detected more than 20 PII or Secrets"},
551+
],
552+
'high': [
553+
{'query': "length(matches) > `10` && length(matches) <= `20`", 'description': "Detected more than 10 PII or Secrets"},
554+
],
555+
'medium': [
556+
{'query': "length(matches) > `5` && length(matches) <= `10`", 'description': "Detected more than 5 PII or Secrets"},
557+
],
558+
'low': [
559+
{'query': "length(matches) <= `5`", 'description': "Detected less than 5 PII or Secrets"},
560+
],
561+
}
562+
}
563+
564+
for severity, conditions in rules['severity_rules'].items():
565+
for condition in conditions:
566+
query = condition['query']
567+
description = condition['description']
568+
if jmespath.search(query, json_data):
569+
# Add severity details to the JSON data
570+
json_data['severity'] = severity
571+
json_data['severity_description'] = description
572+
return json_data
573+
574+
# If no match, add default severity
575+
json_data['severity'] = "unknown"
576+
json_data['severity_description'] = "No matching rule found."
577+
return json_data
578+
544579
def enhance_and_ocr(image_path):
545580
# Load the image
546581
original_image = Image.open(image_path)

hawk_scanner/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ def execute_command(command, args):
3838
return module.execute(args)
3939

4040

41-
def group_results(results):
41+
def group_results(args, results):
4242
grouped_results = defaultdict(list)
4343
for result in results:
44+
connection = system.get_connection(args)
45+
result = system.evaluate_severity(result, connection)
4446
grouped_results[result['data_source']].append(result)
4547
return grouped_results
4648

@@ -231,8 +233,7 @@ def main():
231233
system.print_error(args, "Please provide a command to execute")
232234
sys.exit(1)
233235

234-
grouped_results = group_results(results)
235-
236+
grouped_results = group_results(args, results)
236237
if args.json:
237238
if args.json:
238239
with open(args.json, 'w') as file:

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ Note: If you don't provide any command, it will run all commands (firebase, fs,
269269
HAWK Eye uses a YAML file to store connection profiles for various data sources. The connection.yml file is located in the config directory. You can add new profiles to this file to enable HAWK Eye to scan additional data sources. The following sections describe the process for adding new profiles to the connection.yml file.
270270

271271

272-
### Your connection fille will look like this
272+
### Your connection file will look like this
273+
274+
For the full connection schema, have a look at [connection.yml.sample](connection.yml.sample).
273275

274276
```yaml
275277
notify:

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
boto3
22
PyYAML
3+
jmespath
34
rich
45
mysql-connector-python
56
pymysql

0 commit comments

Comments
 (0)