-
Notifications
You must be signed in to change notification settings - Fork 3
/
reconAgent.ts
70 lines (62 loc) · 1.86 KB
/
reconAgent.ts
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
import { z } from "zod";
/**
* Represents information gathered by a recon agent. It will be converted into XML format.
* For example:
* ```xml
* <dbQuery query="SELECT COUNT(*) FROM users" time="2021-09-01T12:00:00Z">
* 1700
* </dbQuery>
*/
export interface GatheredInformation {
/**
* The tag of the gathered information. Used to group related information together. e.g. "dbQuery"
*/
tag: string;
/**
* Attributes of the gathered information. e.g. { query: "SELECT COUNT(*) FROM users", time: "2021-09-01T12:00:00Z" }
*/
attrs: {
[attrName: string]: string;
};
/**
* The actual information gathered.
*/
content: string;
}
const GatheredInformationSchema = z.object({
tag: z.string(),
attrs: z.record(z.string()),
content: z.string(),
});
export function isGatheredInformation(
obj: unknown,
): obj is GatheredInformation {
return GatheredInformationSchema.safeParse(obj).success;
}
/**
* Represents a recon agent that can gather information based on the provided options.
*/
export interface ReconAgent<T> {
/**
* The name of the recon agent, which will be used as an identifier in the configuration.
* Each agent must provide a unique name.
*/
readonly name: string;
/**
* A brief description of what the recon agent does.
* Each agent must provide a description.
*/
readonly description: string;
/**
* Gathers information based on the provided options.
* Each subclass must provide its own implementation of this method.
*
* @param options - The options specifying what information to gather.
* @returns A promise that resolves to the gathered information as a string.
*/
gather(options: T): Promise<GatheredInformation[]>;
/**
* Converts a string representation of the options (used in the CLI) into the appropriate type for the agent..
*/
parseOptions?(options: string): T;
}