def __init__(self, host, port, messages, proto="udp", timeout="3.0", \ crash_detection=False): ''' Handles the dispatching of a group of SIP torture messages extracted from RFC 4475 @type host: String @param host: The host to send the test messages to @type port: Integer @param port: The port to send the test messages to @type messages: Dictionary @param messages: A dictionary containing lists of valid and invalid test messages @type proto: String @param proto: (Optional, def=udp) The protocol to encapsulate the test messages in @type timeout: Float @param timeout: (Optional, def=3.0) Timeout for all socket operations @type crash_detection: Boolean @param crash_detection: (Optional, def=False) Attempt to detect crashes using OPTIONS probes or not ''' self.host = host self.port = port self.proto = proto self.messages = messages self.timeout = timeout self.last_recv = "" self.crash_detection = crash_detection if self.crash_detection: self.crash_detector = SIPCrashDetector(self.host, self.port, \ timeout)
def __init__(self, host, port, messages, proto="udp", timeout="3.0", crash_detection=False): """ Handles the dispatching of a group of SIP torture messages extracted from RFC 4475 @type host: String @param host: The host to send the test messages to @type port: Integer @param port: The port to send the test messages to @type messages: Dictionary @param messages: A dictionary containing lists of valid and invalid test messages @type proto: String @param proto: (Optional, def=udp) The protocol to encapsulate the test messages in @type timeout: Float @param timeout: (Optional, def=3.0) Timeout for all socket operations @type crash_detection: Boolean @param crash_detection: (Optional, def=False) Attempt to detect crashes using OPTIONS probes or not """ self.host = host self.port = port self.proto = proto self.messages = messages self.timeout = timeout self.last_recv = "" self.crash_detection = crash_detection if self.crash_detection: self.crash_detector = SIPCrashDetector(self.host, self.port, timeout)
class Dispatcher: def __init__(self, host, port, messages, proto="udp", timeout="3.0", crash_detection=False): """ Handles the dispatching of a group of SIP torture messages extracted from RFC 4475 @type host: String @param host: The host to send the test messages to @type port: Integer @param port: The port to send the test messages to @type messages: Dictionary @param messages: A dictionary containing lists of valid and invalid test messages @type proto: String @param proto: (Optional, def=udp) The protocol to encapsulate the test messages in @type timeout: Float @param timeout: (Optional, def=3.0) Timeout for all socket operations @type crash_detection: Boolean @param crash_detection: (Optional, def=False) Attempt to detect crashes using OPTIONS probes or not """ self.host = host self.port = port self.proto = proto self.messages = messages self.timeout = timeout self.last_recv = "" self.crash_detection = crash_detection if self.crash_detection: self.crash_detector = SIPCrashDetector(self.host, self.port, timeout) def __target_responding(self): """ Attempts to detect if the target application has crashed using the SIPCrashDetector class """ return self.crash_detector.is_responding() def __send(self, torture_msg): """ Send a torture message @type torture_msg: TortureMessage @param torture_msg: The torture message to be sent """ data = torture_msg.get_data() if self.proto == "udp": sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.settimeout(self.timeout) if len(data) > 9216: print "Too much data for UDP, truncating to 9216 bytes" data = data[:9216] sock.sendto(data, (self.host, self.port)) try: self.last_recv = sock.recvfrom(4096)[0] except Exception, e: self.last_recv = "" print "[=] Response : " + self.last_recv elif self.proto == "tcp": sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(self.timeout) sock.connect((self.host, self.port)) total_sent = 0 while total_sent < len(data): sent = sock.send(data[totalSent:]) if sent == 0: raise RuntimeError("Error on socket.send()") total_sent += sent try: self.last_recv = sock.recv(4096) except Exception, e: self.last_recv = ""
class Dispatcher: def __init__(self, host, port, messages, proto="udp", timeout="3.0", \ crash_detection=False): ''' Handles the dispatching of a group of SIP torture messages extracted from RFC 4475 @type host: String @param host: The host to send the test messages to @type port: Integer @param port: The port to send the test messages to @type messages: Dictionary @param messages: A dictionary containing lists of valid and invalid test messages @type proto: String @param proto: (Optional, def=udp) The protocol to encapsulate the test messages in @type timeout: Float @param timeout: (Optional, def=3.0) Timeout for all socket operations @type crash_detection: Boolean @param crash_detection: (Optional, def=False) Attempt to detect crashes using OPTIONS probes or not ''' self.host = host self.port = port self.proto = proto self.messages = messages self.timeout = timeout self.last_recv = "" self.crash_detection = crash_detection if self.crash_detection: self.crash_detector = SIPCrashDetector(self.host, self.port, \ timeout) def __target_responding(self): ''' Attempts to detect if the target application has crashed using the SIPCrashDetector class ''' return self.crash_detector.is_responding() def __send(self, torture_msg): ''' Send a torture message @type torture_msg: TortureMessage @param torture_msg: The torture message to be sent ''' data = torture_msg.get_data() if self.proto == "udp": sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.settimeout(self.timeout) if len(data) > 9216: print "Too much data for UDP, truncating to 9216 bytes" data = data[:9216] sock.sendto(data, (self.host, self.port)) try: self.last_recv = sock.recvfrom(4096)[0] except Exception, e: self.last_recv = "" print '[=] Response : ' + self.last_recv elif self.proto == "tcp": sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(self.timeout) sock.connect((self.host, self.port)) total_sent = 0 while total_sent < len(data): sent = sock.send(data[totalSent:]) if sent == 0: raise RuntimeError("Error on socket.send()") total_sent += sent try: self.last_recv = sock.recv(4096) except Exception, e: self.last_recv = ""