Example #1
0
 def dispatch(self, msg, trail=True):
     if trail:
         msg = '{0}\n\r'.format(msg)
     if self.ansi:
         msg = color.colorize(msg)
     else:
         msg = color.decolorize(msg)
     self.outbuf = '{0}{1}'.format(self.outbuf, msg)
Example #2
0
 async def dispatch(self, msg, trail=True):
     if self.state['connected']:
         if trail:
             msg = f'{msg}\n\r'
         if self.ansi:
             msg = color.colorize(f'{msg}{{x')
         else:
             msg = color.decolorize(msg)
         await self.out_buf.put((msg, "false"))
Example #3
0
 def dispatch(self, msg, trail=True):
     if trail:
         msg = f"{msg}\n\r"
     if self.ansi:
         msg = color.colorize(msg)
     else:
         msg = color.decolorize(msg)
     self.outbuf = f"{self.outbuf}{msg}"
     if hasattr(self.owner,
                "snooped_by") and len(self.owner.snooped_by) > 0:
         for each_person in self.owner.snooped_by:
             each_person.write(self.outbuf)
Example #4
0
 def dispatch(self, msg, trail=True):
     if self.state['connected']:
         log.info('Dispatching something')
         if trail:
             msg = f'{msg}\n\r'
         if self.ansi:
             msg = color.colorize(msg)
         else:
             msg = color.decolorize(msg)
         asyncio.create_task(self.out_buf.put(msg), name=self.session)
     elif self.state['connected'] and self.state['logged in']:
         log.info('Writing something')
         if hasattr(self.owner, "editing"):
             asyncio.create_task(self.out_buf.put(">"))
         elif self.promptable:
             if self.owner.oocflags["afk"]:
                 pretext = "{W[{RAFK{W]{x "
             else:
                 pretext = ""
             output = color.colorize(
                 f"\n\r{pretext}{self.owner.prompt}\n\r")
             asyncio.create_task(self.out_buf.put(output),
                                 name=self.session)
Example #5
0
def generate_report(app, pcapfile=''):
    '''
    Print report based on collected data
    '''

    global sslpacketcount

    if app.endswith('.pcap'):
        app_or_pcap = 'pcap'
        jsonfile = '%s.%s' % (pcapfile, json_output)
    else:
        app_or_pcap = 'application'
        jsonfile = os.path.join(os.path.dirname(pcapfile), json_output)

    report = {}
    report['app'] = app
    report['testtime'] = os.path.getmtime(pcapfile)
    report['sslversions'] = net.sslversions
    report['requestedciphers'] = net.requestedciphers
    report['negotiatedciphers'] = net.negotiatedciphers
    report['dtlsversions'] = net.dtlsversions
    report['negotiateddtlsciphers'] = net.negotiateddtlsciphers

    seen_mandatory_ciphers = []
    seen_optional_ciphers = []
    seen_other_ciphers = []
    failedtest = False
    failedreasons = []

    print('')
    print('Summary for application: %s' % color.bright(color.cyan(app)))
    print('')

    if net.sslpacketcount > 0:
        print(color.bright('TLS/SSL protocols used:'))
        # For each target (unsorted)

        for sslversion in net.sslversions:
            if sslversion == 'TLS 1.2':
                sslversion = color.bright(color.green(sslversion))
            else:
                failedtest = True
                failedreasons.append('%s is used, rather than TLS 1.2' %
                                     sslversion)
                sslversion = color.bright(color.red(sslversion))
            print(sslversion)
            print(
                color.bright('Hosts using %s:' % color.decolorize(sslversion)))
            for host in net.sslversions[color.decolorize(sslversion)]:
                print(host)
        print('')

        for ciphersuite in net.requestedciphers:
            if ciphersuite in net.mandatory_ciphers:
                #ciphersuite = color.bright(color.green(ciphersuite))
                seen_mandatory_ciphers.append(ciphersuite)
            elif ciphersuite in net.optional_ciphers:
                #ciphersuite = color.bright(ciphersuite)
                seen_optional_ciphers.append(ciphersuite)
            else:
                #ciphersuite = color.dim(ciphersuite)
                seen_other_ciphers.append(ciphersuite)

        if len(seen_mandatory_ciphers) == 0:
            failedtest = True
            failedreasons.append('%s is not supported by client' %
                                 net.mandatory_ciphers[0])

        print(
            color.bright(
                'Observed mandatory ciphers in TLS/SSL client requests:'))
        for cipher in seen_mandatory_ciphers:
            print(color.bright(color.green(cipher)))
        report['seen_mandatory_ciphers'] = seen_mandatory_ciphers
        print('')
        print(
            color.bright(
                'Observed optional ciphers in TLS/SSL client requests:'))
        for cipher in seen_optional_ciphers:
            print(cipher)
        report['seen_optional_ciphers'] = seen_optional_ciphers
        print('')
        print(
            color.bright('Observed other ciphers in TLS/SSL client requests:'))
        for cipher in seen_other_ciphers:
            print(color.dim(cipher))
        report['seen_other_ciphers'] = seen_other_ciphers
        print('')

        print(color.bright('Negotiated TLS/SSL ciphers:'))

        for ciphersuite in net.negotiatedciphers:
            if ciphersuite in net.mandatory_ciphers:
                ciphersuite = color.bright(color.green(ciphersuite))
            elif ciphersuite in net.optional_ciphers:
                pass
                #ciphersuite = color.bright(ciphersuite)
            else:
                ciphersuite = color.dim(ciphersuite)

            print(ciphersuite)
            print(
                color.bright('Hosts using %s:' %
                             color.decolorize(ciphersuite)))
            for host in net.negotiatedciphers[color.decolorize(ciphersuite)]:
                print(host)
            print('')
        print('')
    else:
        print(color.bright(color.green('No TLS/SSL traffic seen')))
        print('')

    if net.dtlspacketcount > 0:
        print(color.bright('DTLS protocols used:'))

        # For each target (unsorted)
        for dtlsversion in net.dtlsversions:
            if dtlsversion == 'DTLS 1.2':
                dtlsversion = color.bright(color.green(dtlsversion))
            else:
                failedtest = True
                failedreasons.append('%s is used, rather than DTLS 1.2' %
                                     dtlsversion)
                dtlsversion = color.bright(color.red(dtlsversion))
            print(dtlsversion)
            print(
                color.bright('Hosts using %s:' %
                             color.decolorize(dtlsversion)))
            for host in net.dtlsversions[color.decolorize(dtlsversion)]:
                print(host)
        print('')

        report['dtlsciphers'] = net.requesteddtlsciphers
        for ciphersuite in net.requesteddtlsciphers:
            if ciphersuite in net.mandatory_ciphers:
                #ciphersuite = color.bright(color.green(ciphersuite))
                seen_mandatory_ciphers.append(ciphersuite)
            elif ciphersuite in net.optional_ciphers:
                #ciphersuite = color.bright(ciphersuite)
                seen_optional_ciphers.append(ciphersuite)
            else:
                #ciphersuite = color.dim(ciphersuite)
                seen_other_ciphers.append(ciphersuite)

        if len(seen_mandatory_ciphers) == 0:
            failedtest = True
            failedreasons.append('%s is not supported by client' %
                                 net.mandatory_ciphers[0])

        print(
            color.bright(
                'Observed mandatory ciphers in DTLS client requests:'))
        for cipher in seen_mandatory_ciphers:
            print(color.bright(color.green(cipher)))
        print('')
        report['seen_mandatory_dtls_ciphers'] = seen_mandatory_ciphers
        print(
            color.bright('Observed optional ciphers in DTLS client requests:'))
        for cipher in seen_optional_ciphers:
            print(cipher)
        print('')
        report['seen_optional_dtls_ciphers'] = seen_optional_ciphers
        print(color.bright('Observed other ciphers in DTLS client requests:'))
        for cipher in seen_other_ciphers:
            print(color.dim(cipher))
        print('')
        report['seen_other_dtls_ciphers'] = seen_other_ciphers

        print(color.bright('Negotiated DTLS ciphers:'))
        for ciphersuite in net.negotiateddtlsciphers:
            if ciphersuite in net.mandatory_ciphers:
                ciphersuite = color.bright(color.green(ciphersuite))
            elif ciphersuite in net.optional_ciphers:
                pass
                #ciphersuite = color.bright(ciphersuite)
            else:
                ciphersuite = color.dim(ciphersuite)

            print(ciphersuite)
            print(
                color.bright('Hosts using %s:' %
                             color.decolorize(ciphersuite)))
            for host in net.negotiateddtlsciphers[color.decolorize(
                    ciphersuite)]:
                print(host)
            print('')
        print('')

    else:
        print(color.bright(color.green('No DTLS traffic seen')))

    report['failedtest'] = failedtest
    report['failedreasons'] = failedreasons
    if failedtest:
        print(
            color.bright(
                color.red('App %s failed crypto checking because:' % app)))
        for reason in failedreasons:
            print(color.bright(color.red(reason)))
    else:
        print(color.bright(color.green('App %s passed crypto checking' % app)))

    # print(report)

    with open(jsonfile, 'w') as fp:
        json.dump(report, fp)
Example #6
0
 def write(self, message):
     self.terminal.write(message)
     self.log.write(color.decolorize(message))