@deepbounty/sdk 1.1.9 → 1.2.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/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
@@ -13,11 +29,15 @@ export interface CoreEvents {
13
29
  context: TrafficContext;
14
30
  html: string;
15
31
  };
32
+ "target:created": Target;
33
+ "target:updated": Target;
34
+ "target:deleted": Target;
16
35
  }
17
36
  /**
18
37
  * Event handler function signature
38
+ * Receives event data wrapped with metadata about its origin
19
39
  */
20
- export type EventHandler<T = any> = (data: T) => void | Promise<void>;
40
+ export type EventHandler<T = any> = (event: EventMetadata<T>) => void | Promise<void>;
21
41
  /**
22
42
  * Subscription object returned when subscribing to events
23
43
  */
@@ -37,7 +57,7 @@ export interface IEventBus {
37
57
  * Emit an event with data
38
58
  * Non-blocking, async execution with rate limiting and error isolation
39
59
  * @param event - Event name
40
- * @param data - Event data
60
+ * @param data - Event data (will be wrapped with origin metadata internally)
41
61
  */
42
62
  emit<K extends keyof CoreEvents>(event: K, data: CoreEvents[K]): void;
43
63
  emit<T = any>(event: string, data: T): void;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Alert, ModuleSetting, TaskContent, TaskResult, Tool } from "./types";
1
+ import { Alert, ModuleSetting, TaskContent, TaskResult, Tool, ModuleCallback, CallbackHandler, CreateCallbackOptions } from "./types";
2
2
  import { IEventBus } from "./events";
3
3
  export interface Logger {
4
4
  info: (...args: any[]) => void;
@@ -77,22 +77,143 @@ 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
+ }
151
+ /**
152
+ * CallbackAPI provides external callback functionality for modules.
153
+ * Used for out-of-band exfiltration detection.
154
+ */
155
+ export interface CallbackAPI {
156
+ /**
157
+ * Create a new callback with auto-generated UUID
158
+ * @param name Human-readable name for the callback
159
+ * @param metadata Arbitrary data to associate with this callback (e.g., target info)
160
+ * @param options Optional configuration (expiration, multiple triggers)
161
+ * @returns Object containing the UUID and full callback URL
162
+ */
163
+ create(name: string, metadata?: Record<string, any>, options?: CreateCallbackOptions): Promise<{
164
+ uuid: string;
165
+ url: string;
166
+ }>;
167
+ /**
168
+ * Register a handler for when callbacks are triggered
169
+ * Only one handler per module - calling again replaces the previous handler
170
+ * @param handler Function called when any callback for this module is triggered
171
+ */
172
+ onTrigger(handler: CallbackHandler): void;
173
+ /**
174
+ * Get a callback by UUID
175
+ * @param uuid The callback UUID
176
+ * @returns The callback data or null if not found
177
+ */
178
+ get(uuid: string): Promise<ModuleCallback | null>;
179
+ /**
180
+ * List all callbacks registered by this module
181
+ * @param includeExpired Include expired callbacks (default: false)
182
+ * @returns Array of callbacks
183
+ */
184
+ list(includeExpired?: boolean): Promise<ModuleCallback[]>;
185
+ /**
186
+ * Delete a callback by UUID
187
+ * @param uuid The callback UUID
188
+ * @returns true if deleted, false if not found
189
+ */
190
+ delete(uuid: string): Promise<boolean>;
191
+ /**
192
+ * Delete all callbacks for this module
193
+ * @returns Number of callbacks deleted
194
+ */
195
+ deleteAll(): Promise<number>;
196
+ }
80
197
  export interface ServerAPI {
81
198
  version: string;
82
199
  logger: Logger;
83
200
  config: ConfigAPI;
84
201
  storage: StorageAPI;
202
+ files: FilesAPI;
85
203
  events: IEventBus;
204
+ callbacks: CallbackAPI;
205
+ /** Check if a hostname is in scope based on targets_subdomains */
206
+ isHostnameInScope(hostname: string): Promise<boolean>;
86
207
  /**
87
208
  * Register a task template that can be scheduled for all targets
88
209
  * @param uniqueKey Unique identifier for this task within the module (e.g., "subdomain-scan")
89
210
  * @param name Friendly name for the task
90
211
  * @param description Task description
91
212
  * @param taskContent The task content including commands and tools
92
- * @param interval Interval in seconds between task executions
213
+ * @param interval Interval in seconds between task executions. For CUSTOM mode: if <= 0, no automatic scheduling (manual mode only)
93
214
  * @param schedulingType How to schedule tasks: "TARGET_BASED" (one per target), "GLOBAL" (single instance), or "CUSTOM" (callback-based)
94
215
  * @param onComplete Optional callback executed when a task instance completes
95
- * @param onSchedule Optional callback for CUSTOM mode, invoked at interval to create instances
216
+ * @param onSchedule Optional callback for CUSTOM mode, invoked at interval to create instances (not called if interval <= 0)
96
217
  * @returns The ID of the registered task template
97
218
  */
98
219
  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>;
@@ -117,22 +238,33 @@ export interface ServerAPI {
117
238
  registerTool(tool: Tool): void;
118
239
  /**
119
240
  * Create a new alert for a target
120
- * @param targetId The ID of the target
241
+ * The target is automatically detected from the subdomain parameter
242
+ * @param name The title of the alert
243
+ * @param subdomain The subdomain where the vulnerability was found (can be main domain or subdomain)
244
+ * @param score The severity score (0=Informational, 1=Low, 2=Medium, 3=High, 4=Critical)
245
+ * @param description Detailed description of the alert
246
+ * @param endpoint Specific endpoint/path where the vulnerability was found
247
+ * @param confirmed Whether the vulnerability has been confirmed (default: false)
248
+ * @returns The created alert
249
+ */
250
+ createAlert(name: string, subdomain: string, score: number, description: string, endpoint: string, confirmed?: boolean): Promise<Alert>;
251
+ /**
252
+ * Create a new alert for a target using its ID
121
253
  * @param name The title of the alert
122
- * @param subdomain The subdomain where the vulnerability was found
254
+ * @param targetId The ID of the target
123
255
  * @param score The severity score (0=Informational, 1=Low, 2=Medium, 3=High, 4=Critical)
124
256
  * @param description Detailed description of the alert
125
257
  * @param endpoint Specific endpoint/path where the vulnerability was found
126
258
  * @param confirmed Whether the vulnerability has been confirmed (default: false)
127
- * @returns The created alert ID
259
+ * @returns The created alert
128
260
  */
129
- createAlert(targetId: number, name: string, subdomain: string, score: number, description: string, endpoint: string, confirmed?: boolean): Promise<Alert>;
261
+ createAlert(name: string, targetId: number, score: number, description: string, endpoint: string, confirmed?: boolean): Promise<Alert>;
130
262
  }
131
263
  export interface ModuleLifecycle {
132
264
  run?(api: ServerAPI): Promise<void> | void;
133
265
  stop?(): Promise<void> | void;
134
266
  }
135
267
  export type ModuleFactory = (api: ServerAPI) => ModuleLifecycle | Promise<ModuleLifecycle>;
136
- export { IEventBus, EventSubscription, CoreEvents, EventHandler, } from "./events";
268
+ export * from "./events";
137
269
  declare const _default: any;
138
270
  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
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Callback types for external exfiltration detection
3
+ * Used by modules to register callbacks that can be triggered by external HTTP requests
4
+ */
5
+ /**
6
+ * Options for creating a callback
7
+ */
8
+ export interface CreateCallbackOptions {
9
+ /** Time-to-live in seconds. If not set, the callback never expires */
10
+ expiresIn?: number;
11
+ /** Whether the callback can be triggered multiple times (default: true) */
12
+ allowMultipleTriggers?: boolean;
13
+ }
14
+ /**
15
+ * Data stored with a callback
16
+ */
17
+ export interface ModuleCallback {
18
+ /** Unique identifier (UUID) for the callback */
19
+ uuid: string;
20
+ /** Module that registered this callback */
21
+ moduleId: string;
22
+ /** Human-readable name for the callback */
23
+ name: string;
24
+ /** Arbitrary metadata associated with this callback (e.g., target info) */
25
+ metadata: Record<string, any>;
26
+ /** When the callback was created */
27
+ createdAt: string;
28
+ /** When the callback expires (null = never) */
29
+ expiresAt: string | null;
30
+ /** Whether multiple triggers are allowed */
31
+ allowMultipleTriggers: boolean;
32
+ /** Number of times this callback has been triggered */
33
+ triggerCount: number;
34
+ /** When the callback was last triggered (null = never) */
35
+ lastTriggeredAt: string | null;
36
+ }
37
+ /**
38
+ * Data received when a callback is triggered
39
+ */
40
+ export interface CallbackTriggerData {
41
+ /** The request body sent by the external caller */
42
+ body: Record<string, any>;
43
+ /** HTTP headers from the request */
44
+ headers: Record<string, string>;
45
+ /** IP address of the caller */
46
+ remoteIp: string;
47
+ /** User agent of the caller */
48
+ userAgent: string;
49
+ /** When this trigger occurred */
50
+ triggeredAt: string;
51
+ }
52
+ /**
53
+ * Handler function called when a callback is triggered
54
+ */
55
+ export type CallbackHandler = (callback: ModuleCallback, triggerData: CallbackTriggerData) => void | Promise<void>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Callback types for external exfiltration detection
3
+ * Used by modules to register callbacks that can be triggered by external HTTP requests
4
+ */
5
+ export {};
@@ -6,3 +6,4 @@ export * from "./websockets.js";
6
6
  export * from "./tasks.js";
7
7
  export * from "./tools.js";
8
8
  export * from "./notifications.js";
9
+ export * from "./callbacks.js";
@@ -6,3 +6,4 @@ export * from "./websockets.js";
6
6
  export * from "./tasks.js";
7
7
  export * from "./tools.js";
8
8
  export * from "./notifications.js";
9
+ export * from "./callbacks.js";
@@ -44,7 +44,7 @@ export interface TaskResult {
44
44
  executionId: number;
45
45
  scheduledTaskId: number;
46
46
  success: boolean;
47
- output?: any;
47
+ output?: string;
48
48
  error?: string;
49
49
  targetId?: number;
50
50
  customData?: Record<string, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepbounty/sdk",
3
- "version": "1.1.9",
3
+ "version": "1.2.1",
4
4
  "description": "DeepBounty SDK for module development",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",