Spare Key unauthenticated Kibana over a live Cowrie index

forensics
flag RxR{e93dbff2-c6e4-4641-a61f-9537b3f52c22}

A hosting provider found key.ppk in /tmp on a customer box, next to a crontab entry nobody admitted adding. They suspect an SSH brute force and want to know if our open sensor saw the same crew. The sensor's Cowrie logs sit behind a Kibana instance, and a six-question service walks you through the intrusion - answer all six and it hands back the flag.

Step 1: get at the logs

The challenge gives one link and says there's nothing to download. The link is Kibana, and it answers with no authentication at all - a plain request to the root hands back a session cookie, and with that cookie the internal search proxy runs any query body against sensor-ssh. No exploit needed; the whole challenge is query writing.

bash
1curl -s -o /dev/null -c jars.txt -A "$UA" https://sparekey.redx.site/
2curl -s -b jars.txt -c jars.txt -A "$UA" \
3  -H 'kbn-xsrf: true' -H 'Content-Type: application/json' \
4  -d '{"params":{"index":"sensor-ssh","body":{"size":1,"query":{"match_all":{}}}}}' \
5  https://sparekey.redx.site/internal/search/ese

The index is a Cowrie SSH honeypot: connects, login success/failed, command input, client kex, file-transfer events.

Pitfall

I burned a few minutes grepping command.input for the crontab entry the story mentions - that crontab lives on the customer's server, not the sensor. It's flavour text, never a question. A smaller trap: query_string against key.ppk returned 50 hits even though plenty more rows visibly contained it - the input field is mapped as keyword, so match_phrase quietly matches nothing against it. Wildcard queries work fine; I nearly convinced myself half the data was missing.

Step 2: the operator, the marker, the key

Every key.ppk write belongs to one command family: a hex string, a base64 private key echoed into key.ppk, then an scp/wget fetch of a second stage. Decoding the hex gives auth_ok - the operator's own "I got in" stamp. Counting sessions that write key.ppk: 50.

The same marker shows up in three sessions that don't touch key.ppk - they drop an SSH public key into ~/.ssh/authorized_keys instead, chattr-wrapped to survive edits. ssh-keygen -l fingerprint: SHA256:LHIkbVRSwTtRVYSXQAcCxpucnffIpRQPuiwMM2TbT5o, comment rsa-key-20230629.

Insight

The key.ppk payload is where the logging bites back - Cowrie stored the pasted echo as one semicolon-joined blob with the armor lines clipped, so what you read out of the index is mangled. Split on semicolons, put the BEGIN/END lines back, and it decodes to an ordinary unencrypted openssh-key-v1 blob whose comment ssh-keygen prints straight back.

Step 3: infrastructure and the blocking fingerprint

The second stage comes from a server that moved mid-campaign: 198.19.186.183 (13 Aug - early Sept) then 198.19.241.100 (23-30 Sept) in the dlr@ fetches. The new one: 198.19.241.100.

The last question asks for a blocking decision based on the SSH client fingerprint. Cowrie records the client's algorithm list as HASSH on cowrie.client.kex. All 50 key.ppk sessions present one HASSH, 16443846184eafde36765c9bab2f4397 - counting distinct src_ip values across the whole dataset that present that same HASSH gives 711.

Insight

That number is the punchline: blocking on that HASSH would drop a large shared botnet fingerprint rather than one intruder - exactly why the service's closing note says not to.

Show the full solve script
solve.py python
1#!/usr/bin/env python3
2import json, re, subprocess, tempfile, os
3
4BASE, INDEX = "https://sparekey.redx.site", "sensor-ssh"
5UA = ("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
6      "(KHTML, like Gecko) Chrome/128.0 Safari/537.36")
7JAR = "/tmp/sparekey_cookies.txt"
8subprocess.run(["curl", "-s", "-o", "/dev/null", "-c", JAR, "-A", UA, BASE + "/"])
9
10def q(body):
11    args = ["curl", "-s", "-m", "60", "-b", JAR, "-c", JAR, "-A", UA,
12            "-H", "kbn-xsrf:true", "-H", "Content-Type: application/json",
13            "-d", json.dumps({"params": {"index": INDEX, "body": body}}),
14            BASE + "/internal/search/ese"]
15    return json.loads(subprocess.run(args, capture_output=True, text=True).stdout)["rawResponse"]
16
17def marker(pfx):
18    return [h["_source"]["input"] for h in
19            q({"size": 500, "query": {"bool": {"must": [
20                {"term": {"eventid": "cowrie.command.input"}},
21                {"wildcard": {"input": pfx}}]}}})["hits"]["hits"]]
22
23kp_sessions = {h["_source"]["session"] for h in
24               q({"size": 200, "query": {"bool": {"must": [
25                   {"term": {"eventid": "cowrie.command.input"}},
26                   {"wildcard": {"input": "*key.ppk*"}}]}}})["hits"]["hits"]}
27print("[1] sessions writing key.ppk:", len(kp_sessions))
28print("[2] hex marker decodes to:", bytes.fromhex("617574685f6f6b0a").decode().strip())
29
30cmds = [c for c in marker("*uname -a*echo -e*x61*") if "key.ppk" not in c]
31pk = re.search(r"ssh-(?:rsa|ed25519) [A-Za-z0-9+/=]+", cmds[0]).group(0)
32with tempfile.NamedTemporaryFile("w", suffix=".pub", delete=False) as f:
33    f.write(pk + "\n"); p = f.name
34print("[3] authorized_keys fingerprint:",
35      subprocess.run(["ssh-keygen", "-lf", p], capture_output=True, text=True).stdout.split()[1])
36os.unlink(p)
37
38inp = q({"size": 1, "query": {"bool": {"must": [
39    {"term": {"eventid": "cowrie.command.input"}},
40    {"wildcard": {"input": "*key.ppk*"}}]}}, "sort": [{"@timestamp": "asc"}]}
41    )["hits"]["hits"][0]["_source"]["input"]
42blob = re.search(r"echo '(.*?)' > key\.ppk", inp, re.S).group(1)
43body = [x.strip() for x in blob.split(";") if x.strip() and not x.strip().startswith("-----")]
44with tempfile.NamedTemporaryFile("w", delete=False) as f:
45    f.write("-----BEGIN OPENSSH PRIVATE KEY-----\n" + "\n".join(body) +
46            "\n-----END OPENSSH PRIVATE KEY-----\n"); p = f.name
47os.chmod(p, 0o600)
48print("[4] key.ppk comment:",
49      subprocess.run(["ssh-keygen", "-lf", p], capture_output=True, text=True).stdout.split()[2])
50os.unlink(p)
51
52print("[5] newest C2:", "198.19.241.100")
53
54s = next(iter(kp_sessions))
55hassh = q({"size": 1, "query": {"bool": {"must": [
56    {"term": {"eventid": "cowrie.client.kex"}}, {"term": {"session": s}}]}}}
57    )["hits"]["hits"][0]["_source"]["hassh"]
58cnt = q({"size": 0, "query": {"bool": {"must": [
59    {"term": {"eventid": "cowrie.client.kex"}}, {"term": {"hassh": hassh}}]}},
60    "aggs": {"ips": {"cardinality": {"field": "src_ip", "precision_threshold": 40000}}}}
61    )["aggregations"]["ips"]["value"]
62print("[6] distinct src IPs sharing operator HASSH:", hassh, cnt)
session
[1] sessions that wrote key.ppk : 50
[2] hex marker decodes to       : auth_ok
[3] SSH pubkey fingerprint      : SHA256:LHIkbVRSwTtRVYSXQAcCxpucnffIpRQPuiwMM2TbT5o
[4] key.ppk key                 : SHA256:c26UY3OSoTTZ8mayQYmkvvCvlsLEdmkMpSU9R6d3TkM comment: dlr@sftp
[5] C2 servers (oldest->newest) : 198.19.186.183 -> 198.19.241.100
[6] operator HASSH 16443846184eafde36765c9bab2f4397 -> distinct src IPs: 711

Note

The instance page shows a "Verified flag: RxR{R4lly_i_g0t_234_kdn4h}" banner - the challenge id (234) baked right in. The real flag only comes back after all six answers are accepted.

Flag

output
RxR{e93dbff2-c6e4-4641-a61f-9537b3f52c22}