@naraya/cli 0.1.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +184 -93
- package/bin/naraya-native.mjs +4 -0
- package/bin/naraya.mjs +1 -142
- package/bin/undici-timeout.mjs +1 -0
- package/dist/assets.pack.gz +0 -0
- package/dist/mcp/config-loader.js +32 -0
- package/dist/mcp/lifecycle.js +90 -0
- package/dist/mcp/tool-mapper.js +31 -0
- package/dist/mcp/transport.js +30 -0
- package/dist/pentest/catalog/catalog-loader.js +45 -0
- package/dist/pentest/catalog/index.js +1 -0
- package/dist/pentest/cli.js +117 -0
- package/dist/pentest/command-builder/command-builder.js +90 -0
- package/dist/pentest/command-builder/index.js +1 -0
- package/dist/pentest/index.js +10 -0
- package/dist/pentest/installer/index.js +1 -0
- package/dist/pentest/installer/tool-installer.js +90 -0
- package/dist/pentest/manager.js +125 -0
- package/dist/pentest/mode/index.js +1 -0
- package/dist/pentest/mode/mode-selector.js +127 -0
- package/dist/pentest/selector/index.js +1 -0
- package/dist/pentest/selector/tool-selector.js +66 -0
- package/dist/pentest/skill-bridge/index.js +1 -0
- package/dist/pentest/skill-bridge/skill-bridge.js +66 -0
- package/dist/pentest/skills/generator/index.js +1 -0
- package/dist/pentest/skills/generator/skill-generator.js +310 -0
- package/dist/pentest/skills/index.js +3 -0
- package/dist/pentest/skills/loader/index.js +1 -0
- package/dist/pentest/skills/loader/skill-loader.js +167 -0
- package/dist/pentest/skills/register/index.js +1 -0
- package/dist/pentest/skills/register/skill-register.js +162 -0
- package/dist/pentest/skills/types.js +1 -0
- package/dist/pentest/types.js +90 -0
- package/package.json +42 -14
- package/src/assets-pack.mjs +1 -0
- package/src/banner.mjs +5 -0
- package/src/clipboard.mjs +1 -0
- package/src/config.mjs +1 -40
- package/src/goodbye.mjs +7 -0
- package/src/login.mjs +7 -49
- package/src/mcp/config-loader.ts +50 -0
- package/src/mcp/lifecycle.ts +113 -0
- package/src/mcp/tool-mapper.ts +42 -0
- package/src/mcp/transport.ts +38 -0
- package/src/mcp-cli.mjs +5 -0
- package/src/pentest/catalog/catalog-loader.ts +55 -0
- package/src/pentest/catalog/index.ts +1 -0
- package/src/pentest/cli.ts +130 -0
- package/src/pentest/command-builder/command-builder.ts +109 -0
- package/src/pentest/command-builder/index.ts +1 -0
- package/src/pentest/index.ts +11 -0
- package/src/pentest/installer/index.ts +1 -0
- package/src/pentest/installer/tool-installer.ts +107 -0
- package/src/pentest/manager.ts +167 -0
- package/src/pentest/mode/index.ts +1 -0
- package/src/pentest/mode/mode-selector.ts +159 -0
- package/src/pentest/selector/index.ts +1 -0
- package/src/pentest/selector/tool-selector.ts +87 -0
- package/src/pentest/skill-bridge/index.ts +1 -0
- package/src/pentest/skill-bridge/skill-bridge.ts +86 -0
- package/src/pentest/skills/generator/index.ts +1 -0
- package/src/pentest/skills/generator/skill-generator.ts +373 -0
- package/src/pentest/skills/index.ts +4 -0
- package/src/pentest/skills/loader/index.ts +1 -0
- package/src/pentest/skills/loader/skill-loader.ts +206 -0
- package/src/pentest/skills/register/index.ts +1 -0
- package/src/pentest/skills/register/skill-register.ts +196 -0
- package/src/pentest/skills/types.ts +66 -0
- package/src/pentest/types.ts +341 -0
- package/src/seed.mjs +1 -36
- package/src/splash.mjs +4 -0
- package/src/status.mjs +2 -71
- package/assets/APPEND-SYSTEM.md +0 -9
- package/assets/extensions/naraya-brand.ts +0 -251
- package/assets/extensions/naraya-gate.ts +0 -23
- package/assets/naraya-logo.txt +0 -5
- package/assets/skills/narabuild/SKILL.md +0 -156
- package/assets/skills/naradroid/SKILL.md +0 -118
- package/assets/skills/naraexplore/SKILL.md +0 -71
- package/assets/skills/narafe/SKILL.md +0 -94
- package/assets/skills/naraplan/SKILL.md +0 -47
- package/assets/skills/narasearch/SKILL.md +0 -141
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
2
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
|
+
export async function createTransport(config, projectDir) {
|
|
4
|
+
if (config.type === "http" || config.type === "streamable-http") {
|
|
5
|
+
if (!config.url) {
|
|
6
|
+
throw new Error("url is required for HTTP transport");
|
|
7
|
+
}
|
|
8
|
+
return new StreamableHTTPClientTransport(new URL(config.url), {
|
|
9
|
+
requestInit: {
|
|
10
|
+
headers: config.headers
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
// Default: stdio
|
|
15
|
+
if (!config.command) {
|
|
16
|
+
throw new Error("command is required for stdio transport");
|
|
17
|
+
}
|
|
18
|
+
const env = {
|
|
19
|
+
...process.env,
|
|
20
|
+
...config.env,
|
|
21
|
+
NARAYA_PROJECT_DIR: projectDir
|
|
22
|
+
};
|
|
23
|
+
return new StdioClientTransport({
|
|
24
|
+
command: config.command,
|
|
25
|
+
args: config.args ?? [],
|
|
26
|
+
env,
|
|
27
|
+
// Suppress MCP server startup logs by discarding stderr
|
|
28
|
+
stderr: "ignore"
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const DEFAULT_CATALOG_PATH = "tools-catalog.json";
|
|
2
|
+
export async function loadToolsCatalog(options) {
|
|
3
|
+
const path = options?.catalogPath ?? DEFAULT_CATALOG_PATH;
|
|
4
|
+
const response = await fetch(`file://${process.cwd()}/${path}`);
|
|
5
|
+
if (!response.ok) {
|
|
6
|
+
throw new Error(`Failed to load tools catalog from ${path}: ${response.statusText}`);
|
|
7
|
+
}
|
|
8
|
+
return response.json();
|
|
9
|
+
}
|
|
10
|
+
export async function loadToolsCatalogFromFs(fs, options) {
|
|
11
|
+
const path = options?.catalogPath ?? DEFAULT_CATALOG_PATH;
|
|
12
|
+
const content = await fs.readFile(path, "utf-8");
|
|
13
|
+
return JSON.parse(content);
|
|
14
|
+
}
|
|
15
|
+
export function getToolByName(catalog, name) {
|
|
16
|
+
return catalog.tools.find((t) => t.tools_name === name);
|
|
17
|
+
}
|
|
18
|
+
export function getToolNames(catalog) {
|
|
19
|
+
return catalog.tools.map((t) => t.tools_name);
|
|
20
|
+
}
|
|
21
|
+
export function validateCatalog(catalog) {
|
|
22
|
+
if (typeof catalog !== "object" || catalog === null)
|
|
23
|
+
return false;
|
|
24
|
+
const c = catalog;
|
|
25
|
+
if (typeof c.$schema !== "string")
|
|
26
|
+
return false;
|
|
27
|
+
if (typeof c.version !== "string")
|
|
28
|
+
return false;
|
|
29
|
+
if (!Array.isArray(c.categories))
|
|
30
|
+
return false;
|
|
31
|
+
if (!Array.isArray(c.tools))
|
|
32
|
+
return false;
|
|
33
|
+
return c.tools.every(validateToolEntry);
|
|
34
|
+
}
|
|
35
|
+
function validateToolEntry(tool) {
|
|
36
|
+
if (typeof tool !== "object" || tool === null)
|
|
37
|
+
return false;
|
|
38
|
+
const t = tool;
|
|
39
|
+
return (typeof t.tools_name === "string" &&
|
|
40
|
+
typeof t.description === "string" &&
|
|
41
|
+
typeof t.category === "string" &&
|
|
42
|
+
typeof t.command === "object" &&
|
|
43
|
+
typeof t.skills_loader === "string" &&
|
|
44
|
+
Array.isArray(t.phase));
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./catalog-loader.js";
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { PentestManager } from "./manager.js";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
export async function pentestCLI(argv) {
|
|
4
|
+
const program = new Command()
|
|
5
|
+
.name("naraya pentest")
|
|
6
|
+
.description("Pentest orchestration for authorized engagements")
|
|
7
|
+
.version("0.2.0");
|
|
8
|
+
const manager = new PentestManager();
|
|
9
|
+
// naraya pentest list
|
|
10
|
+
program
|
|
11
|
+
.command("list")
|
|
12
|
+
.description("List all available pentest skills")
|
|
13
|
+
.action(() => {
|
|
14
|
+
const manifests = manager.discoverSkills();
|
|
15
|
+
if (manifests.length === 0) {
|
|
16
|
+
console.log("No pentest skills found.");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
console.log(`Found ${manifests.length} skill(s):\n`);
|
|
20
|
+
for (const m of manifests) {
|
|
21
|
+
console.log(` * ${m.name} v${m.version} [${m.phase.join(", ")}]`);
|
|
22
|
+
console.log(` ${m.description}`);
|
|
23
|
+
console.log(` Tools: ${m.tools.join(", ")}`);
|
|
24
|
+
console.log(` Tags: ${m.tags.join(", ")}\n`);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
// naraya pentest mode --target example.com
|
|
28
|
+
program
|
|
29
|
+
.command("mode")
|
|
30
|
+
.description("Auto-detect or set pentest mode")
|
|
31
|
+
.option("--target <target>", "Target to analyze for mode detection")
|
|
32
|
+
.option("--mode <mode>", "Force specific mode (auto|ctf|bug-bounty|red-team|blue-team|offensive|grey-hat)")
|
|
33
|
+
.action((options) => {
|
|
34
|
+
const result = manager.selectMode({
|
|
35
|
+
target: options.target,
|
|
36
|
+
preferred_mode: options.mode,
|
|
37
|
+
auto_detect: options.target !== undefined,
|
|
38
|
+
});
|
|
39
|
+
console.log(`\nMode: ${result.selected_mode}`);
|
|
40
|
+
console.log(`Auto-detected: ${result.auto_detected ? "Yes" : "No"}`);
|
|
41
|
+
console.log(`Reason: ${result.detection_reason}`);
|
|
42
|
+
console.log(`\nConfig:`);
|
|
43
|
+
console.log(` Description: ${result.config.description}`);
|
|
44
|
+
console.log(` Parallelism: ${result.config.parallelism}`);
|
|
45
|
+
console.log(` Stealth: ${result.config.stealth ? "Yes" : "No"}`);
|
|
46
|
+
console.log(` Report Format: ${result.config.report_format}`);
|
|
47
|
+
console.log(` Skill Chain: ${result.config.skill_chain.join(" -> ")}`);
|
|
48
|
+
console.log(` Tool Priority: ${result.config.tool_priority.join(" -> ")}\n`);
|
|
49
|
+
});
|
|
50
|
+
// naraya pentest phase --phase recon
|
|
51
|
+
program
|
|
52
|
+
.command("phase")
|
|
53
|
+
.description("Run a pentest phase")
|
|
54
|
+
.option("--target <url>", "Target domain or IP")
|
|
55
|
+
.option("--phase <phase>", "Phase: recon, enumeration, exploitation, reporting")
|
|
56
|
+
.option("--mode <mode>", "Pentest mode")
|
|
57
|
+
.option("--passive", "Passive-only mode")
|
|
58
|
+
.action((options) => {
|
|
59
|
+
if (!options.target) {
|
|
60
|
+
console.error("Error: --target is required");
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
if (!options.phase) {
|
|
64
|
+
console.error("Error: --phase is required");
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
const mode = options.mode || "auto";
|
|
68
|
+
const modeConfig = manager.getModeConfig(mode);
|
|
69
|
+
console.log(`Running ${options.phase} on ${options.target}...`);
|
|
70
|
+
console.log(`Mode: ${mode}`);
|
|
71
|
+
console.log(`Stealth: ${modeConfig.stealth ? "Yes" : "No"}`);
|
|
72
|
+
console.log(`Parallelism: ${modeConfig.parallelism}`);
|
|
73
|
+
console.log(`Skills: ${modeConfig.skill_chain.join(" -> ")}`);
|
|
74
|
+
const skills = manager.loadSkillsByPhase(options.phase);
|
|
75
|
+
const loaded = skills.filter((s) => s.loaded);
|
|
76
|
+
if (loaded.length > 0) {
|
|
77
|
+
console.log(`\nLoaded ${loaded.length} skill(s):`);
|
|
78
|
+
for (const s of loaded) {
|
|
79
|
+
console.log(` * ${s.name} v${s.skill?.version}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
console.log(`\nNo skills found for phase: ${options.phase}`);
|
|
84
|
+
}
|
|
85
|
+
console.log(`\n${options.phase} completed.`);
|
|
86
|
+
});
|
|
87
|
+
// naraya pentest register
|
|
88
|
+
program
|
|
89
|
+
.command("register")
|
|
90
|
+
.description("Register skills with the skill register")
|
|
91
|
+
.option("--skill <name>", "Register specific skill")
|
|
92
|
+
.option("--all", "Register all discovered skills")
|
|
93
|
+
.action((options) => {
|
|
94
|
+
const register = manager.getRegister();
|
|
95
|
+
if (options.all) {
|
|
96
|
+
const manifests = manager.discoverSkills();
|
|
97
|
+
const entries = register.registerFromFiles(manifests.map((m) => m.name));
|
|
98
|
+
console.log(`Registered ${entries.length} skill(s)`);
|
|
99
|
+
}
|
|
100
|
+
else if (options.skill) {
|
|
101
|
+
const entry = register.registerFromFile(options.skill);
|
|
102
|
+
if (entry) {
|
|
103
|
+
console.log(`Registered: ${entry.name} v${entry.skill.version}`);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
console.error(`Skill not found: ${options.skill}`);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
console.log("Use --skill <name> or --all to register skills");
|
|
112
|
+
}
|
|
113
|
+
console.log(`\nTotal registered: ${register.count()}`);
|
|
114
|
+
console.log(`Enabled: ${register.enabledCount()}`);
|
|
115
|
+
});
|
|
116
|
+
program.parse(argv);
|
|
117
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export function buildCommand(tool, options = {}) {
|
|
2
|
+
const args = [];
|
|
3
|
+
const flags = options.flags ?? {};
|
|
4
|
+
const positional = options.positional ?? [];
|
|
5
|
+
for (const flagDef of tool.command.flags) {
|
|
6
|
+
const value = flags[flagDef.name];
|
|
7
|
+
const argValue = buildFlagArg(flagDef, value);
|
|
8
|
+
if (argValue) {
|
|
9
|
+
args.push(...argValue);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (positional.length > 0) {
|
|
13
|
+
args.push(...positional);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
for (const posDef of tool.command.positional) {
|
|
17
|
+
const value = flags[posDef.name];
|
|
18
|
+
if (value !== undefined) {
|
|
19
|
+
args.push(String(value));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
let fullCommand = `${tool.command.base} ${args.join(" ")}`.trim();
|
|
24
|
+
if (options.pipe_to && options.pipe_to.length > 0) {
|
|
25
|
+
fullCommand += ` | ${options.pipe_to.join(" | ")}`;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
command: tool.command.base,
|
|
29
|
+
args,
|
|
30
|
+
fullCommand,
|
|
31
|
+
requires_root: tool.requires_root
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function buildFlagArg(flag, value) {
|
|
35
|
+
if (value === undefined || value === null) {
|
|
36
|
+
if (flag.default !== undefined && flag.type === "boolean" && flag.default === true) {
|
|
37
|
+
return [flag.name];
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
switch (flag.type) {
|
|
42
|
+
case "boolean":
|
|
43
|
+
return value === true ? [flag.name] : null;
|
|
44
|
+
case "string":
|
|
45
|
+
case "number":
|
|
46
|
+
return [flag.name, String(value)];
|
|
47
|
+
case "path":
|
|
48
|
+
return [flag.name, String(value)];
|
|
49
|
+
case "choice":
|
|
50
|
+
if (flag.choices && !flag.choices.includes(String(value))) {
|
|
51
|
+
throw new Error(`Invalid choice for ${flag.name}: ${value}. Valid: ${flag.choices.join(", ")}`);
|
|
52
|
+
}
|
|
53
|
+
return [flag.name, String(value)];
|
|
54
|
+
case "repeat":
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
return value.flatMap(v => [flag.name, String(v)]);
|
|
57
|
+
}
|
|
58
|
+
return [flag.name, String(value)];
|
|
59
|
+
default:
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function buildCommandWithSudo(tool, options = {}) {
|
|
64
|
+
const result = buildCommand(tool, options);
|
|
65
|
+
return result.requires_root ? `sudo ${result.fullCommand}` : result.fullCommand;
|
|
66
|
+
}
|
|
67
|
+
export function buildPipeline(tools, optionsPerTool) {
|
|
68
|
+
const commands = tools.map((tool, i) => buildCommand(tool, optionsPerTool[i]));
|
|
69
|
+
return commands.map(c => c.fullCommand).join(" | ");
|
|
70
|
+
}
|
|
71
|
+
export function validateRequiredFlags(tool, options) {
|
|
72
|
+
const errors = [];
|
|
73
|
+
const flags = options.flags ?? {};
|
|
74
|
+
for (const flag of tool.command.flags) {
|
|
75
|
+
if (flag.required && flags[flag.name] === undefined) {
|
|
76
|
+
errors.push(`Missing required flag: ${flag.name}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const pos of tool.command.positional) {
|
|
80
|
+
if (pos.required) {
|
|
81
|
+
const hasValue = options.positional?.length
|
|
82
|
+
? options.positional.length > 0
|
|
83
|
+
: flags[pos.name] !== undefined;
|
|
84
|
+
if (!hasValue) {
|
|
85
|
+
errors.push(`Missing required positional argument: ${pos.name}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return errors;
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./command-builder.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./catalog/index.js";
|
|
2
|
+
export * from "./selector/index.js";
|
|
3
|
+
export * from "./command-builder/index.js";
|
|
4
|
+
export * from "./installer/index.js";
|
|
5
|
+
export * from "./skill-bridge/index.js";
|
|
6
|
+
export * from "./mode/index.js";
|
|
7
|
+
// skills re-exports overlap with types - only re-export the classes/functions, not types
|
|
8
|
+
export { discoverSkills, loadSkill, loadAllSkills, loadSkillsByPhase, loadSkillsByTools, getSkillsForTool, resolveSkillPath as resolveSkillPathFromLoader } from "./skills/loader/skill-loader.js";
|
|
9
|
+
export { SkillRegister, createSkillRegister } from "./skills/register/skill-register.js";
|
|
10
|
+
export { generateSkill, generateAndSaveSkill, generateSkillsForPhase, generateSkillsForTool, generateFullPentestSuite, saveGeneratedSkills } from "./skills/generator/skill-generator.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./tool-installer.js";
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { exec } from "child_process";
|
|
2
|
+
import { promisify } from "util";
|
|
3
|
+
const execAsync = promisify(exec);
|
|
4
|
+
export async function checkToolInstalled(tool) {
|
|
5
|
+
try {
|
|
6
|
+
const { stdout } = await execAsync(tool.check_installed.command, { timeout: 10000 });
|
|
7
|
+
let version;
|
|
8
|
+
if (tool.check_installed.parse_version) {
|
|
9
|
+
const match = stdout.match(new RegExp(tool.check_installed.parse_version));
|
|
10
|
+
version = match?.[1];
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
tools_name: tool.tools_name,
|
|
14
|
+
installed: true,
|
|
15
|
+
version
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
return {
|
|
20
|
+
tools_name: tool.tools_name,
|
|
21
|
+
installed: false,
|
|
22
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export async function checkAllToolsInstalled(tools) {
|
|
27
|
+
return Promise.all(tools.map(checkToolInstalled));
|
|
28
|
+
}
|
|
29
|
+
export function getInstallCommand(tool, platform = process.platform) {
|
|
30
|
+
const config = tool.installation[platform];
|
|
31
|
+
return config?.command ?? null;
|
|
32
|
+
}
|
|
33
|
+
export function getInstallCommands(tool) {
|
|
34
|
+
const result = {};
|
|
35
|
+
if (tool.installation.linux)
|
|
36
|
+
result.linux = tool.installation.linux;
|
|
37
|
+
if (tool.installation.darwin)
|
|
38
|
+
result.darwin = tool.installation.darwin;
|
|
39
|
+
if (tool.installation.win32)
|
|
40
|
+
result.win32 = tool.installation.win32;
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
export async function installTool(tool, platform = process.platform) {
|
|
44
|
+
const config = tool.installation[platform];
|
|
45
|
+
if (!config) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
message: `No installation command available for platform: ${platform}`
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const { stdout, stderr } = await execAsync(config.command, { timeout: 300000 });
|
|
53
|
+
return {
|
|
54
|
+
success: true,
|
|
55
|
+
message: stdout || stderr || "Installation completed"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
message: error instanceof Error ? error.message : "Installation failed"
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function getMissingTools(availability) {
|
|
66
|
+
return availability.filter(a => !a.installed);
|
|
67
|
+
}
|
|
68
|
+
export function getInstalledTools(availability) {
|
|
69
|
+
return availability.filter(a => a.installed);
|
|
70
|
+
}
|
|
71
|
+
export async function ensureToolsInstalled(tools, platform = process.platform) {
|
|
72
|
+
const availability = await checkAllToolsInstalled(tools);
|
|
73
|
+
const missing = getMissingTools(availability);
|
|
74
|
+
const failed = [];
|
|
75
|
+
for (const tool of missing) {
|
|
76
|
+
const toolEntry = tools.find(t => t.tools_name === tool.tools_name);
|
|
77
|
+
if (!toolEntry)
|
|
78
|
+
continue;
|
|
79
|
+
const result = await installTool(toolEntry, platform);
|
|
80
|
+
if (!result.success) {
|
|
81
|
+
failed.push({ tool: tool.tools_name, error: result.message });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const recheck = await checkAllToolsInstalled(tools);
|
|
85
|
+
return {
|
|
86
|
+
installed: getInstalledTools(recheck),
|
|
87
|
+
missing: getMissingTools(recheck),
|
|
88
|
+
failed
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { discoverSkills, loadSkill, loadAllSkills, loadSkillsByPhase } from "./skills/loader/skill-loader.js";
|
|
2
|
+
import { SkillRegister } from "./skills/register/skill-register.js";
|
|
3
|
+
import { selectTools, selectToolsByPhase, selectToolsByCategory } from "./selector/tool-selector.js";
|
|
4
|
+
import { buildCommand, buildCommandWithSudo, validateRequiredFlags } from "./command-builder/command-builder.js";
|
|
5
|
+
import { checkToolInstalled, checkAllToolsInstalled, getInstallCommand, installTool } from "./installer/tool-installer.js";
|
|
6
|
+
import { selectMode, detectMode, getModeConfig, getSkillsForMode, getLoopConfig, getSafetyConfig } from "./mode/mode-selector.js";
|
|
7
|
+
import { existsSync, readFileSync } from "fs";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
const DEFAULT_SKILL_DIRS = [
|
|
10
|
+
"assets/agents/skills",
|
|
11
|
+
"skills/",
|
|
12
|
+
"packages/pentest-skills/skills",
|
|
13
|
+
];
|
|
14
|
+
const DEFAULT_CATALOG_PATH = "tools-catalog.json";
|
|
15
|
+
export class PentestManager {
|
|
16
|
+
config;
|
|
17
|
+
cache = {
|
|
18
|
+
manifests: new Map(),
|
|
19
|
+
skills: new Map(),
|
|
20
|
+
catalog: null,
|
|
21
|
+
};
|
|
22
|
+
skillRegister = null;
|
|
23
|
+
constructor(config = {}) {
|
|
24
|
+
this.config = {
|
|
25
|
+
baseDir: config.baseDir ?? process.cwd(),
|
|
26
|
+
skillDirs: config.skillDirs ?? DEFAULT_SKILL_DIRS,
|
|
27
|
+
configPath: config.configPath ?? join(config.baseDir ?? process.cwd(), ".pentestrc"),
|
|
28
|
+
catalogPath: config.catalogPath ?? join(config.baseDir ?? process.cwd(), DEFAULT_CATALOG_PATH),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// ── Mode Operations ──
|
|
32
|
+
selectMode(options = {}) {
|
|
33
|
+
return selectMode(options);
|
|
34
|
+
}
|
|
35
|
+
detectMode(target) {
|
|
36
|
+
return detectMode(target);
|
|
37
|
+
}
|
|
38
|
+
getModeConfig(mode) {
|
|
39
|
+
return getModeConfig(mode);
|
|
40
|
+
}
|
|
41
|
+
getSkillsForMode(mode) {
|
|
42
|
+
return getSkillsForMode(mode);
|
|
43
|
+
}
|
|
44
|
+
getLoopConfig(mode) {
|
|
45
|
+
return getLoopConfig(mode);
|
|
46
|
+
}
|
|
47
|
+
getSafetyConfig(mode) {
|
|
48
|
+
return getSafetyConfig(mode);
|
|
49
|
+
}
|
|
50
|
+
// ── Skill Operations ──
|
|
51
|
+
discoverSkills() {
|
|
52
|
+
return discoverSkills(this.config.baseDir);
|
|
53
|
+
}
|
|
54
|
+
loadSkill(skillName) {
|
|
55
|
+
return loadSkill(skillName, this.config.baseDir);
|
|
56
|
+
}
|
|
57
|
+
loadAllSkills() {
|
|
58
|
+
return loadAllSkills(this.config.baseDir);
|
|
59
|
+
}
|
|
60
|
+
loadSkillsByPhase(phase) {
|
|
61
|
+
return loadSkillsByPhase(phase, this.config.baseDir);
|
|
62
|
+
}
|
|
63
|
+
// ── Catalog Operations ──
|
|
64
|
+
async loadCatalog() {
|
|
65
|
+
if (this.cache.catalog)
|
|
66
|
+
return this.cache.catalog;
|
|
67
|
+
const catalogPath = this.config.catalogPath;
|
|
68
|
+
if (!existsSync(catalogPath)) {
|
|
69
|
+
throw new Error(`Tools catalog not found: ${catalogPath}`);
|
|
70
|
+
}
|
|
71
|
+
const content = readFileSync(catalogPath, "utf-8");
|
|
72
|
+
this.cache.catalog = JSON.parse(content);
|
|
73
|
+
return this.cache.catalog;
|
|
74
|
+
}
|
|
75
|
+
async selectTools(options) {
|
|
76
|
+
const catalog = await this.loadCatalog();
|
|
77
|
+
return selectTools(catalog, options);
|
|
78
|
+
}
|
|
79
|
+
async selectToolsByPhase(phase) {
|
|
80
|
+
const catalog = await this.loadCatalog();
|
|
81
|
+
return selectToolsByPhase(catalog, phase);
|
|
82
|
+
}
|
|
83
|
+
async selectToolsByCategory(category) {
|
|
84
|
+
const catalog = await this.loadCatalog();
|
|
85
|
+
return selectToolsByCategory(catalog, category);
|
|
86
|
+
}
|
|
87
|
+
// ── Command Operations ──
|
|
88
|
+
buildToolCommand(tool, flags = {}, positional = []) {
|
|
89
|
+
const result = buildCommand(tool, { flags, positional });
|
|
90
|
+
return result.fullCommand;
|
|
91
|
+
}
|
|
92
|
+
buildToolCommandWithSudo(tool, flags = {}, positional = []) {
|
|
93
|
+
return buildCommandWithSudo(tool, { flags, positional });
|
|
94
|
+
}
|
|
95
|
+
validateToolFlags(tool, flags) {
|
|
96
|
+
return validateRequiredFlags(tool, { flags });
|
|
97
|
+
}
|
|
98
|
+
// ── Installation Operations ──
|
|
99
|
+
async checkToolInstalled(tool) {
|
|
100
|
+
return checkToolInstalled(tool);
|
|
101
|
+
}
|
|
102
|
+
async checkAllToolsInstalled(tools) {
|
|
103
|
+
return checkAllToolsInstalled(tools);
|
|
104
|
+
}
|
|
105
|
+
getInstallCommandForTool(tool) {
|
|
106
|
+
return getInstallCommand(tool);
|
|
107
|
+
}
|
|
108
|
+
async installTool(tool) {
|
|
109
|
+
return installTool(tool);
|
|
110
|
+
}
|
|
111
|
+
// ── Skill Register ──
|
|
112
|
+
getRegister() {
|
|
113
|
+
if (!this.skillRegister) {
|
|
114
|
+
this.skillRegister = new SkillRegister({
|
|
115
|
+
skills_dir: join(this.config.baseDir, ".agents/skills"),
|
|
116
|
+
search_paths: [
|
|
117
|
+
join(this.config.baseDir, ".agents/skills"),
|
|
118
|
+
join(this.config.baseDir, ".opencode/skills"),
|
|
119
|
+
join(this.config.baseDir, ".claude/skills"),
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return this.skillRegister;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./mode-selector.js";
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { MODE_PRESETS } from "../types.js";
|
|
2
|
+
const WEB_EXTENSIONS = [".php", ".asp", ".aspx", ".jsp", ".cgi", ".pl", ".py", ".rb"];
|
|
3
|
+
const NETWORK_PORTS = [22, 23, 3389, 445, 139, 135, 1433, 3306, 5432, 27017];
|
|
4
|
+
const CTF_INDICATORS = ["ctf", "chall", "pwn", "crypto", "forensics", "rev", "misc", "web"];
|
|
5
|
+
const RED_TEAM_INDICATORS = ["ad", "active-directory", "kerberos", "ldap", "smb", "rdp"];
|
|
6
|
+
export function detectMode(target) {
|
|
7
|
+
const lower = target.toLowerCase();
|
|
8
|
+
for (const indicator of CTF_INDICATORS) {
|
|
9
|
+
if (lower.includes(indicator)) {
|
|
10
|
+
return { mode: "ctf", reason: `CTF indicator detected: ${indicator}` };
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
for (const indicator of RED_TEAM_INDICATORS) {
|
|
14
|
+
if (lower.includes(indicator)) {
|
|
15
|
+
return { mode: "red-team", reason: `Red team indicator detected: ${indicator}` };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
for (const ext of WEB_EXTENSIONS) {
|
|
19
|
+
if (lower.endsWith(ext)) {
|
|
20
|
+
return { mode: "bug-bounty", reason: `Web extension detected: ${ext}` };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const portMatch = lower.match(/:(\d+)/);
|
|
24
|
+
if (portMatch) {
|
|
25
|
+
const port = parseInt(portMatch[1], 10);
|
|
26
|
+
if (NETWORK_PORTS.includes(port)) {
|
|
27
|
+
return { mode: "red-team", reason: `Network service port detected: ${port}` };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (lower.includes("http://") || lower.includes("https://")) {
|
|
31
|
+
return { mode: "bug-bounty", reason: "Web target detected (HTTP/HTTPS)" };
|
|
32
|
+
}
|
|
33
|
+
const ipMatch = lower.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/);
|
|
34
|
+
if (ipMatch) {
|
|
35
|
+
return { mode: "red-team", reason: `IP address target: ${ipMatch[0]}` };
|
|
36
|
+
}
|
|
37
|
+
return { mode: "auto", reason: "No specific indicators detected, using adaptive mode" };
|
|
38
|
+
}
|
|
39
|
+
export function selectMode(options = {}) {
|
|
40
|
+
if (options.preferred_mode && options.preferred_mode !== "auto") {
|
|
41
|
+
const config = MODE_PRESETS[options.preferred_mode];
|
|
42
|
+
return {
|
|
43
|
+
selected_mode: options.preferred_mode,
|
|
44
|
+
config,
|
|
45
|
+
auto_detected: false,
|
|
46
|
+
detection_reason: `User selected mode: ${options.preferred_mode}`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (options.auto_detect !== false && options.target) {
|
|
50
|
+
const detection = detectMode(options.target);
|
|
51
|
+
if (detection.mode !== "auto") {
|
|
52
|
+
const config = MODE_PRESETS[detection.mode];
|
|
53
|
+
return {
|
|
54
|
+
selected_mode: detection.mode,
|
|
55
|
+
config,
|
|
56
|
+
auto_detected: true,
|
|
57
|
+
detection_reason: detection.reason,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const config = MODE_PRESETS["auto"];
|
|
62
|
+
return {
|
|
63
|
+
selected_mode: "auto",
|
|
64
|
+
config,
|
|
65
|
+
auto_detected: false,
|
|
66
|
+
detection_reason: "No specific mode detected, using adaptive auto mode",
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function getModeConfig(mode) {
|
|
70
|
+
return MODE_PRESETS[mode];
|
|
71
|
+
}
|
|
72
|
+
export function getToolsForMode(mode, availableTools) {
|
|
73
|
+
const config = MODE_PRESETS[mode];
|
|
74
|
+
const priority = config.tool_priority;
|
|
75
|
+
const prioritized = [];
|
|
76
|
+
const remaining = [];
|
|
77
|
+
for (const tool of availableTools) {
|
|
78
|
+
const toolCategory = getToolCategory(tool);
|
|
79
|
+
if (toolCategory && priority.includes(toolCategory)) {
|
|
80
|
+
prioritized.push(tool);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
remaining.push(tool);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
prioritized.sort((a, b) => {
|
|
87
|
+
const catA = getToolCategory(a);
|
|
88
|
+
const catB = getToolCategory(b);
|
|
89
|
+
if (!catA || !catB)
|
|
90
|
+
return 0;
|
|
91
|
+
return priority.indexOf(catA) - priority.indexOf(catB);
|
|
92
|
+
});
|
|
93
|
+
return [...prioritized, ...remaining];
|
|
94
|
+
}
|
|
95
|
+
function getToolCategory(toolName) {
|
|
96
|
+
const categoryMap = {
|
|
97
|
+
subfinder: "recon", amass: "recon", assetfinder: "recon", httpx: "recon",
|
|
98
|
+
naabu: "recon", massdns: "recon", nmap: "enumeration", nuclei: "enumeration",
|
|
99
|
+
ffuf: "enumeration", dirsearch: "enumeration", gobuster: "enumeration",
|
|
100
|
+
feroxbuster: "enumeration", whatweb: "enumeration", wafw00f: "enumeration",
|
|
101
|
+
nikto: "enumeration", burpsuite: "enumeration", owasp_zap: "enumeration",
|
|
102
|
+
sqlmap: "exploitation", commix: "exploitation", hydra: "exploitation",
|
|
103
|
+
hashcat: "exploitation", john: "exploitation", metasploit: "exploitation",
|
|
104
|
+
pwntools: "exploitation",
|
|
105
|
+
curl: "utility", jq: "utility", anew: "utility", grep: "utility",
|
|
106
|
+
sort: "utility", uniq: "utility", notify: "reporting",
|
|
107
|
+
};
|
|
108
|
+
return categoryMap[toolName];
|
|
109
|
+
}
|
|
110
|
+
export function getSkillsForMode(mode) {
|
|
111
|
+
return [...MODE_PRESETS[mode].skill_chain];
|
|
112
|
+
}
|
|
113
|
+
export function getLoopConfig(mode) {
|
|
114
|
+
return MODE_PRESETS[mode].loop_config;
|
|
115
|
+
}
|
|
116
|
+
export function getSafetyConfig(mode) {
|
|
117
|
+
return MODE_PRESETS[mode].safety_constraints;
|
|
118
|
+
}
|
|
119
|
+
export function getReportFormat(mode) {
|
|
120
|
+
return MODE_PRESETS[mode].report_format;
|
|
121
|
+
}
|
|
122
|
+
export function isModeStealth(mode) {
|
|
123
|
+
return MODE_PRESETS[mode].stealth;
|
|
124
|
+
}
|
|
125
|
+
export function getModeParallelism(mode) {
|
|
126
|
+
return MODE_PRESETS[mode].parallelism;
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./tool-selector.js";
|