Exemplo n.º 1
0
def client(debug):
    '''
    Command that starts the application in CLIENT mode.
    '''
    logger.setLevel(logging.DEBUG if debug else logging.INFO)
    logger.debug('DEBUG mode enabled.')
    logger.info('Application started in CLIENT mode.')
Exemplo n.º 2
0
def server(debug):
    '''
    Command that starts the application in SERVER mode.
    '''
    logger.setLevel(logging.DEBUG if debug else logging.INFO)
    logger.debug('DEBUG mode enabled.')
    logger.info('Application started in SERVER mode.')
Exemplo n.º 3
0
 def handle(self):
     self.hasher = hashlib.md5()
     datagram = self.rfile.readline().strip()
     host, port = self.client_address
     str_datagram = datagram.decode('utf-8')
     self.hasher.update(datagram)
     unique_id = self.hasher.hexdigest()
     logger.debug('Information received: {}'.format(str_datagram))
     logger.debug('Information sent: {}'.format(str_datagram.upper()))
     self.wfile.write(str_datagram.upper().encode('utf-8'))
     logger.info('Receiving tests of {}:{} - [{}]'.format(
         host, port, unique_id))
Exemplo n.º 4
0
def  send_loop(socket, size, loop):
    status = list()
    durations = list()

    for i in range(loop):
        try:
            data = ''.join(choices(ascii_lowercase, k=(size - 44)))
            start = time()
            logger.debug('Data sent: {}'.format(data))
            socket.send(data.encode())
            response = socket.recv(4096).decode('ASCII')
            end = time()
            logger.debug('Data recived: {}'.format(response))
            status.append(data.upper() == response)
            durations.append(end - start)
        
        except ConnectionRefusedError:
            status.append(False)
            durations.append(5)

    return status, durations
Exemplo n.º 5
0
def aug(host, port, test):
    logger.info('Performing ALG test.')
    with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as interface:
        interface.settimeout(5)
        destiny_address = (host, port)
        logger.info('Destiny IP: {}'.format(host))
        logger.info('Destiny Port: {}'.format(port))
        interface.connect(destiny_address)
        in_host, in_port = interface.getsockname()
        ip_hash = hashlib.md5(in_host.encode())
        logger.info('Internal IP used: {}'.format(in_host))
        logger.info('Internal selected port: {}'.format(in_port))
        callid = Message.make_hash(str(time() * random()))
        to_tag = Message.make_hash(str(time() * random()))
        branch = Message.make_hash(str(time() * random()))
        logger.debug('Call-ID generated for the package: {}'.format(callid))
        logger.debug('To-Tag generated for the package: {}'.format(to_tag))
        logger.debug('Branch-Tag generated for the package: {}'.format(branch))
        logger.debug('Generating INVITE that will be forwarded to the Host.')
        message = Message('invite',
                          callid=callid,
                          branch=branch,
                          test=test,
                          address={
                              'ip': in_host,
                              'port': in_port
                          },
                          iphash={'hash': ip_hash.hexdigest()},
                          sip_from={
                              'user': "******",
                              'domain': in_host,
                              'tag': to_tag
                          })

        try:
            interface.send(message.render)
            response = interface.recv(4096).decode('ASCII')
            resp_list = [v for v in response.split('\r\n') if v]
            result = dict(parse_header(value) for value in resp_list)
            logger.info('Response title: {}'.format(result["title"]))
            logger.debug('Call-ID response: {}'.format(result["Call-ID"]))
            logger.debug('Response source server: {}'.format(result["Server"]))
            _, title = result["title"].split('200')

            if title.strip() == 'OK':
                logger.info('No ALG detected')

            else:
                logger.warn('Router with ALG detected.')

        except KeyError:
            logger.error('Could not parse the response.')

        except socket.timeout:
            logger.error('Connection timeout with SipProxy.')