1- import pandas as pd
21import os
3- import subprocess
42import platform
3+ import subprocess
4+ import pandas as pd
5+ import argparse
6+ from colorama import Fore , Style , init
7+ from tabulate import tabulate
8+
9+ # Initialize colorama
10+ init (autoreset = True )
511
6- # Lee los CSVs y crea los DataFrames
7- df1 = pd . read_csv ( 'bin_data.csv' )
8- df2 = pd . read_csv ( 'bin_data_relevant.csv' )
12+ def highlight_term ( text , term ):
13+ """Highlight the search term in the given text."""
14+ return text . replace ( term , f" { Fore . GREEN } { term } { Style . RESET_ALL } " )
915
10- # Guarda los DataFrames como Parquet
11- df1 .to_parquet ('binarios.parquet' )
12- df2 .to_parquet ('detalles.parquet' )
16+ def search_in_parquet (term , parquet_files ):
17+ """Search for a term in the given Parquet files and return matching rows."""
18+ # Read the Parquet files into DataFrames
19+ dataframes = [pd .read_parquet (file ) for file in parquet_files ]
1320
14- # Función para realizar la búsqueda y generar el CSV de salida
15- def buscar_binarios ():
21+ # Concatenate DataFrames into a single DataFrame
22+ df = pd .concat (dataframes , ignore_index = True )
23+
24+ # Filter rows containing the search term
25+ result = df [df .apply (lambda row : row .astype (str ).str .contains (term , case = False ).any (), axis = 1 )]
26+
27+ return result
28+
29+ def buscar_binarios (args ):
30+ """Search for binaries with special permissions and generate a results CSV."""
1631 binarios_encontrados = set ()
1732
18- # Detecta el sistema operativo
33+ # Detect the operating system
1934 sistema_operativo = platform .system ()
35+ print (f"[+] Sistema operativo detectado: { sistema_operativo } " )
2036
2137 if sistema_operativo == 'Linux' :
22- # Ejecuta el comando find para Linux
23- result = subprocess .run (['find' , '/' , '-perm' , '4000' , '-ls' ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
24- output = result .stdout
25-
26- # Extrae los binarios encontrados
27- for line in output .split ('\n ' ):
28- if line :
29- binario = os .path .basename (line .split ()[- 1 ])
30- binarios_encontrados .add (binario )
31-
38+ print ("[+] Ejecutando búsqueda de binarios con permisos especiales en Linux..." )
39+ try :
40+ # Execute the find command for Linux
41+ result = subprocess .run (['find' , '/' , '-perm' , '4000' , '-ls' ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
42+ output = result .stdout
43+
44+ # Extract found binaries
45+ for line in output .split ('\n ' ):
46+ if line :
47+ parts = line .split ()
48+ if parts :
49+ binario = os .path .basename (parts [- 1 ])
50+ binarios_encontrados .add (binario )
51+ except Exception as e :
52+ print (f"[-] Error ejecutando el comando find: { e } " )
53+
3254 elif sistema_operativo == 'Windows' :
33- # Script de PowerShell para Windows
34- powershell_script = """
35- $directories = @("C:\\ Windows\\ System32", "C:\\ ", "C:\\ Program Files", "C:\\ Program Files (x86)")
36- foreach ($dir in $directories) {
37- Get-ChildItem -Path $dir -Recurse -Filter *.exe -ErrorAction SilentlyContinue |
38- ForEach-Object {
39- $acl = Get-Acl $_.FullName
40- $privileges = $acl.Access | Where-Object { $_.FileSystemRights -match "FullControl" }
41- if ($privileges) {
42- Write-Output "$($_.FullName)"
55+ print ("[+] Ejecutando búsqueda de binarios con permisos especiales en Windows..." )
56+ try :
57+ # PowerShell script for Windows
58+ powershell_script = """
59+ $directories = @("C:\\ Windows\\ System32", "C:\\ ", "C:\\ Program Files", "C:\\ Program Files (x86)")
60+ foreach ($dir in $directories) {
61+ Get-ChildItem -Path $dir -Recurse -Filter *.exe -ErrorAction SilentlyContinue |
62+ ForEach-Object {
63+ $acl = Get-Acl $_.FullName
64+ $privileges = $acl.Access | Where-Object { $_.FileSystemRights -match "FullControl" }
65+ if ($privileges) {
66+ Write-Output "$($_.FullName)"
67+ }
4368 }
4469 }
45- }
46- """
70+ """
71+
72+ # Execute the PowerShell script
73+ result = subprocess .run (['powershell' , '-Command' , powershell_script ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
74+ output = result .stdout
75+
76+ # Extract found binaries
77+ for line in output .split ('\n ' ):
78+ if line :
79+ binario = os .path .basename (line .strip ())
80+ binarios_encontrados .add (binario )
81+ except Exception as e :
82+ print (f"[-] Error ejecutando el script de PowerShell: { e } " )
83+
84+ if binarios_encontrados :
85+ print (f"[+] Binarios encontrados: { binarios_encontrados } " )
4786
48- # Ejecuta el script de PowerShell
49- result = subprocess .run (['powershell' , '-Command' , powershell_script ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
50- output = result .stdout
87+ # Filter the main DataFrame with the found binaries
88+ df_binarios_encontrados = df1 [df1 ['Binary' ].isin (binarios_encontrados )]
5189
52- # Extrae los binarios encontrados
53- for line in output .split ('\n ' ):
54- if line :
55- binario = os .path .basename (line .strip ())
56- binarios_encontrados .add (binario )
90+ # Generate a CSV with details of the found binaries
91+ with open ('resultado.csv' , 'w' ) as f :
92+ for binario in binarios_encontrados :
93+ result = search_in_parquet (binario , args .parquet_files )
94+ print (f"[**] Buscando resultados para '{ binario } '" )
95+ if not result .empty :
96+ result_str = result .astype (str )
97+ highlighted_result = result_str .applymap (lambda x : highlight_term (x , binario ))
5798
58- # Filtra el DataFrame principal con los binarios encontrados
59- df_binarios_encontrados = df1 [df1 ['Binary' ].isin (binarios_encontrados )]
60-
61- # Genera un CSV con los detalles de los binarios encontrados
62- with open ('resultado.csv' , 'w' ) as f :
63- for binario in binarios_encontrados :
64- detalles = df2 [df2 ['Binary' ] == binario ]
65- if not detalles .empty :
66- f .write (detalles .to_csv (index = False , header = False ))
67- print (detalles .to_csv (index = False , header = False ))
99+ print (f"Resultados encontrados para '{ binario } ':" )
100+ print (tabulate (highlighted_result , headers = 'keys' , tablefmt = 'psql' , showindex = False ))
101+ else :
102+ print (f"No se encontraron resultados para '{ binario } '" )
103+ detalles = df2 [df2 ['Binary' ] == binario ]
104+ if not detalles .empty :
105+ f .write (detalles .to_csv (index = False , header = False ))
106+ print (f"[+] Detalles del binario '{ binario } ':" )
107+ print (detalles .to_csv (index = False , header = False ))
108+ else :
109+ print ("[-] No se encontraron binarios con permisos especiales." )
68110
69- # Función para ejecutar opciones basadas en los datos encontrados
70111def ejecutar_opciones ():
112+ """Execute options based on the found data."""
113+ if not os .path .exists ('resultado.csv' ):
114+ print ("[-] No se encontró el archivo 'resultado.csv'. Asegúrese de que la búsqueda de binarios se haya realizado correctamente." )
115+ return
116+
117+ print ("[+] Leyendo resultado de búsqueda de binarios..." )
71118 df_resultado = pd .read_csv ('resultado.csv' , header = None , names = ['Binary' , 'Function Name' , 'Function URL' , 'Description' , 'Example' ])
72119
73120 for binario in df_resultado ['Binary' ].unique ():
74- print (f"Binario encontrado: { binario } " )
121+ print (f"[*] Binario encontrado: { binario } " )
75122 detalles = df_resultado [df_resultado ['Binary' ] == binario ]
76123
77124 print ("Opciones:" )
@@ -89,14 +136,35 @@ def ejecutar_opciones():
89136 opcion = int (opcion )
90137
91138 if opcion <= len (detalles ):
92- print (f"Ejecutando opción { opcion } para { binario } " )
93- # Código para ejecutar la opción correspondiente
94- print (f"Ejemplo de ejecución:\n { detalles .iloc [opcion - 1 ]['Example' ]} " )
95- # Aquí puedes agregar el código para ejecutar el ejemplo si es necesario
139+ print (f"[+] Ejecutando opción { opcion } para { binario } " )
140+ # Execute the corresponding option
141+ print (f"[*] Ejemplo de ejecución:\n { detalles .iloc [opcion - 1 ]['Example' ]} " )
142+ # Add code to execute the example if necessary
96143 else :
97- print ("Saliendo" )
144+ print ("[+] Saliendo" )
98145 break
99146
100147if __name__ == '__main__' :
101- buscar_binarios ()
148+ # Banner
149+ print ("██╗ █████╗ ███████╗██╗ ██╗ ██████╗ ██╗ ██╗███╗ ██╗" )
150+ print ("██║ ██╔══██╗╚══███╔╝╚██╗ ██╔╝██╔═══██╗██║ ██║████╗ ██║" )
151+ print ("██║ ███████║ ███╔╝ ╚████╔╝ ██║ ██║██║ █╗ ██║██╔██╗ ██║" )
152+ print ("██║ ██╔══██║ ███╔╝ ╚██╔╝ ██║ ██║██║███╗██║██║╚██╗██║" )
153+ print ("███████╗██║ ██║███████╗ ██║ ╚██████╔╝╚███╔███╔╝██║ ╚████║" )
154+ print ("╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚═╝ ╚═══╝" )
155+ print (f"[*] Iniciando: LazyOwn [;,;]" )
156+
157+ parser = argparse .ArgumentParser (description = "Buscar en archivos Parquet" )
158+ parser .add_argument ("--parquet_files" , nargs = '+' , default = ["binarios.parquet" , "detalles.parquet" ], help = "Lista de archivos Parquet a buscar" )
159+ args = parser .parse_args ()
160+
161+ # Read CSVs and create DataFrames
162+ df1 = pd .read_csv ('bin_data.csv' )
163+ df2 = pd .read_csv ('bin_data_relevant.csv' )
164+
165+ # Save DataFrames as Parquet
166+ df1 .to_parquet ('binarios.parquet' )
167+ df2 .to_parquet ('detalles.parquet' )
168+
169+ buscar_binarios (args )
102170 ejecutar_opciones ()
0 commit comments