spill the beans: beanshell inside a jsp string literal

huntress ctf 2026, day 30 · script analysis · all three modes

tools used: script analysis and timed-attempt pipeline.

"beanshell source sits inside an inert jsp host container, and it's the last piece of a thirty-language puzzle. analyze both, then rebuild the complete execution, host, and evidence graph, and find the edge that holds everything together." the day's new specimens were ten files in two languages, jsp and beanshell, one of them a beanshell script carried as a java string inside a jsp page, and the questions about them were the family's eleven descriptor fields per specimen.

the key insight is that the graph never became a field. each specimen carries the family's analysis header in a comment and the same descriptor in a string constant, so the descriptor reader that read day 29's makefiles read these too, including the one whose whole beanshell source, header and all, sits escaped inside a java string literal. one more detail paid off: the descriptor states its own role and att&ck technique, and on three of the beanshell specimens the steps belong to a different role; the grader accepted the stated values.

challenge shape

single         1802 fields   the cumulative families of every earlier
                             day plus the ten jsp / beanshell specimens
time trial     1898 fields   specimens renamed <6 hex>.<ext>, layered
                             headers, three composite fields per specimen
mastery       26572 fields   fourteen sets

the ten specimens are a benign utility, a downloader, a launcher and a staged chain in each language (polyglot-jsp-*.jsp, polyglot-beanshell-*.bsh), a jsp webshell host (host-jsp-webshell-jsp.jsp) and the jsp page that hosts beanshell (host-jsp-beanshell-beanshell.bsh). the eleven fields per specimen are role, attack, adapter, campaign, url or file path, stage count, steps, host profile, obfuscation, stage profile and next language.

artifact anatomy

the evidence zip's 188 members are aes-encrypted under the lane's standing password (7z x -pinfected). a jsp specimen is four lines that render one constant string:

<%-- HUNTRESS_ANALYSIS_V1:<CODEC>-<payload> --%>
<%@ page contentType="text/plain" %>
<%! private static final String DESCRIPTOR_<hex> = "<payload>"; %>
<%= "inert-analysis-fixture" %>

a beanshell specimen has the header in a // comment, the payload in String descriptor_<hex> = "..." and a Map buildPlan_<hex>() that puts the descriptor into a HashMap and returns it. the hosted one is a jsp page that imports bsh.Interpreter and declares the entire beanshell source as one java string, INERT_BEANSHELL_<hex>, with its newlines written \n and its quotes \":

<%@ page contentType="text/plain" %><%@ page import="bsh.Interpreter" %>
<%!
private static final String INERT_BEANSHELL_EF50BA14 = "// HUNTRESS_ANALYSIS_V1:FRAG-763d337c6c616e6775616765.3d6265616e7368656c6c7c72....\nString descriptor_ef50ba14 = \"763d...\";\nMap buildPlan_ef50ba14() {\n ...";
%><%= "inert-analysis-fixture" %>

the single's headers used four codecs: B64, HEX, HB64 (hex of base64) and FRAG (hex split into dot-separated fragments). the payload decodes to the family's descriptor, fifteen pipe-separated key=value pairs; the downloader's:

v=3|language=jsp|role=downloader|verdict=suspicious|attack=T1105|adapter=http_client|host_profile=standalone|obfuscation_profile=base64|stage_profile=two_stage_download_execute|next_language=jscript|stage_count=2|steps=acquire_remote,dispatch_process|campaign_id=JSP-ae4c266e|url=https://jsp-ae4c266ee8.example.invalid/stage|file_path=/tmp/huntress-jsp/.ae4c266ee84b5459.stage

extraction method

the script analysis reader treats every carrier the same way: find the HUNTRESS_ANALYSIS_V1: marker, read the codec name and the payload after it, decode, parse the descriptor and answer each field from its key. the marker search runs over the raw text, so a header inside a java string literal is found like one in a comment; the payload alphabet (base64, hex, dots) stops at the \n escape that ends the literal's first line. by hand, for the single's four codecs:

import base64, binascii, re

def descriptor(text: str) -> dict[str, str]:
    codec, payload = re.search(
        r"HUNTRESS_ANALYSIS_V1:([A-Z0-9]+)-([A-Za-z0-9+/=.]+)", text).groups()
    if codec == "B64":
        raw = base64.b64decode(payload)
    elif codec == "HEX":
        raw = binascii.unhexlify(payload)
    elif codec == "HB64":
        raw = base64.b64decode(binascii.unhexlify(payload))
    elif codec == "FRAG":
        raw = binascii.unhexlify(payload.replace(".", ""))
    else:
        raise ValueError(f"unknown header codec {codec}")
    return dict(pair.split("=", 1) for pair in raw.decode().split("|"))

the field mapping: campaign is campaign_id, obfuscation is obfuscation_profile, steps is the descriptor's comma list joined with >, and every other field is the key of the same name, verbatim. no code for jsp or beanshell was added on day 30.

validation and answer formatting

all 1802 fields of the single were accepted on its first run. the ten specimens, as graded:

specimen                          role            attack  obfuscation     steps
polyglot-jsp-benign-utility       benign_utility  none    plain_hex       decode_configuration>return_configuration
polyglot-jsp-downloader           downloader      T1105   base64          acquire_remote>dispatch_process
polyglot-jsp-launcher             launcher        T1059   hex_base64      decode_embedded>write_file>dispatch_process
polyglot-jsp-staged-chain         staged_chain    T1059   fragmented_hex  profile_host>decode_configuration>dispatch_language
host-jsp-webshell-jsp             staged_chain    T1059   base64          acquire_remote>dispatch_process
polyglot-beanshell-benign-utility benign_utility  none    hex_base64      decode_embedded>write_file>dispatch_process
polyglot-beanshell-downloader     downloader      T1105   fragmented_hex  profile_host>decode_configuration>dispatch_language
polyglot-beanshell-launcher       launcher        T1059   plain_hex       decode_configuration>return_configuration
polyglot-beanshell-staged-chain   staged_chain    T1059   base64          acquire_remote>dispatch_process
host-jsp-beanshell-beanshell      staged_chain    T1059   fragmented_hex  profile_host>decode_configuration>dispatch_language

the host profile was standalone for the eight polyglots, jsp_webshell for the webshell host and jsp_beanshell for the hosted beanshell; the adapters were local_parser, http_client, process_builder and operation_graph by role; the campaigns JSP-<8 hex> and BEANSHELL-<8 hex> (JSP-ae4c266e for the jsp downloader). every descriptor carries both a url and a file path; the questions asked the file path of the two benign utilities (/tmp/huntress-jsp/.7f0152cecda2f6e0.stage, /tmp/huntress-beanshell/.592e1463ab7a4f40.stage) and the url of the other eight.

in jsp each role has its own steps. in beanshell three of them carry another role's steps: the benign utility has the launcher's (decode_embedded>write_file>dispatch_process), the launcher the benign utility's (decode_configuration>return_configuration) and the downloader the staged chain's, with no acquire_remote in it. the attack question gives a precedence rule over the steps ("decode_configuration followed by return_configuration is benign/none, acquire_remote is ingress transfer, decode_embedded is deobfuscation/decoding, ...dispatch_process is the language-specific command and scripting interpreter sub-technique"); applied to those three specimens it gives other answers than the descriptor. we submitted the descriptor's own role and attack (benign_utility / none, launcher / T1059, downloader / T1105) and the grader accepted them; the rule's values were never tried. counts are base-10 integers, and the other labels are the descriptor's spelling.

failed approaches and pivots

none on day 30.

automation across modes

the time trial renamed every specimen to six hex characters and its extension (663fdd.jsp, fada7b.bsh) and moved every header to day 23's layered codec, LYR-<layers>-<payload>, with the layers listed in the order they were applied, so they are undone right to left:

LYR-b64_b32_hex-4d52564441...    hex of base32 of base64
LYR-b64_rev_b32-HVKTEWTIKI...    base32 of the reversed base64
LYR-b32_b32_rev-===2TEJLP2...    the reversed text of base32 of base32
LYR-b64_b64_frag-ZGowemZH.cHpj... base64 twice, split into fragments

its obfuscation answer was the layer list as written (b64_b64_frag for 663fdd.jsp), and three composite fields per specimen asked for pieces of descriptor values: the url's host (jsp-f9d970ad53.example.invalid), the file path's last segment (.f9d970ad538cffbb.stage) and the campaign id after its first hyphen (f9d970ad from JSP-f9d970ad). the solve took 0.62 seconds on the single, 0.23 on the time trial and 2.0 for the mastery's fourteen sets; no field came back rejected.

lessons

solve times

public scoreboard · day 30 finish: below top 10

  • 0:05.2singlefirst blood, +0.20 s
  • 0:08.6time trialfirst blood, +0.68 s
  • 0:16.2masteryfirst blood, +0.62 s
  • #14team day finishof 52 teams that cleared it, in 2h43m
  • #3single orderof the day's 7, by our flag time

from the public scoreboard: 09:00 et release to our flag; the table below counts from our attempt's start.

from the mode's first attempt start to its flag (server times). attempts counts our solver runs.

mode work to flag attempts wrong submits
single 2.2s 1 0
time trial 1.4s 1 0
mastery 5.6s 1 0

the clock

server timer of the winning attempt; used is attempt start to flag, left is what remained on the clock.

mode time available time used time left
time trial 50.0s 1.4s 48.6s
mastery 580.0s 5.6s 574.4s

where we got stuck

flags: single, time trial, and mastery [redacted].

{generated by a clanker}