From fad1f1388ea80eb07b4321d1a06e5dd38e81a513 Mon Sep 17 00:00:00 2001 From: Michel Oosterhof Date: Mon, 14 Sep 2020 00:08:27 +0800 Subject: [PATCH] Fix nc hang (#1406) * add libvirt group membership * stop nc hanging on bad input --- docs/BACKEND_POOL.rst | 11 ++++++++++- src/cowrie/commands/nc.py | 10 ++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/BACKEND_POOL.rst b/docs/BACKEND_POOL.rst index 9a4bd528..cd805f9f 100644 --- a/docs/BACKEND_POOL.rst +++ b/docs/BACKEND_POOL.rst @@ -19,6 +19,15 @@ libvirt's XML configuration files. First of all, install the needed dependencies for the pool, as explained in `the installation steps `_. +Authorization +************* + +Add your cowrie user to the libvrit group to ensure you have permission to run the VMs on the backend server:: + +.. code-block:: bash + + sudo usermod -aG "COWRIE_USER_HERE" libvirt + Provided images *************** @@ -255,4 +264,4 @@ References * `libvirt network filter XML syntax `_ -* `Create a OpenWRT image `_ \ No newline at end of file +* `Create a OpenWRT image `_ diff --git a/src/cowrie/commands/nc.py b/src/cowrie/commands/nc.py index c47111b7..a6048894 100644 --- a/src/cowrie/commands/nc.py +++ b/src/cowrie/commands/nc.py @@ -25,6 +25,7 @@ def makeMask(n): def dottedQuadToNum(ip): """ convert decimal dotted quad string to long integer + this will throw builtins.OSError on failure """ return struct.unpack('I', socket.inet_aton(ip))[0] @@ -72,7 +73,7 @@ usage: nc [-46bCDdhjklnrStUuvZz] [-I length] [-i interval] [-O length] host = args[0] port = args[1] - if not re.match(r'\d+', port): + if not re.match(r'^\d+$', port): self.errorWrite('nc: port number invalid: {}\n'.format(port)) self.exit() return @@ -80,10 +81,15 @@ usage: nc [-46bCDdhjklnrStUuvZz] [-I length] [-i interval] [-O length] if re.match(r'^\d+$', host): address = int(host) elif re.match(r'^[\d\.]+$', host): - address = dottedQuadToNum(host) + try: + address = dottedQuadToNum(host) + except OSError: + self.exit() + return else: # TODO: should do dns lookup self.exit() + return for net in local_networks: if addressInNetwork(address, net):