mirror of
https://github.com/mblanke/StrikePackageGPT.git
synced 2026-03-01 14:20:21 -05:00
Add bidirectional command capture - CLI commands now visible in dashboard
Co-authored-by: mblanke <9078342+mblanke@users.noreply.github.com>
This commit is contained in:
@@ -10,18 +10,30 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install additional Python tools
|
||||
# Install additional Python tools and utilities for command logging
|
||||
RUN pip3 install --break-system-packages \
|
||||
requests \
|
||||
beautifulsoup4 \
|
||||
shodan \
|
||||
censys
|
||||
|
||||
# Install jq and uuid-runtime for command logging
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
jq \
|
||||
uuid-runtime \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create workspace directory
|
||||
WORKDIR /workspace
|
||||
|
||||
# Copy entrypoint script
|
||||
# Copy scripts
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
COPY command_logger.sh /usr/local/bin/command_logger.sh
|
||||
COPY capture_wrapper.sh /usr/local/bin/capture
|
||||
RUN chmod +x /entrypoint.sh /usr/local/bin/command_logger.sh /usr/local/bin/capture
|
||||
|
||||
# Create command history directory
|
||||
RUN mkdir -p /workspace/.command_history
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
76
services/kali/capture_wrapper.sh
Normal file
76
services/kali/capture_wrapper.sh
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
# Output Capture Wrapper for Security Tools
|
||||
# Wraps command execution to capture stdout/stderr and save results
|
||||
|
||||
COMMAND_LOG_DIR="${COMMAND_LOG_DIR:-/workspace/.command_history}"
|
||||
mkdir -p "$COMMAND_LOG_DIR"
|
||||
|
||||
# Get command from arguments
|
||||
cmd_string="$@"
|
||||
[[ -z "$cmd_string" ]] && exit 1
|
||||
|
||||
# Generate unique ID
|
||||
cmd_id=$(uuidgen 2>/dev/null || echo "$(date +%s)-$$")
|
||||
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
output_file="$COMMAND_LOG_DIR/${cmd_id}.json"
|
||||
stdout_file="$COMMAND_LOG_DIR/${cmd_id}.stdout"
|
||||
stderr_file="$COMMAND_LOG_DIR/${cmd_id}.stderr"
|
||||
|
||||
# Create initial log entry
|
||||
cat > "$output_file" << EOF
|
||||
{
|
||||
"command_id": "$cmd_id",
|
||||
"command": $(echo "$cmd_string" | jq -Rs .),
|
||||
"timestamp": "$timestamp",
|
||||
"user": "$(whoami)",
|
||||
"working_dir": "$(pwd)",
|
||||
"source": "capture_wrapper",
|
||||
"status": "running"
|
||||
}
|
||||
EOF
|
||||
|
||||
# Execute command and capture output
|
||||
start_time=$(date +%s)
|
||||
set +e
|
||||
eval "$cmd_string" > "$stdout_file" 2> "$stderr_file"
|
||||
exit_code=$?
|
||||
set -e
|
||||
end_time=$(date +%s)
|
||||
duration=$((end_time - start_time))
|
||||
completed_at=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
# Read captured output
|
||||
stdout_content=$(cat "$stdout_file" 2>/dev/null || echo "")
|
||||
stderr_content=$(cat "$stderr_file" 2>/dev/null || echo "")
|
||||
|
||||
# Update log entry with results
|
||||
cat > "$output_file" << EOF
|
||||
{
|
||||
"command_id": "$cmd_id",
|
||||
"command": $(echo "$cmd_string" | jq -Rs .),
|
||||
"timestamp": "$timestamp",
|
||||
"completed_at": "$completed_at",
|
||||
"user": "$(whoami)",
|
||||
"working_dir": "$(pwd)",
|
||||
"source": "capture_wrapper",
|
||||
"status": "$([ $exit_code -eq 0 ] && echo 'completed' || echo 'failed')",
|
||||
"exit_code": $exit_code,
|
||||
"duration": $duration,
|
||||
"stdout": $(echo "$stdout_content" | jq -Rs .),
|
||||
"stderr": $(echo "$stderr_content" | jq -Rs .)
|
||||
}
|
||||
EOF
|
||||
|
||||
# Clean up temp files
|
||||
rm -f "$stdout_file" "$stderr_file"
|
||||
|
||||
# Output results to terminal
|
||||
cat "$stdout_file" 2>/dev/null || true
|
||||
cat "$stderr_file" >&2 2>/dev/null || true
|
||||
|
||||
echo "" >&2
|
||||
echo "[StrikePackageGPT] Command captured: $cmd_id" >&2
|
||||
echo "[StrikePackageGPT] Exit code: $exit_code | Duration: ${duration}s" >&2
|
||||
echo "[StrikePackageGPT] Results available in dashboard" >&2
|
||||
|
||||
exit $exit_code
|
||||
53
services/kali/command_logger.sh
Normal file
53
services/kali/command_logger.sh
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
# Command Logger for StrikePackageGPT
|
||||
# Logs all commands executed in interactive shell sessions
|
||||
# Results are captured and made available to the API
|
||||
|
||||
COMMAND_LOG_DIR="${COMMAND_LOG_DIR:-/workspace/.command_history}"
|
||||
mkdir -p "$COMMAND_LOG_DIR"
|
||||
|
||||
# Function to log command execution
|
||||
log_command() {
|
||||
local cmd="$1"
|
||||
local timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
local cmd_id=$(uuidgen 2>/dev/null || echo "$(date +%s)-$$")
|
||||
local output_file="$COMMAND_LOG_DIR/${cmd_id}.json"
|
||||
|
||||
# Skip logging for cd, ls, echo, and other basic commands
|
||||
local first_word=$(echo "$cmd" | awk '{print $1}')
|
||||
case "$first_word" in
|
||||
cd|ls|pwd|echo|exit|clear|history|source|alias|\
|
||||
export|unset|env|printenv|which|type|whereis)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
# Skip empty commands
|
||||
[[ -z "$cmd" ]] && return 0
|
||||
|
||||
# Create log entry with metadata
|
||||
cat > "$output_file" << EOF
|
||||
{
|
||||
"command_id": "$cmd_id",
|
||||
"command": $(echo "$cmd" | jq -Rs .),
|
||||
"timestamp": "$timestamp",
|
||||
"user": "$(whoami)",
|
||||
"working_dir": "$(pwd)",
|
||||
"source": "interactive_shell",
|
||||
"status": "pending"
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "[StrikePackageGPT] Command logged: $cmd_id" >&2
|
||||
echo "[StrikePackageGPT] Results will be visible in dashboard" >&2
|
||||
}
|
||||
|
||||
# PROMPT_COMMAND hook to log each command after execution
|
||||
export PROMPT_COMMAND='history -a; if [ -n "$LAST_CMD" ]; then log_command "$LAST_CMD"; fi; LAST_CMD=$(history 1 | sed "s/^[ ]*[0-9]*[ ]*//"); '
|
||||
|
||||
# Also trap DEBUG for more comprehensive logging
|
||||
trap 'LAST_EXEC_CMD="$BASH_COMMAND"' DEBUG
|
||||
|
||||
echo "[StrikePackageGPT] Command logging enabled"
|
||||
echo "[StrikePackageGPT] All security tool commands will be captured and visible in the dashboard"
|
||||
echo ""
|
||||
@@ -1,8 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Enable command logging by default for all bash sessions
|
||||
echo 'source /usr/local/bin/command_logger.sh' >> /root/.bashrc
|
||||
echo 'export COMMAND_LOG_DIR=/workspace/.command_history' >> /root/.bashrc
|
||||
|
||||
# Create convenience aliases for captured execution
|
||||
cat >> /root/.bashrc << 'ALIASES'
|
||||
# Convenience alias to run commands with automatic capture
|
||||
alias run='capture'
|
||||
|
||||
# Helper function to show recent commands
|
||||
recent_commands() {
|
||||
echo "Recent commands logged:"
|
||||
ls -lt /workspace/.command_history/*.json 2>/dev/null | head -10 | while read line; do
|
||||
file=$(echo "$line" | awk '{print $NF}')
|
||||
[ -f "$file" ] && jq -r '"\(.timestamp) - \(.command) [\(.status)]"' "$file" 2>/dev/null
|
||||
done
|
||||
}
|
||||
alias recent='recent_commands'
|
||||
ALIASES
|
||||
|
||||
echo "=================================================="
|
||||
echo " StrikePackageGPT - Kali Container"
|
||||
echo " Security Tools Ready"
|
||||
echo " Security Tools Ready + Command Capture Enabled"
|
||||
echo "=================================================="
|
||||
echo ""
|
||||
echo "Available tools:"
|
||||
@@ -13,6 +33,21 @@ echo " - sqlmap (SQL injection)"
|
||||
echo " - hydra (brute force)"
|
||||
echo " - metasploit (exploitation)"
|
||||
echo " - searchsploit (exploit database)"
|
||||
echo " - aircrack-ng, wifite (wireless)"
|
||||
echo " - john, hashcat (password cracking)"
|
||||
echo " - and 600+ more Kali tools"
|
||||
echo ""
|
||||
echo "🔄 BIDIRECTIONAL CAPTURE ENABLED 🔄"
|
||||
echo ""
|
||||
echo "Commands you run here will be captured and visible in:"
|
||||
echo " • Dashboard history"
|
||||
echo " • API scan results"
|
||||
echo " • Network visualization"
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo " • Run commands normally: nmap -sV 192.168.1.1"
|
||||
echo " • Use 'capture' prefix for explicit capture: capture nmap -sV 192.168.1.1"
|
||||
echo " • View recent: recent"
|
||||
echo ""
|
||||
echo "Container is ready for security testing."
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user