[7260bdc2] | 1 | from engine.SystemLib import * |
---|
| 2 | |
---|
| 3 | def ogLoadHiveWindows(): |
---|
| 4 | FUNCNAME = ogLoadHiveWindows.__name__ |
---|
| 5 | # Variables locales. |
---|
| 6 | PART = None |
---|
| 7 | DISK = None |
---|
| 8 | |
---|
| 9 | # Si se solicita, mostrar ayuda. |
---|
| 10 | if len(sys.argv) > 1 and sys.argv[1] == "help": |
---|
| 11 | ogHelp(FUNCNAME, f"{FUNCNAME} int_ndisk int_partition", f"{FUNCNAME} 1 1") |
---|
| 12 | return |
---|
| 13 | |
---|
| 14 | # Error si no se reciben 2 parámetros. |
---|
| 15 | if len(sys.argv) != 3: |
---|
| 16 | return ogRaiseError(OG_ERR_FORMAT) |
---|
| 17 | |
---|
| 18 | DISK = int(sys.argv[1]) |
---|
| 19 | PART = int(sys.argv[2]) |
---|
| 20 | |
---|
| 21 | # Comprobaciones redundantes: borrar" |
---|
| 22 | # ogDiskToDev(DISK, PART) or return ogRaiseError(OG_ERR_PARTITION, "particion de windows no detectada") |
---|
| 23 | # ogGetOsType(DISK, PART).startswith("Windows") or return ogRaiseError(OG_ERR_NOTOS, "no es windows") |
---|
| 24 | # VERSION = ogGetOsVersion(DISK, PART) |
---|
| 25 | # Fin Comprobaciones redundantes: borrar" |
---|
| 26 | |
---|
| 27 | # primera fase, carga de los hive del sistema |
---|
| 28 | if ogGetPath(DISK, PART, "WINDOWS"): |
---|
| 29 | SYSTEMROOT = "Windows" |
---|
| 30 | elif ogGetPath(DISK, PART, "WINNT"): |
---|
| 31 | SYSTEMROOT = "winnt" |
---|
| 32 | else: |
---|
| 33 | return ogRaiseError(OG_ERR_NOTOS, "version windows no detectada") |
---|
| 34 | |
---|
| 35 | hiveSAM = ogGetPath(DISK, PART, f"/{SYSTEMROOT}/system32/config/SAM") |
---|
| 36 | if hiveSAM: |
---|
| 37 | os.environ["hiveSAM"] = hiveSAM |
---|
| 38 | else: |
---|
| 39 | return ogRaiseError(OG_ERR_NOTOS, "hive SAM no detectada") |
---|
| 40 | |
---|
| 41 | hiveSYSTEM = ogGetPath(DISK, PART, f"/{SYSTEMROOT}/system32/config/system") |
---|
| 42 | if hiveSYSTEM: |
---|
| 43 | os.environ["hiveSYSTEM"] = hiveSYSTEM |
---|
| 44 | else: |
---|
| 45 | return ogRaiseError(OG_ERR_NOTOS, "hive SYSTEM no detectada") |
---|
| 46 | |
---|
| 47 | hiveSOFTWARE = ogGetPath(DISK, PART, f"/{SYSTEMROOT}/system32/config/software") |
---|
| 48 | if hiveSOFTWARE: |
---|
| 49 | os.environ["hiveSOFTWARE"] = hiveSOFTWARE |
---|
| 50 | else: |
---|
| 51 | return ogRaiseError(OG_ERR_NOTOS, "hive SOFTWARE no detectada") |
---|
| 52 | |
---|
| 53 | os.environ["TEMPhive"] = "/tmp/tmpregistry" |
---|
| 54 | |
---|
| 55 | # segunda fase, carga de los hive de usuarios windows. |
---|
| 56 | COUNT = 3 |
---|
| 57 | # TODO WINDOWS XP WINDOWS7 |
---|
| 58 | BASEHOMEDIR = ogGetPath(DISK, PART, "/Documents and Settings") |
---|
| 59 | TMPUSERFILE = "/tmp/WuserRegAndDAT.tmp" |
---|
| 60 | with open(TMPUSERFILE, "w") as f: |
---|
| 61 | f.write("\n".join(glob.glob(f"{BASEHOMEDIR}/**/NTUSER.DAT", recursive=True))) |
---|
| 62 | |
---|
| 63 | LISTUSERS = subprocess.check_output(["drbl-chntpw", "-l", hiveSAM]).decode().splitlines() |
---|
| 64 | LISTUSERS = [user.split("<")[1].split(">")[0] for user in LISTUSERS if "RID" in user] |
---|
| 65 | |
---|
| 66 | for user in LISTUSERS: |
---|
| 67 | # Comprobamos que el usuario registrado tiene .DAT |
---|
| 68 | if HOMEDIR := next((line for line in open(TMPUSERFILE) if user in line), None): |
---|
| 69 | os.environ[user] = f"hiveUSER{COUNT}" |
---|
| 70 | os.environ[f"hiveUSER{COUNT}"] = HOMEDIR.strip() |
---|
| 71 | COUNT += 1 |
---|
| 72 | |
---|
| 73 | COUNT = 0 |
---|
| 74 | |
---|
| 75 | def ogUpdateHiveWindows(): |
---|
| 76 | FUNCNAME = ogUpdateHiveWindows.__name__ |
---|
| 77 | # Variables locales. |
---|
| 78 | PART = None |
---|
| 79 | DISK = None |
---|
| 80 | FILE = None |
---|
| 81 | |
---|
| 82 | # TODO detectar llamada a ogLoadHiveWindows |
---|
| 83 | |
---|
| 84 | # Si se solicita, mostrar ayuda. |
---|
| 85 | if len(sys.argv) > 1 and sys.argv[1] == "help": |
---|
| 86 | ogHelp(FUNCNAME, f"{FUNCNAME} ", f"{FUNCNAME} ") |
---|
| 87 | return |
---|
| 88 | |
---|
| 89 | subprocess.call(["drbl-chntpw", "-f", os.environ["TEMPhive"], os.environ["hiveSAM"], os.environ["hiveSYSTEM"], os.environ["hiveSOFTWARE"], os.environ["hiveUSER3"], os.environ["hiveUSER4"], os.environ["hiveUSER5"], os.environ["hiveUSER6"], os.environ["hiveUSER7"], os.environ["hiveUSER8"], os.environ["hiveUSER9"]]) |
---|
| 90 | |
---|
| 91 | os.remove(os.environ["TEMPhive"]) |
---|
| 92 | |
---|
| 93 | del os.environ["hiveSAM"] |
---|
| 94 | del os.environ["hiveSYSTEM"] |
---|
| 95 | del os.environ["hiveSOFTWARE"] |
---|
| 96 | del os.environ["TEMPhive"] |
---|
| 97 | del os.environ["hiveUSER3"] |
---|
| 98 | del os.environ["hiveUSER4"] |
---|
| 99 | del os.environ["hiveUSER5"] |
---|
| 100 | del os.environ["hiveUSER6"] |
---|
| 101 | del os.environ["hiveUSER7"] |
---|
| 102 | del os.environ["hiveUSER8"] |
---|
| 103 | del os.environ["hiveUSER9"] |
---|
| 104 | |
---|
| 105 | def ogHiveNTRunMachine(): |
---|
| 106 | FUNCNAME = ogHiveNTRunMachine.__name__ |
---|
| 107 | # Variables locales. |
---|
| 108 | PART = None |
---|
| 109 | DISK = None |
---|
| 110 | FILE = None |
---|
| 111 | |
---|
| 112 | # Si se solicita, mostrar ayuda. |
---|
| 113 | if len(sys.argv) > 1 and sys.argv[1] == "help": |
---|
| 114 | ogHelp(FUNCNAME, f"{FUNCNAME} PathScripts|command keyName", |
---|
| 115 | f"{FUNCNAME} c:\\\\Windows\\\\crearusuarios.cmd scripts_crearUsuarios", |
---|
| 116 | f"{FUNCNAME} \"cmd /c del c:\ogboot.*\" ogcleanboot", |
---|
| 117 | f"{FUNCNAME} Requiere la previa ejecución de ogLoadHive int_disk int_part", |
---|
| 118 | f"{FUNCNAME} Despues requiere el ogUpdateHive") |
---|
| 119 | return |
---|
| 120 | |
---|
| 121 | # Error si no se reciben al menos 1 parámetros. |
---|
| 122 | if len(sys.argv) != 3: |
---|
| 123 | return ogRaiseError(OG_ERR_FORMAT) |
---|
| 124 | |
---|
| 125 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 126 | f.write(f"h 2\ncd \\Microsoft\\Windows\\CurrentVersion\\Run\nnv 1 {sys.argv[2]}\ned {sys.argv[2]}\n{sys.argv[1]}\n") |
---|
| 127 | |
---|
| 128 | def ogNTPolUserOn(): |
---|
| 129 | FUNCNAME = ogNTPolUserOn.__name__ |
---|
| 130 | # Variables locales. |
---|
| 131 | PART = None |
---|
| 132 | DISK = None |
---|
| 133 | FILE = None |
---|
| 134 | |
---|
| 135 | # Si se solicita, mostrar ayuda. |
---|
| 136 | if len(sys.argv) > 1 and sys.argv[1] == "help": |
---|
| 137 | ogHelp(FUNCNAME, f"{FUNCNAME} id_hive_user", f"{FUNCNAME} NombreUsuario", f"{FUNCNAME}") |
---|
| 138 | return |
---|
| 139 | |
---|
| 140 | # TODO: error si no se ha llamado previamente a ogLoadHiveWindows |
---|
| 141 | if "hiveSAM" not in os.environ: |
---|
| 142 | return ogRaiseError(OG_ERR_FORMAT, "se debe utilizar primero la utilidad ogLoadHiveWindows") |
---|
| 143 | |
---|
| 144 | # TODO: error si el usuario no tiene cuenta en windows. |
---|
| 145 | if subprocess.call(["drbl-chntpw", "-l", os.environ["hiveSAM"]], stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.decode().count(f"RID: {sys.argv[1]}") == 0: |
---|
| 146 | return ogRaiseError(OG_ERR_FORMAT, f"el usuario {sys.argv[1]} no tiene cuenta en este windows: Compruebe mayusculas o minusculas") |
---|
| 147 | |
---|
| 148 | # TODO: error si no el usario no no tiene HIVE asociado. |
---|
| 149 | if sys.argv[1] not in os.environ: |
---|
| 150 | return ogRaiseError(OG_ERR_FORMAT, "el usuario no tiene hive creado") |
---|
| 151 | |
---|
| 152 | HIVEID = os.environ[sys.argv[1]].replace("hiveUSER", "") |
---|
| 153 | |
---|
| 154 | # echo "IMPORTANTE: la variable HiveUser3=/mnt/windows/Document/\ and/\ Seeting\alumnmos\NTUSER.dat" |
---|
| 155 | print(HIVEID) |
---|
| 156 | # cp /var/EAC/admin/utilswin/Fondo.BMP ${particion}/WINDOWS/ |
---|
| 157 | |
---|
| 158 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 159 | f.write(f"h {HIVEID}\n") |
---|
| 160 | f.write("cd \\Control Panel\\Desktop\n") |
---|
| 161 | f.write("ed Wallpaper\n") |
---|
| 162 | f.write("C:\\WINDOWS\\fondo.bmp\n") |
---|
| 163 | f.write("\n") |
---|
| 164 | f.write("cd \\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\n") |
---|
| 165 | f.write("nk Explorer\n") |
---|
| 166 | f.write("cd Explorer\n") |
---|
| 167 | f.write("\n") |
---|
| 168 | f.write("nv 4 NoDesktop\n") |
---|
| 169 | f.write("ed NoDesktop\n") |
---|
| 170 | f.write("1\n") |
---|
| 171 | f.write("\n") |
---|
| 172 | f.write("nv 4 NoSimpleStartMenu\n") |
---|
| 173 | f.write("ed NoSimpleStartMenu\n") |
---|
| 174 | f.write("1\n") |
---|
| 175 | f.write("nv 4 NoWindowsUpdate\n") |
---|
| 176 | f.write("ed NoWindowsUpdate\n") |
---|
| 177 | f.write("1\n") |
---|
| 178 | f.write("\n") |
---|
| 179 | f.write("nv 4 NoSMConfigurePrograms\n") |
---|
| 180 | f.write("ed NoSMConfigurePrograms\n") |
---|
| 181 | f.write("1\n") |
---|
| 182 | f.write("\n") |
---|
| 183 | f.write("nv 4 NoChangeStartMenu\n") |
---|
| 184 | f.write("ed NoChangeStartMenu\n") |
---|
| 185 | f.write("1\n") |
---|
| 186 | f.write("\n") |
---|
| 187 | f.write("nv 4 Intellimenus\n") |
---|
| 188 | f.write("ed Intellimenus\n") |
---|
| 189 | f.write("1\n") |
---|
| 190 | f.write("\n") |
---|
| 191 | f.write("nv 4 NoRun\n") |
---|
| 192 | f.write("ed NoRun\n") |
---|
| 193 | f.write("1\n") |
---|
| 194 | f.write("\n") |
---|
| 195 | f.write("nv 4 NoRecentDocsHistory\n") |
---|
| 196 | f.write("ed NoRecentDocsHistory\n") |
---|
| 197 | f.write("1\n") |
---|
| 198 | |
---|
| 199 | def NTChangeName(): |
---|
| 200 | if len(sys.argv) == 1: |
---|
| 201 | print("sintaxis: NTChangeName str_$var") |
---|
| 202 | print("ejemplos: NTChangeName adi${IPcuatro}-xp") |
---|
| 203 | return |
---|
| 204 | |
---|
| 205 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 206 | f.write("h 1\n") |
---|
| 207 | f.write("ed ControlSet001\\Control\\ComputerName\\ComputerName\\ComputerName\n") |
---|
| 208 | f.write(sys.argv[1] + "\n") |
---|
| 209 | f.write("ed ControlSet001\\Services\\Tcpip\\Parameters\\Hostname\n") |
---|
| 210 | f.write(sys.argv[1] + "\n") |
---|
| 211 | f.write("ed ControlSet001\\Services\\Tcpip\\Parameters\\NV Hostname\n") |
---|
| 212 | f.write(sys.argv[1] + "\n") |
---|
| 213 | f.write("h 2\n") |
---|
| 214 | f.write("cd \\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\n") |
---|
| 215 | f.write("ed DefaultDomainName\n") |
---|
| 216 | f.write(sys.argv[1] + "\n") |
---|
| 217 | |
---|
| 218 | def NTSetGroupName(group_name): |
---|
| 219 | if len(sys.argv) == 1: |
---|
| 220 | print("sintaxis: NTSetGroupName str_$var") |
---|
| 221 | print("ejemplos: NTSetGroupName adi") |
---|
| 222 | return |
---|
| 223 | |
---|
| 224 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 225 | f.write("h 2\n") |
---|
| 226 | f.write("ed \\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\DefaultDomainName\n") |
---|
| 227 | f.write(group_name + "\n") |
---|
| 228 | |
---|
| 229 | def NTSetOwner(owner, organization): |
---|
| 230 | if len(sys.argv) == 1: |
---|
| 231 | print("sintaxis: NtSetOwner str_propietario str_organizacion") |
---|
| 232 | print("ejemplos: NTSetOwner eu\\ politecnica universidad\\ de\\ malaga") |
---|
| 233 | return |
---|
| 234 | |
---|
| 235 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 236 | f.write("h 2\n") |
---|
| 237 | f.write("ed \\Microsoft\\Windows NT\\CurrentVersion\\RegisteredOwner\n") |
---|
| 238 | f.write(owner + "\n") |
---|
| 239 | f.write("ed \\Microsoft\\Windows NT\\CurrentVersion\\RegisteredOrganization\n") |
---|
| 240 | f.write(organization + "\n") |
---|
| 241 | |
---|
| 242 | def NTAutoLogon(): |
---|
| 243 | if len(sys.argv) == 1: |
---|
| 244 | print("sintaxis: NTAutoLogon int_Activar int_nves str_usuario str_passwd str_equipo") |
---|
| 245 | print("ejemplos: NTAutoLogon 1 2 administrador 3451 $equipo") |
---|
| 246 | print("IMPORTANTE: cuando AutoLogonCount llegue a 0, activa el AutoAdminLogon a 0. Pero no borra los valores de DefaultPassword") |
---|
| 247 | return 2 |
---|
| 248 | |
---|
| 249 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 250 | f.write("hive 2\n") |
---|
| 251 | f.write("cd \\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\n") |
---|
| 252 | f.write(f"nv 1 AutoAdminLogon\n") |
---|
| 253 | f.write(f"ed AutoAdminLogon\n") |
---|
| 254 | f.write(f"{sys.argv[1]}\n") |
---|
| 255 | f.write(f"nv 1 AutoLogonCount\n") |
---|
| 256 | f.write(f"ed AutoLogonCount\n") |
---|
| 257 | f.write(f"{sys.argv[2]}\n") |
---|
| 258 | f.write(f"nv 1 DefaultUserName\n") |
---|
| 259 | f.write(f"ed DefaultUserName\n") |
---|
| 260 | f.write(f"{sys.argv[3]}\n") |
---|
| 261 | f.write(f"nv 1 DefaultDomainName\n") |
---|
| 262 | f.write(f"ed DefaultDomainName\n") |
---|
| 263 | f.write(f"{sys.argv[5]}\n") |
---|
| 264 | |
---|
| 265 | if sys.argv[4] == "none": |
---|
| 266 | f.write("dv DefaultPassword\n") |
---|
| 267 | else: |
---|
| 268 | f.write(f"nv 1 DefaultPassword\n") |
---|
| 269 | f.write(f"ed DefaultPassword\n") |
---|
| 270 | f.write(f"{sys.argv[4]}\n") |
---|
| 271 | |
---|
| 272 | def NTStatusRatonTeclado(): |
---|
| 273 | if len(sys.argv) == 1: |
---|
| 274 | print("sintaxis: NTStatusRatonTeclado int_StatusRaton int_StatusTeclado") |
---|
| 275 | print("ejemplos: NTStatusRatonTeclado 1 4") |
---|
| 276 | return 2 |
---|
| 277 | |
---|
| 278 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 279 | f.write("hive 1\n") |
---|
| 280 | f.write("cd \\ControlSet001\\Services\\Mouclass\n") |
---|
| 281 | f.write("ed Start\n") |
---|
| 282 | f.write(sys.argv[1] + "\n") |
---|
| 283 | f.write("cd \\ControlSet001\\Services\\Kbdclass\n") |
---|
| 284 | f.write("ed Start\n") |
---|
| 285 | f.write(sys.argv[2] + "\n") |
---|
| 286 | |
---|
| 287 | def NTRunOnceMachine(): |
---|
| 288 | if len(sys.argv) == 1: |
---|
| 289 | print("sintaxis: NTRunOnceMachine PathScripts idScripts") |
---|
| 290 | print("ejemplo: NTRunOnceMachine c:\\\\WINDOWS\\\\crearusuarios.bat scripts1") |
---|
| 291 | print("IMPORTANTE: el path debe llevar dos barras \\, pero como se deben 'escapar' debes poner cuatro \\\\") |
---|
| 292 | return 2 |
---|
| 293 | |
---|
| 294 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 295 | f.write("h 2\n") |
---|
| 296 | f.write("cd \\Microsoft\\Windows\\CurrentVersion\\RunOnce\n") |
---|
| 297 | f.write(f"nv 1 {sys.argv[2]}\n") |
---|
| 298 | f.write(f"ed {sys.argv[2]}\n") |
---|
| 299 | f.write(f"{sys.argv[1]}\n") |
---|
| 300 | |
---|
| 301 | def NTRunMachine(): |
---|
| 302 | if len(sys.argv) == 1: |
---|
| 303 | print("sintaxis: NTRunMachine PathScripts idScripts") |
---|
| 304 | print("ejemplo: NTRunMachine c:\\\\WINDOWS\\\\crearusuarios.bat scripts1") |
---|
| 305 | print("IMPORTANTE: el path debe llevar dos barras \\, pero como se deben 'escapar' debes poner cuatro \\\\") |
---|
| 306 | return 2 |
---|
| 307 | |
---|
| 308 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 309 | f.write("h 2\n") |
---|
| 310 | f.write("cd \\Microsoft\\Windows\\CurrentVersion\\Run\n") |
---|
| 311 | f.write(f"nv 1 {sys.argv[2]}\n") |
---|
| 312 | f.write(f"ed {sys.argv[2]}\n") |
---|
| 313 | f.write(f"{sys.argv[1]}\n") |
---|
| 314 | |
---|
| 315 | def NTRunUser(): |
---|
| 316 | if len(sys.argv) == 1: |
---|
| 317 | print("sintaxis: str_PathWINScripts str_idScripts Int_hive||$usuario") |
---|
| 318 | print("ejemplo: c:\\\\WINDOWS\\\\crearusuarios.bat scripts1 3") |
---|
| 319 | print("IMPORTANTE: el pathWIN debe llevar dos barras \\, pero como se deben 'escapar' debes poner cuatro \\\\") |
---|
| 320 | print("IMPORTANTE: el pathLinux si lleva espacios debe escaparse con una barra \\") |
---|
| 321 | print("IMPORTANTE Int_hive: 3 para el primer usuario, 4 para el segundo usuario") |
---|
| 322 | print("requiere export un HiveUser3=/mnt/windows/Document\\ and\\ Seeting\\alumnmos\\NTUSER.dat") |
---|
| 323 | return 2 |
---|
| 324 | |
---|
| 325 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 326 | f.write(f"h {sys.argv[3]}\n") |
---|
| 327 | f.write("cd \\Software\\Microsoft\\Windows\\CurrentVersion\\Run\n") |
---|
| 328 | f.write(f"nv 1 {sys.argv[2]}\n") |
---|
| 329 | f.write(f"ed {sys.argv[2]}\n") |
---|
| 330 | f.write(f"{sys.argv[1]}\n") |
---|
| 331 | |
---|
| 332 | def NTPolUserOn(): |
---|
| 333 | if len(sys.argv) == 1: |
---|
| 334 | print("sintaxis: NTPolUserOn Int_hive") |
---|
| 335 | print("ejemplo: NTPolUserOn 3") |
---|
| 336 | print("IMPORTANTE: la variable HiveUser3=/mnt/windows/Document/ and/ Seeting/alumnmos/NTUSER.dat") |
---|
| 337 | return 2 |
---|
| 338 | |
---|
| 339 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 340 | f.write(f"h {sys.argv[1]}\n") |
---|
| 341 | f.write("cd \\Control Panel\\Desktop\n") |
---|
| 342 | f.write("ed Wallpaper\n") |
---|
| 343 | f.write("C:\\WINDOWS\\fondo.bmp\n") |
---|
| 344 | f.write("\n") |
---|
| 345 | f.write("cd \\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\n") |
---|
| 346 | f.write("nk Explorer\n") |
---|
| 347 | f.write("cd Explorer\n") |
---|
| 348 | f.write("\n") |
---|
| 349 | f.write("nv 4 NoDesktop\n") |
---|
| 350 | f.write("ed NoDesktop\n") |
---|
| 351 | f.write("1\n") |
---|
| 352 | f.write("\n") |
---|
| 353 | f.write("nv 4 NoSimpleStartMenu\n") |
---|
| 354 | f.write("ed NoSimpleStartMenu\n") |
---|
| 355 | f.write("1\n") |
---|
| 356 | f.write("nv 4 NoWindowsUpdate\n") |
---|
| 357 | f.write("ed NoWindowsUpdate\n") |
---|
| 358 | f.write("1\n") |
---|
| 359 | f.write("\n") |
---|
| 360 | f.write("nv 4 NoSMConfigurePrograms\n") |
---|
| 361 | f.write("ed NoSMConfigurePrograms\n") |
---|
| 362 | f.write("1\n") |
---|
| 363 | f.write("\n") |
---|
| 364 | f.write("nv 4 NoChangeStartMenu\n") |
---|
| 365 | f.write("ed NoChangeStartMenu\n") |
---|
| 366 | f.write("1\n") |
---|
| 367 | f.write("\n") |
---|
| 368 | f.write("nv 4 Intellimenus\n") |
---|
| 369 | f.write("ed Intellimenus\n") |
---|
| 370 | f.write("1\n") |
---|
| 371 | f.write("\n") |
---|
| 372 | f.write("nv 4 NoRun\n") |
---|
| 373 | f.write("ed NoRun\n") |
---|
| 374 | f.write("1\n") |
---|
| 375 | f.write("\n") |
---|
| 376 | f.write("nv 4 NoRecentDocsHistory\n") |
---|
| 377 | f.write("ed NoRecentDocsHistory\n") |
---|
| 378 | f.write("1\n") |
---|
| 379 | |
---|
| 380 | def NTPolUserOFF(hive): |
---|
| 381 | if len(sys.argv) == 1: |
---|
| 382 | print("sintaxis: NTPolUserOFF Int_hive") |
---|
| 383 | print("ejemplo: NTPolUserOFF 3") |
---|
| 384 | print("IMPORTANTE: la variable HiveUser3=/mnt/windows/Document/ and/ Seeting/alumnmos/NTUSER.dat") |
---|
| 385 | return 2 |
---|
| 386 | |
---|
| 387 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 388 | f.write(f"h {hive}\n") |
---|
| 389 | f.write("cd \\Control Panel\\Desktop\n") |
---|
| 390 | f.write("ed Wallpaper\n") |
---|
| 391 | f.write("C:\\WINDOWS\\web\\wallpaper\\Felicidad.bmp\n") |
---|
| 392 | f.write("\n") |
---|
| 393 | f.write("cd \\Software\\Microsoft\\Windows\\CurrentVersion\\\n") |
---|
| 394 | f.write("rdel Policies\n") |
---|
| 395 | f.write("nk Policies\n") |
---|
| 396 | f.write("1\n") |
---|
| 397 | |
---|
| 398 | def ogSetWindowsChkdisk(): |
---|
| 399 | if len(sys.argv) == 1: |
---|
| 400 | print("sintaxis: true|TRUE|0 false|false|1") |
---|
| 401 | print("ejemplos: int=0 desactivado int=1 activado") |
---|
| 402 | return 2 |
---|
| 403 | |
---|
| 404 | valor = "" |
---|
| 405 | if sys.argv[1] in ["0", "true", "TRUE"]: |
---|
| 406 | valor = "autocheck autochk *" |
---|
| 407 | elif sys.argv[1] in ["1", "false", "FALSE"]: |
---|
| 408 | valor = "none" |
---|
| 409 | else: |
---|
| 410 | return 0 |
---|
| 411 | |
---|
| 412 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 413 | f.write("hive 1\n") |
---|
| 414 | f.write("cd \\ControlSet001\\Control\\Session Manager\n") |
---|
| 415 | f.write("ed BootExecute\n") |
---|
| 416 | f.write(valor + "\n") |
---|
| 417 | f.write("--n\n") |
---|
| 418 | |
---|
| 419 | def NTStartRecovery(): |
---|
| 420 | if len(sys.argv) == 1: |
---|
| 421 | print("sintaxis: Int-Status") |
---|
| 422 | print("ejemplos: int=0 desactivado int=1 activado") |
---|
| 423 | return 2 |
---|
| 424 | |
---|
| 425 | valor = "" |
---|
| 426 | if sys.argv[1] == "0": |
---|
| 427 | valor = "none" |
---|
| 428 | elif sys.argv[1] == "1": |
---|
| 429 | valor = "00000000" |
---|
| 430 | else: |
---|
| 431 | return 0 |
---|
| 432 | |
---|
| 433 | with open(os.environ["TEMPhive"], "a") as f: |
---|
| 434 | f.write("hive 2\n") |
---|
| 435 | f.write("#cd \\Policies\\Microsoft\\Windows\\WinRE\n") |
---|
| 436 | f.write("#ed DisableSetup\n") |
---|
| 437 | f.write("cd \\Policies\\Microsoft\\Windows\n") |
---|
| 438 | f.write("nk WinRE\n") |
---|
| 439 | f.write("nv 4 DisableSetup\n") |
---|
| 440 | f.write("ed DisableSetup\n") |
---|
| 441 | f.write(valor + "\n") |
---|
| 442 | f.write("--n\n") |
---|
| 443 | |
---|
| 444 | def ogSchrootLinux(): |
---|
| 445 | FUNCNAME = ogSchrootLinux.__name |
---|
| 446 | # Variables locales. |
---|
| 447 | PART = None |
---|
| 448 | DISK = None |
---|
| 449 | DIRCONF = "/etc/schroot" |
---|
| 450 | |
---|
| 451 | # Si se solicita, mostrar ayuda. |
---|
| 452 | if len(sys.argv) > 1 and sys.argv[1] == "help": |
---|
| 453 | ogHelp(FUNCNAME, f"{FUNCNAME} int_ndisk int_partition", f"{FUNCNAME} 1 1") |
---|
| 454 | return |
---|
| 455 | |
---|
| 456 | # Error si no se reciben 2 parámetros. |
---|
| 457 | if len(sys.argv) != 3: |
---|
| 458 | return ogRaiseError(OG_ERR_FORMAT) |
---|
| 459 | |
---|
| 460 | DISK = int(sys.argv[1]) |
---|
| 461 | PART = int(sys.argv[2]) |
---|
| 462 | |
---|
| 463 | VERSION = ogGetOsVersion(DISK, PART) |
---|
| 464 | if "Linux" not in VERSION: |
---|
| 465 | return ogRaiseError(OG_ERR_NOTOS, "no es linux") |
---|
| 466 | |
---|
| 467 | ogUnmount(DISK, PART) or return ogRaiseError(OG_ERR_NOTOS, "no es linux") |
---|
| 468 | |
---|
| 469 | SCHROOTDEVICE = ogDiskToDev(DISK, PART) |
---|
| 470 | |
---|
| 471 | os.remove(f"{DIRCONF}/mount-defaults") |
---|
| 472 | os.remove(f"{DIRCONF}/schroot.conf") |
---|
| 473 | |
---|
| 474 | with open(f"{DIRCONF}/mount-defaults", "w") as f: |
---|
| 475 | f.write("# <file system> <mount point> <type> <options> <dump> <pass>\n") |
---|
| 476 | f.write("proc /proc proc defaults 0 0\n") |
---|
| 477 | f.write("/dev /dev none rw,bind 0 0\n") |
---|
| 478 | f.write("/dev/pts /dev/pts none rw,bind 0 0\n") |
---|
| 479 | f.write("/dev/shm /dev/shm none rw,bind 0 0\n") |
---|
| 480 | |
---|
| 481 | with open(f"{DIRCONF}/schroot.conf", "w") as f: |
---|
| 482 | f.write("[linux]\n") |
---|
| 483 | f.write(f"description={VERSION}\n") |
---|
| 484 | f.write("type=block-device\n") |
---|
| 485 | f.write(f"device={SCHROOTDEVICE}\n") |
---|
| 486 | |
---|
| 487 | subprocess.call(["schroot", "-c", "linux"]) |
---|
| 488 | subprocess.call(["schroot", "-end-sessiona", "--all-sessions"]) |
---|
| 489 | |
---|
| 490 | def ogDiskToRelativeDev(int_disk, int_partition=None): |
---|
| 491 | FUNCNAME = ogDiskToRelativeDev.__name__ |
---|
| 492 | if int_partition is None: |
---|
| 493 | # Sintaxis1: IdPartition int_disk |
---|
| 494 | # Ejemplo1: IdPartition 1 -> sda |
---|
| 495 | return ogDiskToDev(int_disk) |
---|
| 496 | else: |
---|
| 497 | # Sintaxis2: IdPartition int_disk int_partition |
---|
| 498 | # Ejemplo2: IdPartition 1 2 -> sda2 |
---|
| 499 | return ogDiskToDev(int_disk) + str(int_partition) |
---|
| 500 | |
---|
| 501 | def ogDeletePartitionsLabels(): |
---|
| 502 | FUNCNAME = ogDeletePartitionsLabels.__name__ |
---|
| 503 | # Si se solicita, mostrar ayuda. |
---|
| 504 | if len(sys.argv) > 1 and sys.argv[1] == "help": |
---|
| 505 | ogHelp(FUNCNAME, f"{FUNCNAME}", f"{FUNCNAME}") |
---|
| 506 | return |
---|
| 507 | |
---|
| 508 | subprocess.call(["rm", "/dev/disk/by-label/*"]) |
---|
| 509 | |
---|
| 510 | def ogInfoCache(): |
---|
| 511 | info = subprocess.check_output(["df", "-h"]).decode() |
---|
| 512 | info = info.split("\n") |
---|
| 513 | for line in info: |
---|
| 514 | if "$OGCAC" in line: |
---|
| 515 | infoFilesystem = line.split()[0] |
---|
| 516 | infoSize = line.split()[1] |
---|
| 517 | infoUsed = line.split()[2] |
---|
| 518 | infoAvail = line.split()[3] |
---|
| 519 | infoUsedPorcet = line.split()[4] |
---|
| 520 | infoMountedOn = line.split()[5] |
---|
| 521 | break |
---|
| 522 | else: |
---|
| 523 | return |
---|
| 524 | |
---|
| 525 | if os.path.exists(f"{OGCAC}{OGIMG}"): |
---|
| 526 | os.chdir(f"{OGCAC}{OPENGNSYS}") |
---|
| 527 | content = subprocess.check_output(["find", "images/", "-type", "f"]).decode() |
---|
| 528 | os.chdir("/") |
---|
| 529 | print(info) |
---|
| 530 | print(content) |
---|
| 531 | print(" ") |
---|
| 532 | else: |
---|
| 533 | print(info) |
---|