
Lord Of Active Directory - Active Directory vulnerable automático en AWS

Basado en AWS-Redteam-Lab y OCD GOAD
El precio de ejecutar el laboratorio durante 125 horas durante un mes es de aproximadamente 14$. Con Free Tier obtienes 750h de EC2 al mes, hay 6 máquinas, así que 125h. Pero solo obtienes 30Gb de almacenamiento. Así que necesitas almacenamiento para las otras 5 VMs : 30Gb * 5 = 150Gb = 14$ / mes
Al igual que el proyecto GOAD, la instalación consta de dos partes :
Hasta ahora el laboratorio solo se ha probado en una máquina Linux, pero debería funcionar también en macOS. Ansible tiene algunos problemas con hosts Windows, así que no lo sé.
Para que la configuración funcione correctamente debes instalar:
Si quieres hacer el aprovisionamiento desde un contenedor Docker, puedes ejecutar el siguiente comando para preparar el contenedor:
sudo docker build -t loadansible .
Si quieres ejecutar Ansible desde tu host, debes lanzar los siguientes comandos:
sudo apt install git
git clone [email protected]:0xBallpoint/LOAD.git
cd LOAD/ansible
sudo apt install python3.8-venv
python3.8 -m virtualenv .venv
source .venv/bin/activate
ansible y pywinrm en el .venv
python3 -m pip install --upgrade pip
python3 -m pip install ansible-core==2.12.6
python3 -m pip install pywinrm
ansible-galaxy install -r requirements.yml
Debes instalar Terraform siguiendo su guía en su sitio web hashicorp.com
Si quieres instalar Terraform manualmente en Linux:
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
# Install the HasiCorp GPG key
wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
# Verify the key's fingerprint
gpg --no-default-keyring \
--keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
--fingerprint
# It must match E8A0 32E0 94D8 EB4E A189 D270 DA41 8C88 A321 9F7B (from https://www.hashicorp.com/security)
# Add the official HashiCorp repository to your system
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list
# Update, install, verify
sudo apt update
sudo apt install terraform
terraform -help
Necesitarás la AWS CLI para configurar tus claves de acceso a AWS. Deberías seguir la guía de instalación en su sitio web docs.aws.amazon.com
Para Linux:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
El dominio por defecto será middle-earth.local, en la subred 10.0.1.0/24 y cada máquina ha sido asignada solo con 1CPU y 1024MB de memoria (t2.micro). Si quieres cambiar algunos de estos ajustes de rendimiento puedes modificar el archivo : terraform/ami-instance.tf
Para tener el laboratorio en funcionamiento, estos son los comandos que debes ejecutar:
pwd
/opt/LOAD # place yourself in the LOAD folder (where you cloned the project)
cd terraform # start with AWS configuration
Los siguientes pasos te muestran cómo configurar tus VMs en AWS:
Copia var.tf.example a var.tf y cambia los valores :
En tu consola de AWS, debes crear un usuario terraform y obtener tus claves de AWS:
terraformAccess key - Programmatic accessAccess key ID y Secret access keyAñade las claves en tu máquina con la AWS CLI:
aws configure --profile terraform
AWS Access Key ID [None]: <access_key_id>
AWS Secret Access Key [None]: <secret_access_key>
cd LOAD
ssh-keygen -t rsa -N "" -b 2048 -C "TerraformKey" -f ./terraform/keys/TerraformKey.pem
terraform init
terraform apply
Si quieres destruir tu laboratorio :
terraform destroy
Cada vez que tus instancias EC2 se inicien, tienes que cambiar su IP pública en el archivo ansible/hosts. Añade la salida de este comando al final del archivo :
aws ec2 describe-instances --profile terraform --region eu-central-1 --query "Reservations[*].Instances[*].{Name:Tags[?Key=='Name'].Value|[],PublicIP:PublicIpAddress}" --filters "Name=instance-state-name,Values=running" --output text |tac |awk 'NR%2 ==0 {print $0}; NR%2 != 0 {print "["tolower(substr($2,5))"]"};'
Para configurar las VMs usa el comando ansible-playbook. Tiempo habitual de ejecución : 1h30
ansible-playbook main.yml # this will configure the vms in order to play ansible when the vms are ready
Para ejecutar el aprovisionamiento desde el contenedor Docker, ejecuta (debes estar en la misma carpeta que el Dockerfile. Aún no probado):
sudo docker run -ti --rm --network host -h loadansible -v $(pwd):/load -w /load/ansible loadansible ansible-playbook main.yml
A veces puede ocurrir un error durante la instalación. La mayoría de las veces, puedes simplemente volver a ejecutar el playbook y debería funcionar. Para ejecutar los playbooks uno por uno:
# The main.yml playbook is build in multiples parts. each parts can be re-run independently but the play order must be keep in cas you want to play one by one :
ansible-playbook prepare.yml # updates, passwords, dns settings...
ansible-playbook ad-servers.yml # create servers configuration
ansible-playbook ad-trusts.yml # create the trust relationships
ansible-playbook ad-data.yml # import the ad datas : users/groups...
ansible-playbook ad-groups.yml # set the rights and the group domains relations
ansible-playbook servers.yml # create IIS and MSSQL
ansible-playbook adcs.yml # add adcs and adcs templates
ansible-playbook ad-acl.yml # set ACL
ansible-playbook linux.yml # configure linux entrypoint with GLPI
ansible-playbook security.yml # enable or disable windows defender here
ansible-playbook vulnerabilities.yml # specifics vulns linked to the scenario are here
# You can also install wireguard VPN on the linux host, for that check the VPN paragraph
Si quieres ejecutar solo una parte específica de un playbook, puedes usar tags (pon siempre data como tag):
ansible-playbook servers.yml
ansible-playbook servers.yml --tags data,iis
ansible-playbook linux.yml --tags data,glpi
Algunos comandos para ayudarte a gestionar tu laboratorio AWS (es feo pero funciona):
# aws cli profile : terraform
# region : eu-central-1
# Disable instance metadata
for i in $(aws ec2 --profile terraform --region eu-central-1 describe-instances --filters "Name=tag:Name,Values=lab-*" --query 'Reservations[].Instances[].InstanceId' |cut -d '"' -f2); do aws ec2 --profile terraform --region eu-central-1 modify-instance-metadata-options --http-endpoint disabled --instance-id $i --output json --no-cli-pager;done
# Start instances
aws ec2 --profile terraform --region eu-central-1 start-instances --instance-ids `aws ec2 --profile terraform --region eu-central-1 describe-instances --filters "Name=tag:Name,Values=lab-*" "Name=instance-state-name,Values=stopping,stopped" --query 'Reservations[].Instances[].InstanceId' --output text`
# Get running instance and output it to ansible format
aws ec2 describe-instances --profile terraform --region eu-central-1 --query "Reservations[*].Instances[*].{Name:Tags[?Key=='Name'].Value|[],PublicIP:PublicIpAddress}" --filters "Name=instance-state-name,Values=running" --output text |tac |awk 'NR%2 ==0 {print $0}; NR%2 != 0 {print "["tolower(substr($2,5))"]"};'
Opcionalmente, puedes añadir un servidor VPN en el host Linux y configurar tantos clientes como quieras. Empieza generando las claves para el servidor VPN y cambia el número de clientes:
apt install wireguard
# generate wireguard keys
privkey=$(wg genkey) sh -c 'echo "
server_privkey: $privkey
server_pubkey: $(echo $privkey | wg pubkey)"'
# encrypt server_privkey with ansible-vault and
ansible-vault encrypt_string --ask-vault-password --stdin-name server_privkey
# Add the result to group_vars/all.yml
# You can change the number of client configuration files it will create. By default it creates 6 clients.
Ejecuta el playbook de la VPN con este comando (cambiará las claves de los clientes cada vez que ejecutes el comando):
ansible-playbook --ask-vault-password vpn.yml
Si obtienes este error Timeout (12s) waiting for privilege escalation prompt, simplemente vuelve a ejecutar el comando.
Encontrarás tu archivo de configuración de cliente en ansible/wireguard/lab_client[0-9].conf.
Para conectarte a la VPN, necesitas copiar los archivos de cliente con la clave privada a tu host local en /etc/wireguard/.
Inicias la conexión VPN para el primer cliente con:
sudo wg-quick up lab_client1
Obtendrás una IP en 10.0.20.0/24

SHIRE (srv02)
- GLPI SQLi
- GLPI-htmlawed-CVE-2022-35914
USERS
- privesc user with vulnerable crontab
- privesc root with password in bash_history and sudo nopasswd for /bin/systemctl
RIVENDELL (dc02)
- anonymous RPC (enum users, pass pol, groups / rpcclient)
- brute force users names
ELF
- celebrian Responder crack hash (bot 3min)
- elrond: Responder with NTLM relay domain admin (bot 5min)
HOBBIT
- bilbo: password in description
- pippin: ASREPROAST
- merry: Constrained delegation with protocol transition / Kerberoasting
- froddo:
- sam:
MINAS-TIRITH(dc01)
- Open share RW, LNK exploit
- khamul.easterling : Open backup share, with GPO with cpassword, password increment
MORIA (srv01)
- MSSQL trusted link : donPapi to get sql_svc password
- mitm6 SRV01 -> DC01
MEN
- denethor: DOMAIN ADMIN
- theoden: ACL self-self-membership-on-group DOMAIN ADMIN
- faramir: ACL genericwrite-on-user Denethor
- boromir: ACL genericall-on-user Denethor
ACL forcechangepassword on Faramir
WriteDACL MEN
FELLOWSHIP
- legolas: execute as user on MSSQL
KERBEROASTING
- gimli: ACL genericall-on-computer MORIA
ACL writeproperty-self-membership DOMAIN ADMIN
- aragorn: execute as login on mssql / administrator
- gandalf: mssql admin
group cross domain
mssql trusted link
ACL writeproperty-self-membership Domain Admins #TODO change for someone who is not administrator, he has DCSYNC (administrator?)
ENTS
- treebeard: ACL writeproperty-on-group DOMAIN ADMIN
- skinbark: ACL genericall-on-group DOMAIN ADMIN
- ginglas: ACL write owner on group DOMAIN ADMIN
BARAD-DUR (dc03)
- Coerced DC + ntlmrelayx to ldaps
- ADCS ESC1, ESC2, ESC3, ESC4, ESC8
- NTLM downgrade attack
MINAS-MORGL (srv03)
- IIS upload webshell
- Privilege escalation Windows 2016 : SeImpersontePrivilege
DARKFORCE
- sauron: domain admin MORDOR
- saruman: mssql admin / GenericAll on gothmog (shadow credentials) / GenericAll on ECS4
- balrog:
PRISONER
- gollum: mssql trusted link
password spray -> user=pwd
ORC
- gothmog: DOMAIN ADMIN
- lurtz:
- ugluk:
- guritz:
NAZGUL
- angmar: