Skip to content

Instantly share code, notes, and snippets.

@0xZDH
Created August 26, 2020 03:59
Show Gist options
  • Select an option

  • Save 0xZDH/f75c61adfc95290eec5299764ab0ab18 to your computer and use it in GitHub Desktop.

Select an option

Save 0xZDH/f75c61adfc95290eec5299764ab0ab18 to your computer and use it in GitHub Desktop.
# Break up user enumeration into chunks of users
# i.e. Enumerate 100/5,000 users at a time
# The reason for this code is to expand on the functionality of o365spray as
# it currently only supports enumerating a single user or an entire list of users.
# Instead this allows us to break enumeration attempts up by groups of users.
DOMAIN=changeme # TODO: Fill this out
USERFILE=changeme # TODO: Fill this out
NUM_USERS_PER_PASS=100 # TODO: Update this value
TIME_TO_WAIT=15 # TODO: Update this value
# Counter for tracking users
COUNT=1
# Iterate over a sequence of users based on the number to split by
# i.e. Perform a pass of 100 users at a time
# To do this we take the number of users and divide by the split count (users/split)
TOTAL_USER_COUNT=$(wc -l ${USERFILE} | awk '{print $1}')
USER_SPLIT_COUNT=$(( ${TOTAL_USER_COUNT}/${NUM_USERS_PER_PASS} ))
for i in $(seq 1 ${USER_SPLIT_COUNT})
do
# Cut the users by N each pass
# We remove 1 each iteration to account for starting points
# i.e. 1 -> 100, 101 -> 200, 201 -> 300, ...
COUNT_UPPER=$(( ${COUNT} + $(( ${NUM_USERS_PER_PASS} - 1 )) ))
sed -n ${COUNT},${COUNT_UPPER}p ${USERFILE} > tmp_users.txt
# Enumerate the N users via tmp_users.txt
python3 o365spray.py --enum --domain "${DOMAIN}" -U tmp_users.txt
# Move the user starting point up N
COUNT=$(( ${COUNT} + ${NUM_USERS_PER_PASS} ))
# Wait N minutes
sleep ${TIME_TO_WAIT}m
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment