Active Directory (AD) environments often require usernames to follow specific formats, which can make generating and managing usernames a bit cumbersome. In this post, we’ll introduce a tool designed to take a list of usernames and automatically format them to match common AD conventions. This tool will save time, eliminate human errors, and make it easy to integrate lists into an AD environment.
The tool’s source code is adapted from this repository, which features a collection of bash tools useful for various CTF and penetration testing scenarios.
first.last
firstl
(first name + last initial)f_last
(first initial + last name)Consider the following list of usernames:
John Doe
Jane Smith
Bob Johnson
Alice Brown
After running the tool, you might get outputs like:
john.doe
jane.smith
b.johnson
alice.b
#!/bin/bash
#
# Gets a list with `firstname lastname` and formats them into the following:
# NameSurname, Name.Surname, NamSur (3letters of each), Nam.Sur, NSurname, N.Surname, SurnameName, Surname.Name, SurnameN, Surname.N,
#
if [[ $ == "-h" || $# != 1 ]]; then
echo "Usage: ctf-wordlist-names names-file"
exit
fi
if [ -f formatted_name_wordlist.txt ]; then
echo "[!] formatted_name_wordlist.txt file already exist."
exit 1
fi
cat $1 | while read line; do
firstname=$(echo $line | cut -d ' ' -f1 | tr '[:upper:]' '[:lower:]')
lastname=$(echo $line | cut -d ' ' -f2 | tr '[:upper:]' '[:lower:]')
echo "$firstname.$lastname
$(echo $firstname | cut -c1).$lastname
$(echo $firstname | cut -c1)-$lastname
$firstname$lastname
$firstname-$lastname
$(echo $firstname | cut -c1-3)$(echo $lastname | cut -c1-3)
$(echo $firstname | cut -c1-3).$(echo $lastname | cut -c1-3)
$(echo $firstname | cut -c1)$lastname
$lastname$firstname
$lastname-$firstname
$lastname.$firstname
$lastname$(echo $firstname | cut -c1)
$lastname-$(echo $firstname | cut -c1)
$lastname.$(echo $firstname | cut -c1)" >> formatted_name_wordlist.txt
done