
Lord Of Active Directory - AWS에서 취약한 Active Directory 자동 구축

AWS-Redteam-Lab 및 OCD GOAD 기반
한 달 동안 125시간 동안 랩을 실행하는 비용은 약 $14입니다. Free Tier에서는 월 750시간의 EC2를 제공하며, 머신이 6대이므로 125시간입니다. 하지만 스토리지는 30GB만 제공됩니다. 따라서 나머지 5개 VM을 위한 스토리지가 필요합니다: 30GB * 5 = 150GB = 월 14달러
GOAD 프로젝트와 마찬가지로 설치도 두 부분으로 나뉩니다:
지금까지 랩은 Linux 머신에서만 테스트되었지만 macOS에서도 작동할 것입니다. Ansible은 Windows 호스트에서 문제가 있으므로 그것에 대해서는 잘 모르겠습니다.
설정이 제대로 작동하려면 다음을 설치해야 합니다:
Docker 컨테이너에서 프로비저닝을 수행하려면 다음 명령을 실행하여 컨테이너를 준비할 수 있습니다.
sudo docker build -t loadansible .
호스트에서 Ansible을 실행하려면 다음 명령을 실행해야 합니다:
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
.venv에 ansible 및 pywinrm 설치
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
Terraform을 설치하려면 공식 웹사이트의 가이드 hashicorp.com를 따라야 합니다.
Linux에 Terraform을 수동으로 설치하려면:
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
AWS에 액세스 키를 구성하려면 AWS CLI가 필요합니다. 공식 웹사이트의 설치 가이드 docs.aws.amazon.com를 따르세요.
Linux의 경우:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
기본 도메인은 middle-earth.local이며, 서브넷은 10.0.1.0/24입니다. 각 머신에는 1CPU와 1024MB 메모리(t2.micro)만 할당되었습니다. 이러한 성능 설정 중 일부를 변경하려면 terraform/ami-instance.tf 파일을 수정할 수 있습니다.
랩을 실행하려면 다음 명령을 수행하세요:
pwd
/opt/LOAD # place yourself in the LOAD folder (where you cloned the project)
cd terraform # start with AWS configuration
다음 단계는 AWS에서 VM을 구성하는 방법을 보여줍니다:
var.tf.example을 var.tf로 복사하고 값을 변경합니다:
AWS 콘솔에서 terraform 사용자를 생성하고 AWS 키를 받아야 합니다:
terraformAccess key - Programmatic accessAccess key ID 및 Secret access key 복사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
랩을 삭제하려면:
terraform destroy
EC2 인스턴스가 시작될 때마다 ansible/hosts 파일에서 공용 IP를 변경해야 합니다. 이 명령의 출력을 파일 끝에 추가하세요:
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))"]"};'
VM을 구성하려면 ansible-playbook 명령을 사용하세요. 일반적인 실행 시간: 1시간 30분
ansible-playbook main.yml # this will configure the vms in order to play ansible when the vms are ready
Docker 컨테이너에서 프로비저닝을 실행하려면 다음을 실행하세요(Dockerfile과 같은 폴더에 있어야 합니다. 아직 테스트되지 않음):
sudo docker run -ti --rm --network host -h loadansible -v $(pwd):/load -w /load/ansible loadansible ansible-playbook main.yml
설치 중에 오류가 발생할 수 있습니다. 대부분의 경우 플레이북을 다시 실행하면 작동합니다.
플레이북을 하나씩 실행하려면:
# 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
플레이북의 특정 부분만 실행하려면 태그를 사용할 수 있습니다(항상 data를 태그로 넣으세요):
ansible-playbook servers.yml
ansible-playbook servers.yml --tags data,iis
ansible-playbook linux.yml --tags data,glpi
AWS 랩을 관리하는 데 도움이 되는 몇 가지 명령(지저분하지만 작동합니다):
# 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))"]"};'
선택적으로 Linux 호스트에 VPN 서버를 추가하고 원하는 만큼 많은 클라이언트를 구성할 수 있습니다.
VPN 서버용 키를 생성하고 클라이언트 수를 변경하는 것부터 시작합니다:
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.
다음 명령으로 VPN 플레이북을 실행합니다(명령을 실행할 때마다 클라이언트 키가 변경됩니다):
ansible-playbook --ask-vault-password vpn.yml
Timeout (12s) waiting for privilege escalation prompt 오류가 발생하면 명령을 다시 실행하세요.
클라이언트 구성 파일은 ansible/wireguard/lab_client[0-9].conf에서 찾을 수 있습니다.
VPN에 연결하려면 개인 키가 포함된 클라이언트 파일을 로컬 호스트의 /etc/wireguard/에 복사해야 합니다.
첫 번째 클라이언트의 VPN 연결은 다음과 같이 시작합니다:
sudo wg-quick up lab_client1
10.0.20.0/24 대역의 IP를 받게 됩니다.

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: