-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·370 lines (322 loc) · 11.2 KB
/
install.sh
File metadata and controls
executable file
·370 lines (322 loc) · 11.2 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#!/bin/bash
# API Security Scanner - Installation Script
# This script automates the entire setup process
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}🚀 API Security Scanner - Installation Script${NC}"
echo -e "${BLUE}==========================================${NC}"
# Check if script is run as root
if [ "$EUID" -eq 0 ]; then
echo -e "${YELLOW}⚠️ Running as root. Some checks may behave differently.${NC}"
fi
# Detect operating system
detect_os() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
if [ -f /etc/debian_version ]; then
DISTRO="debian"
elif [ -f /etc/redhat-release ]; then
DISTRO="redhat"
elif [ -f /etc/arch-release ]; then
DISTRO="arch"
else
DISTRO="unknown"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
DISTRO="macos"
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
OS="windows"
DISTRO="windows"
else
OS="unknown"
DISTRO="unknown"
fi
echo -e "${GREEN}📋 Detected OS: $OS ($DISTRO)${NC}"
}
# Check and install Go
install_go() {
echo -e "${YELLOW}🔍 Checking Go installation...${NC}"
if command -v go &> /dev/null; then
GO_VERSION=$(go version | awk '{print $3}' | sed 's/go//')
echo -e "${GREEN}✅ Go is installed: version $GO_VERSION${NC}"
# Check if version is 1.24 or higher
if python3 -c "import sys; version_parts = '$GO_VERSION'.split('.'); major, minor = int(version_parts[0]), int(version_parts[1]); sys.exit(0 if major > 1 or (major == 1 and minor >= 24) else 1)"; then
echo -e "${GREEN}✅ Go version is compatible (1.24+ required)${NC}"
else
echo -e "${RED}❌ Go version $GO_VERSION is too old. Please install Go 1.24 or higher.${NC}"
echo -e "${YELLOW}💡 Download from: https://golang.org/dl/${NC}"
exit 1
fi
else
echo -e "${RED}❌ Go is not installed.${NC}"
if [[ "$DISTRO" == "debian" ]]; then
echo -e "${YELLOW}📦 Installing Go on Debian/Ubuntu...${NC}"
sudo apt update
sudo apt install -y golang-go
elif [[ "$DISTRO" == "redhat" ]]; then
echo -e "${YELLOW}📦 Installing Go on RedHat/CentOS...${NC}"
sudo yum install -y golang
elif [[ "$DISTRO" == "arch" ]]; then
echo -e "${YELLOW}📦 Installing Go on Arch Linux...${NC}"
sudo pacman -S go
elif [[ "$OS" == "macos" ]]; then
echo -e "${YELLOW}📦 Installing Go on macOS...${NC}"
if command -v brew &> /dev/null; then
brew install go
else
echo -e "${RED}❌ Homebrew not found. Please install Homebrew first:${NC}"
echo -e "${YELLOW}/bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"${NC}"
exit 1
fi
else
echo -e "${RED}❌ Please install Go manually:${NC}"
echo -e "${YELLOW}💡 Download from: https://golang.org/dl/${NC}"
exit 1
fi
# Verify installation
if command -v go &> /dev/null; then
echo -e "${GREEN}✅ Go installed successfully${NC}"
else
echo -e "${RED}❌ Go installation failed. Please install manually.${NC}"
exit 1
fi
fi
}
# Check and install Node.js
install_nodejs() {
echo -e "${YELLOW}🔍 Checking Node.js installation...${NC}"
if command -v node &> /dev/null; then
NODE_VERSION=$(node --version | sed 's/v//')
echo -e "${GREEN}✅ Node.js is installed: version $NODE_VERSION${NC}"
# Check if version is 16 or higher
if python3 -c "import sys; version_parts = '$NODE_VERSION'.split('.'); major, minor = int(version_parts[0]), int(version_parts[1]); sys.exit(0 if major > 16 or (major == 16 and minor >= 0) else 1)"; then
echo -e "${GREEN}✅ Node.js version is compatible (v16+ required)${NC}"
else
echo -e "${RED}❌ Node.js version $NODE_VERSION is too old. Please install Node.js v16 or higher.${NC}"
echo -e "${YELLOW}💡 Download from: https://nodejs.org/${NC}"
exit 1
fi
else
echo -e "${RED}❌ Node.js is not installed.${NC}"
if [[ "$DISTRO" == "debian" ]]; then
echo -e "${YELLOW}📦 Installing Node.js on Debian/Ubuntu...${NC}"
sudo apt update
sudo apt install -y nodejs npm
elif [[ "$DISTRO" == "redhat" ]]; then
echo -e "${YELLOW}📦 Installing Node.js on RedHat/CentOS...${NC}"
sudo yum install -y nodejs npm
elif [[ "$DISTRO" == "arch" ]]; then
echo -e "${YELLOW}📦 Installing Node.js on Arch Linux...${NC}"
sudo pacman -S nodejs npm
elif [[ "$OS" == "macos" ]]; then
echo -e "${YELLOW}📦 Installing Node.js on macOS...${NC}"
if command -v brew &> /dev/null; then
brew install node
else
echo -e "${RED}❌ Homebrew not found. Please install Homebrew first.${NC}"
exit 1
fi
else
echo -e "${RED}❌ Please install Node.js manually:${NC}"
echo -e "${YELLOW}💡 Download from: https://nodejs.org/${NC}"
exit 1
fi
# Verify installation
if command -v node &> /dev/null && command -v npm &> /dev/null; then
echo -e "${GREEN}✅ Node.js and npm installed successfully${NC}"
else
echo -e "${RED}❌ Node.js installation failed. Please install manually.${NC}"
exit 1
fi
fi
}
# Install GUI dependencies
install_gui_deps() {
echo -e "${YELLOW}📦 Installing GUI dependencies...${NC}"
if [ ! -d "gui" ]; then
echo -e "${RED}❌ GUI directory not found. Please run this script from the project root.${NC}"
exit 1
fi
cd gui
if [ ! -d "node_modules" ]; then
echo -e "${YELLOW}📦 Running npm install...${NC}"
npm install
echo -e "${GREEN}✅ GUI dependencies installed${NC}"
else
echo -e "${GREEN}✅ GUI dependencies already installed${NC}"
fi
cd ..
}
# Build the application
build_application() {
echo -e "${YELLOW}🔨 Building the application...${NC}"
# Download Go dependencies
echo -e "${YELLOW}📦 Downloading Go dependencies...${NC}"
go mod download
go mod tidy
# Build the main application
echo -e "${YELLOW}🔨 Compiling the application...${NC}"
go build -o api-security-scanner .
echo -e "${GREEN}✅ Application built successfully${NC}"
}
# Create desktop shortcut (Linux only)
create_desktop_shortcut() {
if [[ "$OS" == "linux" ]] && [[ -d "$HOME/Desktop" ]]; then
echo -e "${YELLOW}📋 Creating desktop shortcut...${NC}"
cat > "$HOME/Desktop/api-security-scanner.desktop" << EOF
[Desktop Entry]
Version=1.0
Type=Application
Name=API Security Scanner
Comment=Enterprise-grade API security testing platform
Exec=$(pwd)/run.sh prod
Icon=$(pwd)/gui/src/favicon.ico
Terminal=true
Categories=Security;Development;
EOF
chmod +x "$HOME/Desktop/api-security-scanner.desktop"
echo -e "${GREEN}✅ Desktop shortcut created${NC}"
fi
}
# Create configuration file
create_config() {
echo -e "${YELLOW}⚙️ Creating configuration file...${NC}"
if [ ! -f "config.yaml" ]; then
cat > config.yaml << EOF
# API Security Scanner Configuration
# Generated by install.sh
# API endpoints to test
api_endpoints:
- url: "https://httpbin.org/get"
method: "GET"
- url: "https://httpbin.org/post"
method: "POST"
body: '{"test": "data"}'
# Authentication credentials
auth:
username: "admin"
password: "admin"
# Rate limiting configuration
rate_limiting:
requests_per_second: 10
max_concurrent_requests: 5
# Custom headers
headers:
"User-Agent": "API-Security-Scanner/4.0"
"X-Scanner": "true"
# SQL injection test payloads
injection_payloads:
- "' OR '1'='1"
- "'; DROP TABLE users;--"
- "1' OR '1'='1"
- "admin'--"
# XSS test payloads
xss_payloads:
- "<script>alert('XSS')</script>"
- "'><script>alert('XSS')</script>"
- "<img src=x onerror=alert('XSS')>"
# NoSQL injection test payloads
nosql_payloads:
- "{\$ne: null}"
- "{\$gt: ''}"
- "{\$or: [1,1]}"
- "{\$where: 'sleep(100)'}"
# GUI configuration
gui:
enabled: true
development: false
port: 8080
# Historical data configuration
historical_data:
enabled: true
storage_path: "./history"
retention_days: 30
compare_previous: true
trend_analysis: true
# Metrics configuration
metrics:
enabled: true
port: 8080
update_interval: 30s
retention_days: 30
EOF
echo -e "${GREEN}✅ Configuration file created: config.yaml${NC}"
else
echo -e "${GREEN}✅ Configuration file already exists${NC}"
fi
}
# Run initial tests
run_tests() {
echo -e "${YELLOW}🧪 Running initial tests...${NC}"
# Test the application
echo -e "${YELLOW}🧪 Testing application version...${NC}"
./api-security-scanner -version
echo -e "${GREEN}✅ Application tests passed${NC}"
}
# Show success message
show_success() {
echo ""
echo -e "${GREEN}🎉 Installation completed successfully!${NC}"
echo ""
echo -e "${BLUE}🚀 Quick Start Commands:${NC}"
echo -e "${GREEN} ./run.sh dev ${NC}- Start in development mode"
echo -e "${GREEN} ./run.sh prod ${NC}- Start in production mode"
echo -e "${GREEN} ./run.sh help ${NC}- Show all commands"
echo ""
echo -e "${BLUE}🔧 Default Configuration:${NC}"
echo -e "${GREEN} GUI URL: http://localhost:8080${NC}"
echo -e "${GREEN} Backend API: http://localhost:8080/api${NC}"
echo -e "${GREEN} Default Login: admin / admin${NC}"
echo ""
echo -e "${BLUE}📚 Documentation:${NC}"
echo -e "${GREEN} README.md - Full documentation${NC}"
echo -e "${GREEN} GUIDE.md - User guide${NC}"
echo -e "${GREEN} CONFIGURATION.md - Configuration options${NC}"
echo ""
echo -e "${YELLOW}⚠️ First run may take a few moments as the application initializes.${NC}"
}
# Main installation process
main() {
detect_os
install_go
install_nodejs
install_gui_deps
build_application
create_config
create_desktop_shortcut
run_tests
show_success
}
# Handle command line arguments
case "${1:-install}" in
"install")
main
;;
"deps")
detect_os
install_go
install_nodejs
echo -e "${GREEN}✅ Dependencies installed successfully${NC}"
;;
"help")
echo -e "${BLUE}API Security Scanner - Installation Script${NC}"
echo ""
echo "Usage: $0 [COMMAND]"
echo ""
echo "Commands:"
echo -e " ${GREEN}install${NC} Full installation (default)"
echo -e " ${GREEN}deps${NC} Install system dependencies only"
echo -e " ${GREEN}help${NC} Show this help message"
;;
*)
echo -e "${RED}❌ Unknown command: $1${NC}"
echo -e "${YELLOW}Use '$0 help' for available commands${NC}"
exit 1
;;
esac