Skip to content

Cred Hunter

Link: https://app.hackthebox.com/challenges/cred-hunter

During a red team engagement against CygnusCorp, your team gained access to a third-party analytics platform that had been improperly secured.
This system — used for employee behavior profiling — contained a massive, unsanitized credential dump, blending email addresses and plaintext
passwords collected through multiple internal tools, test systems, and staging environments.
Fortunately, CygnusCorp enforces a strict email naming policy internally:
All employees use firstname + first letter of their last name as their username (lowercase), followed by an official company domain.
Examples:
* alicej@cygnus.com
* joshr@cygnuscorp.eu
Many users embed their first names into their passwords — a predictable pattern you can exploit to associate emails with passwords and identify
potential valid logins.
Based on this pattern, your task is to extract all possible (email, password) pairs from this messy dump.
Examples of possible pairs:
Email: joshb@cygnuscorp.com
Password: joshRocks!@
Valid pair
However:
Email: alicew@cygnus.eu
Password: SuperSecurePassword
No match (does not contain "alice", and thus cannot be paired with the email)
Input format:
The first line contains an integer N — the number of strings in the dump.
The next N lines each contain a single string (one per line). This can be an email or a password.
Output format:
For each valid (email, password) pair, output a line in the format:
email password
The output pairs must be sorted lexicographically by email.
If one email has multiple valid passwords, sort those lexicographically by their passwords and output each pair on a new line.
Notes:
* An (email, password) pair is valid if the users first name (extracted from the email address) appears as a substring in the password.
* Not all valid email addresses will have a corresponding password pair, and vice versa.
* Anything that does not follow the email format can be considered a password.
* A password can contain lowercase letters, uppercase letters, digits, and special characters.
* Uppercase to lowercase conversion is not required.
* If no valid pairs exist, the output should be empty.
10 <= N <= 10^4
8 <= Characters in each string <= 50

#!/usr/bin/python3
import re
from operator import itemgetter
def is_valid_company_email(email: str):
pattern = r'^(?P<firstname>[a-z]+)(?P<initial>[a-z])@[a-z0-9-]+\.[a-z]{2,}$'
match = re.fullmatch(pattern, email.lower())
if match:
return match.group('firstname')
return None
n = int(input())
lines = [input() for _ in range(n)]
valid_emails = []
potential_passwords = []
for line in lines:
firstname = is_valid_company_email(line)
if firstname:
valid_emails.append((line, firstname))
else:
potential_passwords.append(line)
valid_emails.sort(key=itemgetter(0))
potential_passwords.sort()
for email, firstname in valid_emails:
for pwd in potential_passwords:
if firstname in pwd:
print(f"{email} {pwd}")