@j3r3mcdev/oast-server 1.1.10 → 1.1.12
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/core/event.normalizer.d.ts +2 -1
- package/dist/core/event.normalizer.js +19 -2
- package/dist/core/router.d.ts +1 -0
- package/dist/core/router.js +3 -3
- package/dist/listeners/smtp/smtp.listener.js +20 -6
- package/dist/types/event.types.d.ts +16 -1
- package/package.json +1 -1
- package/src/core/event.normalizer.ts +24 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RawEvent, RawDnsEvent, RawSmtpEvent, RawTcpEvent, RawSsrfEvent, NormalizedHttpEvent, NormalizedDnsEvent, NormalizedSmtpEvent, NormalizedTcpEvent, NormalizedSsrfEvent, NormalizedWebhookEvent,
|
|
1
|
+
import { RawEvent, RawDnsEvent, RawSmtpEvent, RawTcpEvent, RawSsrfEvent, RawWebhookEvent, RawWebSocketEvent, RawApiEvent, NormalizedHttpEvent, NormalizedDnsEvent, NormalizedSmtpEvent, NormalizedTcpEvent, NormalizedSsrfEvent, NormalizedWebhookEvent, NormalizedWebSocketEvent, NormalizedApiEvent } from "../types/event.types";
|
|
2
2
|
export declare class EventNormalizer {
|
|
3
3
|
static normalizeDns(event: RawDnsEvent): NormalizedDnsEvent;
|
|
4
4
|
static normalizeHttp(event: RawEvent): NormalizedHttpEvent;
|
|
@@ -7,4 +7,5 @@ export declare class EventNormalizer {
|
|
|
7
7
|
static normalizeSsrf(raw: RawSsrfEvent): NormalizedSsrfEvent;
|
|
8
8
|
static normalizeWebhook(raw: RawWebhookEvent): NormalizedWebhookEvent;
|
|
9
9
|
static normalizeWebSocket(raw: RawWebSocketEvent): NormalizedWebSocketEvent;
|
|
10
|
+
static normalizeApi(raw: RawApiEvent): NormalizedApiEvent;
|
|
10
11
|
}
|
|
@@ -95,7 +95,7 @@ class EventNormalizer {
|
|
|
95
95
|
}
|
|
96
96
|
//
|
|
97
97
|
// -------------------------
|
|
98
|
-
//
|
|
98
|
+
// WEBHOOK
|
|
99
99
|
// -------------------------
|
|
100
100
|
//
|
|
101
101
|
static normalizeWebhook(raw) {
|
|
@@ -110,7 +110,7 @@ class EventNormalizer {
|
|
|
110
110
|
}
|
|
111
111
|
//
|
|
112
112
|
// -------------------------
|
|
113
|
-
//
|
|
113
|
+
// WEBSOCKET
|
|
114
114
|
// -------------------------
|
|
115
115
|
//
|
|
116
116
|
static normalizeWebSocket(raw) {
|
|
@@ -122,5 +122,22 @@ class EventNormalizer {
|
|
|
122
122
|
message: raw.message,
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
+
//
|
|
126
|
+
// -------------------------
|
|
127
|
+
// API (NOUVEAU)
|
|
128
|
+
// -------------------------
|
|
129
|
+
//
|
|
130
|
+
static normalizeApi(raw) {
|
|
131
|
+
return {
|
|
132
|
+
id: id_generator_1.IdGenerator.generate(),
|
|
133
|
+
type: "api",
|
|
134
|
+
timestamp: Date.now(),
|
|
135
|
+
sourceIp: raw.ip,
|
|
136
|
+
request: {
|
|
137
|
+
body: raw.body,
|
|
138
|
+
},
|
|
139
|
+
raw: raw.raw,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
125
142
|
}
|
|
126
143
|
exports.EventNormalizer = EventNormalizer;
|
package/dist/core/router.d.ts
CHANGED
package/dist/core/router.js
CHANGED
|
@@ -9,11 +9,8 @@ class CoreRouter {
|
|
|
9
9
|
this.hooks = options.hooks ?? [];
|
|
10
10
|
}
|
|
11
11
|
async dispatch(event) {
|
|
12
|
-
// 1. Log
|
|
13
12
|
this.logger.info(`Event received (${event.type})`, { id: event.id });
|
|
14
|
-
// 2. Save
|
|
15
13
|
await this.storage.save(event);
|
|
16
|
-
// 3. Hooks
|
|
17
14
|
for (const hook of this.hooks) {
|
|
18
15
|
try {
|
|
19
16
|
await hook(event);
|
|
@@ -23,6 +20,9 @@ class CoreRouter {
|
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
22
|
}
|
|
23
|
+
async route(event) {
|
|
24
|
+
return this.dispatch(event);
|
|
25
|
+
}
|
|
26
26
|
addHook(hook) {
|
|
27
27
|
this.hooks.push(hook);
|
|
28
28
|
}
|
|
@@ -13,10 +13,15 @@ class SmtpListener {
|
|
|
13
13
|
this.logger.info("SMTP Listener started");
|
|
14
14
|
this.server.onData = async (stream, session, callback) => {
|
|
15
15
|
let chunks = [];
|
|
16
|
-
|
|
16
|
+
const onData = (chunk) => {
|
|
17
17
|
chunks.push(chunk.toString());
|
|
18
|
-
}
|
|
19
|
-
|
|
18
|
+
};
|
|
19
|
+
const onEnd = async () => {
|
|
20
|
+
// 🔥 Compatible Node + Jest + mocks
|
|
21
|
+
if (stream.removeListener) {
|
|
22
|
+
stream.removeListener("data", onData);
|
|
23
|
+
stream.removeListener("end", onEnd);
|
|
24
|
+
}
|
|
20
25
|
const body = chunks.join("");
|
|
21
26
|
let event;
|
|
22
27
|
try {
|
|
@@ -37,13 +42,22 @@ class SmtpListener {
|
|
|
37
42
|
await this.router.dispatch(event);
|
|
38
43
|
callback(null);
|
|
39
44
|
}
|
|
40
|
-
catch
|
|
41
|
-
callback(new Error("dispatch failed"));
|
|
45
|
+
catch {
|
|
46
|
+
callback(new Error("dispatch failed"));
|
|
42
47
|
}
|
|
43
|
-
|
|
48
|
+
// 🔥 Empêche les fuites de stream
|
|
49
|
+
if (stream.destroy) {
|
|
50
|
+
stream.destroy();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
stream.on("data", onData);
|
|
54
|
+
stream.on("end", onEnd);
|
|
44
55
|
};
|
|
45
56
|
}
|
|
46
57
|
async stop() {
|
|
58
|
+
if (this.server) {
|
|
59
|
+
this.server.onData = undefined;
|
|
60
|
+
}
|
|
47
61
|
if (this.server?.close) {
|
|
48
62
|
this.server.close();
|
|
49
63
|
this.logger.info("SMTP Listener stopped");
|
|
@@ -46,6 +46,11 @@ export interface RawWebSocketEvent {
|
|
|
46
46
|
message: string;
|
|
47
47
|
raw: any;
|
|
48
48
|
}
|
|
49
|
+
export interface RawApiEvent {
|
|
50
|
+
ip: string;
|
|
51
|
+
body: any;
|
|
52
|
+
raw: any;
|
|
53
|
+
}
|
|
49
54
|
export interface NormalizedHttpEvent {
|
|
50
55
|
id: string;
|
|
51
56
|
type: "http";
|
|
@@ -115,4 +120,14 @@ export interface NormalizedWebSocketEvent {
|
|
|
115
120
|
sourceIp: string;
|
|
116
121
|
message: string;
|
|
117
122
|
}
|
|
118
|
-
export
|
|
123
|
+
export interface NormalizedApiEvent {
|
|
124
|
+
id: string;
|
|
125
|
+
type: "api";
|
|
126
|
+
timestamp: number;
|
|
127
|
+
sourceIp: string;
|
|
128
|
+
request: {
|
|
129
|
+
body: any;
|
|
130
|
+
};
|
|
131
|
+
raw: any;
|
|
132
|
+
}
|
|
133
|
+
export type AnyNormalizedEvent = NormalizedHttpEvent | NormalizedDnsEvent | NormalizedSmtpEvent | NormalizedTcpEvent | NormalizedSsrfEvent | NormalizedWebhookEvent | NormalizedWebSocketEvent | NormalizedApiEvent;
|
package/package.json
CHANGED
|
@@ -4,15 +4,17 @@ import {
|
|
|
4
4
|
RawSmtpEvent,
|
|
5
5
|
RawTcpEvent,
|
|
6
6
|
RawSsrfEvent,
|
|
7
|
+
RawWebhookEvent,
|
|
8
|
+
RawWebSocketEvent,
|
|
9
|
+
RawApiEvent,
|
|
7
10
|
NormalizedHttpEvent,
|
|
8
11
|
NormalizedDnsEvent,
|
|
9
12
|
NormalizedSmtpEvent,
|
|
10
13
|
NormalizedTcpEvent,
|
|
11
14
|
NormalizedSsrfEvent,
|
|
12
15
|
NormalizedWebhookEvent,
|
|
13
|
-
RawWebhookEvent,
|
|
14
16
|
NormalizedWebSocketEvent,
|
|
15
|
-
|
|
17
|
+
NormalizedApiEvent,
|
|
16
18
|
} from "../types/event.types";
|
|
17
19
|
|
|
18
20
|
import { IdGenerator } from "./id-generator";
|
|
@@ -116,7 +118,7 @@ export class EventNormalizer {
|
|
|
116
118
|
|
|
117
119
|
//
|
|
118
120
|
// -------------------------
|
|
119
|
-
//
|
|
121
|
+
// WEBHOOK
|
|
120
122
|
// -------------------------
|
|
121
123
|
//
|
|
122
124
|
static normalizeWebhook(raw: RawWebhookEvent): NormalizedWebhookEvent {
|
|
@@ -132,7 +134,7 @@ export class EventNormalizer {
|
|
|
132
134
|
|
|
133
135
|
//
|
|
134
136
|
// -------------------------
|
|
135
|
-
//
|
|
137
|
+
// WEBSOCKET
|
|
136
138
|
// -------------------------
|
|
137
139
|
//
|
|
138
140
|
static normalizeWebSocket(raw: RawWebSocketEvent): NormalizedWebSocketEvent {
|
|
@@ -144,4 +146,22 @@ export class EventNormalizer {
|
|
|
144
146
|
message: raw.message,
|
|
145
147
|
};
|
|
146
148
|
}
|
|
149
|
+
|
|
150
|
+
//
|
|
151
|
+
// -------------------------
|
|
152
|
+
// API (NOUVEAU)
|
|
153
|
+
// -------------------------
|
|
154
|
+
//
|
|
155
|
+
static normalizeApi(raw: RawApiEvent): NormalizedApiEvent {
|
|
156
|
+
return {
|
|
157
|
+
id: IdGenerator.generate(),
|
|
158
|
+
type: "api",
|
|
159
|
+
timestamp: Date.now(),
|
|
160
|
+
sourceIp: raw.ip,
|
|
161
|
+
request: {
|
|
162
|
+
body: raw.body,
|
|
163
|
+
},
|
|
164
|
+
raw: raw.raw,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
147
167
|
}
|