-
Notifications
You must be signed in to change notification settings - Fork 38
/
honeycreds.py
273 lines (251 loc) · 11.2 KB
/
honeycreds.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Ben Ten (Ben0xA)
# HoneyCreds - Detecting LLMNR/NBNS/HTTP Listeners
# Updated: 5/9/2021
# Version: 0.2
# Requires:
# python 3
# smbprotocol
# cffi
# configparser
# splunk-sdk
import smbclient
import os
import subprocess
import logging
import time
import sys
import requests
import socket
import threading
import configparser
import splunklib.client as client
from datetime import datetime
from signal import signal, SIGINT
class Config:
def __init__(self, conf_file='./honeycreds.conf'):
config_file = configparser.RawConfigParser(allow_no_value=True)
config_file.read(conf_file)
self.def_username = config_file.get('general', 'def_username')
self.def_domain = config_file.get('general', 'def_domain')
self.def_password = config_file.get('general', 'def_password')
self.def_fqdn = config_file.get('general', 'def_fqdn')
self.def_hostname = config_file.get('general', 'def_hostname')
self.def_logfile = config_file.get('general', 'def_logfile')
self.SMB = config_file.get('protocols', 'SMB')
self.HTTP = config_file.get('protocols', 'HTTP')
self.SMB_SLEEP = config_file.getint('protocols', 'SMB_SLEEP')
self.HTTP_SLEEP = config_file.getint('protocols', 'HTTP_SLEEP')
self.SPLUNK = config_file.get('forwarders', 'SPLUNK')
self.ELK = config_file.get('forwarders', 'ELK')
self.SPLUNK_HOSTNAME = config_file.get('splunk', 'SPLUNK_HOSTNAME')
self.SPLUNK_PORT = config_file.getint('splunk', 'SPLUNK_PORT')
self.SPLUNK_USERNAME = config_file.get('splunk', 'SPLUNK_USERNAME')
self.SPLUNK_PASSWORD = config_file.get('splunk', 'SPLUNK_PASSWORD')
self.SPLUNK_TOKEN = config_file.get('splunk', 'SPLUNK_TOKEN')
self.SPLUNK_INDEX = config_file.get('splunk', 'SPLUNK_INDEX')
smb_Thread = None
http_Thread = None
smb_exit = threading.Event()
http_exit = threading.Event()
splunk_service = None
splunk_index = None
local_hostname = socket.gethostname()
config = Config()
def signal_handler(sig, frame):
global smb_Thread, http_Thread, exit
print('')
print('[*] Exiting...')
if smb_Thread and smb_Thread.is_alive():
print('[*] Terminating SMB Client, please wait...')
smb_exit.set()
smb_Thread.join()
print('[*] SMB Client terminated.')
if http_Thread and http_Thread.is_alive():
print('[*] Terminating HTTP Client, please wait...')
http_exit.set()
http_Thread.join()
print('[*] HTTP Client terminated.')
def init():
global config
log_format = ('[%(asctime)s] %(levelname)-8s %(name)-12s %(message)s')
logging.basicConfig(
level=logging.CRITICAL,
format=log_format,
filename=(config.def_logfile)
)
SMB = str.upper(config.SMB)
HTTP = str.upper(config.HTTP)
def init_splunk():
global splunk_service, splunk_index, config
if config.SPLUNK_TOKEN != None:
try:
splunk_service = client.connect(host=config.SPLUNK_HOSTNAME, port=config.SPLUNK_PORT, splunkToken=config.SPLUNK_TOKEN)
except:
print('[-] Failed to Authenticate to Splunk! Check configuration settings.')
splunk_service = None
else:
try:
splunk_service = client.connect(host=config.SPLUNK_HOSTNAME, port=config.SPLUNK_PORT, username=config.SPLUNK_USERNAME, password=config.SPLUNK_PASSWORD)
except:
print('[-] Failed to Authenticate to Splunk! Check configuration settings.')
splunk_service = None
#Get or create index
if splunk_service:
try:
splunk_index = splunk_service.indexes[config.SPLUNK_INDEX]
except:
try:
splunk_index = splunk_service.indexes.create(config.SPLUNK_INDEX)
except:
print('[-] Failed to get Splunk indexes! Check configuration settings.')
def banner():
oncolor = termcolor.GREEN
print(termcolor.YELLOW + termcolor.BOLD + ' .-=-=-=-. ' + termcolor.END)
print(termcolor.YELLOW + termcolor.BOLD + ' (`-=-=-=-=-`) ' + termcolor.END)
print(termcolor.YELLOW + termcolor.BOLD + ' (`-=-=-=-=-=-=-`) ' + termcolor.WHITE + ' _ _ ___ _ ' + termcolor.END)
print(termcolor.YELLOW + termcolor.BOLD + ' (`-=-=-=-=-=-=-=-`) ' + termcolor.WHITE + ' ( ) ( ) ( _ \\ ( ) ' + termcolor.END)
print(termcolor.YELLOW + termcolor.BOLD + ' ( `-=-=-=-(@)-=-=-` ) ' + termcolor.WHITE + ' | |_| | _ ___ __ _ _ | ( (_) _ __ __ _| | ___ ' + termcolor.END)
print(termcolor.YELLOW + termcolor.BOLD + ' (`-=-=-=-=-=-=-=-=-`) ' + termcolor.WHITE + ' | _ | / _ \\ / _ \\ / __ \\( ) ( )| | _ ( __) / __ \\ / _ |/ __)' + termcolor.END)
print(termcolor.YELLOW + termcolor.BOLD + ' (`-=-=-=-=-=-=-=-=-`) ' + termcolor.WHITE + ' | | | |( (_) )| ( ) |( ___/| (_) || (_( )| | ( ___/( (_| |\\__ \\' + termcolor.END)
print(termcolor.YELLOW + termcolor.BOLD + ' (`-=-=-=-=-=-=-=-=-`) ' + termcolor.WHITE + ' (_) (_) \\ __/ (() (_) )\\___) \\__ |(____/ (() )\\___) ) _ _)(__(_/' + termcolor.END)
print(termcolor.YELLOW + termcolor.BOLD + ' (`-=-=-=-=-=-=-=-=-`) ' + termcolor.WHITE + ' /( (_) (__) ( )_| | (_) (__) (__) /( ' + termcolor.END)
print(termcolor.YELLOW + termcolor.BOLD + ' (`-=-=-=-=-=-=-=-`) ' + termcolor.WHITE + ' (__) \\___/ (__) ' + termcolor.END)
print(termcolor.YELLOW + termcolor.BOLD + ' (`-=-=-=-=-=-=-`)' + termcolor.END)
print(termcolor.YELLOW + termcolor.BOLD + ' (`-=-=-=-=-`)' + termcolor.END)
print(termcolor.YELLOW + termcolor.BOLD + ' `-=-=-=-=-`' + termcolor.END)
print(termcolor.YELLOW + ' Author: ' + termcolor.WHITE + termcolor.BOLD + 'Ben Ten (@ben0xa)' + termcolor.END + termcolor.WHITE + ' - ' + termcolor.YELLOW + 'Version: ' + termcolor.WHITE + termcolor.BOLD + '0.2' + termcolor.END)
print('')
print(termcolor.GREEN + termcolor.BOLD + '[+]' + termcolor.END + ' Clients:')
if str.upper(config.SMB) == 'OFF':
oncolor = termcolor.RED
else:
oncolor = termcolor.GREEN
print(' SMB Client\t\t' + oncolor + termcolor.BOLD + '[' + config.SMB + ']' + termcolor.END)
if str.upper(config.HTTP) == 'OFF':
oncolor = termcolor.RED
else:
oncolor = termcolor.GREEN
print(' HTTP Client\t\t' + oncolor + termcolor.BOLD + '[' + config.HTTP + ']' + termcolor.END)
print('')
print(termcolor.GREEN + termcolor.BOLD + '[+]' + termcolor.END + ' Generic Options:')
print(' Domain\t\t' + termcolor.YELLOW + termcolor.BOLD + '[' + config.def_domain + ']' + termcolor.END)
print(' Username\t\t' + termcolor.YELLOW + termcolor.BOLD + '[' + config.def_username + ']' + termcolor.END)
print(' Password\t\t' + termcolor.YELLOW + termcolor.BOLD + '[' + config.def_password + ']' + termcolor.END)
print(' Hostname\t\t' + termcolor.YELLOW + termcolor.BOLD + '[' + config.def_hostname + ']' + termcolor.END)
print(' FQDN\t\t' + termcolor.YELLOW + termcolor.BOLD + '[' + config.def_fqdn + ']' + termcolor.END)
print(' SMB Sleep\t\t' + termcolor.YELLOW + termcolor.BOLD + '[' + str(config.SMB_SLEEP) + ' seconds]' + termcolor.END)
print(' HTTP Sleep\t\t' + termcolor.YELLOW + termcolor.BOLD + '[' + str(config.HTTP_SLEEP) + ' seconds]' + termcolor.END)
print('')
class termcolor:
WHITE = '\033[37m'
GREEN = '\033[32m'
YELLOW = '\033[33m'
BLUE = '\033[34m'
RED = '\033[31m'
END = '\033[0m'
BOLD = '\033[1m'
class messages:
RSP_RECVD = '%(color)s%(bold)s[%(proto)s]%(end)s Poisoned response received from %(ip)s for name %(hostname)s.'
class SMBClient(threading.Thread):
def __init__(self, username, hostname):
threading.Thread.__init__(self)
self.username = username
self.hostname = hostname
def run(self):
global config, smb_exit, splunk_index, local_hostname
username = self.username
hostname = self.hostname
while smb_exit.is_set() == False:
smbclient.ClientConfig(username=username, password=config.def_password, connection_timeout=1)
connected = False
try:
with smbclient.open_file(r'\\\\' + hostname + '\\share\\file.txt', mode='r') as f:
connected = True
except Exception as exception:
if type(exception).__name__ == 'AccessDenied':
try:
drslt = subprocess.check_output('dig +short ' + hostname, shell=True).decode('utf-8')
except:
pass
drslt_parts = drslt.split('\n')
rmt_ip = 'Unknown'
if len(drslt_parts) > 1:
if hostname in drslt_parts[0]:
rmt_ip = drslt_parts[1]
else:
rmt_ip = drslt_parts[0]
if str.upper(config.SPLUNK) == 'ON' and splunk_index:
event = str(time.time()) + ','
event += 'protocol="SMB",'
event += 'ip_address=' + rmt_ip + ','
event += 'honey_hostname="' + hostname + '",'
event += 'honey_username="' + username + '",'
event += 'message="Responder activity detected!"'
splunk_index.submit(event, sourcetype="honeycreds.service", host=local_hostname)
logging.critical(messages.RSP_RECVD % {'color':'', 'bold':'', 'proto':'SMB', 'end':'', 'ip':rmt_ip, 'hostname':hostname})
print(messages.RSP_RECVD % {'color':termcolor.BLUE, 'bold':termcolor.BOLD, 'proto':'SMB', 'end':termcolor.END, 'ip':rmt_ip, 'hostname':hostname})
except:
pass
smbclient.reset_connection_cache()
if smb_exit.is_set() == False:
smb_exit.wait(config.SMB_SLEEP)
class HTTPClient(threading.Thread):
def __init__(self, username, hostname):
threading.Thread.__init__(self)
self.username = username
self.hostname = hostname
def run(self):
global config, http_exit, splunk_index, local_hostname
username = self.username
hostname = self.hostname
url = 'http://' + hostname
while http_exit.is_set() == False:
try:
hrsp = requests.get(url, auth=(username, config.def_password), timeout=(1,5))
try:
drslt = subprocess.check_output('dig +short ' + hostname, shell=True).decode('utf-8')
except:
pass
drslt_parts = drslt.split('\n')
rmt_ip = 'Unknown'
if len(drslt_parts) > 1:
if len(drslt_parts) > 1:
if hostname in drslt_parts[0]:
rmt_ip = drslt_parts[1]
else:
rmt_ip = drslt_parts[0]
if str.upper(config.SPLUNK) == 'ON' and splunk_index:
event = str(time.time()) + ','
event += 'protocol="HTTP",'
event += 'ip_address=' + rmt_ip + ','
event += 'honey_hostname="' + hostname + '",'
event += 'honey_username="' + username + '",'
event += 'message="Responder activity detected!"'
splunk_index.submit(event, sourcetype="honeycreds.service", host=local_hostname)
logging.critical(messages.RSP_RECVD % {'color':'', 'bold':'', 'proto':'HTTP', 'end':'', 'ip':rmt_ip, 'hostname':hostname})
print(messages.RSP_RECVD % {'color':termcolor.BLUE, 'bold':termcolor.BOLD, 'proto':'HTTP', 'end':termcolor.END, 'ip':rmt_ip, 'hostname':hostname})
except:
pass
if http_exit.is_set() == False:
http_exit.wait(config.HTTP_SLEEP)
def main():
global config, smb_Thread, http_Thread
os.system('clear')
banner()
print(termcolor.GREEN + termcolor.BOLD + '[+]' + termcolor.END + ' Sending events...')
username = config.def_domain + '\\' + config.def_username
hostname = config.def_hostname + '.' + config.def_fqdn
if str.upper(config.SPLUNK) == 'ON':
init_splunk()
if str.upper(config.SMB) == 'ON':
smb_Thread = SMBClient(username, hostname)
smb_Thread.start()
if str.upper(config.HTTP) == 'ON':
http_Thread = HTTPClient(username, hostname)
http_Thread.start()
if __name__ == '__main__':
signal(SIGINT, signal_handler)
init()
main()