-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathclockwork_sms.py
72 lines (64 loc) · 2.45 KB
/
clockwork_sms.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
69
70
71
72
import re
import king_phisher.client.plugins as plugins
import requests
class Plugin(plugins.ClientPlugin):
authors = ['Spencer McIntyre']
classifiers = ['Plugin :: Client']
title = 'Clockwork SMS'
description = """
Send SMS messages using the Clockwork SMS API's email gateway. While
enabled, this plugin will automatically update phone numbers into email
addresses for sending using the service.
"""
homepage = 'https://github.com/securestate/king-phisher-plugins'
options = [
plugins.ClientOptionString(
'api_key',
'Clockwork API Key',
display_name='Clockwork SMS API Key'
)
]
req_min_version = '1.10.0'
version = '1.0.1'
_sms_number_regex = re.compile(r'^[0-9]{10,12}')
def initialize(self):
mailer_tab = self.application.main_tabs['mailer']
self.signal_connect('send-precheck', self.signal_send_precheck, gobject=mailer_tab)
self.signal_connect('target-create', self.signal_target_create, gobject=mailer_tab)
return True
def _get_balance(self):
api_key = self.config['api_key']
try:
resp = requests.get('https://api.clockworksms.com/http/balance?key=' + api_key)
except requests.exceptions.RequestException:
self.logger.warning('failed to check the clockwork sms balance', exc_info=True)
return None
resp = resp.text.strip()
message, details = resp.split(':', 1)
details = details.lstrip()
return message, details
def signal_send_precheck(self, mailer_tab):
api_key = self.config['api_key']
text_insert = mailer_tab.tabs['send_messages'].text_insert
if not api_key:
text_insert('Invalid Clockwork SMS API key.\n')
return False
resp = self._get_balance()
if resp is None:
text_insert('Failed to check the Clockwork SMS API key.\n')
return False
message, details = resp
if message.lower().startswith('error'):
self.logger.warning('received ' + message + ' (' + details + ') from clockwork api')
text_insert("Received {0}: ({1}) from Clockwork SMS API.\n".format(message, details))
return False
if message.lower() != 'balance':
self.logger.warning('received unknown response from clockwork api')
text_insert('Received an unknown response from the Clockwork SMS API.\n')
return False
text_insert('Current Clockwork SMS API balance: ' + details + '\n')
return True
def signal_target_create(self, mailer_tab, target):
if self._sms_number_regex.match(target.email_address) is None:
return
target.email_address = target.email_address + '@' + self.config['api_key'] + '.clockworksms.com'