mirror of
https://github.com/CyberMind-FR/secubox-deb.git
synced 2026-07-29 18:36:55 +00:00
feat(openclaw): openclawctl scan — run tools in-container, write host-side result JSON
This commit is contained in:
parent
1220e59147
commit
d57b5decf8
|
|
@ -86,6 +86,37 @@ cmd_install() {
|
|||
&& echo "[openclaw] install complete" || { err "toolchain missing after install"; return 1; }
|
||||
}
|
||||
|
||||
# jq is available on the HOST (SecuBox base). Build the record on the host from
|
||||
# captured container stdout; never let the target reach a shell unquoted.
|
||||
_scan_write() { # $1=id $2=json-object-of-record
|
||||
local f="$SCANS_DIR/$1.json"; mkdir -p "$SCANS_DIR"; printf '%s\n' "$2" > "$f"; chmod 640 "$f"
|
||||
}
|
||||
|
||||
cmd_scan() {
|
||||
local type="${1:-}" target="${2:-}" id="${3:-}"
|
||||
_valid_type "$type" || { err "bad type"; return 2; }
|
||||
_valid_target "$target"|| { err "bad target"; return 2; }
|
||||
_valid_scanid "$id" || { err "bad id"; return 2; }
|
||||
lxc_running || { _scan_write "$id" "$(jq -nc --arg i "$id" --arg t "$type" --arg g "$target" '{id:$i,type:$t,target:$g,status:"failed",error:"container not running",results:null}')"; return 1; }
|
||||
local started; started="$(date -u +%FT%TZ)"
|
||||
local raw rc
|
||||
case "$type" in
|
||||
dns) raw="$(lxc_attach 'dig +noall +answer ANY "$1"' "$target" 2>&1)"; rc=$? ;;
|
||||
whois) raw="$(lxc_attach 'whois -- "$1"' "$target" 2>&1)"; rc=$? ;;
|
||||
certs) raw="$(lxc_attach 'curl -s --max-time 20 "https://crt.sh/?q=$1&output=json"' "$target" 2>&1)"; rc=$? ;;
|
||||
ports) raw="$(lxc_attach 'nmap -Pn -T4 --top-ports 100 -oG - "$1"' "$target" 2>&1)"; rc=$? ;;
|
||||
ip) raw="$(lxc_attach 'nmap -Pn -T4 -sV --top-ports 200 "$1"' "$target" 2>&1)"; rc=$? ;;
|
||||
domain) raw="$(lxc_attach 'echo "== DNS =="; dig +noall +answer ANY "$1"; echo "== WHOIS =="; whois -- "$1" 2>/dev/null | head -40; echo "== CERTS =="; curl -s --max-time 20 "https://crt.sh/?q=$1&output=json" | head -c 20000' "$target" 2>&1)"; rc=$? ;;
|
||||
email) raw="$(lxc_attach 'd="${1#*@}"; echo "== MX =="; dig +short MX "$d"; echo "== SPF =="; dig +short TXT "$d" | grep -i spf' "$target" 2>&1)"; rc=$? ;;
|
||||
*) err "unhandled type"; return 2 ;;
|
||||
esac
|
||||
local status="completed"; [ "$rc" -ne 0 ] && status="failed"
|
||||
_scan_write "$id" "$(jq -nc --arg i "$id" --arg t "$type" --arg g "$target" --arg s "$status" \
|
||||
--arg st "$started" --arg fi "$(date -u +%FT%TZ)" --arg raw "$raw" \
|
||||
'{id:$i,type:$t,target:$g,status:$s,started_at:$st,finished_at:$fi,results:{raw:$raw},error:(if $s=="failed" then "tool exit non-zero" else null end)}')"
|
||||
[ "$status" = completed ]
|
||||
}
|
||||
|
||||
usage() { echo "usage: openclawctl {install|start|stop|status [--json]|scan <type> <target> <id>|selftest}" >&2; }
|
||||
|
||||
case "${1:-}" in
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user