-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.sh
More file actions
172 lines (142 loc) · 5.1 KB
/
runner.sh
File metadata and controls
172 lines (142 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
# NMAP Agent Runner with IP Rotation
# Continuously runs scans while rotating IP addresses to avoid detection
set -e
# Configuration
INTERFACE="${INTERFACE:-eth0}"
GATEWAY="${GATEWAY:-10.223.255.254}"
LOG_FILE="${LOG_FILE:-/var/log/nmap-agent-rotation.log}"
SLEEP_BETWEEN_SCANS="${SLEEP_BETWEEN_SCANS:-0}"
AGENT_BINARY="${AGENT_BINARY:-./nmap-agent-improved}"
PARALLEL_MODE="${PARALLEL_MODE:-false}" # Set to "true" for parallel scanning
# Network: 10.192.0.0/11
# Range: 10.192.0.0 - 10.223.255.255
# Second octet: 192-223 (binary: 110xxxxx, so 192 + 0-31 = 192-223)
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
log() {
local level=$1
shift
local msg="$*"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local color=""
case $level in
"INFO") color=$CYAN ;;
"OK") color=$GREEN ;;
"WARN") color=$YELLOW ;;
"ERROR") color=$RED ;;
esac
echo -e "${timestamp} [${color}${level}${NC}] ${msg}" | tee -a "$LOG_FILE"
}
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}[-] Please run as root${NC}"
exit 1
fi
# Check if agent binary exists
if [ ! -f "$AGENT_BINARY" ]; then
log "ERROR" "Agent binary not found at $AGENT_BINARY"
log "ERROR" "Run 'go build -o nmap-agent-improved' first"
exit 1
fi
# Check if .env exists
if [ ! -f ".env" ]; then
log "ERROR" ".env file not found. Copy env_example to .env and configure it."
exit 1
fi
# Build the agent command
AGENT_CMD="$AGENT_BINARY"
if [ "$PARALLEL_MODE" = "true" ]; then
AGENT_CMD="$AGENT_BINARY -p"
log "INFO" "Parallel mode ENABLED - will scan all teams simultaneously"
else
log "INFO" "Single scan mode - set PARALLEL_MODE=true for parallel scanning"
fi
# Function to generate a safe IP address in 10.192.0.0/11
# Valid range: 10.192.0.1 - 10.223.255.254
generate_safe_ip() {
while true; do
# Second octet: 192-223 (32 values)
local o2=$(( 192 + RANDOM % 32 ))
local o3=$(( RANDOM % 256 ))
local o4=$(( RANDOM % 254 + 1 )) # 1-254, avoid .0 and .255
# Skip gateway network 10.223.255.x
if [[ "$o2" -eq 223 && "$o3" -eq 255 ]]; then
continue
fi
# Skip common infrastructure ranges (adjust as needed)
# 10.192.0.x - often used for infrastructure
if [[ "$o2" -eq 192 && "$o3" -eq 0 ]]; then
continue
fi
echo "10.$o2.$o3.$o4/11"
return
done
}
# Function to rotate IP
rotate_ip() {
local new_ip=$(generate_safe_ip)
log "INFO" "Rotating to new IP: $new_ip"
# Flush current IP
ip addr flush dev "$INTERFACE" 2>/dev/null || true
# Add new IP
ip addr add "$new_ip" dev "$INTERFACE"
ip link set "$INTERFACE" up
# Re-add default route
ip route add default via "$GATEWAY" dev "$INTERFACE" 2>/dev/null || true
log "OK" "IP rotation complete"
}
# Trap to handle graceful shutdown
cleanup() {
log "INFO" "Shutting down..."
exit 0
}
trap cleanup SIGINT SIGTERM
# Print banner
echo -e "${CYAN}"
echo "╔═══════════════════════════════════════════════════════════╗"
echo "║ NMAP Agent Runner with IP Rotation ║"
echo "║ ║"
echo "║ Network: 10.192.0.0/11 ║"
echo "║ Range: 10.192.0.0 - 10.223.255.255 ║"
echo "║ Interface: $INTERFACE ║"
echo "║ Gateway: $GATEWAY ║"
echo "║ Parallel: $PARALLEL_MODE ║"
echo "╚═══════════════════════════════════════════════════════════╝"
echo -e "${NC}"
log "INFO" "=== NMAP Agent Runner Started ==="
# Main loop
scan_count=0
consecutive_failures=0
max_failures=5
while true; do
scan_count=$((scan_count + 1))
log "INFO" "--- Scan #$scan_count starting ---"
# Run the scanner
if $AGENT_CMD; then
log "OK" "Scan #$scan_count completed successfully"
consecutive_failures=0
else
exit_code=$?
consecutive_failures=$((consecutive_failures + 1))
if [ $consecutive_failures -ge $max_failures ]; then
log "ERROR" "Too many consecutive failures ($consecutive_failures). Check configuration."
log "INFO" "Waiting 60 seconds before retrying..."
sleep 60
consecutive_failures=0
else
log "WARN" "Scan #$scan_count failed (exit code: $exit_code) - Failure $consecutive_failures/$max_failures"
fi
fi
# Optional sleep between scans
if [ "$SLEEP_BETWEEN_SCANS" -gt 0 ]; then
log "INFO" "Sleeping for $SLEEP_BETWEEN_SCANS seconds..."
sleep "$SLEEP_BETWEEN_SCANS"
fi
# Rotate IP for next scan
rotate_ip
done