r"""Parse credentials from the command line or from a file specified. Usernames can be specified with a domain (domain\\username) or without (username). If the file contains domain\\username the domain specified will be overwritten by the one in the file. :return: domain[],
(self)
| 376 | return domains, usernames, owned, secrets, cred_types, data |
| 377 | |
| 378 | def parse_credentials(self): |
| 379 | r"""Parse credentials from the command line or from a file specified. |
| 380 | |
| 381 | Usernames can be specified with a domain (domain\\username) or without (username). |
| 382 | If the file contains domain\\username the domain specified will be overwritten by the one in the file. |
| 383 | |
| 384 | :return: domain[], username[], owned[], secret[], cred_type[] |
| 385 | """ |
| 386 | domain = [] |
| 387 | username = [] |
| 388 | owned = [] |
| 389 | secret = [] |
| 390 | cred_type = [] |
| 391 | |
| 392 | # Parse usernames |
| 393 | for user in self.args.username: |
| 394 | if isfile(user): |
| 395 | with open(user) as user_file: |
| 396 | for line in user_file: |
| 397 | if "\\" in line and len(line.split("\\")) == 2: |
| 398 | domain_single, username_single = line.split("\\") |
| 399 | else: |
| 400 | domain_single = self.args.domain if hasattr(self.args, "domain") and self.args.domain is not None else self.domain |
| 401 | username_single = line |
| 402 | domain.append(domain_single) |
| 403 | username.append(username_single.strip()) |
| 404 | owned.append(False) |
| 405 | else: |
| 406 | if "\\" in user: |
| 407 | domain_single, username_single = user.split("\\") |
| 408 | else: |
| 409 | domain_single = self.args.domain if hasattr(self.args, "domain") and self.args.domain is not None else self.domain |
| 410 | username_single = user |
| 411 | domain.append(domain_single) |
| 412 | username.append(username_single) |
| 413 | owned.append(False) |
| 414 | |
| 415 | # Parse passwords |
| 416 | for password in self.args.password: |
| 417 | if isfile(password): |
| 418 | try: |
| 419 | with open(password, errors=("ignore" if self.args.ignore_pw_decoding else "strict")) as password_file: |
| 420 | for line in password_file: |
| 421 | secret.append(line.strip()) |
| 422 | cred_type.append("plaintext") |
| 423 | except UnicodeDecodeError as e: |
| 424 | self.logger.error(f"{type(e).__name__}: Could not decode password file. Make sure the file only contains UTF-8 characters.") |
| 425 | self.logger.error("You can ignore non UTF-8 characters with the option '--ignore-pw-decoding'") |
| 426 | sys.exit(1) |
| 427 | else: |
| 428 | secret.append(password) |
| 429 | cred_type.append("plaintext") |
| 430 | |
| 431 | # Parse NTLM-hashes |
| 432 | if hasattr(self.args, "hash") and self.args.hash: |
| 433 | for ntlm_hash in self.args.hash: |
| 434 | if isfile(ntlm_hash): |
| 435 | with open(ntlm_hash) as ntlm_hash_file: |