Skip to content

Instantly share code, notes, and snippets.

@dadevel
Last active January 27, 2023 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadevel/e4c57757a8865b2a91bbb1eac42306b2 to your computer and use it in GitHub Desktop.
Save dadevel/e4c57757a8865b2a91bbb1eac42306b2 to your computer and use it in GitHub Desktop.
AD Trust Discovery with franc-pentest/ldeep#27
#!/usr/bin/env bash
set -euo pipefail
# usage: ldeep-trust-discover child.corp.com -u user -p passw0rd
discover() {
if [[ ! -e "./trust-$1.json" ]]; then
echo "discovering $1" >&2
ldeep ldap -s ldaps://"$1" "${@:2}" trusts -v > "./trust-$1.json" 2> /dev/null || \
ldeep ldap -s ldap://"$1" "${@:2}" trusts -v > "./trust-$1.json" 2> /dev/null || {
echo "error: failed to query $1"
return 1
}
jq -r '.[].trustPartner' "./trust-$1.json" | while read -r partner; do
discover "${partner}" "${@:2}"
done
fi
declare domain
for path in ./trust-*.json; do
domain="${path#./trust-}"
domain="${domain%.json}"
jq -r --arg domain "${domain}" '.[]|[$domain,.trustPartner,.trustDirection,.trustAttributes,.trustType]|@tsv' "${path}"
done
}
discover "$1" -d "$1" "${@:2}" | sort -Vu | cat <(echo -e 'source\tdestination\tdirection\tattributes\ttype') - | column -ts $'\t'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment