-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-interface.js
More file actions
executable file
·355 lines (321 loc) · 15.6 KB
/
Copy pathcli-interface.js
File metadata and controls
executable file
·355 lines (321 loc) · 15.6 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
#!/usr/bin/env node
import readline from 'readline';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// ANSI color codes for cyberpunk styling
const colors = {
cyan: '\x1b[36m',
green: '\x1b[32m',
red: '\x1b[31m',
yellow: '\x1b[33m',
magenta: '\x1b[35m',
blue: '\x1b[34m',
reset: '\x1b[0m',
bright: '\x1b[1m',
dim: '\x1b[2m'
};
// Load cybersecurity commands database
let commandsDB = {};
try {
const commandsPath = path.join(process.cwd(), 'cybershell-commands', 'commands.json');
const commandsData = fs.readFileSync(commandsPath, 'utf8');
commandsDB = JSON.parse(commandsData);
} catch (error) {
console.log(`${colors.yellow}Warning: Could not load commands database${colors.reset}`);
}
// Enhanced command processing with AI integration
async function processCommandWithAI(command) {
try {
const response = await fetch('http://localhost:5000/api/command', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ command })
});
if (response.ok) {
const data = await response.json();
return data.response || executeCommand(command);
} else {
return executeCommand(command);
}
} catch (error) {
console.log(`${colors.dim}Note: AI enhancement unavailable, using local simulation${colors.reset}`);
return executeCommand(command);
}
}
function showBanner() {
console.clear();
console.log(`${colors.cyan}╔══════════════════════════════════════════════════════════════╗${colors.reset}`);
console.log(`${colors.cyan}║ ${colors.bright}CyberShellX Nexus CLI${colors.reset}${colors.cyan} ║${colors.reset}`);
console.log(`${colors.cyan}║ ${colors.magenta}Advanced Cybersecurity Terminal${colors.reset}${colors.cyan} ║${colors.reset}`);
console.log(`${colors.cyan}╚══════════════════════════════════════════════════════════════╝${colors.reset}`);
console.log(`${colors.dim} Enhanced with AI integration • Type 'help' for commands${colors.reset}`);
console.log(``);
}
function showHelp() {
console.log(`${colors.cyan}═══ CyberShellX Nexus CLI Help ═══${colors.reset}`);
console.log(``);
console.log(`${colors.bright}System Commands:${colors.reset}`);
console.log(`${colors.yellow}help${colors.reset} - Show this help menu`);
console.log(`${colors.yellow}status${colors.reset} - Show system status and AI connection`);
console.log(`${colors.yellow}clear${colors.reset} - Clear the terminal`);
console.log(`${colors.yellow}exit/quit${colors.reset} - Exit CyberShellX`);
console.log(``);
console.log(`${colors.bright}Scan Commands:${colors.reset}`);
console.log(`${colors.green}scan <target>${colors.reset} - Start vulnerability scan`);
console.log(`${colors.green}recon <target>${colors.reset} - Start reconnaissance`);
console.log(`${colors.green}scans${colors.reset} - List recent scans`);
console.log(`${colors.green}risk <vuln_type>${colors.reset} - Calculate risk score`);
console.log(``);
console.log(`${colors.bright}Agent Commands:${colors.reset}`);
console.log(`${colors.green}agents${colors.reset} - Show agent status`);
console.log(`${colors.green}orchestrate <target>${colors.reset} - Run full agent pipeline`);
console.log(``);
console.log(`${colors.bright}Tool Commands:${colors.reset}`);
console.log(`${colors.green}tools${colors.reset} - List available tools`);
console.log(`${colors.green}run <tool> <target>${colors.reset} - Execute a tool (simulated)`);
console.log(``);
console.log(`${colors.bright}Network Scanning:${colors.reset}`);
console.log(`${colors.green}nmap -sV <target>${colors.reset} - Version detection scan`);
console.log(`${colors.green}nmap -sS <target>${colors.reset} - SYN stealth scan`);
console.log(`${colors.green}masscan <target>${colors.reset} - High-speed port scanner`);
console.log(``);
console.log(`${colors.bright}Vulnerability Assessment:${colors.reset}`);
console.log(`${colors.green}nikto -h <target>${colors.reset} - Web vulnerability scanner`);
console.log(`${colors.green}dirb <target>${colors.reset} - Directory brute force`);
console.log(`${colors.green}sqlmap -u <url>${colors.reset} - SQL injection testing`);
console.log(``);
console.log(`${colors.bright}Network Analysis:${colors.reset}`);
console.log(`${colors.green}wireshark${colors.reset} - Network protocol analyzer`);
console.log(`${colors.green}tcpdump -i eth0${colors.reset} - Packet capture`);
console.log(`${colors.green}netstat -an${colors.reset} - Network connections`);
console.log(``);
console.log(`${colors.bright}Exploitation:${colors.reset}`);
console.log(`${colors.green}msfconsole${colors.reset} - Metasploit framework`);
console.log(`${colors.green}searchsploit <term>${colors.reset} - Exploit database search`);
console.log(`${colors.green}hydra -l <user>${colors.reset} - Password brute force`);
console.log(``);
console.log(`${colors.red}⚠️ Educational purposes only! Always obtain proper authorization.${colors.reset}`);
console.log(``);
}
async function showSystemStatus() {
console.log(`${colors.cyan}═══ CyberShellX System Status ═══${colors.reset}`);
try {
const response = await fetch('http://localhost:5000/api/ai/status');
if (response.ok) {
const status = await response.json();
console.log(`${colors.green}✓ Server Connection: Active${colors.reset}`);
console.log(`${colors.green}✓ AI APIs Available: ${status.available.length}${colors.reset}`);
console.log(`${colors.green}✓ Current API: ${status.current}${colors.reset}`);
}
} catch (error) {
console.log(`${colors.red}✗ Server Connection: Offline${colors.reset}`);
console.log(`${colors.yellow} Running in local simulation mode${colors.reset}`);
}
console.log(`${colors.green}✓ Commands Database: Loaded${colors.reset}`);
console.log(`${colors.green}✓ Security Tools: Available${colors.reset}`);
}
function executeCommand(cmd) {
const command = cmd.toLowerCase().trim();
// Network scanning commands
if (command.includes('nmap')) {
if (command.includes('-sV')) {
return `${colors.green}Starting Nmap 7.94 ( https://nmap.org )
Nmap scan report for target.com (192.168.1.100)
Host is up (0.023s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.1 (Ubuntu Linux; protocol 2.0)
80/tcp open http Apache httpd 2.4.52 ((Ubuntu))
443/tcp open ssl/http Apache httpd 2.4.52 ((Ubuntu))
3306/tcp open mysql MySQL 8.0.32-0ubuntu0.22.04.2${colors.reset}`;
} else if (command.includes('-sS')) {
return `${colors.green}Starting Nmap 7.94 ( https://nmap.org )
Nmap scan report for target.com (192.168.1.100)
Host is up (0.012s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp open https
3306/tcp open mysql${colors.reset}`;
}
return `${colors.green}Nmap scan initiated. Use -sV for version detection or -sS for stealth scan.${colors.reset}`;
}
// Vulnerability scanning
if (command.includes('nikto')) {
return `${colors.green}- Nikto v2.5.0
---------------------------------------------------------------------------
+ Target IP: 192.168.1.100
+ Target Hostname: target.com
+ Target Port: 80
+ Start Time: 2024-12-26 22:00:00 (GMT+7)
---------------------------------------------------------------------------
+ Server: Apache/2.4.52 (Ubuntu)
+ /: The anti-clickjacking X-Frame-Options header is not present.
+ /: The X-Content-Type-Options header is not set.
+ /admin/: Admin login page/section found.
+ /config.php: PHP configuration file may contain database credentials.${colors.reset}`;
}
if (command.includes('sqlmap')) {
return `${colors.green} ___
__H__
___ ___[)]_____ ___ ___ {1.7.12#stable}
|_ -| . ['] | .'| . |
|___|_ [.]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[*] starting @ 22:00:00 /2024-12-26/
[22:00:01] [INFO] testing connection to the target URL
[22:00:02] [INFO] checking if the target is protected by some kind of WAF/IPS
[22:00:03] [INFO] testing if the parameter 'id' is dynamic
[22:00:04] [INFO] heuristic (basic) test shows that GET parameter 'id' might be injectable${colors.reset}`;
}
// Network analysis
if (command.includes('wireshark')) {
return `${colors.green}Wireshark GUI launched...
Capturing on interface: eth0
Frame 1: 74 bytes on wire (592 bits), 74 bytes captured (592 bits)
Ethernet II, Src: 00:1b:44:11:3a:b7, Dst: 00:50:56:c0:00:01
Internet Protocol Version 4, Src: 192.168.1.100, Dst: 8.8.8.8
Transmission Control Protocol, Src Port: 45632, Dst Port: 80${colors.reset}`;
}
if (command.includes('tcpdump')) {
return `${colors.green}tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
22:00:01.123456 IP 192.168.1.100.45632 > 8.8.8.8.80: Flags [S], seq 123456789
22:00:01.145678 IP 8.8.8.8.80 > 192.168.1.100.45632: Flags [S.], seq 987654321
22:00:01.145890 IP 192.168.1.100.45632 > 8.8.8.8.80: Flags [.], ack 987654322${colors.reset}`;
}
// Exploitation tools
if (command.includes('msfconsole')) {
return `${colors.red}
_ _
/ \ | |
| ___ ____ ___ ____ __ ___ __ ____ _ ___| |_
| | / _ \ / _| _ | _ \/ \| __/| \| \ ||| |___| |
| |_| __/| (| | _| __/ | | | | | | | (_) |_|_| __|_
\___/\____|_ _|_| \___ _|_|_|___|___|_/\___/ _\___)
Metasploit v6.3.55-dev
msf6 > search ms17-010
msf6 > use exploit/windows/smb/ms17_010_eternalblue
msf6 exploit(windows/smb/ms17_010_eternalblue) > show options${colors.reset}`;
}
if (command.includes('hydra')) {
return `${colors.green}Hydra v9.4 (c) 2022 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes.
Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2024-12-26 22:00:00
[DATA] max 16 tasks per 1 server, overall 16 tasks, 100 login tries (l:1/p:100)
[DATA] attacking ssh://192.168.1.100:22/
[22/tcp][ssh] host: 192.168.1.100 login: admin password: admin123
1 of 1 target successfully completed, 1 valid password found${colors.reset}`;
}
// Default response
return `${colors.yellow}Command simulation: ${cmd}
${colors.dim}This is a cybersecurity training environment.
For real penetration testing, use actual tools with proper authorization.
Type 'help' for available commands.${colors.reset}`;
}
async function startCLI() {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: `${colors.cyan}cyber@shell${colors.reset}:${colors.blue}~${colors.reset}$ `
});
showBanner();
// Check server connection
try {
const response = await fetch('http://localhost:5000/api/ai/status');
if (response.ok) {
const status = await response.json();
console.log(`${colors.green}✓ AI Enhancement Active${colors.reset} (${status.available.length} APIs available)`);
}
} catch (error) {
console.log(`${colors.yellow}⚠ Running in offline mode${colors.reset}`);
}
console.log('');
rl.prompt();
rl.on('line', async (input) => {
const command = input.trim();
if (command === 'exit' || command === 'quit') {
console.log(`${colors.green}Goodbye! Stay secure! 🛡️${colors.reset}`);
rl.close();
return;
}
if (command === 'help') {
showHelp();
} else if (command === 'clear') {
console.clear();
showBanner();
} else if (command === 'status') {
await showSystemStatus();
} else if (command.startsWith('scan ')) {
const target = command.substring(5).trim();
try {
const res = await fetch('http://localhost:5000/api/scan/start', {
method: 'POST', headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ target, type: 'vulnerability' })
});
const data = await res.json();
console.log(`${colors.cyan}Scan started: ${data.scanId}${colors.reset}`);
console.log(`${colors.yellow}${data.legalNotice}${colors.reset}`);
} catch { console.log(`${colors.red}Failed to start scan${colors.reset}`); }
} else if (command.startsWith('recon ')) {
const target = command.substring(6).trim();
try {
const res = await fetch('http://localhost:5000/api/recon/start', {
method: 'POST', headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ target })
});
const data = await res.json();
console.log(`${colors.cyan}Recon started: ${data.reconId}${colors.reset}`);
console.log(`${colors.yellow}${data.legalNotice}${colors.reset}`);
} catch { console.log(`${colors.red}Failed to start recon${colors.reset}`); }
} else if (command === 'scans') {
try {
const res = await fetch('http://localhost:5000/api/scans');
const data = await res.json();
if (data.length === 0) {
console.log(`${colors.dim}No scans yet${colors.reset}`);
} else {
data.forEach(s => console.log(`${colors.green}${s.target}${colors.reset} - ${s.status} (${s.type})`));
}
} catch { console.log(`${colors.red}Failed to list scans${colors.reset}`); }
} else if (command === 'agents') {
try {
const res = await fetch('http://localhost:5000/api/agents/status');
const data = await res.json();
console.log(`${colors.cyan}Running: ${data.isRunning}${colors.reset}`);
data.agents.forEach(a => console.log(` ${colors.green}${a.type}${colors.reset}: ${a.status} (${a.progress}%)`));
} catch { console.log(`${colors.red}Failed to get agent status${colors.reset}`); }
} else if (command === 'tools') {
try {
const res = await fetch('http://localhost:5000/api/tools');
const data = await res.json();
data.forEach(t => console.log(` ${t.installed ? colors.green : colors.red}${t.name}${colors.reset} - ${t.description} [${t.safetyLevel}]`));
} catch { console.log(`${colors.red}Failed to list tools${colors.reset}`); }
} else if (command.startsWith('risk ')) {
const vulnType = command.substring(5).trim().toUpperCase();
try {
const res = await fetch('http://localhost:5000/api/risk/calculate', {
method: 'POST', headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ vulnType })
});
const data = await res.json();
console.log(`${colors.cyan}Risk Score: ${data.risk.overall}/10${colors.reset}`);
console.log(` CVSS: ${data.risk.cvss} | Severity: ${data.severity}`);
} catch { console.log(`${colors.red}Failed to calculate risk${colors.reset}`); }
} else if (command) {
const result = await processCommandWithAI(command);
console.log(result);
}
console.log('');
rl.prompt();
});
rl.on('close', () => {
console.log(`${colors.dim}Session terminated.${colors.reset}`);
process.exit(0);
});
}
// Start the CLI
startCLI().catch(console.error);