[HTB] Included

nzero·2024년 3월 14일
0

Wargame

목록 보기
3/3

Port Scan

웹 서비스 구동 중

Web

file 파라미터에 home.php가 들어가는걸 보고 LFI로 접근



/etc/passwd 확인 가능. mike, tftp 계정이 눈에 띈다.



tftp는 사용자 인증 없이 파일을 전송하는 UDP 프로토콜이며, 기본 설정 포트는 69. UDP 포트를 스캔해보니 69 포트가 열려있다.



리버스 쉘을 작성한 파일을 tftp를 통해 박스에 올리고, 쉘에 설정해 둔 포트를 열어둔다.



웹 계정 쉘 탈취 성공



User Flag

웹 계정의 홈에서 파일 탐색. /var/www/html 아래에서 .htaccess.htpasswd 확인. .htpasswd 파일에 mike 계정 정보가 기록되어 있다.



획득한 정보로 mike 계정으로 접속해 user flag 획득 가능



Root Flag

mike의 id를 확인해보면 lxd 그룹에 속해있다. lxd는 리눅스의 컨테이너 환경 전용 하이버파이저이며, 즉 mike는 컨테이너를 관리할 수 있는 계정이다.

Lxd에 관련 된 exploit은 이 페이지를 참고했으며, 아래와 같이 친절하게 요약해 둔 내용이 있다.

  1. Steps to be performed on the attacker machine:
  • Download build-alpine in your local machine through the git repository.
  • Execute the script “build -alpine” that will build the latest Alpine image as a compressed file, this step must be executed by the root user.
  • Transfer the tar file to the host machine
  1. Steps to be performed on the host machine:
  • Download the alpine image
  • Import image for lxd
  • Initialize the image inside a new container.
  • Mount the container inside the /root directory



위의 과정을 따라, 로컬에서 alpine 이미지를 빌드하고 박스에 올리기 위해 python으로 서버를 연다.

git clone  https://github.com/saghul/lxd-alpine-builder.git
cd lxd-alpine-builder
sudo ./build-alpine



박스 내에서 빌드한 이미지를 다운로드한 후 임포트 한다.



컨테이너가 루트 파일 시스템에 모든 권한을 갖도록 security.privileged=true로 설정하여 생성한다. / 경로를 컨테이너의 /mnt/root에 마운트한 후 sh 쉘로 접속한다.

lxc init myimage ignite -c security.privileged=true
lxc config device add ignite mydevice disk source=/ path=/mnt/root recursive=true
lxc start ignite
lxc exec ignite /bin/sh
~# id



마운트했던 /mnt/root/ 하위 경로로 찾아가면 root flag 획득 가능

0개의 댓글