def __init__(self, host, port, timeout = 0.25, throttle = 0):
		'''
		@type	host: string
		@param	host: Remote host
		@type	port: number
		@param	port: Remote port
		@type	timeout: number
		@param	timeout: How long to wait for reponse
		@type	throttle: number
		@param	throttle: How long to wait between connections
		'''
		Publisher.__init__(self)
		self._host = host
		
		try:
			self._port = int(port)
		except:
			raise PeachException("The Tcp publisher parameter for port was not a valid number.")
		
		try:
			self._timeout = float(timeout)
		except:
			raise PeachException("The Tcp publisher parameter for timeout was not a valid number.")
		
		try:
			self._throttle = float(throttle)
		except:
			raise PeachException("The Tcp publisher parameter for throttle was not a valid number.")
		
		self._socket = None
Example #2
0
    def start(self):
        #if self.dev:
        #    return

        self.dev = usb.core.find(idVendor=self.idVendor,
                                 idProduct=self.idProduct)

        if not self.dev:
            raise PeachException("Device not found.")

        try:
            self.dev.set_configuration()
        except usb.core.USBError as e:
            raise PeachException(str(e))
Example #3
0
 def __init__(self, args):
     self.restartOnTest = False
     if args.has_key('RestartOnEachTest'):
         if args['RestartOnEachTest'].replace("'''", "").lower() == 'true':
             self.restartOnTest = True
     self.faultOnEarlyExit = True
     if args.has_key('FaultOnEarlyExit'):
         if args['FaultOnEarlyExit'].replace("'''", "").lower() != 'true':
             self.faultOnEarlyExit = False
     self.startOnCall = False
     if args.has_key('StartOnCall'):
         self.startOnCall = True
         self.startOnCallMethod = args['StartOnCall'].replace("'''", "").lower()
     self.waitForExitOnCall = False
     if args.has_key('WaitForExitOnCall'):
         self.waitForExitOnCall = True
         self.waitForExitOnCallMethod = args['WaitForExitOnCall'].replace("'''", "").lower()
     if not args.has_key('Command'):
         raise PeachException("Error, monitor Process requires a parameter named 'Command'")
     self.strangeExit = False
     self.command = args["Command"].replace("'''", "")
     self.args = None
     self.pid = None
     self.hProcess = None
     self.hThread = None
     self.dwProcessId = None
     self.dwThreadId = None
Example #4
0
    def start(self):
        self.close()

        if self._listen is None:
            for i in range(3):
                try:
                    self._listen = socket.socket(socket.AF_INET,
                                                 socket.SOCK_STREAM)
                    self._listen.setsockopt(socket.SOL_SOCKET,
                                            socket.SO_REUSEADDR, 1)
                    self._listen.bind((self._host, self._port))
                    self._listen.listen(1)
                    exception = None
                    break

                except:
                    self._listen = None
                    exception = sys.exc_info()

                time.sleep(0.5)

            if self._listen is None:
                value = ""
                try:
                    value = str(exception[1])
                except:
                    pass

                raise PeachException("TCP bind attempt failed: %s" % value)

        self.buff = ""
        self.pos = 0
Example #5
0
 def send(self, data):
     if not self.loadBalance % 500 and self.loadBalance != 0:
         print("[*] Pause ...")
         time.sleep(10)
     for i in range(3):
         try:
             self.smtp.sendmail(self.mailFrom, self.mailTo, data)
             exception = None
             break
         except:
             exception = sys.exc_info()
         time.sleep(5)
     if exception:
         reason = ""
         try:
             reason = str(exception[1])
         except:
             reason = "unknown reason."
         message = "SMTP send mail to %s:%d failed: %s" % (
             self.host, self.port, reason)
         if message.find("5.4.0") > -1:
             print(message)
         else:
             self.smtp.close()
             raise PeachException(message)
     self.loadBalance += 1
	def start(self):
		self.close()
		
		if self._listen == None:
			# Try connection three times befor
			# exiting fuzzer run
			for i in range(3):
				try:
					self._listen = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
					self._listen.bind((self._host,self._port))
					self._listen.listen(1)
					exception = None
					break
				
				except:
					self._listen = None
					exception = sys.exc_info()
				
				time.sleep(0.5)
			
			if self._listen == None:
				value = ""
				try:
					value = str(exception[1])
				except:
					pass
				
				raise PeachException("TCP bind attempt failed: %s" % value)
		
		self.buff = ""
		self.pos = 0
    def accept(self):
        '''
		Accept incoming connection.  Blocks until incoming connection
		occurs.
		'''

        raise PeachException("Action 'accept' not supported by publisher")
    def send(self, data):
        '''
		Publish some data
		
		@type	data: string
		@param	data: Data to publish
		'''
        raise PeachException("Action 'send' not supported by publisher")
Example #9
0
    def send(self, data):
        """
        Publish some data.

        :param data: data to publish
        :type data: str
        """
        raise PeachException("Action 'send' not supported by publisher.")
    def property(self, property, value=None):
        '''
		Get or set property
		
		@type	property: string
		@param	property: Name of method to invoke
		@type	value: object
		@param	value: Value to set.  If None, return property instead
		'''
        raise PeachException("Action 'property' not supported by publisher")
Example #11
0
    def property(self, property, value=None):
        """
        Get or set property.

        :param property: name of method to invoke
        :type property: str
        :param value: value to set. If None, return property instead
        :type value: object
        """
        raise PeachException("Action 'property' not supported by publisher.")
Example #12
0
    def receive(self, size=None):
        """
        Receive some data.

        :param size: number of bytes to return
        :type size: int
        :returns: data received
        :rtype: str
        """
        raise PeachException("Action 'receive' not supported by publisher.")
    def sendWithNode(self, data, dataNode):
        '''
		Publish some data
		
		@type	data: string
		@param	data: Data to publish
		@type   dataNode: DataElement
		@param  dataNode: Root of data model that produced data
		'''
        raise PeachException("Action 'send' not supported by publisher")
    def receive(self, size=None):
        '''
		Receive some data.
		
		@type	size: integer
		@param	size: Number of bytes to return
		@rtype: string
		@return: data received
		'''
        raise PeachException("Action 'receive' not supported by publisher")
Example #15
0
    def accept(self):
        print("[*] Waiting for incoming connection")
        client, addr = self._listen.accept()
        print("[*] Client:", addr[0], addr[1])

        print("[*] Wrapping socket to TLS/SSL")
        try:
            self._socket = ssl.wrap_socket(client,
                                           server_side=True,
                                           certfile=self.cert,
                                           keyfile=self.pkey,
                                           do_handshake_on_connect=False)
        except ssl.SSLError as e:
            raise PeachException(str(e))

        print("[*] Performing TLS/SSL handshake")
        try:
            self._socket.do_handshake()
        except ssl.SSLError as e:
            raise PeachException(str(e))
Example #16
0
    def sendWithNode(self, data, dataNode):
        """
        Publish some data.

        :param data: data to publish
        :type data: str
        :param dataNode: root of data model that produced data
        :type dataNode: DataElement
        """
        raise PeachException("Action 'sendWithNode' not supported by "
                             "publisher.")
    def propertyWithNode(self, property, value, valueNode):
        '''
		Get or set property
		
		@type	property: string
		@param	property: Name of method to invoke
		@type	value: object
		@param	value: Value to set.  If None, return property instead
		@type	valueNode: DataElement
		@param	valueNode: data model root node that produced value.
		'''
        raise PeachException("Action 'property' not supported by publisher")
Example #18
0
    def call(self, method, args):
        """
        Call a method using arguments.

        :param method: method to call
        :type method: str
        :param args: list of strings as arguments
        :type args: list
        :returns: data (if any)
        :rtype: str
        """
        raise PeachException("Action 'call' not supported by publisher.")
    def call(self, method, args):
        '''
		Call a method using arguments.
		
		@type	method: string
		@param	method: Method to call
		@type	args: Array
		@param	args: Array of strings as arguments
		@rtype: string
		@return: data returned (if any)
		'''
        raise PeachException("Action 'call' not supported by publisher")
Example #20
0
    def start(self):
        if self._connected:
            return

        print("[*] Connecting to %s:%d ..." % (self.host, self.port))
        try:
            self.smtp = smtplib.SMTP(self.host, self.port)
        except:
            raise PeachException(
                "Peer %s:%d is down or connection settings are wrong." %
                (self.host, self.port))
        self._connected = True
        self.smtp.set_debuglevel(self.debugLevel)
Example #21
0
    def propertyWithNode(self, property, value, valueNode):
        """
        Get or set property.

        :param property: name of method to invoke
        :type property: str
        :param value: value to set. If None, return property instead
        :type value: object
        :param valueNode: data model root node that produced value
        :type valueNode: DataElement
        """
        raise PeachException(
            "Action 'propertyWithNode' not supported by publisher.")
Example #22
0
    def __init__(self, host, port, version, cert, pkey, timeout=0.25):
        TcpListener.__init__(self, host, port, timeout)

        self.cert = cert
        self.pkey = pkey
        self.version = version

        try:
            with open(self.cert) as fd:
                cert_content = fd.read()
        except IOError:
            raise PeachException("Unable to open %s" % self.cert)

        x509 = tlslite.api.X509()
        x509.parse(cert_content)
        self.certChain = tlslite.api.X509CertChain([x509])

        try:
            with open(self.pkey) as fd:
                pkey_content = fd.read()
        except IOError:
            raise PeachException("Unable to open %s" % self.pkey)

        self.privateKey = tlslite.api.parsePEMKey(pkey_content, private=True)
Example #23
0
    def __init__(self, ba_addr, port, timeout=8.0, giveup=3.0):
        Publisher.__init__(self)

        self.ba_addr = ba_addr

        try:
            self.port = int(port)
        except:
            raise PeachException(
                "Publisher parameter for port was not a valid number.")

        try:
            self.timeout = float(timeout)
        except:
            raise PeachException(
                "Publisher parameter for timeout was not a valid number.")

        try:
            self.giveup = float(giveup)
        except:
            raise PeachException(
                "Publisher parameter for giveup was not a valid number.")

        self._socket = None
Example #24
0
 def __init__(self,
              host="localhost",
              port=smtplib.SMTP_PORT,
              debugLevel=0,
              mailFrom="localhost@localhost",
              mailTo="localhost@localhost",
              username="",
              password=""):
     Publisher.__init__(self)
     self.host = host
     try:
         self.port = int(port)
     except:
         raise PeachException(
             "The SMTP publisher parameter for port is not a valid number.")
     self.debugLevel = int(debugLevel)
     self.mailFrom = mailFrom
     self.mailTo = mailTo
     self.username = username
     self.password = password
     self.loadBalance = 0
     self._connected = None
Example #25
0
    def start(self):
        if self._socket:
            return

        if usingLightBlue:
            for each_try in range(1, 5):
                print("[*] Connecting to %s on PSM %d (%d)" %
                      (self.ba_addr, self.port, each_try))
                try:
                    self._socket = lightblue.socket(lightblue.L2CAP)
                    self._socket.connect((self.ba_addr, self.port))
                except socket.error:
                    self._socket = None
                    print("Failed.")
                    print("Wait {} seconds ...".format(self.giveup))
                    time.sleep(self.giveup)
                else:
                    print("Done.")
                    break

        if usingBluetooth:
            for each_try in range(1, 5):
                print("[*] Connecting to %s on PSM %d (%d)" %
                      (self.ba_addr, self.port, each_try))
                try:
                    self._socket = bluetooth.BluetoothSocket(bluetooth.L2CAP)
                    self._socket.connect((self.ba_addr, self.port))
                except socket.error:
                    self._socket = None
                    print("Failed.")
                    print("Wait {} seconds ...".format(self.giveup))
                    time.sleep(self.giveup)
                else:
                    print("Done.")
                    break
        print("")

        if not self._socket:
            raise PeachException("L2CAP connection attempt failed.")
Example #26
0
    def connect(self):
        """
        Create connection.
        """
        self.close()

        if self._throttle > 0:
            time.sleep(self._throttle)

        # Try connecting many times
        # before we crash.
        for i in range(30):
            try:
                self._socket = socket.socket(socket.AF_INET,
                                             socket.SOCK_STREAM)
                self._socket.connect((self._host, self._port))
                exception = None
                break

            except:
                self._socket = None
                exception = sys.exc_info()

            # Wait half sec and try again
            time.sleep(1)

        if self._socket is None:
            value = ""
            try:
                value = str(exception[1])
            except:
                pass

            raise PeachException("TCP onnection attempt failed: %s" % value)

        self.buff = ""
        self.pos = 0
Example #27
0
 def close(self):
     """
     Close current stream/connection.
     """
     raise PeachException("Action 'close' not supported by publisher.")
Example #28
0
 def connect(self):
     """
     Called to connect or open a connection / file.
     """
     raise PeachException("Action 'connect' not supported by publisher.")
    def close(self):
        '''
		Close current stream/connection.
		'''
        raise PeachException("Action 'close' not supported by publisher")
	def connect(self):
		raise PeachException("Action 'connect' not supported")