Skip to content

Commit 50f4ef4

Browse files
committed
Released version 0.1.7
1 parent 4cc0672 commit 50f4ef4

File tree

7 files changed

+147
-10
lines changed

7 files changed

+147
-10
lines changed

connection.yml.sample

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,20 @@ sources:
3535
user: YOUR_MYSQL_USERNAME
3636
password: YOUR_MYSQL_PASSWORD
3737
database: YOUR_MYSQL_DATABASE_NAME
38-
postgresql:
39-
postgresql1:
38+
postgresql:
39+
postgresql_example:
4040
host: YOUR_POSTGRESQL_HOST
4141
port: YOUR_POSTGRESQL_PORT
4242
user: YOUR_POSTGRESQL_USERNAME
4343
password: YOUR_POSTGRESQL_PASSWORD
4444
database: YOUR_POSTGRESQL_DATABASE_NAME
45+
mongodb: # New MongoDB configuration
46+
mongodb_example:
47+
host: YOUR_MONGODB_HOST
48+
port: YOUR_MONGODB_PORT
49+
username: YOUR_MONGODB_USERNAME
50+
password: YOUR_MONGODB_PASSWORD
51+
database: YOUR_MONGODB_DATABASE_NAME
4552
fs:
4653
fs_example:
4754
path: /path/to/your/filesystem/directory

hawk_scanner/commands/mongodb.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import pymongo
2+
from hawk_scanner.internals import system
3+
import re
4+
from rich.console import Console
5+
from rich.table import Table
6+
7+
console = Console()
8+
9+
def connect_mongodb(host, port, username, password, database, uri=None):
10+
try:
11+
if uri:
12+
client = pymongo.MongoClient(uri)
13+
else:
14+
client = pymongo.MongoClient(host=host, port=port, username=username, password=password)
15+
16+
if database not in client.list_database_names():
17+
system.print_error(f"Database {database} not found on MongoDB server.")
18+
return None
19+
20+
db = client[database]
21+
system.print_info(f"Connected to MongoDB database")
22+
return db
23+
except Exception as e:
24+
system.print_error(f"Failed to connect to MongoDB database with error: {e}")
25+
return None
26+
27+
28+
def check_data_patterns(db, patterns, profile_name, database_name):
29+
results = []
30+
for collection_name in db.list_collection_names():
31+
collection = db[collection_name]
32+
for document in collection.find():
33+
for field_name, field_value in document.items():
34+
if field_value:
35+
value_str = str(field_value)
36+
matches = system.match_strings(value_str)
37+
if matches:
38+
for match in matches:
39+
results.append({
40+
'host': db.client.address[0],
41+
'database': database_name,
42+
'collection': collection_name,
43+
'field': field_name,
44+
'pattern_name': match['pattern_name'],
45+
'matches': match['matches'],
46+
'sample_text': match['sample_text'],
47+
'profile': profile_name,
48+
'data_source': 'mongodb'
49+
})
50+
51+
return results
52+
53+
def execute(args):
54+
results = []
55+
system.print_info(f"Running Checks for MongoDB Sources")
56+
connections = system.get_connection()
57+
58+
if 'sources' in connections:
59+
sources_config = connections['sources']
60+
mongodb_config = sources_config.get('mongodb')
61+
62+
if mongodb_config:
63+
patterns = system.get_fingerprint_file()
64+
65+
for key, config in mongodb_config.items():
66+
host = config.get('host')
67+
port = config.get('port', 27017) # default MongoDB port
68+
username = config.get('username')
69+
password = config.get('password')
70+
database = config.get('database')
71+
uri = config.get('uri') # Added support for URI
72+
73+
if uri:
74+
system.print_info(f"Checking MongoDB Profile {key} using URI")
75+
elif host and username and password and database:
76+
system.print_info(f"Checking MongoDB Profile {key} with host and authentication")
77+
else:
78+
system.print_error(f"Incomplete MongoDB configuration for key: {key}")
79+
continue
80+
81+
db = connect_mongodb(host, port, username, password, database, uri)
82+
if db:
83+
results += check_data_patterns(db, patterns, key, database)
84+
else:
85+
system.print_error("No MongoDB connection details found in connection.yml")
86+
else:
87+
system.print_error("No 'sources' section found in connection.yml")
88+
return results

hawk_scanner/internals/system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import json
99

1010
console = Console()
11-
parser = argparse.ArgumentParser(description='🦅 A powerful scanner to scan your Filesystem, S3, MySQL, Redis, Google Cloud Storage and Firebase storage for PII and sensitive data.')
11+
parser = argparse.ArgumentParser(description='🦅 A powerful scanner to scan your Filesystem, S3, MySQL, PostgreSQL, MongoDB, Redis, Google Cloud Storage and Firebase storage for PII and sensitive data.')
1212
parser.add_argument('--connection', action='store', help='YAML Connection file path')
1313
parser.add_argument('--fingerprint', action='store', help='Override YAML fingerprint file path')
1414
parser.add_argument('--debug', action='store_true', help='Enable debug mode')

hawk_scanner/main.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def clear_screen():
2121
console = Console()
2222

2323
## Now separate the results by data_source
24-
data_sources = ['s3', 'mysql', 'redis', 'firebase', 'gcs', 'fs', 'postgresql']
24+
data_sources = ['s3', 'mysql', 'redis', 'firebase', 'gcs', 'fs', 'postgresql', 'mongodb']
2525

2626
def load_command_module(command):
2727
try:
@@ -85,14 +85,16 @@ def main():
8585
table.add_column("Vulnerable Profile")
8686
if group == 's3':
8787
table.add_column("Bucket > File Path")
88-
elif group == 'mysql':
88+
elif group == 'mysql' or group == 'postgresql':
8989
table.add_column("Host > Database > Table.Column")
9090
elif group == 'redis':
9191
table.add_column("Host > Key")
9292
elif group == 'firebase' or group == 'gcs':
9393
table.add_column("Bucket > File Path")
9494
elif group == 'fs':
9595
table.add_column("File Path")
96+
elif group == 'mongodb':
97+
table.add_column("Host > Database > Collection > Field")
9698

9799
table.add_column("Pattern Name")
98100
table.add_column("Total Exposed")
@@ -162,7 +164,41 @@ def main():
162164
)
163165

164166
system.SlackNotify(AlertMsg)
165-
167+
168+
elif group == 'mongodb':
169+
table.add_row(
170+
str(i),
171+
result['profile'],
172+
f"{result['host']} > {result['database']} > {result['collection']} > {result['field']}",
173+
result['pattern_name'],
174+
str(len(result['matches'])),
175+
str(', '.join(result['matches'])),
176+
result['sample_text'],
177+
)
178+
179+
# Slack notification for MongoDB
180+
AlertMsg = """
181+
*** PII Or Secret Found ***
182+
Data Source: MongoDB
183+
Host: {host}
184+
Database: {database}
185+
Collection: {collection}
186+
Field: {field}
187+
Pattern Name: {pattern_name}
188+
Total Exposed: {total_exposed}
189+
Exposed Values: {exposed_values}
190+
""".format(
191+
host=result['host'],
192+
database=result['database'],
193+
collection=result['collection'],
194+
field=result['field'],
195+
pattern_name=result['pattern_name'],
196+
total_exposed=str(len(result['matches'])),
197+
exposed_values=', '.join(result['matches'])
198+
)
199+
200+
system.SlackNotify(AlertMsg)
201+
166202
elif group == 'postgresql':
167203
table.add_row(
168204
str(i),

readme.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
### 🦅 HAWK Eye - Highly Advanced Watchful Keeper Eye
1919

20-
HAWK Eye is a powerful and versatile CLI (Command-Line Interface) tool designed to be your vigilant watchkeeper, guarding against potential data breaches and cyber threats across various platforms. Inspired by the precision and vision of majestic birds of prey, HAWK Eye swiftly scans multiple data sources, including S3, MySQL, PostgreSQL, Redis, Firebase, filesystem, and Google Cloud buckets (GCS), for Personally Identifiable Information (PII) and secrets.
20+
HAWK Eye is a powerful and versatile CLI (Command-Line Interface) tool designed to be your vigilant watchkeeper, guarding against potential data breaches and cyber threats across various platforms. Inspired by the precision and vision of majestic birds of prey, HAWK Eye swiftly scans multiple data sources, including S3, MySQL, PostgreSQL, MongoDB, Redis, Firebase, filesystem, and Google Cloud buckets (GCS), for Personally Identifiable Information (PII) and secrets.
2121

2222

2323
### Why "HAWK Eye"?
@@ -113,6 +113,11 @@ Note: If you don't provide any command, it will run all commands (firebase, fs,
113113
mysql
114114
<td>Scan MySQL profiles for PII and secrets data.</td>
115115
</tr>
116+
<tr>
117+
<td>
118+
mongodb
119+
<td>Scan MongoDB profiles for PII and secrets data.</td>
120+
</tr>
116121
<tr>
117122
<td>
118123
postgresql

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ redis
66
firebase-admin
77
google-cloud-core
88
google-cloud-storage
9-
psycopg2-binary
9+
psycopg2-binary
10+
pymongo==3.13.0

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "0.1.6"
1+
VERSION = "0.1.7"
22

33
from setuptools import setup, find_packages
44

@@ -11,7 +11,7 @@
1111
setup(
1212
name='hawk_scanner',
1313
version=VERSION,
14-
description='A powerful scanner to scan your Filesystem, S3, MySQL, PostgreSQL, Redis, Google Cloud Storage and Firebase storage for PII and sensitive data.',
14+
description='A powerful scanner to scan your Filesystem, S3, MongoDB, MySQL, PostgreSQL, Redis, Google Cloud Storage and Firebase storage for PII and sensitive data.',
1515
long_description=long_description,
1616
long_description_content_type="text/markdown",
1717
url='https://github.com/rohitcoder/hawk-eye',

0 commit comments

Comments
 (0)