Skip to content

Commit 55c3c1f

Browse files
Merge pull request #12 from cowrie/claude/c17-c23-comparison-UEqFB
2 parents 7f77b59 + 057d6f3 commit 55c3c1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+413
-589
lines changed

modules/python/dionaea/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def load_config_from_files(filename_patterns: list[str]) -> list[dict[str, Any]]
170170
e.problem # type: ignore[attr-defined]
171171
)
172172
if e.context is not None: # type: ignore[attr-defined]
173-
logger.debug("Parser(context): %s" % e.context) # type: ignore[attr-defined]
173+
logger.debug(f"Parser(context): {e.context}") # type: ignore[attr-defined]
174174
else:
175175
logger.error("Unknown error while parsing config file '%s'", filename)
176176

modules/python/dionaea/cmd.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def execute(self, cmd, args):
9090

9191
def cmd_ECHO(self, args):
9292
out = " ".join(args) + '\n'
93-
logger.debug("echo %s" % (out))
93+
logger.debug(f"echo {out}")
9494
return out,None
9595

9696
def cmd_FTP(self, args):
@@ -140,11 +140,11 @@ def cmd_FTP(self, args):
140140
for i in range(len(lines)):
141141
line = lines[i]
142142
logger.debug(f"FTP PARSER STATE {state}")
143-
logger.debug("FTP CMD LINE: %s" % (line) )
143+
logger.debug(f"FTP CMD LINE: {line}")
144144
args = line.split()
145145
if len(args) == 0:
146146
continue
147-
logger.debug("FTP CMD ARGS: %s" % (args) )
147+
logger.debug(f"FTP CMD ARGS: {args}")
148148
if state == 'NEXT_IS_SOMETHING':
149149
if args[0] == 'open':
150150
if len(args) == 1:
@@ -181,8 +181,7 @@ def cmd_FTP(self, args):
181181
i.con = self
182182
elif hasattr(self, 'con') and isinstance(self.con, connection):
183183
i.con = self.con
184-
i.url = "ftp://%s:%s@%s:%i/%s" % (
185-
user,passwd,host,port,dfile)
184+
i.url = f"ftp://{user}:{passwd}@{host}:{port}/{dfile}"
186185
i.ftpmode = ftpmode
187186
i.report()
188187
elif args[0] == 'cd':
@@ -228,20 +227,18 @@ def cmd_FTP(self, args):
228227
elif hasattr(self, 'con') and isinstance(self.con, connection):
229228
i.con = self.con
230229
i.ftpmode = ftpmode
231-
i.url = "ftp://%s:%s@%s:%i/%s" % (user,
232-
passwd,host,port,dfile)
230+
i.url = f"ftp://{user}:{passwd}@{host}:{port}/{dfile}"
233231
i.report()
234232

235233
elif state == 'NEXT_IS_PATH':
236234
if len(args) == 1:
237235
fpath = args[0]
238236
state = 'NEXT_IS_SOMETHING'
239-
logger.info("ftp://%s:%s@%s:%i/%s/%s" %
240-
(user,passwd,host,port,fpath,dfile))
237+
logger.info(f"ftp://{user}:{passwd}@{host}:{port}/{fpath}/{dfile}")
241238
return out,None
242239

243240
def cmd_TFTP(self, args):
244-
logger.debug("TFTP %s" % (args) )
241+
logger.debug(f"TFTP {args}")
245242
if len(args) != 4:
246243
logger.warning("TFTP command invalid number of args: expected 4, got %d", len(args))
247244
return "foo","error, invalid number of args"
@@ -388,7 +385,7 @@ def handle_origin(self, parent):
388385
class cmdshellhandler(ihandler):
389386

390387
def __init__(self, path, config=None):
391-
logger.debug("%s ready!" % (self.__class__.__name__))
388+
logger.debug(f"{self.__class__.__name__} ready!")
392389
ihandler.__init__(self, path)
393390

394391
def handle_incident(self, icd):

modules/python/dionaea/emu.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def start(cls, config: dict[str, Any] | None = None) -> 'emuprofilehandler':
2626
class emuprofilehandler(ihandler):
2727

2828
def __init__(self, path: str, config: dict[str, Any] | None = None) -> None:
29-
logger.debug("%s ready!" % (self.__class__.__name__))
29+
logger.debug(f"{self.__class__.__name__} ready!")
3030
ihandler.__init__(self, path)
3131

3232
def handle_incident(self, icd: incident) -> None:
@@ -39,7 +39,7 @@ def handle_incident(self, icd: incident) -> None:
3939
con = None
4040
p = json.loads(p)
4141
# print(p)
42-
logger.info("profiledump %s" % (p))
42+
logger.info(f"profiledump {p}")
4343
state = "NONE"
4444
host = None
4545
port = None
@@ -51,7 +51,7 @@ def handle_incident(self, icd: incident) -> None:
5151
state = "SOCKET"
5252
if api['call'] == 'URLDownloadToFile':
5353
url = api['args'][1]
54-
logger.debug("download file %s" % (url))
54+
logger.debug(f"download file {url}")
5555
i = incident("dionaea.download.offer")
5656
i.set("url", url)
5757
if con is not None:
@@ -88,7 +88,7 @@ def handle_incident(self, icd: incident) -> None:
8888

8989
elif state == "ACCEPT":
9090
if api['call'] == 'CreateProcess':
91-
logger.debug("bindshell host %s port %s" % (host, port) )
91+
logger.debug(f"bindshell host {host} port {port}")
9292
i = incident("dionaea.service.shell.listen")
9393
assert port is not None # For mypy
9494
i.set("port", int(port))
@@ -98,8 +98,7 @@ def handle_incident(self, icd: incident) -> None:
9898

9999
elif state == "CONNECT":
100100
if api['call'] == 'CreateProcess':
101-
logger.debug(
102-
"connectbackshell host %s port %s" % (host, port) )
101+
logger.debug(f"connectbackshell host {host} port {port}")
103102
i = incident("dionaea.service.shell.connect")
104103
assert port is not None # For mypy
105104
i.set("port", int(port))
@@ -112,8 +111,7 @@ def handle_incident(self, icd: incident) -> None:
112111
if api['call'] == 'connect':
113112
host = api['args'][1]['sin_addr']['s_addr']
114113
port = api['args'][1]['sin_port']
115-
logger.debug(
116-
"connectbackshell host %s port %s" % (host, port) )
114+
logger.debug(f"connectbackshell host {host} port {port}")
117115
i = incident("dionaea.service.shell.connect")
118116
assert port is not None # For mypy
119117
i.set("port", int(port))

modules/python/dionaea/emu_scripts/handler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# SPDX-License-Identifier: GPL-2.0-or-later
66

7-
from typing import Any, Pattern
7+
from typing import Any
88
import logging
99
import re
1010

@@ -20,9 +20,9 @@ def __init__(self, config: dict[str, Any] | None = None) -> None:
2020
self._config = config
2121

2222
self.min_match_count: int = 0
23-
self._regex_detect: list[Pattern[bytes]] = []
23+
self._regex_detect: list[re.Pattern[bytes]] = []
2424

25-
self._regex_url: Pattern[bytes] = re.compile(
25+
self._regex_url: re.Pattern[bytes] = re.compile(
2626
br"(?P<url>(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)"
2727
)
2828

@@ -52,7 +52,7 @@ def __init__(self, config: dict[str, Any] | None = None) -> None:
5252
if isinstance(config, dict):
5353
self._config = config
5454

55-
self._regex_url: Pattern[bytes] = re.compile(
55+
self._regex_url: re.Pattern[bytes] = re.compile(
5656
br"(?P<url>(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)"
5757
)
5858

modules/python/dionaea/exception.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ def __init__(self, connection: Any = None, error_id: int | None = None) -> None:
3535

3636
class ConnectionDNSTimeout(DionaeaConnectionError):
3737
def __str__(self) -> str:
38-
return "Timeout resolving the hostname/domain: %s" % (
39-
self.connection.remote.hostname
40-
)
38+
return f"Timeout resolving the hostname/domain: {self.connection.remote.hostname}"
4139

4240

4341
class ConnectionUnreachable(DionaeaConnectionError):
@@ -46,17 +44,12 @@ def __str__(self) -> str:
4644
if hostname is None or hostname == "":
4745
hostname = self.connection.remote.host
4846

49-
return "Could not connect to host(s): %s:%d" % (
50-
hostname,
51-
self.connection.remote.port
52-
)
47+
return f"Could not connect to host(s): {hostname}:{self.connection.remote.port}"
5348

5449

5550
class ConnectionNoSuchDomain(DionaeaConnectionError):
5651
def __str__(self) -> str:
57-
return "Could not resolve the domain: %s" % (
58-
self.connection.remote.hostname
59-
)
52+
return f"Could not resolve the domain: {self.connection.remote.hostname}"
6053

6154

6255
class ConnectionTooMany(DionaeaConnectionError):
@@ -67,6 +60,4 @@ def __str__(self) -> str:
6760
class ConnectionUnknownError(DionaeaConnectionError):
6861
def __str__(self) -> str:
6962
assert self.error_id is not None # For mypy
70-
return "Unknown error occurred: error_id=%d" % (
71-
self.error_id
72-
)
63+
return f"Unknown error occurred: error_id={self.error_id}"

modules/python/dionaea/fail2ban.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def start(cls, config: dict[str, Any] | None = None) -> 'fail2banhandler | None'
3030

3131
class fail2banhandler(ihandler):
3232
def __init__(self, config: dict[str, Any] | None = None) -> None:
33-
logger.debug("%s ready!" % (self.__class__.__name__))
33+
logger.debug(f"{self.__class__.__name__} ready!")
3434
ihandler.__init__(self, "*")
3535
if config is None:
3636
config = {}

modules/python/dionaea/ftp.py

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def reply(self, name, **kwargs):
191191
self.sendline(msg.format(**kwargs))
192192

193193
def handle_origin(self, parent):
194-
logger.debug("setting basedir to %s" % parent.basedir)
194+
logger.debug(f"setting basedir to {parent.basedir}")
195195
self.basedir = parent.basedir
196196

197197
def handle_established(self):
@@ -231,7 +231,7 @@ def handle_io_in(self, data: bytes) -> int:
231231
return lastsep
232232

233233
def processcmd(self, cmd, args):
234-
logger.debug("cmd '%s'" % cmd)
234+
logger.debug(f"cmd '{cmd}'")
235235
arguments = [i.decode('latin-1') for i in args]
236236

237237
i = incident("dionaea.modules.python.ftp.command")
@@ -307,9 +307,9 @@ def ftp_PORT(self, address):
307307
self.dtp.close()
308308
self.dtp = None
309309
addr = list(map(int, address.split(',')))
310-
ip = '%d.%d.%d.%d' % tuple(addr[:4])
310+
ip = f'{addr[0]}.{addr[1]}.{addr[2]}.{addr[3]}'
311311
port = addr[4] << 8 | addr[5]
312-
logger.debug("PORT cmd for port %i" % port)
312+
logger.debug(f"PORT cmd for port {port}")
313313
if self.remote.host != ip and "::ffff:" + self.remote.host != ip:
314314
logger.warning("Potential FTP Bounce Scan detected")
315315
return None
@@ -582,7 +582,7 @@ def handle_error(self, err):
582582

583583
def send_list(self, p, rm):
584584
def ls(f, r):
585-
logger.debug("stat %s" % f)
585+
logger.debug(f"stat {f}")
586586
name = f[r:]
587587
s=os.stat(f)
588588
size = s.st_size
@@ -598,41 +598,26 @@ def formatMode(mode):
598598

599599
def formatDate(mtime):
600600
now = time.gmtime()
601-
info = {
602-
'month': mtime.tm_mon,
603-
'day': mtime.tm_mday,
604-
'year': mtime.tm_year,
605-
'hour': mtime.tm_hour,
606-
'minute': mtime.tm_min
607-
}
608601
if now.tm_year != mtime.tm_year:
609-
return '%(month)s %(day)02d %(year)5d' % info
602+
return f'{mtime.tm_mon} {mtime.tm_mday:02d} {mtime.tm_year:5d}'
610603
else:
611-
return '%(month)s %(day)02d %(hour)02d:%(minute)02d' % info
612-
613-
format = (
614-
'%(directory)s%(permissions)s%(hardlinks)4d '
615-
'%(owner)-9s %(group)-9s %(size)15d %(date)12s '
616-
'%(name)s'
604+
return f'{mtime.tm_mon} {mtime.tm_mday:02d} {mtime.tm_hour:02d}:{mtime.tm_min:02d}'
605+
606+
dir_char = 'd' if directory else '-'
607+
date_str = formatDate(time.gmtime(modified))
608+
return (
609+
f'{dir_char}{formatMode(permissions)}{hardlinks:4d} '
610+
f'{owner:<9} {group:<9} {size:15d} {date_str:>12} '
611+
f'{name}'
617612
)
618-
return format % {
619-
'directory': directory and 'd' or '-',
620-
'permissions': formatMode(permissions),
621-
'hardlinks': hardlinks,
622-
'owner': owner,
623-
'group': group,
624-
'size': size,
625-
'date': formatDate(time.gmtime(modified)),
626-
'name': name
627-
}
628613

629614
self.mode = 'list'
630615
if os.path.isdir(p):
631616
self.data = [ls(os.path.join(p,f), rm) for f in os.listdir(p)]
632617
elif os.path.isfile(p):
633618
self.data = [ls(p)]
634619

635-
logger.debug("p %s len %i" % (p, len(self.data)) )
620+
logger.debug(f"p {p} len {len(self.data)}")
636621
if len(self.data) > 0:
637622
self.off = 0
638623
self.off = self.off + 1

modules/python/dionaea/hpfeeds.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def __init__(self, path, config=None):
267267
try:
268268
reconnect_timeout = float(reconnect_timeout)
269269
except (TypeError, ValueError):
270-
logger.warning("Unable to convert value '%s' for reconnect timeout to float" % reconnect_timeout)
270+
logger.warning(f"Unable to convert value '{reconnect_timeout}' for reconnect timeout to float")
271271
reconnect_timeout = self.default_reconnect_timeout
272272

273273
port = config.get("port")
@@ -276,7 +276,7 @@ def __init__(self, path, config=None):
276276
try:
277277
port = int(port)
278278
except (TypeError, ValueError):
279-
logger.warning("Unable to convert value '%s' for port to int" % port)
279+
logger.warning(f"Unable to convert value '{port}' for port to int")
280280
port = self.default_port
281281

282282
self.client = hpclient(
@@ -341,56 +341,47 @@ def handle_incident(self, i):
341341
def handle_incident_dionaea_connection_tcp_listen(self, icd):
342342
self.connection_publish(icd, 'listen')
343343
con=icd.con
344-
logger.info("listen connection on %s:%i" %
345-
(con.remote.host, con.remote.port))
344+
logger.info(f"listen connection on {con.remote.host}:{con.remote.port}")
346345

347346
def handle_incident_dionaea_connection_tls_listen(self, icd):
348347
self.connection_publish(icd, 'listen')
349348
con=icd.con
350-
logger.info("listen connection on %s:%i" %
351-
(con.remote.host, con.remote.port))
349+
logger.info(f"listen connection on {con.remote.host}:{con.remote.port}")
352350

353351
def handle_incident_dionaea_connection_tcp_connect(self, icd):
354352
self.connection_publish(icd, 'connect')
355353
con=icd.con
356-
logger.info("connect connection to %s/%s:%i from %s:%i" %
357-
(con.remote.host, con.remote.hostname, con.remote.port, self._ownip(icd), con.local.port))
354+
logger.info(f"connect connection to {con.remote.host}/{con.remote.hostname}:{con.remote.port} from {self._ownip(icd)}:{con.local.port}")
358355

359356
def handle_incident_dionaea_connection_tls_connect(self, icd):
360357
self.connection_publish(icd, 'connect')
361358
con=icd.con
362-
logger.info("connect connection to %s/%s:%i from %s:%i" %
363-
(con.remote.host, con.remote.hostname, con.remote.port, self._ownip(icd), con.local.port))
359+
logger.info(f"connect connection to {con.remote.host}/{con.remote.hostname}:{con.remote.port} from {self._ownip(icd)}:{con.local.port}")
364360

365361
def handle_incident_dionaea_connection_udp_connect(self, icd):
366362
self.connection_publish(icd, 'connect')
367363
con=icd.con
368-
logger.info("connect connection to %s/%s:%i from %s:%i" %
369-
(con.remote.host, con.remote.hostname, con.remote.port, self._ownip(icd), con.local.port))
364+
logger.info(f"connect connection to {con.remote.host}/{con.remote.hostname}:{con.remote.port} from {self._ownip(icd)}:{con.local.port}")
370365

371366
def handle_incident_dionaea_connection_tcp_accept(self, icd):
372367
self.connection_publish(icd, 'accept')
373368
con=icd.con
374-
logger.info("accepted connection from %s:%i to %s:%i" %
375-
(con.remote.host, con.remote.port, self._ownip(icd), con.local.port))
369+
logger.info(f"accepted connection from {con.remote.host}:{con.remote.port} to {self._ownip(icd)}:{con.local.port}")
376370

377371
def handle_incident_dionaea_connection_tls_accept(self, icd):
378372
self.connection_publish(icd, 'accept')
379373
con=icd.con
380-
logger.info("accepted connection from %s:%i to %s:%i" %
381-
(con.remote.host, con.remote.port, self._ownip(icd), con.local.port))
374+
logger.info(f"accepted connection from {con.remote.host}:{con.remote.port} to {self._ownip(icd)}:{con.local.port}")
382375

383376
def handle_incident_dionaea_connection_tcp_reject(self, icd):
384377
self.connection_publish(icd, 'reject')
385378
con=icd.con
386-
logger.info("reject connection from %s:%i to %s:%i" %
387-
(con.remote.host, con.remote.port, self._ownip(icd), con.local.port))
379+
logger.info(f"reject connection from {con.remote.host}:{con.remote.port} to {self._ownip(icd)}:{con.local.port}")
388380

389381
def handle_incident_dionaea_connection_tcp_pending(self, icd):
390382
self.connection_publish(icd, 'pending')
391383
con=icd.con
392-
logger.info("pending connection from %s:%i to %s:%i" %
393-
(con.remote.host, con.remote.port, self._ownip(icd), con.local.port))
384+
logger.info(f"pending connection from {con.remote.host}:{con.remote.port} to {self._ownip(icd)}:{con.local.port}")
394385

395386
def handle_incident_dionaea_download_complete_unique(self, i):
396387
self.handle_incident_dionaea_download_complete_again(i)

0 commit comments

Comments
 (0)