@deepbounty/sdk 1.1.8 → 1.2.0

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/dist/events.d.ts CHANGED
@@ -1,4 +1,20 @@
1
1
  import { TrafficContext, HttpTraffic } from "./types/burpsuite";
2
+ import { Target } from "./types/targets";
3
+ /**
4
+ * Event origin metadata
5
+ */
6
+ export type EventOrigin = "server" | "module";
7
+ /**
8
+ * Event wrapper with origin metadata
9
+ */
10
+ export interface EventMetadata<T> {
11
+ /** Origin of the event */
12
+ origin: EventOrigin;
13
+ /** Module ID if origin is "module", undefined if origin is "server" */
14
+ moduleId?: string;
15
+ /** Actual event data */
16
+ data: T;
17
+ }
2
18
  /**
3
19
  * Predefined core events emitted by the server
4
20
  * Modules can also emit custom events for inter-module communication
@@ -9,11 +25,19 @@ export interface CoreEvents {
9
25
  context: TrafficContext;
10
26
  js: string;
11
27
  };
28
+ "http:html": {
29
+ context: TrafficContext;
30
+ html: string;
31
+ };
32
+ "target:created": Target;
33
+ "target:updated": Target;
34
+ "target:deleted": Target;
12
35
  }
13
36
  /**
14
37
  * Event handler function signature
38
+ * Receives event data wrapped with metadata about its origin
15
39
  */
16
- export type EventHandler<T = any> = (data: T) => void | Promise<void>;
40
+ export type EventHandler<T = any> = (event: EventMetadata<T>) => void | Promise<void>;
17
41
  /**
18
42
  * Subscription object returned when subscribing to events
19
43
  */
@@ -33,7 +57,7 @@ export interface IEventBus {
33
57
  * Emit an event with data
34
58
  * Non-blocking, async execution with rate limiting and error isolation
35
59
  * @param event - Event name
36
- * @param data - Event data
60
+ * @param data - Event data (will be wrapped with origin metadata internally)
37
61
  */
38
62
  emit<K extends keyof CoreEvents>(event: K, data: CoreEvents[K]): void;
39
63
  emit<T = any>(event: string, data: T): void;
package/dist/index.d.ts CHANGED
@@ -77,22 +77,96 @@ export interface StorageAPI {
77
77
  */
78
78
  dropTable(tableName: string): void;
79
79
  }
80
+ /**
81
+ * ScopedDirectory provides isolated file system access within a specific directory.
82
+ * All file operations are restricted to the base directory and its subdirectories.
83
+ */
84
+ export interface ScopedDirectory {
85
+ /**
86
+ * Write binary data to a file (creates parent directories if needed)
87
+ * @param relativePath Path relative to this directory (supports nested paths like "subfolder/file.bin")
88
+ * @param data Binary data to write
89
+ */
90
+ writeFile(relativePath: string, data: Buffer | Uint8Array): void;
91
+ /**
92
+ * Write text to a file (creates parent directories if needed)
93
+ * @param relativePath Path relative to this directory (supports nested paths like "logs/output.txt")
94
+ * @param text Text content to write
95
+ * @param encoding Text encoding (default: "utf8")
96
+ */
97
+ writeFileText(relativePath: string, text: string, encoding?: BufferEncoding): void;
98
+ /**
99
+ * Read binary data from a file
100
+ * @param relativePath Path relative to this directory
101
+ * @returns Binary data as Buffer
102
+ */
103
+ readFile(relativePath: string): Buffer;
104
+ /**
105
+ * Read text from a file
106
+ * @param relativePath Path relative to this directory
107
+ * @param encoding Text encoding (default: "utf8")
108
+ * @returns Text content
109
+ */
110
+ readFileText(relativePath: string, encoding?: BufferEncoding): string;
111
+ /**
112
+ * Delete a file
113
+ * @param relativePath Path relative to this directory
114
+ */
115
+ deleteFile(relativePath: string): void;
116
+ /**
117
+ * Get a scoped subdirectory (creates it if it doesn't exist)
118
+ * Returns a new ScopedDirectory object for the subdirectory
119
+ * @param relativePath Path relative to this directory
120
+ * @returns New ScopedDirectory for the subdirectory
121
+ */
122
+ getSubdirectory(relativePath: string): ScopedDirectory;
123
+ /**
124
+ * List all files in a directory (optionally in a subdirectory)
125
+ * @param subdirPath Optional subdirectory path to list files from
126
+ * @returns Array of relative file paths
127
+ */
128
+ listFiles(subdirPath?: string): string[];
129
+ /**
130
+ * Check if a file exists
131
+ * @param relativePath Path relative to this directory
132
+ * @returns true if the file exists, false otherwise
133
+ */
134
+ fileExists(relativePath: string): boolean;
135
+ }
136
+ /**
137
+ * FilesAPI provides file system access for modules.
138
+ * Each module can create isolated directories within their module folder.
139
+ */
140
+ export interface FilesAPI {
141
+ /**
142
+ * Get or create a directory by path (supports nested paths like "cache/images")
143
+ * Returns a ScopedDirectory object for isolated file operations.
144
+ * The directory is automatically created if it doesn't exist.
145
+ *
146
+ * @param directoryPath Directory path relative to module's files folder (e.g., "cache", "exports/json")
147
+ * @returns ScopedDirectory object for file operations within this directory
148
+ */
149
+ getDirectory(directoryPath: string): ScopedDirectory;
150
+ }
80
151
  export interface ServerAPI {
81
152
  version: string;
82
153
  logger: Logger;
83
154
  config: ConfigAPI;
84
155
  storage: StorageAPI;
156
+ files: FilesAPI;
85
157
  events: IEventBus;
158
+ /** Check if a hostname is in scope based on targets_subdomains */
159
+ isHostnameInScope(hostname: string): Promise<boolean>;
86
160
  /**
87
161
  * Register a task template that can be scheduled for all targets
88
162
  * @param uniqueKey Unique identifier for this task within the module (e.g., "subdomain-scan")
89
163
  * @param name Friendly name for the task
90
164
  * @param description Task description
91
165
  * @param taskContent The task content including commands and tools
92
- * @param interval Interval in seconds between task executions
166
+ * @param interval Interval in seconds between task executions. For CUSTOM mode: if <= 0, no automatic scheduling (manual mode only)
93
167
  * @param schedulingType How to schedule tasks: "TARGET_BASED" (one per target), "GLOBAL" (single instance), or "CUSTOM" (callback-based)
94
168
  * @param onComplete Optional callback executed when a task instance completes
95
- * @param onSchedule Optional callback for CUSTOM mode, invoked at interval to create instances
169
+ * @param onSchedule Optional callback for CUSTOM mode, invoked at interval to create instances (not called if interval <= 0)
96
170
  * @returns The ID of the registered task template
97
171
  */
98
172
  registerTaskTemplate(uniqueKey: string, name: string, description: string, taskContent: TaskContent, interval: number, schedulingType?: "TARGET_BASED" | "GLOBAL" | "CUSTOM", onComplete?: (result: TaskResult) => void, onSchedule?: (templateId: number) => void | Promise<void>): Promise<number>;
@@ -104,35 +178,46 @@ export interface ServerAPI {
104
178
  unregisterTaskTemplate(templateId: number): Promise<boolean>;
105
179
  /**
106
180
  * Create a task instance manually (for CUSTOM scheduling type)
181
+ * Task instances are always one-time and automatically deleted after execution.
107
182
  * @param templateId The ID of the task template
108
183
  * @param targetId Optional target ID for this instance
109
184
  * @param customData Optional custom data to attach to this instance (accessible via {{KEY}} placeholders)
110
- * @param oneTime If true, delete the scheduled task after execution (default: false)
111
185
  * @returns The scheduled task ID
112
186
  */
113
- createTaskInstance(templateId: number, targetId?: number, customData?: Record<string, any>, oneTime?: boolean): Promise<number>;
187
+ createTaskInstance(templateId: number, targetId?: number, customData?: Record<string, any>): Promise<number>;
114
188
  /** Register a tool
115
189
  * @param tool The tool to register
116
190
  */
117
191
  registerTool(tool: Tool): void;
118
192
  /**
119
193
  * Create a new alert for a target
120
- * @param targetId The ID of the target
194
+ * The target is automatically detected from the subdomain parameter
195
+ * @param name The title of the alert
196
+ * @param subdomain The subdomain where the vulnerability was found (can be main domain or subdomain)
197
+ * @param score The severity score (0=Informational, 1=Low, 2=Medium, 3=High, 4=Critical)
198
+ * @param description Detailed description of the alert
199
+ * @param endpoint Specific endpoint/path where the vulnerability was found
200
+ * @param confirmed Whether the vulnerability has been confirmed (default: false)
201
+ * @returns The created alert
202
+ */
203
+ createAlert(name: string, subdomain: string, score: number, description: string, endpoint: string, confirmed?: boolean): Promise<Alert>;
204
+ /**
205
+ * Create a new alert for a target using its ID
121
206
  * @param name The title of the alert
122
- * @param subdomain The subdomain where the vulnerability was found
207
+ * @param targetId The ID of the target
123
208
  * @param score The severity score (0=Informational, 1=Low, 2=Medium, 3=High, 4=Critical)
124
209
  * @param description Detailed description of the alert
125
210
  * @param endpoint Specific endpoint/path where the vulnerability was found
126
211
  * @param confirmed Whether the vulnerability has been confirmed (default: false)
127
- * @returns The created alert ID
212
+ * @returns The created alert
128
213
  */
129
- createAlert(targetId: number, name: string, subdomain: string, score: number, description: string, endpoint: string, confirmed?: boolean): Promise<Alert>;
214
+ createAlert(name: string, targetId: number, score: number, description: string, endpoint: string, confirmed?: boolean): Promise<Alert>;
130
215
  }
131
216
  export interface ModuleLifecycle {
132
217
  run?(api: ServerAPI): Promise<void> | void;
133
218
  stop?(): Promise<void> | void;
134
219
  }
135
220
  export type ModuleFactory = (api: ServerAPI) => ModuleLifecycle | Promise<ModuleLifecycle>;
136
- export { IEventBus, EventSubscription, CoreEvents, EventHandler, } from "./events";
221
+ export * from "./events";
137
222
  declare const _default: any;
138
223
  export default _default;
package/dist/index.js CHANGED
@@ -1 +1,3 @@
1
+ // Re-export EventBus and related types
2
+ export * from "./events";
1
3
  export default {}; // Type-only module for modules to import types during compile
@@ -32,6 +32,7 @@ export interface ScheduledTask {
32
32
  export interface TaskExecution {
33
33
  executionId: number;
34
34
  scheduledTaskId: number;
35
+ templateId?: number;
35
36
  workerId?: number;
36
37
  status: "pending" | "running" | "completed" | "failed";
37
38
  createdAt: Date;
@@ -43,7 +44,7 @@ export interface TaskResult {
43
44
  executionId: number;
44
45
  scheduledTaskId: number;
45
46
  success: boolean;
46
- output?: any;
47
+ output?: string;
47
48
  error?: string;
48
49
  targetId?: number;
49
50
  customData?: Record<string, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepbounty/sdk",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "DeepBounty SDK for module development",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",