189 lines
No EOL
6.8 KiB
Bash
189 lines
No EOL
6.8 KiB
Bash
#!/bin/bash
|
|
# ==============================================================================
|
|
# SECHPOINT WALLARM SMART DEPLOYER - V6 (FULL BINARY INSTALL + PORT SELECTION)
|
|
# ==============================================================================
|
|
|
|
YELLOW='\033[1;33m'; GREEN='\033[0;32m'; RED='\033[0;31m'; BLUE='\033[0;34m'; NC='\033[0m'; BOLD='\033[1m'
|
|
LOG_FILE="/var/log/wallarm-deploy.log"
|
|
EU_DATA_NODES=("api.wallarm.com" "node-data0.eu1.wallarm.com")
|
|
US_DATA_NODES=("us1.api.wallarm.com" "node-data0.us1.wallarm.com")
|
|
|
|
# --- Initialization ---
|
|
sudo touch "$LOG_FILE" && sudo chmod 644 "$LOG_FILE"
|
|
exec > >(tee -a "$LOG_FILE") 2>&1
|
|
|
|
clear
|
|
echo -e "${BLUE}${BOLD}==========================================================${NC}"
|
|
echo -e "${BLUE}${BOLD} Wallarm Full Binary & Container Deployer V6 ${NC}"
|
|
echo -e "${BLUE}${BOLD}==========================================================${NC}"
|
|
|
|
# --- 1. PRE-FLIGHT & CONNECTIVITY ---
|
|
|
|
check_connectivity() {
|
|
echo -e "\n${YELLOW}[1/5] Testing Cloud & Registry Connectivity...${NC}"
|
|
|
|
read -p " Wallarm Cloud (US/EU) [US]: " CLOUD_SEL
|
|
CLOUD_SEL=${CLOUD_SEL^^}; CLOUD_SEL=${CLOUD_SEL:-US}
|
|
|
|
local nodes_to_test=("${US_DATA_NODES[@]}")
|
|
[[ "$CLOUD_SEL" == "EU" ]] && nodes_to_test=("${EU_DATA_NODES[@]}")
|
|
|
|
echo " Testing $CLOUD_SEL Cloud Endpoints..."
|
|
for node in "${nodes_to_test[@]}"; do
|
|
if curl -skI --connect-timeout 5 "https://$node" > /dev/null 2>&1; then
|
|
echo -e " ${GREEN}[PASS]${NC} Reached $node"
|
|
else
|
|
echo -e " ${RED}[FAIL]${NC} Cannot reach $node"
|
|
fi
|
|
done
|
|
|
|
API_HOST=$([[ "$CLOUD_SEL" == "EU" ]] && echo "api.wallarm.com" || echo "us1.api.wallarm.com")
|
|
|
|
echo -n " Testing Docker Hub Registry Path... "
|
|
REGISTRY_STATUS=$(curl -skI --connect-timeout 5 -o /dev/null -w "%{http_code}" "https://registry-1.docker.io/v2/")
|
|
|
|
if [[ "$REGISTRY_STATUS" == "200" || "$REGISTRY_STATUS" == "401" ]]; then
|
|
REGISTRY_REACHABLE=true
|
|
echo -e "${GREEN}REACHABLE${NC} ($REGISTRY_STATUS)"
|
|
else
|
|
REGISTRY_REACHABLE=false
|
|
echo -e "${RED}OFFLINE${NC} ($REGISTRY_STATUS)"
|
|
if ! ls *.tar >/dev/null 2>&1; then
|
|
echo -e " ${RED}✗ FATAL: No registry and no local .tar found.${NC}"; exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# --- 2. ENGINE SETUP (Manual Binary Download & Install) ---
|
|
|
|
setup_manual_engine() {
|
|
echo -e "\n${YELLOW}[2/5] Setting up Docker Engine (Manual Binaries)...${NC}"
|
|
|
|
if command -v docker > /dev/null 2>&1 && sudo docker info > /dev/null 2>&1; then
|
|
echo -e " ${GREEN}✓${NC} Docker is already installed and running."
|
|
else
|
|
echo " Docker not found. Proceeding with static binary installation..."
|
|
|
|
# Determine Architecture
|
|
ARCH=$(uname -m)
|
|
BINARY_URL="https://download.docker.com/linux/static/stable/$ARCH/docker-24.0.7.tgz"
|
|
|
|
echo " Downloading Docker Binaries ($ARCH)..."
|
|
curl -L "$BINARY_URL" -o docker-static.tgz || { echo -e "${RED}Download failed.${NC}"; exit 1; }
|
|
|
|
echo " Extracting and moving binaries to /usr/bin/..."
|
|
tar xzvf docker-static.tgz > /dev/null
|
|
sudo cp docker/* /usr/bin/
|
|
rm -rf docker docker-static.tgz
|
|
|
|
echo " Creating systemd service..."
|
|
sudo tee /etc/systemd/system/docker.service > /dev/null <<EOF
|
|
[Unit]
|
|
Description=Docker Engine
|
|
After=network-online.target
|
|
[Service]
|
|
Type=notify
|
|
ExecStart=/usr/bin/dockerd
|
|
Restart=on-failure
|
|
LimitNOFILE=infinity
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable --now docker
|
|
|
|
# Wait for daemon to wake up
|
|
sleep 5
|
|
sudo docker info > /dev/null 2>&1 || { echo -e "${RED}Engine failed to start.${NC}"; exit 1; }
|
|
echo -e " ${GREEN}✓${NC} Docker Engine manually installed and started."
|
|
fi
|
|
}
|
|
|
|
# --- 3. INPUT & WORKSPACE ---
|
|
|
|
get_user_input() {
|
|
echo -e "\n${YELLOW}[3/5] Configuration Setup...${NC}"
|
|
|
|
read -p " Enter Inbound Traffic Port [80]: " IN_PORT
|
|
IN_PORT=${IN_PORT:-80}
|
|
MON_PORT=$((IN_PORT + 10))
|
|
echo -e " ${YELLOW}i${NC} Monitoring port set to: ${BOLD}$MON_PORT${NC}"
|
|
|
|
INSTANCE_DIR="/opt/wallarm/poc_$IN_PORT"
|
|
NODE_NAME="wallarm-node-$IN_PORT"
|
|
|
|
read -p " Upstream App IP [127.0.0.1]: " UPSTREAM_IP
|
|
UPSTREAM_IP=${UPSTREAM_IP:-127.0.0.1}
|
|
read -p " Upstream App Port [8080]: " UPSTREAM_PORT
|
|
UPSTREAM_PORT=${UPSTREAM_PORT:-8080}
|
|
read -p " Paste Wallarm Token: " TOKEN
|
|
|
|
# Port Collision Check
|
|
if sudo netstat -tulpn | grep -E ":$IN_PORT |:$MON_PORT " > /dev/null 2>&1; then
|
|
echo -e " ${RED}✗ FATAL: Port $IN_PORT or $MON_PORT is already in use.${NC}"; exit 1
|
|
fi
|
|
}
|
|
|
|
# --- 4. DEPLOYMENT & PERSISTENCE ---
|
|
|
|
execute_deployment() {
|
|
echo -e "\n${YELLOW}[4/5] Launching Wallarm Instance...${NC}"
|
|
sudo mkdir -p "$INSTANCE_DIR"
|
|
|
|
# Nginx Config
|
|
sudo tee "$INSTANCE_DIR/nginx.conf" > /dev/null <<EOF
|
|
server {
|
|
listen 80;
|
|
wallarm_mode monitoring;
|
|
location / {
|
|
proxy_pass http://$UPSTREAM_IP:$UPSTREAM_PORT;
|
|
proxy_set_header Host \$host;
|
|
proxy_set_header X-Real-IP \$remote_addr;
|
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
|
}
|
|
}
|
|
server { listen 90; location /wallarm-status { wallarm_status on; allow all; } }
|
|
EOF
|
|
|
|
# Image Logic
|
|
if [ "$REGISTRY_REACHABLE" = true ]; then
|
|
echo " Pulling wallarm/node:latest..."
|
|
sudo docker pull wallarm/node:latest
|
|
else
|
|
echo " Registry offline. Loading local .tar..."
|
|
sudo docker load < *.tar
|
|
fi
|
|
|
|
# The Persistence Script
|
|
sudo tee "$INSTANCE_DIR/start.sh" > /dev/null <<EOF
|
|
#!/bin/bash
|
|
sudo docker rm -f $NODE_NAME 2>/dev/null
|
|
sudo docker run -d --name $NODE_NAME --restart always \\
|
|
-p $IN_PORT:80 -p $MON_PORT:90 \\
|
|
-e WALLARM_API_TOKEN=$TOKEN -e WALLARM_API_HOST=$API_HOST \\
|
|
-v "$INSTANCE_DIR/nginx.conf:/etc/nginx/http.d/default.conf:ro" \\
|
|
wallarm/node:latest
|
|
EOF
|
|
sudo chmod +x "$INSTANCE_DIR/start.sh"
|
|
sudo "$INSTANCE_DIR/start.sh"
|
|
}
|
|
|
|
# --- 5. VERIFY ---
|
|
|
|
verify_and_test() {
|
|
echo -e "\n${YELLOW}[5/5] Final Verification...${NC}"
|
|
sleep 15
|
|
if curl -s "http://localhost:$MON_PORT/wallarm-status" | grep -q "requests"; then
|
|
echo -e "\n${GREEN}${BOLD}✅ SUCCESS: Wallarm Node is active on Port $IN_PORT${NC}"
|
|
echo -e "Monitoring available at: http://localhost:$MON_PORT/wallarm-status\n"
|
|
|
|
echo -e "${YELLOW}⚔️ Simulating SQLi Attack...${NC}"
|
|
curl -s -o /dev/null -w "Result: HTTP %{http_code}\n" "http://localhost:$IN_PORT/?id='OR+1=1--"
|
|
else
|
|
echo -e "\n${RED}❌ FAILED: Container started but status page is unreachable.${NC}"
|
|
sudo docker logs $NODE_NAME | tail -n 5
|
|
fi
|
|
}
|
|
|
|
# --- RUN ---
|
|
check_connectivity; setup_manual_engine; get_user_input; execute_deployment; verify_and_test |