Skip to content

Commit 9a1da68

Browse files
committed
New Version 1.32 cowrie issue fix
1 parent 47ab938 commit 9a1da68

File tree

4 files changed

+50
-75
lines changed

4 files changed

+50
-75
lines changed

ews.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from modules.einit import locksocket, ecfg
88
from modules.elog import ELog
9-
from modules.etoolbox import readonecfg
9+
from modules.etoolbox import readMYcfg
1010
from modules.ealert import EAlert
1111
from modules.esend import ESend
1212

@@ -21,7 +21,7 @@
2121
if __name__ == "__main__":
2222

2323
name = "EWS Poster"
24-
version = "v1.31"
24+
version = "v1.32"
2525

2626
functions = [adbhoney, beelzebub, ciscoasa, citrix, conpot, cowrie, ddospot, dicompot, dionaea,
2727
elasticpot, emobility, endlessh, fatt, galah, glastopfv3, glutton, gopot, h0neytr4p,
@@ -42,13 +42,13 @@
4242
honeypotname = honeypot.__name__
4343

4444
if ECFG["a.modul"] and ECFG["a.modul"] == honeypotname:
45-
if readonecfg(honeypotname.upper(), honeypotname, ECFG["cfgfile"]).lower() == "true":
45+
if readMYcfg(honeypotname.upper(), honeypotname, ECFG["cfgfile"]):
4646
honeypot(ECFG)
4747
break
4848
elif ECFG["a.modul"]:
4949
continue
5050

51-
if readonecfg(honeypotname.upper(), honeypotname, ECFG["cfgfile"]).lower() == "true":
51+
if readMYcfg(honeypotname.upper(), honeypotname, ECFG["cfgfile"]):
5252
honeypot(ECFG)
5353

5454
if int(ECFG["a.loop"]) == 0:

honeypots/cowrie.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,40 @@ def cowrie(ECFG):
3636

3737
if line['eventid'] == 'cowrie.session.connect' and line['session'] not in cowrieSessions:
3838
cowrieSessions[sid] = {}
39-
cowrieSessions[sid]['timestamp_start'] = line['timestamp']
40-
cowrieSessions[sid]['source_ip'] = line['src_ip']
41-
cowrieSessions[sid]['source_port'] = line['src_port']
42-
cowrieSessions[sid]['target_ip'] = line['dst_ip']
43-
cowrieSessions[sid]['target_port'] = line['dst_port']
44-
cowrieSessions[sid]['session_id'] = line['session']
45-
cowrieSessions[sid]['protocol'] = line['protocol']
39+
cowrieSessions[sid]['timestamp_start'] = line.get('timestamp')
40+
cowrieSessions[sid]['source_ip'] = line.get('src_ip')
41+
cowrieSessions[sid]['source_port'] = line.get('src_port')
42+
cowrieSessions[sid]['target_ip'] = line.get('dst_ip')
43+
cowrieSessions[sid]['target_port'] = line.get('dst_port')
44+
cowrieSessions[sid]['session_id'] = line.get('session')
45+
cowrieSessions[sid]['protocol'] = line.get('protocol')
4646

4747
if line['eventid'] == 'cowrie.login.success' and line['session'] in cowrieSessions:
4848
cowrieSessions[sid]['login'] = "Success"
49-
cowrieSessions[sid]['username'] = line['username']
50-
cowrieSessions[sid]['password'] = line['password']
51-
cowrieSessions[sid]['timestamp_login'] = line['timestamp']
49+
cowrieSessions[sid]['username'] = line.get('username')
50+
cowrieSessions[sid]['password'] = line.get('password')
51+
cowrieSessions[sid]['timestamp_login'] = line.get('timestamp')
5252

5353
if line['eventid'] == 'cowrie.login.failed' and line['session'] in cowrieSessions:
5454
cowrieSessions[sid]['login'] = "Fail"
55-
cowrieSessions[sid]['username'] = line['username']
56-
cowrieSessions[sid]['password'] = line['password']
57-
cowrieSessions[sid]['timestamp_login'] = line['timestamp']
55+
cowrieSessions[sid]['username'] = line.get('username')
56+
cowrieSessions[sid]['password'] = line.get('password')
57+
cowrieSessions[sid]['timestamp_login'] = line.get('timestamp')
5858

5959
if line['eventid'] == 'cowrie.session.closed' and line['session'] in cowrieSessions:
60-
cowrieSessions[sid]['timestamp_close'] = line['timestamp']
60+
cowrieSessions[sid]['timestamp_close'] = line.get('timestamp')
6161

6262
if line['eventid'] == 'cowrie.command.input' and line['session'] in cowrieSessions:
6363
try:
6464
cowrieSessions[sid]['input'].append(line['input'])
6565
except:
66-
cowrieSessions[sid]['input'] = [line['input']]
66+
cowrieSessions[sid]['input'] = [line.get('input')]
6767

6868
if line['eventid'] == 'cowrie.client.version' and line['session'] in cowrieSessions:
6969
if "b'" in line["version"]:
70-
cowrieSessions[sid]['version'] = re.search(r"b'(.*)'", line["version"], re.M).group(1)
70+
cowrieSessions[sid]['version'] = re.search(r"b'(.*)'", line.get("version"), re.M).group(1)
7171
else:
72-
cowrieSessions[sid]['version'] = line["version"]
72+
cowrieSessions[sid]['version'] = line.get("version")
7373

7474
""" second loop """
7575

@@ -111,4 +111,4 @@ def cowrie(ECFG):
111111
break
112112

113113
cowrie.finAlert()
114-
return()
114+
return()

modules/einit.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import ipaddress
88
import uuid
99
from modules.elog import ELog
10-
from modules.etoolbox import readcfg, getHostname, getIP, readcfg2
10+
from modules.etoolbox import getHostname, getIP, readMYcfg
1111

1212
logger = ELog('EInit')
1313

@@ -82,8 +82,8 @@ def ecfg(name, version, functions):
8282
ITEMS = ("homedir", "spooldir", "logdir", "del_malware_after_send", "send_malware",
8383
"sendlimit", "contact", "proxy", "ip_int", "ip_ext")
8484

85-
MCFG = readcfg('MAIN', ITEMS, ECFG['cfgfile'])
86-
85+
MCFG = readMYcfg('MAIN', ITEMS, ECFG['cfgfile'])
86+
8787
# home dir available?
8888
if not os.path.isdir(MCFG["homedir"]):
8989
logger.error(f"Missing homedir {MCFG['homedir']}. Abort!", '1E')
@@ -142,7 +142,7 @@ def ecfg(name, version, functions):
142142
# Read EWS Config Parameter
143143

144144
ITEMS = ("ews", "username", "token", "rhost_first", "rhost_second", "ignorecert")
145-
EWSCFG = readcfg("EWS", ITEMS, ECFG["cfgfile"])
145+
EWSCFG = readMYcfg("EWS", ITEMS, ECFG["cfgfile"])
146146

147147
if EWSCFG["ews"].lower() == "true":
148148
EWSCFG["ews"] = True
@@ -165,7 +165,7 @@ def ecfg(name, version, functions):
165165
ITEMS = ("hpfeed", "host", "port", "channels", "ident", "secret", "hpfformat",
166166
"tlscert")
167167

168-
HCFG = readcfg("HPFEED", ITEMS, ECFG["cfgfile"])
168+
HCFG = readMYcfg("HPFEED", ITEMS, ECFG["cfgfile"])
169169

170170
if HCFG["hpfeed"].lower() == "true":
171171
HCFG["hpfeed"] = True
@@ -191,7 +191,7 @@ def ecfg(name, version, functions):
191191
# Read EWSJSON Config Parameter
192192

193193
ITEMS = ("json", "jsondir")
194-
EWSJSON = readcfg("EWSJSON", ITEMS, ECFG["cfgfile"])
194+
EWSJSON = readMYcfg("EWSJSON", ITEMS, ECFG["cfgfile"])
195195

196196
if ECFG["a.jsondir"] != "":
197197
EWSJSON["json"] = True
@@ -211,7 +211,7 @@ def ecfg(name, version, functions):
211211
# Read INFLUX Config Parameter
212212

213213
ITEMS = ('influxdb', 'host', 'port', 'username', 'password', 'token', 'bucket', 'org')
214-
ICFG = readcfg2("INFLUXDB", ITEMS, ECFG["cfgfile"])
214+
ICFG = readMYcfg("INFLUXDB", ITEMS, ECFG["cfgfile"], loghandler='')
215215

216216
if 'influxdb' not in ICFG:
217217
ICFG['influxdb'] = False

modules/etoolbox.py

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,27 @@
1212

1313
logger = ELog('Etoolbox')
1414

15-
16-
def readcfg(MODUL, ITEMS, FILE):
15+
def readMYcfg(MODUL, ITEMS, FILE, loghandler='1E'):
1716
result = {}
1817

1918
config = configparser.ConfigParser(os.environ)
2019
config.read(FILE)
21-
22-
for item in ITEMS:
23-
if config.has_option(MODUL, item) is True and len(config.get(MODUL, item)) > 0:
24-
result[item] = config.get(MODUL, item)
20+
21+
if isinstance(ITEMS, str):
22+
if config.has_option(MODUL, ITEMS) and len(config.get(MODUL, ITEMS)) > 0:
23+
return(True)
24+
elif config.has_option(MODUL, ITEMS) and len(config.get(MODUL, ITEMS)) == 0:
25+
return(None)
2526
else:
26-
logger.error(f"Config MODUL [{MODUL}] parameter '{item}' didn't find or empty or not 'none' in {FILE} config file. Abort!", '1E')
27-
28-
return(result)
29-
30-
31-
def readcfg2(MODUL, ITEMS, FILE):
32-
result = {}
33-
34-
config = configparser.ConfigParser(os.environ)
35-
config.read(FILE)
36-
37-
for item in ITEMS:
38-
if config.has_option(MODUL, item) is True and len(config.get(MODUL, item)) > 0:
39-
result[item] = config.get(MODUL, item)
40-
return(result)
41-
27+
return(False)
28+
29+
if isinstance(ITEMS, tuple):
30+
for item in ITEMS:
31+
if config.has_option(MODUL, item) and len(config.get(MODUL, item)) > 0:
32+
result[item] = config.get(MODUL, item)
33+
elif loghandler == '1E':
34+
logger.error(f"Config MODUL [{MODUL}] parameter '{item}' didn't find or empty or not 'none' in {FILE} config file. Abort!", '1E')
35+
return(result)
4236

4337
def checkSECTIONcfg(MODUL, FILE):
4438
config = configparser.ConfigParser(os.environ)
@@ -49,21 +43,6 @@ def checkSECTIONcfg(MODUL, FILE):
4943
else:
5044
return(False)
5145

52-
53-
def readonecfg(MODUL, item, FILE):
54-
config = configparser.ConfigParser(os.environ)
55-
config.read(FILE)
56-
57-
if config.has_option(MODUL, item) is True and len(config.get(MODUL, item)) > 0:
58-
return config.get(MODUL, item)
59-
elif config.has_option(MODUL, item) is True and len(config.get(MODUL, item)) == 0:
60-
return('NULL')
61-
elif config.has_option(MODUL, item) is False:
62-
return('FALSE')
63-
else:
64-
return ('UNKNOW')
65-
66-
6746
def getIP(MODUL, ECFG):
6847
myIP = {}
6948

@@ -128,16 +107,12 @@ def getIP(MODUL, ECFG):
128107

129108
return(myIP)
130109

131-
132110
def getHostname(MODUL, ECFG):
133-
""" get Hostname from ENV/SOCKET/RANDOM """
134-
if os.environ.get('MY_HOSTNAME') is not None:
135-
return(os.environ.get('MY_HOSTNAME'))
136-
elif socket.gethostname() is not None:
137-
return(socket.gethostname())
138-
else:
139-
return("host-".join(random.choice(string.ascii_lowercase) for i in range(16)))
140-
111+
# get Hostname from ENV/SOCKET/RANDOM
112+
hostname = os.environ.get('MY_HOSTNAME')
113+
if hostname:
114+
return hostname
115+
return socket.gethostname() or f"host-{''.join(random.choices(string.ascii_lowercase, k=16))}"
141116

142117
if __name__ == "__main__":
143118
pass

0 commit comments

Comments
 (0)