From 19241a374dec3e8d198e7d679ed4e5c6cefe1e2c Mon Sep 17 00:00:00 2001 From: Michel Oosterhof Date: Tue, 27 Jan 2015 05:55:56 +0000 Subject: [PATCH] Fix for ability to ping non-existent IP addresses --- kippo/commands/ping.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/kippo/commands/ping.py b/kippo/commands/ping.py index 6f8ff25..1cf3691 100644 --- a/kippo/commands/ping.py +++ b/kippo/commands/ping.py @@ -1,13 +1,26 @@ # Copyright (c) 2009 Upi Tamminen # See the COPYRIGHT file for more information +import time +import re +import random +import hashlib +import socket + from kippo.core.honeypot import HoneyPotCommand from twisted.internet import reactor -import time, re, random, hashlib commands = {} class command_ping(HoneyPotCommand): + + def valid_ip(self, address): + try: + socket.inet_aton(address) + return True + except: + return False + def start(self): self.host = None for arg in self.args: @@ -26,9 +39,12 @@ class command_ping(HoneyPotCommand): self.exit() return - if re.match('^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$', - self.host): - self.ip = self.host + if re.match('^[0-9.]+$', self.host): + if self.valid_ip(self.host): + self.ip = self.host + else: + self.writeln('ping: unknown host %s' % self.host) + self.exit() else: s = hashlib.md5(self.host).hexdigest() self.ip = '.'.join([str(int(x, 16)) for x in