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):