Skip to content

Commit 224583a

Browse files
authored
Merge pull request #7 from rohitcoder/bug-fix/slack-channels-pagination
Bug fix/slack channels pagination
2 parents 4f35736 + 74a0e14 commit 224583a

File tree

4 files changed

+69
-26
lines changed

4 files changed

+69
-26
lines changed

connection.yml.sample

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ sources:
4444
- table1
4545
- table2
4646
exclude_columns:
47-
- column1
48-
- column2
49-
text:
50-
profile1:
51-
text: "Hello World HHWPK6943Q"
47+
- column1
48+
- column2
5249
postgresql:
5350
postgresql_example:
5451
host: YOUR_POSTGRESQL_HOST
@@ -84,17 +81,8 @@ sources:
8481
- private
8582
- venv
8683
- node_modules
87-
88-
slack:
89-
slack_example:
90-
token: xoxp-XXXXXXXXXXXXXXXXXXXXXXXXX # get your slack app these permissiosn https://api.slack.com/methods/team.info and https://api.slack.com/methods/conversations.list
91-
channel_types: "public_channel,private_channel"
92-
# Optional: List of channel names to check
93-
# channel_names:
94-
# - general
95-
# - random
9684

97-
gdrive:
85+
gdrive:
9886
drive_example:
9987
folder_name:
10088
credentials_file: /Users/kumarohit/Downloads/client_secret.json ## this will be oauth app json file
@@ -114,3 +102,14 @@ sources:
114102
exclude_patterns:
115103
- .pdf
116104
- .docx
105+
text:
106+
profile1:
107+
text: "Hello World HHXXXXX"
108+
slack:
109+
slack_example:
110+
channel_types: "public_channel,private_channel"
111+
token: xoxp-XXXXXXXXXXXXXXXXXXXXXXXXX
112+
archived_channels: True ## By default False, set to True if you want to scan archived channels also
113+
limit_mins: 15 ## By default 60 mins
114+
channel_ids:
115+
- XXXXXXXX

hawk_scanner/commands/slack.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def connect_slack(args, token):
2222
system.print_error(args, f"Failed to connect to Slack with error: {e.response['error']}")
2323
return None
2424

25-
def check_slack_messages(args, client, patterns, profile_name, channel_types, channel_ids=None, limit_mins=60):
25+
def check_slack_messages(args, client, patterns, profile_name, channel_types, channel_ids=None, limit_mins=60, archived_channels=False):
2626
results = []
2727
try:
2828
team_info = client.team_info()
@@ -41,20 +41,53 @@ def check_slack_messages(args, client, patterns, profile_name, channel_types, ch
4141

4242
# Get all channels of specified types
4343
channels = []
44+
4445
if not channel_ids:
4546
system.print_info(args, "Getting all channels because no channel_ids provided")
46-
channels = client.conversations_list(types=channel_types)["channels"]
47+
48+
# Pagination logic to fetch all non-archived channels
49+
cursor = None
50+
while True:
51+
try:
52+
if archived_channels:
53+
system.print_debug(args, f"Considering archived channels, you may want to set archived_channels to False")
54+
else:
55+
system.print_debug(args, f"Skipping archived channels, you may want to set archived_channels to True")
56+
response = client.conversations_list(
57+
types=channel_types,
58+
limit=1000,
59+
cursor=cursor,
60+
exclude_archived=not archived_channels
61+
)
62+
channels.extend(response.get("channels", []))
63+
64+
# Update the cursor for the next batch
65+
cursor = response.get("response_metadata", {}).get("next_cursor")
66+
67+
if not cursor: # Break the loop if there are no more channels to fetch
68+
break
69+
except SlackApiError as e:
70+
system.print_error(args, f"Failed to fetch channels: {e.response['error']}")
71+
break
4772
else:
4873
system.print_info(args, "Getting channels by channel_ids")
4974
for channel_id in channel_ids:
5075
try:
5176
channel = client.conversations_info(channel=channel_id)["channel"]
52-
channels.append(channel)
77+
## if archived_channels is set to True, include archived channels
78+
if archived_channels or not channel.get("is_archived"):
79+
system.print_debug(args, f"Considering archived channels, you may want to set archived_channels to False")
80+
channels.append(channel)
81+
else:
82+
system.print_debug(args, f"Skipping archived channel: {channel_id}")
83+
5384
except SlackApiError as e:
5485
system.print_error(args, f"Failed to fetch channel with id {channel_id} with error: {e.response['error']}")
5586

87+
# Optional: Print or log the total number of channels fetched
88+
system.print_info(args, f"Total channels fetched: {len(channels)}")
5689
system.print_info(args, f"Found {len(channels)} channels of type {channel_types}")
57-
system.print_info(args, f"Checking messages in channels: {', '.join([channel['name'] for channel in channels])}")
90+
system.print_debug(args, f"Checking messages in channels: {', '.join([channel['name'] for channel in channels])}")
5891

5992
for channel in channels:
6093
channel_name = channel["name"]
@@ -211,6 +244,7 @@ def execute(args):
211244
channel_types = config.get('channel_types', "public_channel,private_channel")
212245
channel_ids = config.get('channel_ids', [])
213246
limit_mins = config.get('limit_mins', 60)
247+
archived_channels = config.get('archived_channels', False)
214248

215249
if token:
216250
system.print_info(args, f"Checking Slack Profile {key}")
@@ -220,7 +254,7 @@ def execute(args):
220254

221255
client = connect_slack(args, token)
222256
if client:
223-
results += check_slack_messages(args, client, patterns, key, channel_types, channel_ids, limit_mins)
257+
results += check_slack_messages(args, client, patterns, key, channel_types, channel_ids, limit_mins, archived_channels)
224258
else:
225259
system.print_error(args, "No Slack connection details found in connection.yml")
226260
else:

readme.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<p align="center">
44
<a href="#description">Description</a> • <a href="#installation">Installation</a> • <a href="#features">Features</a> • <a href="#config">Configuration</a> • <a href="#acknowledgements">Acknowledgements</a><br><br>
55

6-
[![Publish to PyPI.org](https://github.com/rohitcoder/hawk-eye/actions/workflows/pypi.yml/badge.svg)](https://github.com/rohitcoder/hawk-eye/actions/workflows/pypi.yml)
6+
77
<img alt="Static Badge" src="https://img.shields.io/badge/Supports-S3-yellow?logo=amazons3">
88
<img alt="Static Badge" src="https://img.shields.io/badge/Supports-GCP-red?logo=googlecloud">
99
<img alt="Static Badge" src="https://img.shields.io/badge/Supports-MysQL-green?logo=mysql">
@@ -12,19 +12,29 @@
1212
<img alt="Static Badge" src="https://img.shields.io/badge/Supports-On Prem-black?logo=amazonec2">
1313
</p>
1414

15+
16+
Join our Slack community for support, discussions, or to contribute!
17+
18+
<a href="https://join.slack.com/t/hawkeyecommunity/shared_invite/zt-2xz0qbo8n-KQQ9UQ1KW2QfaMVDmCWYrw" target="_blank">
19+
<img src="https://i.imgur.com/BUtBFwE.png" alt="Join Slack Community" width="150" />
20+
</a>
21+
1522
<div id="description">
1623

17-
### 🦅 HAWK Eye - Uncover Secrets and PII Across All Platforms in Minutes!
24+
### 🦅 Hawk Eye - Uncover Secrets and PII Across All Platforms in Minutes!
1825

19-
HAWK Eye is a robust, command-line tool built to safeguard against data breaches and cyber threats. Much like the sharp vision of a hawk, it quickly scans multiple data sources—S3, MySQL, PostgreSQL, MongoDB, CouchDB, Google Drive, Slack, Redis, Firebase, file systems, and Google Cloud buckets (GCS)—for Personally Identifiable Information (PII) and secrets. Using advanced text analysis and OCR techniques, HAWK Eye delves into various document formats like docx, xlsx, pptx, pdf, images (jpg, png, gif), compressed files (zip, tar, rar), and even video files to ensure comprehensive protection across platforms.
26+
Hawk Eye is a robust, command-line tool built to safeguard against data breaches and cyber threats. Much like the sharp vision of a hawk, it quickly scans multiple data sources—S3, MySQL, PostgreSQL, MongoDB, CouchDB, Google Drive, Slack, Redis, Firebase, file systems, and Google Cloud buckets (GCS)—for Personally Identifiable Information (PII) and secrets. Using advanced text analysis and OCR techniques, HAWK Eye delves into various document formats like docx, xlsx, pptx, pdf, images (jpg, png, gif), compressed files (zip, tar, rar), and even video files to ensure comprehensive protection across platforms.
2027

2128

2229
### Why "HAWK Eye"?
2330
Like the keen vision of a hawk, this tool enables you to monitor and safeguard your data with precision and accuracy, ensuring data privacy and security.
2431
</div>
2532

2633
## Commercial Support
27-
For commercial support and help with HAWK Eye, please contact us at [LinkedIn](https://linkedin.com/in/rohitcoder) or [Twitter](https://twitter.com/rohitcoder).
34+
35+
For commercial support and help with HAWK Eye, please contact us on [LinkedIn](https://linkedin.com/in/rohitcoder) or [Twitter](https://twitter.com/rohitcoder).
36+
37+
Alternatively, you can reach out to us in our Slack community.
2838

2939
## HAWK Eye in Action
3040

@@ -373,7 +383,7 @@ sources:
373383
slack_example:
374384
channel_types: "public_channel,private_channel"
375385
token: xoxp-XXXXXXXXXXXXXXXXXXXXXXXXX
376-
channel_types: "public_channel,private_channel"
386+
archived_channels: True ## By default False, set to True if you want to scan archived channels also
377387
limit_mins: 15 ## By default 60 mins
378388
channel_ids:
379389
- XXXXXXXX

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "0.3.25"
1+
VERSION = "0.3.26"
22

33
from setuptools import setup, find_packages
44

0 commit comments

Comments
 (0)