The Analyzer v1.0 — autonomous bug bounty engine with 20 attack vectors and Ollama brain
This commit is contained in:
213
lib/utils.sh
Executable file
213
lib/utils.sh
Executable file
@@ -0,0 +1,213 @@
|
||||
#!/usr/bin/env bash
|
||||
# The Analyzer - Shared Utilities
|
||||
|
||||
# Load colors
|
||||
__UTILS_SRC="${BASH_SOURCE[0]}"
|
||||
if command -v readlink &>/dev/null; then
|
||||
while [ -h "$__UTILS_SRC" ]; do
|
||||
__UTILS_SRC="$(readlink "$__UTILS_SRC")"
|
||||
[[ "$__UTILS_SRC" != /* ]] && __UTILS_SRC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$__UTILS_SRC"
|
||||
done
|
||||
fi
|
||||
SCRIPT_DIR="$(cd "$(dirname "$__UTILS_SRC")" && pwd 2>/dev/null)" || SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
unset __UTILS_SRC
|
||||
source "$SCRIPT_DIR/colors.sh"
|
||||
|
||||
# Config
|
||||
export ANALYZER_DIR="$SCRIPT_DIR/.."
|
||||
export VECTORS_DIR="$ANALYZER_DIR/vectors"
|
||||
export REPORTS_DIR="$ANALYZER_DIR/reports"
|
||||
export ENGINE_DIR="$ANALYZER_DIR/engine"
|
||||
export TIMEOUT=30
|
||||
export MAX_VECTORS=10
|
||||
export OLLAMA_HOST="${OLLAMA_HOST:-http://10.30.20.110:11434}"
|
||||
export OLLAMA_MODEL="${OLLAMA_MODEL:-granite4.1:8b}"
|
||||
|
||||
# Check dependencies
|
||||
check_deps() {
|
||||
local missing=()
|
||||
for cmd in curl jq; do
|
||||
if ! command -v $cmd &>/dev/null; then
|
||||
missing+=("$cmd")
|
||||
fi
|
||||
done
|
||||
if [ ${#missing[@]} -gt 0 ]; then
|
||||
print_error "Missing dependencies: ${missing[*]}"
|
||||
print_info "Install: apt install ${missing[*]}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Check Ollama is running
|
||||
check_ollama() {
|
||||
if ! curl -s "$OLLAMA_HOST/api/tags" >/dev/null 2>&1; then
|
||||
print_error "Ollama not running at $OLLAMA_HOST"
|
||||
print_info "Start it: ollama serve"
|
||||
return 1
|
||||
fi
|
||||
print_ok "Ollama connected ($OLLAMA_HOST)"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Call Ollama with a prompt, return response
|
||||
ollama_prompt() {
|
||||
local prompt="$1"
|
||||
local system="$2"
|
||||
local model="${3:-$OLLAMA_MODEL}"
|
||||
|
||||
local payload=$(jq -n \
|
||||
--arg model "$model" \
|
||||
--arg prompt "$prompt" \
|
||||
--arg system "$system" \
|
||||
'{
|
||||
model: $model,
|
||||
prompt: $prompt,
|
||||
system: $system,
|
||||
stream: false,
|
||||
options: {
|
||||
temperature: 0.2,
|
||||
num_predict: 2048
|
||||
}
|
||||
}')
|
||||
|
||||
local response=$(curl -s "$OLLAMA_HOST/api/generate" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$payload" 2>/dev/null)
|
||||
|
||||
echo "$response" | jq -r '.response // "ERROR: No response"' 2>/dev/null
|
||||
}
|
||||
|
||||
# Sanitize URL for filenames
|
||||
sanitize() {
|
||||
echo "$1" | sed 's|https\?://||' | sed 's|/|_|g' | sed 's|[^a-zA-Z0-9._-]|_|g'
|
||||
}
|
||||
|
||||
# Extract domain from URL
|
||||
get_domain() {
|
||||
echo "$1" | sed 's|https\?://||' | cut -d/ -f1 | cut -d: -f1
|
||||
}
|
||||
|
||||
# Extract base URL (protocol + domain)
|
||||
get_base() {
|
||||
echo "$1" | sed 's|\(https\?://[^/]*\).*|\1|'
|
||||
}
|
||||
|
||||
# Quick HTTP check
|
||||
http_check() {
|
||||
local url="$1"
|
||||
curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 --max-time 10 "$url" 2>/dev/null
|
||||
}
|
||||
|
||||
# Get response headers
|
||||
get_headers() {
|
||||
local url="$1"
|
||||
curl -sI --connect-timeout 5 --max-time 10 "$url" 2>/dev/null
|
||||
}
|
||||
|
||||
# Get page title
|
||||
get_title() {
|
||||
local url="$1"
|
||||
curl -s --connect-timeout 5 --max-time 10 "$url" 2>/dev/null | sed -n 's/.*<title>\([^<]*\)<\/title>.*/\1/p' | sed 's/<[^>]*>//g' | head -1
|
||||
}
|
||||
|
||||
# Check if target is alive
|
||||
target_alive() {
|
||||
local code=$(http_check "$1")
|
||||
[[ "$code" =~ ^[23] ]] && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
# Run a command with timeout, return output
|
||||
run_timeout() {
|
||||
local cmd="$1"
|
||||
local timeout="${2:-$TIMEOUT}"
|
||||
timeout $timeout bash -c "$cmd" 2>/dev/null || echo "TIMEOUT_OR_ERROR"
|
||||
}
|
||||
|
||||
# Colorize severity
|
||||
severity_color() {
|
||||
case "$1" in
|
||||
critical|CRITICAL) echo -e "${BRIGHT_RED}${BOLD}CRITICAL${NC}" ;;
|
||||
high|HIGH) echo -e "${RED}${BOLD}HIGH${NC}" ;;
|
||||
medium|MEDIUM) echo -e "${YELLOW}${BOLD}MEDIUM${NC}" ;;
|
||||
low|LOW) echo -e "${BLUE}${BOLD}LOW${NC}" ;;
|
||||
info|INFO) echo -e "${DIM}INFO${NC}" ;;
|
||||
*) echo -e "${DIM}$1${NC}" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Create report header
|
||||
init_report() {
|
||||
local target="$1"
|
||||
local domain=$(get_domain "$target")
|
||||
local ts=$(date '+%Y-%m-%d_%H%M%S')
|
||||
local report_file="$REPORTS_DIR/${domain}_${ts}.md"
|
||||
|
||||
cat > "$report_file" << EOF
|
||||
# The Analyzer Report
|
||||
**Target:** $target
|
||||
**Domain:** $domain
|
||||
**Date:** $(date '+%Y-%m-%d %H:%M:%S')
|
||||
**Analyst:** The Analyzer v1.0
|
||||
**Status:** In Progress
|
||||
|
||||
---
|
||||
|
||||
## Reconnaissance
|
||||
|
||||
EOF
|
||||
echo "$report_file"
|
||||
}
|
||||
|
||||
# Append to report
|
||||
append_report() {
|
||||
local report="$1"
|
||||
local content="$2"
|
||||
echo -e "$content" >> "$report"
|
||||
}
|
||||
|
||||
# Finalize report
|
||||
finalize_report() {
|
||||
local report="$1"
|
||||
local find_count="$2"
|
||||
local vuln_count="$3"
|
||||
|
||||
local ts=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
|
||||
cat >> "$report" << EOF
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
- **Total Findings:** $find_count
|
||||
- **Vulnerabilities:** $vuln_count
|
||||
- **Completed:** $ts
|
||||
- **Status:** Complete
|
||||
|
||||
---
|
||||
*Generated by The Analyzer v1.0 — Authorized Bug Bounty Use Only*
|
||||
EOF
|
||||
|
||||
echo "$report"
|
||||
}
|
||||
|
||||
# List available vector modules
|
||||
list_vectors() {
|
||||
echo -e "${BOLD}Available Attack Vectors:${NC}"
|
||||
echo ""
|
||||
for f in "$VECTORS_DIR"/*.sh; do
|
||||
local name=$(basename "$f" .sh)
|
||||
local desc=$(head -5 "$f" | grep "^# Desc:" | sed 's/^# Desc: //')
|
||||
local num=$(echo "$name" | cut -d- -f1)
|
||||
printf " ${CYAN}[%02d]${NC} %-30s %s\n" "$num" "${name#?-}" "$desc"
|
||||
done
|
||||
}
|
||||
|
||||
# User prompt with default
|
||||
prompt_default() {
|
||||
local msg="$1"
|
||||
local default="$2"
|
||||
read -p " ${ICON_ARROW} $msg [$default]: " input
|
||||
echo "${input:-$default}"
|
||||
}
|
||||
Reference in New Issue
Block a user