From 129b2792dc484276379797c263c4373ce48bbbf9 Mon Sep 17 00:00:00 2001 From: xambroz <723625+xambroz@users.noreply.github.com> Date: Wed, 31 Jul 2024 16:34:50 +0200 Subject: [PATCH 1/6] ipv6 structures in are used by the so it should be included first ipv6 structures needs explicit CFLAGS " -D_GNU_SOURCE" to compile on linux --- include/connection.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/connection.h b/include/connection.h index 391512b6..58afd9c9 100644 --- a/include/connection.h +++ b/include/connection.h @@ -9,11 +9,11 @@ #ifndef HAVE_CONNECTION_H #define HAVE_CONNECTION_H +#include #include #include #include -#include //#include #include #include From 09675f6df30e4476bccd726ce976e2146e563359 Mon Sep 17 00:00:00 2001 From: xambroz <723625+xambroz@users.noreply.github.com> Date: Thu, 1 Aug 2024 14:48:09 +0200 Subject: [PATCH 2/6] The PyEval_CallObject API is obsolete in python 3.12, use PyObject_CallObject instead --- modules/python/module.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/python/module.c b/modules/python/module.c index 989df16f..a0fc9af0 100644 --- a/modules/python/module.c +++ b/modules/python/module.c @@ -138,7 +138,7 @@ static void python_mkshell_ihandler_cb(struct incident *i, void *ctx) Py_DECREF(module); PyObject *func = PyObject_GetAttrString(module, "remoteshell"); PyObject *arglist = Py_BuildValue("()"); - PyObject *r = PyEval_CallObject(func, arglist); + PyObject *r = PyObject_CallObject(func, arglist); Py_DECREF(arglist); g_debug("r %p", r); struct head @@ -181,7 +181,7 @@ static bool hupy(void) PyObject *func = PyObject_GetAttrString(i->module, "stop"); if ( func != NULL ) { PyObject *arglist = Py_BuildValue("()"); - PyObject *r = PyEval_CallObject(func, arglist); + PyObject *r = PyObject_CallObject(func, arglist); traceback(); // PyErr_Print(); Py_DECREF(arglist); @@ -203,7 +203,7 @@ static bool hupy(void) func = PyObject_GetAttrString(module, "new"); if( func != NULL ) { PyObject *arglist = Py_BuildValue("()"); - PyObject *r = PyEval_CallObject(func, arglist); + PyObject *r = PyObject_CallObject(func, arglist); traceback(); Py_DECREF(arglist); Py_XDECREF(r); @@ -214,7 +214,7 @@ static bool hupy(void) func = PyObject_GetAttrString(module, "start"); if( func != NULL ) { PyObject *arglist = Py_BuildValue("()"); - PyObject *r = PyEval_CallObject(func, arglist); + PyObject *r = PyObject_CallObject(func, arglist); traceback(); Py_DECREF(arglist); Py_XDECREF(r); @@ -239,7 +239,7 @@ static bool hupy(void) PyObject *func = PyObject_GetAttrString(module, "new"); if( func != NULL ) { PyObject *arglist = Py_BuildValue("()"); - PyObject *r = PyEval_CallObject(func, arglist); + PyObject *r = PyObject_CallObject(func, arglist); Py_DECREF(arglist); Py_XDECREF(r); Py_DECREF(func); @@ -273,7 +273,7 @@ static bool freepy(void) if( func != NULL ) { PyObject *arglist = Py_BuildValue("()"); - PyObject *r = PyEval_CallObject(func, arglist); + PyObject *r = PyObject_CallObject(func, arglist); Py_DECREF(arglist); Py_XDECREF(r); Py_DECREF(func); @@ -306,7 +306,7 @@ static bool start(void) if( func != NULL ) { PyObject *arglist = Py_BuildValue("()"); - PyObject *r = PyEval_CallObject(func, arglist); + PyObject *r = PyObject_CallObject(func, arglist); Py_DECREF(arglist); Py_XDECREF(r); Py_DECREF(func); @@ -389,7 +389,7 @@ static bool new(struct dionaea *dionaea) PyObject *func = PyObject_GetAttrString(module, "new"); if( func != NULL ) { PyObject *arglist = Py_BuildValue("()"); - PyObject *r = PyEval_CallObject(func, arglist); + PyObject *r = PyObject_CallObject(func, arglist); Py_DECREF(arglist); Py_XDECREF(r); Py_DECREF(func); From 7851d0cb413e8005b14caa0c8a7fc31f509a435a Mon Sep 17 00:00:00 2001 From: xambroz <723625+xambroz@users.noreply.github.com> Date: Thu, 1 Aug 2024 14:51:13 +0200 Subject: [PATCH 3/6] APPEND adds unwanted ";" character if there are already some CMAKE_C_FLAGS defined --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4144e225..25aa1d2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ project( set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) # ToDo: move to source file? -list(APPEND CMAKE_C_FLAGS "-D_GNU_SOURCE") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE") list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) From 4a02745ecf6fdbc939aadd90a629bcc244ac72f0 Mon Sep 17 00:00:00 2001 From: xambroz <723625+xambroz@users.noreply.github.com> Date: Thu, 1 Aug 2024 14:54:48 +0200 Subject: [PATCH 4/6] change handling of dirs to be able to configure/install to base system having configuration in /etc/, data files in /var and rest in /usr, while keeping the possibility to install to /opt/dionaea by default --- CMakeLists.txt | 32 ++++++++++++++++++++++++++------ cmake/InstallConfig.cmake | 8 ++++---- cmake/InstallPythonConfig.cmake | 4 ++-- modules/curl/CMakeLists.txt | 2 +- modules/emu/CMakeLists.txt | 2 +- modules/nfq/CMakeLists.txt | 2 +- modules/nl/CMakeLists.txt | 2 +- modules/pcap/CMakeLists.txt | 2 +- modules/python/CMakeLists.txt | 2 +- modules/xmatch/CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- 11 files changed, 40 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25aa1d2f..a7b44dc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,27 @@ option(WITH_MODULE_PCAP "Build the pcap module" ON) option(RELEASE_BUILD "Remove Git revision from program version (use for stable releases)" OFF) +# Default install prefix for Dionaea +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + message(STATUS "INFO: Setting the CMAKE_INSTALL_PREFIX to default - /opt/dionaea") + set_property(CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "/opt/dionaea") +endif() + +message(STATUS "Before GNUInstallDirs: CMAKE_INSTALL_FULL_LOCALSTATEDIR = ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}") include(GNUInstallDirs) +message(STATUS "After GNUInstallDirs: CMAKE_INSTALL_FULL_LOCALSTATEDIR = ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}") + +### Dionaea non-FHS compliant defaults /opt/dionaea +# Dionaea defaults are different from FHS as used in GNUInstallDirs +# for example the default when prefix is set to /opt/dionaea, the configuration +# is expected in /opt/dionaea/etc and not in /etc/opt/dionaea, same for the state dirs +# expected to be in /opt/dionaea/var/lib and not in /var/opt/dionaea/lib +if(CMAKE_INSTALL_PREFIX STREQUAL "/opt/dionaea") + set(CMAKE_INSTALL_FULL_SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/etc" CACHE PATH "Configuration") + set(CMAKE_INSTALL_FULL_LOCALSTATEDIR "${CMAKE_INSTALL_PREFIX}/var" CACHE PATH "Modifiable single-machine data (var)" FORCE) + set(CMAKE_INSTALL_FULL_RUNSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run" CACHE PATH "Run-time variable data (LOCALSTATEDIR/run)") +endif() + include(InstallConfig) include(Packaging) @@ -90,12 +110,12 @@ endif() set(DIONAEA_USER "dionaea" CACHE STRING "Dionaea user") set(DIONAEA_GROUP "dionaea" CACHE STRING "Dionaea group") -set(DIONAEA_MODDIR ${CMAKE_INSTALL_LIBDIR}/dionaea) -set(DIONAEA_CONFDIR ${CMAKE_INSTALL_SYSCONFDIR}/dionaea) -set(DIONAEA_RUNDIR "${CMAKE_INSTALL_LOCALSTATEDIR}/run" CACHE STRING "/run directory") -set(DIONAEA_STATEDIR ${CMAKE_INSTALL_LOCALSTATEDIR}/lib/dionaea) -set(DIONAEA_LOGDIR ${CMAKE_INSTALL_LOCALSTATEDIR}/log/dionaea) -set(DIONAEA_PYTHON_SITELIBDIR ${CMAKE_INSTALL_LIBDIR}/dionaea/python) +set(DIONAEA_MODDIR ${CMAKE_INSTALL_FULL_LIBDIR}/dionaea CACHE PATH "Dionaea directory for plugin modules") +set(DIONAEA_CONFDIR ${CMAKE_INSTALL_FULL_SYSCONFDIR}/dionaea CACHE PATH "Dionaea configuration directory") +set(DIONAEA_RUNDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run" CACHE PATH "Dionaea /run directory") +set(DIONAEA_STATEDIR ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/dionaea CACHE PATH "Dionaea directory for storing the status") +set(DIONAEA_LOGDIR ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/dionaea CACHE PATH "Dionaea log directory") +set(DIONAEA_PYTHON_SITELIBDIR ${CMAKE_INSTALL_FULL_LIBDIR}/dionaea/python CACHE PATH "Dionaea location of python modules") ########### requirements ############### diff --git a/cmake/InstallConfig.cmake b/cmake/InstallConfig.cmake index d687752a..60dc8c1c 100644 --- a/cmake/InstallConfig.cmake +++ b/cmake/InstallConfig.cmake @@ -12,17 +12,17 @@ function(install_if_not_exists src dest) get_filename_component(src_name "${src}" NAME) get_filename_component(basename_dest "${src}" NAME) install(CODE " - if(\${CMAKE_INSTALL_FULL_PREFIX} MATCHES .*/_CPack_Packages/.* OR NOT EXISTS \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${dest}/${src_name}\") - message(STATUS \"Installing: \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${dest}/${src_name}\") + if(\${CMAKE_INSTALL_FULL_PREFIX} MATCHES .*/_CPack_Packages/.* OR NOT EXISTS \"\$ENV{DESTDIR}/${dest}/${src_name}\") + message(STATUS \"Installing: \$ENV{DESTDIR}/${dest}/${src_name}\") execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\" - \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${dest}/${src_name}\" + \"\$ENV{DESTDIR}/${dest}/${src_name}\" RESULT_VARIABLE copy_result ERROR_VARIABLE error_output) if(copy_result) message(FATAL_ERROR \${error_output}) endif() else() - message(STATUS \"Skipping : \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${dest}/${src_name}\") + message(STATUS \"Skipping : \$ENV{DESTDIR}/${dest}/${src_name}\") endif() ") endfunction() diff --git a/cmake/InstallPythonConfig.cmake b/cmake/InstallPythonConfig.cmake index cd51e834..56d90729 100644 --- a/cmake/InstallPythonConfig.cmake +++ b/cmake/InstallPythonConfig.cmake @@ -43,13 +43,13 @@ function(install_enabled_python_config) if(NOT EXISTS "${_conf_dst}") install(DIRECTORY DESTINATION "${_conf_dst}") foreach(filename ${MY_FUNC_FILES}) - install(CODE "message(STATUS \"Enabling Service: ${filename} in \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${_conf_dst}\")") + install(CODE "message(STATUS \"Enabling Service: ${filename} in \$ENV{DESTDIR}/${_conf_dst}\")") install(CODE " EXECUTE_PROCESS( COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ${MY_FUNC_SOURCE_REL_DIR}/${filename} ${filename} - WORKING_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${_conf_dst}\" + WORKING_DIRECTORY \"\$ENV{DESTDIR}/${_conf_dst}\" ) ") endforeach() diff --git a/modules/curl/CMakeLists.txt b/modules/curl/CMakeLists.txt index 7ff08da0..bc03c99b 100644 --- a/modules/curl/CMakeLists.txt +++ b/modules/curl/CMakeLists.txt @@ -40,5 +40,5 @@ target_link_libraries( install( TARGETS module_curl - LIBRARY DESTINATION lib/dionaea + LIBRARY DESTINATION ${DIONAEA_MODDIR} ) diff --git a/modules/emu/CMakeLists.txt b/modules/emu/CMakeLists.txt index e5f6a318..7288fbaf 100644 --- a/modules/emu/CMakeLists.txt +++ b/modules/emu/CMakeLists.txt @@ -41,5 +41,5 @@ target_link_libraries( install( TARGETS module_emu - LIBRARY DESTINATION lib/dionaea + LIBRARY DESTINATION ${DIONAEA_MODDIR} ) diff --git a/modules/nfq/CMakeLists.txt b/modules/nfq/CMakeLists.txt index a5b5d633..f26e3973 100644 --- a/modules/nfq/CMakeLists.txt +++ b/modules/nfq/CMakeLists.txt @@ -41,5 +41,5 @@ target_link_libraries( install( TARGETS module_nfq - LIBRARY DESTINATION lib/dionaea + LIBRARY DESTINATION ${DIONAEA_MODDIR} ) diff --git a/modules/nl/CMakeLists.txt b/modules/nl/CMakeLists.txt index 6638d47b..053657c8 100644 --- a/modules/nl/CMakeLists.txt +++ b/modules/nl/CMakeLists.txt @@ -42,5 +42,5 @@ target_link_libraries( install( TARGETS module_nl - LIBRARY DESTINATION lib/dionaea + LIBRARY DESTINATION ${DIONAEA_MODDIR} ) diff --git a/modules/pcap/CMakeLists.txt b/modules/pcap/CMakeLists.txt index 977b547a..f3d2f67e 100644 --- a/modules/pcap/CMakeLists.txt +++ b/modules/pcap/CMakeLists.txt @@ -39,5 +39,5 @@ target_link_libraries( install( TARGETS module_pcap - LIBRARY DESTINATION lib/dionaea + LIBRARY DESTINATION ${DIONAEA_MODDIR} ) diff --git a/modules/python/CMakeLists.txt b/modules/python/CMakeLists.txt index 02ba4415..2feabb82 100644 --- a/modules/python/CMakeLists.txt +++ b/modules/python/CMakeLists.txt @@ -31,7 +31,7 @@ if (PYTHONINTERP_FOUND) ) #install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} install --prefix=${CMAKE_INSTALL_PREFIX})") - install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} install --install-lib=\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${DIONAEA_PYTHON_SITELIBDIR})") + install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} install --install-lib=\$ENV{DESTDIR}/${DIONAEA_PYTHON_SITELIBDIR})") endif() add_library( diff --git a/modules/xmatch/CMakeLists.txt b/modules/xmatch/CMakeLists.txt index 8f5dcd04..cb470e3f 100644 --- a/modules/xmatch/CMakeLists.txt +++ b/modules/xmatch/CMakeLists.txt @@ -27,5 +27,5 @@ target_link_libraries (xmatch ${GMODULE2_LIBRARIES}) install( TARGETS xmatch - LIBRARY DESTINATION lib + LIBRARY DESTINATION ${DIONAEA_MODDIR} ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ac1f4076..f3dc51b4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -59,7 +59,7 @@ target_link_libraries( install ( TARGETS dionaea - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR} ) configure_file( From c6e05f2796ae7a349b9cfca4cf3f9691a8cdb719 Mon Sep 17 00:00:00 2001 From: xambroz <723625+xambroz@users.noreply.github.com> Date: Thu, 1 Aug 2024 14:57:48 +0200 Subject: [PATCH 5/6] new versions of python 3.9+ new regex patterns defined as raw strings, otherwise report syntax error for unknown stirng escape sequence like \s --- doc/source/conf.py | 2 +- modules/python/dionaea/cmd.py | 2 +- modules/python/dionaea/emu_scripts/handler.py | 16 ++++++++-------- modules/python/dionaea/memcache/command.py | 10 +++++----- modules/python/dionaea/mysql/mysql.py | 16 ++++++++-------- modules/python/dionaea/sip/extras.py | 2 +- modules/python/dionaea/sip/rfc2396.py | 18 +++++++++--------- modules/python/dionaea/sip/rfc3261.py | 2 +- modules/python/dionaea/smb/include/asn1/mib.py | 10 +++++----- .../python/dionaea/smb/include/fieldtypes.py | 2 +- modules/python/dionaea/smb/rpcservices.py | 2 +- modules/python/dionaea/util.py | 6 +++--- 12 files changed, 44 insertions(+), 44 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 005cc98a..d05b5fef 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -62,7 +62,7 @@ # The short X.Y version. version = "undefined" regex_version = re.compile( - "^project\s*\([^)]+?\s+VERSION\s+(?P[0-9]+\.[0-9]+\.[0-9]+)$", + r"^project\s*\([^)]+?\s+VERSION\s+(?P[0-9]+\.[0-9]+\.[0-9]+)$", re.MULTILINE|re.DOTALL ) data = open("../../CMakeLists.txt", "r").read() diff --git a/modules/python/dionaea/cmd.py b/modules/python/dionaea/cmd.py index 814aaf99..549a22a6 100644 --- a/modules/python/dionaea/cmd.py +++ b/modules/python/dionaea/cmd.py @@ -29,7 +29,7 @@ def __init__(self, w): else: self.send = self.void self.files = {} - self.cwd = 'C:\WINDOWS\System32' + self.cwd = 'C:\\WINDOWS\\System32' def handle_io_in(self, data): diff --git a/modules/python/dionaea/emu_scripts/handler.py b/modules/python/dionaea/emu_scripts/handler.py index 7833fa39..1bd1b88f 100644 --- a/modules/python/dionaea/emu_scripts/handler.py +++ b/modules/python/dionaea/emu_scripts/handler.py @@ -22,7 +22,7 @@ def __init__(self, config=None): self._regex_detect = [] self._regex_url = re.compile( - b"(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)" + r"(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)" ) def run(self, data): @@ -52,7 +52,7 @@ def __init__(self, config=None): self._config = config self._regex_url = re.compile( - b"(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)" + r"(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)" ) def run(self, data): @@ -70,13 +70,13 @@ def __init__(self, config=None): self.min_match_count = 2 self._regex_detect = [ - re.compile(b"New-Object\s+System\.Net\.WebClient"), - re.compile(b"DownloadFile([^,]+?,[^,]+?)"), - re.compile(b"Invoke-Expression([^)]+?)") + re.compile(r"New-Object\s+System\.Net\.WebClient"), + re.compile(r"DownloadFile([^,]+?,[^,]+?)"), + re.compile(r"Invoke-Expression([^)]+?)") ] self._regex_url = re.compile( - b"\w+\s*=\s*\"\s*(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)\s*\"" + r"\w+\s*=\s*\"\s*(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)\s*\"" ) @@ -88,9 +88,9 @@ def __init__(self, config=None): self.min_match_count = 1 self._regex_detect = [ - re.compile(b"Set\s+\w+\s+=\s+CreateObject\(.*?(Msxml2.XMLHTTP|Wscript.Shell).*?\)") + re.compile(r"Set\s+\w+\s+=\s+CreateObject\(.*?(Msxml2.XMLHTTP|Wscript.Shell).*?\)") ] self._regex_url = re.compile( - b"\.Open\s+\"GET\"\s*,\s*\"(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)\"" + r"\.Open\s+\"GET\"\s*,\s*\"(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)\"" ) diff --git a/modules/python/dionaea/memcache/command.py b/modules/python/dionaea/memcache/command.py index 35683480..17fadfbe 100644 --- a/modules/python/dionaea/memcache/command.py +++ b/modules/python/dionaea/memcache/command.py @@ -18,7 +18,7 @@ def from_line(cls, cmd_line): class Decrement(Command): name = "decr" - regex_cmd = re.compile(b"^decr (?P\w+) (?P\d+)( (?Pnoreply))?$") + regex_cmd = re.compile(r"^decr (?P\w+) (?P\d+)( (?Pnoreply))?$") def __init__(self, key=None, value=0, no_reply=False): self.key = key @@ -37,7 +37,7 @@ def from_line(cls, cmd_line): class Delete(Command): name = "delete" - regex_cmd = re.compile(b"^(?P\w+) (?P\w+)( (?Pnoreply))?$") + regex_cmd = re.compile(r"^(?P\w+) (?P\w+)( (?Pnoreply))?$") def __init__(self, key=None, no_reply=None): self.key = key @@ -73,7 +73,7 @@ def from_line(cls, cmd_line): class Increment(Command): name = "incr" - regex_cmd = re.compile(b"^incr (?P\w+) (?P\d+)( (?Pnoreply))?$") + regex_cmd = re.compile(r"^incr (?P\w+) (?P\d+)( (?Pnoreply))?$") def __init__(self, key=None, value=0, no_reply=False): self.key = key @@ -91,7 +91,7 @@ def from_line(cls, cmd_line): class StorageCommand(Command): - regex_cmd = re.compile(b"^(?P\w+) (?P\w+) (?P\d+) (?P\d+) (?P\d+)( (?Pnoreply))?") + regex_cmd = re.compile(r"^(?P\w+) (?P\w+) (?P\d+) (?P\d+) (?P\d+)( (?Pnoreply))?") def __init__(self, key=None, flags=None, exptime=None, byte_count=None, noreply=None): self.key = key @@ -171,7 +171,7 @@ def from_line(cls, cmd_line): class Touch(Command): name = "touch" - regex_cmd = re.compile(b"^touch (?P\w+) (?P\d+)( (?Pnoreply))?$") + regex_cmd = re.compile(r"^touch (?P\w+) (?P\d+)( (?Pnoreply))?$") def __init__(self, key=None, exptime=None, no_reply=None): self.key = key diff --git a/modules/python/dionaea/mysql/mysql.py b/modules/python/dionaea/mysql/mysql.py index eae2c8e5..9c256c88 100644 --- a/modules/python/dionaea/mysql/mysql.py +++ b/modules/python/dionaea/mysql/mysql.py @@ -19,12 +19,12 @@ logger = logging.getLogger('mysqld') re_show_var = re.compile( - b"show\s+((?Pglobal)\s+)?variables(\s+like\s+(?P\"|')(?P.*?)(?P=sep))?", + r"show\s+((?Pglobal)\s+)?variables(\s+like\s+(?P\"|')(?P.*?)(?P=sep))?", re.I ) re_select_var = re.compile( - b"select\s+(?P@(?P@)?(?P\w+))(\s+limit\s+\d+)?", + r"select\s+(?P@(?P@)?(?P\w+))(\s+limit\s+\d+)?", re.I ) @@ -42,7 +42,7 @@ def __init__(self): self.config = None self.state = "" self.regex_statement = re.compile( - b"""([A-Za-z0-9_.]+\(.*?\)+|\(.*?\)+|"(?:[^"]|\"|"")*"+|'[^'](?:|\'|'')*'+|`(?:[^`]|``)*`+|[^ ,]+|,)""" + r"""([A-Za-z0-9_.]+\(.*?\)+|\(.*?\)+|"(?:[^"]|\"|"")*"+|'[^'](?:|\'|'')*'+|`(?:[^`]|``)*`+|[^ ,]+|,)""" ) self.download_dir = None self.download_suffix = ".tmp" @@ -146,7 +146,7 @@ def _handle_COM_QUERY(self, p): if re.match(b'set ', p.Query, re.I): r = MySQL_Result_OK(Message="#2") - elif re.match(b'select\s+database\s*\(\s*\)$', p.Query, re.I): + elif re.match(r'select\s+database\s*\(\s*\)$', p.Query, re.I): r = [ MySQL_Result_Header(FieldCount=1), MySQL_Result_Field( @@ -167,7 +167,7 @@ def _handle_COM_QUERY(self, p): MySQL_Result_EOF(ServerStatus=0x002) ] - elif re.match(b"show\s+databases$", p.Query, re.I): + elif re.match(r"show\s+databases$", p.Query, re.I): r = [ MySQL_Result_Header(FieldCount=1), MySQL_Result_Field( @@ -192,7 +192,7 @@ def _handle_COM_QUERY(self, p): # r.append(MySQL_Result_Row_Data(ColumnValues=['information_schema'])) r.append(MySQL_Result_EOF(ServerStatus=0x002)) - elif re.match(b'show\s+tables$', p.Query, re.I): + elif re.match(r'show\s+tables$', p.Query, re.I): r = [ MySQL_Result_Header(FieldCount=1), MySQL_Result_Field( @@ -273,8 +273,8 @@ def _handle_com_query_select(self, p, query): if len(query) == 0: return False - regex_function = re.compile(b"(?P[A-Za-z0-9_.]+)\((?P.*?)\)+") - regex_url = re.compile(b"(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)") + regex_function = re.compile(r"(?P[A-Za-z0-9_.]+)\((?P.*?)\)+") + regex_url = re.compile(r"(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)") m = re_select_var.match(p.Query) if m: diff --git a/modules/python/dionaea/sip/extras.py b/modules/python/dionaea/sip/extras.py index 486c2357..b2e77b72 100644 --- a/modules/python/dionaea/sip/extras.py +++ b/modules/python/dionaea/sip/extras.py @@ -261,7 +261,7 @@ def get_sdp_by_name(self, name, media_ports, **params): sdp = data[0] for n,v in media_ports.items(): if v is None: - sdp = re.sub("\[" + n +"\].*\[\/" + n + "\]", "", sdp, 0, re.DOTALL) + sdp = re.sub("\\[" + n +"\\].*\\[\\/" + n + "\\]", "", sdp, 0, re.DOTALL) else: params[n] = v diff --git a/modules/python/dionaea/sip/rfc2396.py b/modules/python/dionaea/sip/rfc2396.py index 908d37f7..807b216f 100644 --- a/modules/python/dionaea/sip/rfc2396.py +++ b/modules/python/dionaea/sip/rfc2396.py @@ -28,9 +28,9 @@ class Address(object): b'"John Doe" ' """ _syntax = [ - re.compile(b'^(?P[a-zA-Z0-9\-\.\_\+\~\ \t]*)<(?P[^>]+)>( *; *(?P.*))?'), - re.compile(b'^(?:"(?P[a-zA-Z0-9\-\.\_\+\~\ \t]+)")[\ \t]*<(?P[^>]+)>( *; *(?P.*))?'), - re.compile(b'^[\ \t]*(?P)(?P[^;]+)( *; *(?P.*))?') + re.compile(r'^(?P[a-zA-Z0-9\-\.\_\+\~\ \t]*)<(?P[^>]+)>( *; *(?P.*))?'), + re.compile(r'^(?:"(?P[a-zA-Z0-9\-\.\_\+\~\ \t]+)")[\ \t]*<(?P[^>]+)>( *; *(?P.*))?'), + re.compile(r'^[\ \t]*(?P)(?P[^;]+)( *; *(?P.*))?') ] def __init__(self, display_name = None, uri = None, must_quote = None, params = None): @@ -128,12 +128,12 @@ class URI(object): True """ - _syntax = re.compile(b"^(?P[a-zA-Z][a-zA-Z0-9\+\-\.]*):" # scheme - + b"(?:(?:(?P[a-zA-Z0-9\-\_\.\!\~\*\'\(\)&=\+\$,;\?\/\%]+)" # user - + b"(?::(?P[^:@;\?]+))?)@)?" # password - + b"(?:(?:(?P[^;\?:]*)(?::(?P[\d]+))?))" # host, port - + b"(?:;(?P[^\?]*))?" # parameters - + b"(?:\?(?P.*))?$" # headers + _syntax = re.compile(r"^(?P[a-zA-Z][a-zA-Z0-9\+\-\.]*):" # scheme + + r"(?:(?:(?P[a-zA-Z0-9\-\_\.\!\~\*\'\(\)&=\+\$,;\?\/\%]+)" # user + + r"(?::(?P[^:@;\?]+))?)@)?" # password + + r"(?:(?:(?P[^;\?:]*)(?::(?P[\d]+))?))" # host, port + + r"(?:;(?P[^\?]*))?" # parameters + + r"(?:\?(?P.*))?$" # headers ) def __init__(self, scheme = None, user = None, password = None, host = None, port = None, params = None, headers = None): diff --git a/modules/python/dionaea/sip/rfc3261.py b/modules/python/dionaea/sip/rfc3261.py index 72af2bb7..4a8a11e3 100644 --- a/modules/python/dionaea/sip/rfc3261.py +++ b/modules/python/dionaea/sip/rfc3261.py @@ -678,7 +678,7 @@ class Via(object): b'z9hG4bK77asjd' b'192.0.2.207' """ - _syntax = re.compile(b"SIP */ *2\.0 */ *(?P[a-zA-Z]+) *(?P
[^ :;]*) *(:(?P[0-9]+))?( *; *(?P.*))?") + _syntax = re.compile(r"SIP */ *2\.0 */ *(?P[a-zA-Z]+) *(?P
[^ :;]*) *(:(?P[0-9]+))?( *; *(?P.*))?") def __init__(self, protocol = None, address = None, port = None, params = None): if params is None: diff --git a/modules/python/dionaea/smb/include/asn1/mib.py b/modules/python/dionaea/smb/include/asn1/mib.py index 724033bc..b5eda6f5 100644 --- a/modules/python/dionaea/smb/include/asn1/mib.py +++ b/modules/python/dionaea/smb/include/asn1/mib.py @@ -19,12 +19,12 @@ ## MIB parsing ## ################# -_mib_re_integer = re.compile("^[0-9]+$") -_mib_re_both = re.compile("^([a-zA-Z_][a-zA-Z0-9_-]*)\(([0-9]+)\)$") +_mib_re_integer = re.compile(r"^[0-9]+$") +_mib_re_both = re.compile(r"^([a-zA-Z_][a-zA-Z0-9_-]*)\(([0-9]+)\)$") _mib_re_oiddecl = re.compile( - "$\s*([a-zA-Z0-9_-]+)\s+OBJECT([^:\{\}]|\{[^:]+\})+::=\s*\{([^\}]+)\}",re.M) -_mib_re_strings = re.compile('"[^"]*"') -_mib_re_comments = re.compile('--.*(\r|\n)') + r"$\s*([a-zA-Z0-9_-]+)\s+OBJECT([^:\{\}]|\{[^:]+\})+::=\s*\{([^\}]+)\}",re.M) +_mib_re_strings = re.compile(r'"[^"]*"') +_mib_re_comments = re.compile(r'--.*(\r|\n)') class MIBDict(DADict): def _findroot(self, x): diff --git a/modules/python/dionaea/smb/include/fieldtypes.py b/modules/python/dionaea/smb/include/fieldtypes.py index fc6fc301..1cbdf8b2 100644 --- a/modules/python/dionaea/smb/include/fieldtypes.py +++ b/modules/python/dionaea/smb/include/fieldtypes.py @@ -188,7 +188,7 @@ def i2m(self, pkt, x): def m2i(self, pkt, x): return str2mac(x) def any2i(self, pkt, x): - if type(x) is str and len(x) is 6: + if type(x) is str and len(x) == 6: x = self.m2i(pkt, x) return x def i2repr(self, pkt, x): diff --git a/modules/python/dionaea/smb/rpcservices.py b/modules/python/dionaea/smb/rpcservices.py index 15bd24a5..c17d5765 100644 --- a/modules/python/dionaea/smb/rpcservices.py +++ b/modules/python/dionaea/smb/rpcservices.py @@ -2802,7 +2802,7 @@ def handle_StartDocPrinter(cls, con, p): rpclog.debug("docname {} outputfile {}".format(DocName, OutputFile)) - if OutputFile.startswith('\\') and OutputFile.endswith('\PIPE\ATSVC'): + if OutputFile.startswith('\\\\') and OutputFile.endswith('\\PIPE\\ATSVC'): # FIXME PIPE ATSVC COMMAND pass else: diff --git a/modules/python/dionaea/util.py b/modules/python/dionaea/util.py index f1c7f8de..f794f905 100644 --- a/modules/python/dionaea/util.py +++ b/modules/python/dionaea/util.py @@ -74,14 +74,14 @@ def detect_shellshock(connection, data, report_incidents=True): :return: List of urls or None """ from dionaea.core import incident - regex = re.compile(b"\(\)\s*\t*\{.*;\s*\}\s*;") + regex = re.compile(r"\(\)\s*\t*\{.*;\s*\}\s*;") if not regex.search(data): return None logger.debug("Shellshock attack found") urls = [] regex = re.compile( - b"(wget|curl).+(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)" + r"(wget|curl).+(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)" ) for m in regex.finditer(data): logger.debug("Found download command with url %s", m.group("url")) @@ -107,7 +107,7 @@ def find_shell_download(connection, data, report_incidents=True): from dionaea.core import incident urls = [] regex = re.compile( - b"(wget|curl).+(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)" + r"(wget|curl).+(?P(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)" ) for m in regex.finditer(data): logger.debug("Found download command with url %s", m.group("url")) From 68feae2e5edf292163ded352de6400f97d64081e Mon Sep 17 00:00:00 2001 From: xambroz <723625+xambroz@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:01:51 +0200 Subject: [PATCH 6/6] Migrate from distutils to setuptools --- modules/python/setup.py.in2 | 95 +++++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 35 deletions(-) diff --git a/modules/python/setup.py.in2 b/modules/python/setup.py.in2 index d44b8b89..1ca4850e 100644 --- a/modules/python/setup.py.in2 +++ b/modules/python/setup.py.in2 @@ -5,33 +5,46 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -from distutils.core import setup -from distutils.extension import Extension -from distutils.util import convert_path +from setuptools import setup, find_packages, Extension +from setuptools.command.install import install as _install +from setuptools.command.build_ext import build_ext as _build_ext + import os -from Cython.Distutils import build_ext - - -def find_packages(base_path): - base_path = convert_path(base_path) - found = [] - for root, dirs, files in os.walk(base_path, followlinks=True): - dirs[:] = [d for d in dirs if d[0] != '.' and d not in ('ez_setup', '__pycache__')] - relpath = os.path.relpath(root, base_path) - parent = relpath.replace(os.sep, '.').lstrip('.') - if relpath != '.' and parent not in found: - continue - for dir in dirs: - if os.path.isfile(os.path.join(root, dir, '__init__.py')): - package = '.'.join((parent, dir)) if parent else dir - found.append(package) - return found - -core_cflags = '${GLIB2_CFLAGS};' # glib -core_cflags += '${GMODULE2_CFLAGS}' # gmodule - -core_ldflags = '${GLIB2_LDFLAGS};' # glib -core_ldflags += '${GMODULE2_LDFLAGS}' # gmodule +# from Cython.Distutils import build_ext + +# Helper function to get absolute path relative to this file +def get_abs_path(rel_path): + return os.path.abspath(os.path.join(os.path.dirname(__file__), rel_path)) + +def get_rel_path(abs_path): + return os.path.relpath(os.path.join(os.path.dirname(__file__), abs_path)) + +# Function to process CMake-style paths +def process_cmake_path(path): + if path.startswith('${CMAKE_CURRENT_SOURCE_DIR}'): + return get_rel_path(get_abs_path(path)) + return path + +class CustomBuildExt(_build_ext): + def build_extensions(self): + if '-Wstrict-prototypes' in self.compiler.compiler_so: + self.compiler.compiler_so.remove('-Wstrict-prototypes') + super().build_extensions() + +class CustomInstall(_install): + def run(self): + _install.run(self) + + +print("=== DEBUG: CMAKE_CURRENT_SOURCE_DIR " + "${CMAKE_CURRENT_SOURCE_DIR}") + +# glib +core_cflags = '${GLIB2_CFLAGS};' +core_ldflags = '${GLIB2_LDFLAGS};' + +# gmodule +core_cflags += '${GMODULE2_CFLAGS}' +core_ldflags += '${GMODULE2_LDFLAGS}' core_include_dirs = set() core_extra_compile_flags = set() @@ -39,7 +52,7 @@ for i in core_cflags.split(';'): if i == '': continue elif i.startswith('-I'): - core_include_dirs.add(i[2:]) + core_include_dirs.add(process_cmake_path(i[2:])) else: core_extra_compile_flags.add(i) @@ -53,15 +66,18 @@ for i in core_ldflags.split(';'): elif i.startswith('-l'): core_libraries.add(i[2:]) elif i.startswith('-L'): - core_library_dirs.add(i[2:]) + core_library_dirs.add(process_cmake_path(i[2:])) else: core_library_other_flags.add(i) -ext_modules=[ +ext_modules = [ Extension("dionaea.core", ['${CMAKE_CURRENT_SOURCE_DIR}/binding.pyx'], language="c", - include_dirs=['${CMAKE_CURRENT_SOURCE_DIR}/../../include', '${CMAKE_CURRENT_SOURCE_DIR}/../../'] + list(core_include_dirs), + include_dirs=[ + process_cmake_path('${CMAKE_CURRENT_SOURCE_DIR}/../../include'), + process_cmake_path('${CMAKE_CURRENT_SOURCE_DIR}/../../') + ] + list(core_include_dirs), extra_compile_args=list(core_extra_compile_flags), libraries=list(core_libraries), library_dirs=list(core_library_dirs), @@ -71,11 +87,20 @@ ext_modules=[ ), ] +d_packages = find_packages(process_cmake_path('${CMAKE_CURRENT_SOURCE_DIR}')) +print("=== DEBUG: d_packages " + str(d_packages)) + +d_dir = {'': process_cmake_path('${CMAKE_CURRENT_SOURCE_DIR}')} +print("=== DEBUG: d_dir " + str(d_dir)) + setup( - name = 'dionaea', + name='dionaea', version="${DIONAEA_VERSION}", - cmdclass = {'build_ext': build_ext}, - ext_modules = ext_modules, - packages=find_packages(base_path='${CMAKE_CURRENT_SOURCE_DIR}'), - package_dir={'': '${CMAKE_CURRENT_SOURCE_DIR}'} + cmdclass={ + 'build_ext': CustomBuildExt, + 'install': CustomInstall, + }, + ext_modules=ext_modules, + packages=d_packages, + package_dir=d_dir )