Detection: Java Base64 Exception With Process or File Activity

Description

The analytic finds Base64-related Java argument exceptions near a process spawned by Java or a file created by Java on the same host and JVM PID.

  1(
  2    `java_hotspot_exceptions`
  3    (
  4        "*Input byte array has wrong*"
  5        OR
  6        "*IllegalArgumentException*"
  7        OR
  8        "*Base64$Decoder*"
  9        OR
 10        "*java/util/Base64*"
 11    )
 12)
 13OR
 14(
 15    `sysmon_linux`
 16    (
 17        (EventID=1 ParentImage="*/java")
 18        OR
 19        (
 20            EventID=11
 21            Image="*/java"
 22            NOT TargetFilename IN ("*/_state/*","*/indices/*")
 23        )
 24    )
 25)
 26
 27| rex field=_raw "^\[(?<jvm_event_time_raw>[^\]]+)\]\[(?<jvm_pid_raw>\d+)\]\[(?<jvm_level_raw>[^\]]+)\]\[(?<jvm_tags_raw>[^\]]+)\]\s*(?<jvm_message_raw>.*)"
 28
 29
 30| eval event_time=_time,
 31       jvm_message=coalesce(jvm_message_raw,jvm_message),
 32       observed_host=coalesce(host,Computer,dest),
 33       process_id=case(
 34            isnotnull(jvm_pid_raw),tostring(jvm_pid_raw),
 35            isnotnull(jvm_pid),tostring(jvm_pid),
 36            EventID==1,tostring(ParentProcessId),
 37            EventID==11,tostring(ProcessId)
 38        )
 39
 40| where isnotnull(observed_host) AND isnotnull(process_id)
 41
 42
 43| rex mode=sed field=jvm_message "s/0x[0-9A-Fa-f]{8,16}/0xXXXXXXXXXXXXXXXX/g"
 44
 45| rex mode=sed field=jvm_message "s/\s+bci\s+\d+\s+/ bci XXX /g"
 46
 47| rex mode=sed field=jvm_message "s/^\d+\s+/XXXX /g"
 48
 49
 50| eval has_argument=if(match(jvm_message,"(?i)Input byte array has wrong
 51|IllegalArgumentException"),1,0),
 52       has_decoder=if(match(jvm_message,"Base64[$]Decoder
 53|java/util/Base64
 54|Input byte array has wrong 4-byte ending unit"),1,0),
 55       has_activity=if(EventID==1 OR EventID==11,1,0)
 56
 57
 58| eval activity=case(
 59      EventID==1,"Java spawned a process",
 60      EventID==11,"Java created a file"
 61  ),
 62  process_name=if(EventID==1,Image,null()),
 63  process=if(EventID==1,CommandLine,null()),
 64  file_path=if(EventID==11,TargetFilename,null()),
 65  file_name=if(EventID==11,mvindex(split(TargetFilename,"/"),-1),null())
 66
 67
 68| bin _time span=1m
 69
 70
 71| stats count
 72        min(event_time) AS firstTime
 73        max(event_time) AS lastTime
 74        max(has_argument) AS has_argument
 75        max(has_decoder) AS has_decoder
 76        max(has_activity) AS has_activity
 77        values(sourcetype) AS sourcetype
 78        dc(sourcetype) AS dc_sourcetype
 79        values(activity) AS activity
 80        values(jvm_message) AS jvm_message
 81        values(process_name) AS process_name
 82        values(process) AS process
 83        values(file_name) AS file_name
 84        values(file_path) AS file_path
 85        BY _time observed_host process_id
 86
 87
 88| where has_argument==1 AND has_decoder==1 AND has_activity==1
 89
 90
 91| rename observed_host AS dest
 92
 93
 94| eval reason="Java Base64 exception observed with ".mvjoin(activity," and ")
 95
 96
 97| fields - has_argument has_decoder has_activity activity
 98
 99
100| `security_content_ctime(firstTime)`
101
102| `security_content_ctime(lastTime)`
103
104| `java_base64_exception_with_process_or_file_activity_filter`

Data Source

Name Platform Sourcetype Source
Sysmon for Linux EventID 11 Linux icon Linux 'sysmon:linux' 'Syslog:Linux-Sysmon/Operational'
Java HotSpot Exceptions Other 'java:hotspot:exceptions' 'exceptions-*.log'
Sysmon for Linux EventID 1 Linux icon Linux 'sysmon:linux' 'Syslog:Linux-Sysmon/Operational'

Macros Used

Name Value
sysmon_linux (sourcetype="sysmon:linux" OR source=Syslog:Linux-Sysmon/Operational)
java_base64_exception_with_process_or_file_activity_filter search *
java_base64_exception_with_process_or_file_activity_filter is an empty macro by default. It allows the user to filter out any results (false positives) without editing the SPL.

Annotations

CVE

Default Configuration

This detection is configured by default in Splunk Enterprise Security to run with the following settings:

Setting Value
Disabled true
Cron Schedule 0 * * * *
Earliest Time -70m@m
Latest Time -10m@m
Schedule Window auto
Creates Finding (Notable) No
Creates Intermediate Finding (Risk Event) Yes
Anomaly detections generate Intermediate Findings (Risk Events). They do not generate a Finding (Notable) directly.

Implementation

Configure java_hotspot_exceptions and sysmon_linux for the indexes and sourcetypes in your environment. HotSpot exception diagnostics have no default file location. Tomcat's CATALINA_BASE/logs, Spring Boot's default console output, and Elasticsearch's application log directory do not supply this JVM stream. Add -Xlog:exceptions=debug:file=/var/log/myapp/exceptions-%p.log:utctime,pid,level,tags:filecount=8,filesize=16m to the Java startup options, using a writable path. Set it through Tomcat CATALINA_OPTS or Windows service Java options, the Spring Boot Java service/container command, or Elasticsearch jvm.options.d. Forward the chosen file and rotations as java:hotspot:exceptions. Configure single-line event breaking and utctime parsing on the Splunk parsing tier. Search-time extraction in props.conf is optional: use EXTRACT-jvm_unified or a shared REPORT transform for reusable jvm_pid and jvm_message fields, or let this search extract them from decorated _raw lines with rex. The search coalesces raw and pre-extracted values before joining to Sysmon. The Java HotSpot Exceptions data source provides the optional extraction pattern. The exact HotSpot message Input byte array has wrong 4-byte ending unit is treated as Base64 decoder evidence because decoder references on separate continuation lines may lack the PID decorator and cannot be joined reliably with single-line event breaking. Install Sysmon for Linux and ingest EventID 1 and 11 with ParentImage, ParentProcessId, Image, ProcessId, TargetFilename, and CommandLine. Normalize the host field so JVM and Sysmon events from the same machine use the same value. The search joins a process creation on ParentProcessId and a file creation on ProcessId; both must identify the Java PID. Verify that exception log volume and rotation are acceptable before deploying this correlation.

Known False Positives

Java applications may decode malformed inputs while independently creating files or child processes. One-minute bins can also miss events at a minute boundary or associate unrelated activity on a busy JVM. Review the process command line, file path, and nearby request logs.

Associated Analytic Story

Intermediate Findings

Message Entity Field Entity Type Risk Score
Java Base64 argument exceptions and process or file activity observed on $dest$ in PID $process_id$. dest system 30

References

Detection Testing

Test Type Status Dataset Source Sourcetype
Validation ✅ Passing N/A N/A N/A
Unit ✅ Passing Dataset exceptions.log java:hotspot:exceptions
Integration ✅ Passing Dataset exceptions.log java:hotspot:exceptions

Replay any dataset to Splunk Enterprise by using our replay.py tool or the UI. Alternatively you can replay a dataset into a Splunk Attack Range


Source: GitHub |

Version: 1