-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendHash.py
68 lines (54 loc) · 1.92 KB
/
sendHash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import requests, sqlite3, json, slack_sdk, logging, os, csv
from responderSlack import DbConnect
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
def loadConfig():
global respDB, channelID, botToken
with open("./config.json", "r") as configFile:
config = json.loads(configFile.read())
respDB = config["ResponderDB"]
channelID = config["channelID"]
botToken = config["botToken"]
print(botToken)
if channelID == "replaceMe" or botToken == "replaceMe":
raise ValueError("Must add channelID and botToken in config.json!")
def sendFileWebhook(fileName):
client = WebClient(token=botToken)
logger = logging.getLogger(__name__)
try:
# Call the files.upload method using the WebClient
# Uploading files requires the `files:write` scope
result = client.files_upload(
channels=channelID,
initial_comment="Here's my file :smile:",
file=fileName,
)
# Log the result
logger.info(result)
except SlackApiError as e:
logger.error("Error uploading file: {}".format(e))
def buildCsv():
res = cursor.execute(f"SELECT user,type,client,fullhash FROM Responder")
output = []
header = ['user','type','client','fullhash']
for row in res.fetchall():
output.append([row[0],row[1],row[2],row[3]])
print(output)
with open('hashes.csv', 'w', newline='') as csvFile:
writer = csv.writer(csvFile)
writer.writerow(header)
writer.writerows(output)
def buildFile():
res = cursor.execute(f"SELECT fullhash FROM Responder")
with open('hashes.txt', 'w') as hashFile:
for row in res.fetchall():
hashFile.writelines(f"{row[0]}\n")
def main():
global cursor
loadConfig()
cursor = DbConnect(respDB)
# buildCsv()
buildFile()
sendFileWebhook("hashes.txt")
if __name__ == "__main__":
main()