dia-gov commited on
Commit
001ba83
·
verified ·
1 Parent(s): 65a9299

Upload 10 files

Browse files
ai/ai_simulations.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ import logging
3
+
4
+ class OffensiveSimulation:
5
+ def __init__(self):
6
+ self.scenarios = [
7
+ "SQL Injection",
8
+ "Cross-Site Scripting (XSS)",
9
+ "Phishing Attack",
10
+ "Privilege Escalation",
11
+ "DDoS Attack"
12
+ ]
13
+
14
+ def simulate_attack(self):
15
+ if not self.scenarios:
16
+ logging.error("Error: No scenarios available for simulation.")
17
+ return
18
+
19
+ try:
20
+ if not self.scenarios:
21
+ raise IndexError("No scenarios available.")
22
+ scenario = random.choice(self.scenarios)
23
+ print(f"[SIMULATION] Executing simulated attack: {scenario}")
24
+
25
+ except IndexError as e:
26
+ logging.error(f"Error during simulation: {e}")
27
+
28
+ except Exception as e:
29
+ logging.error(f"Error during simulation: {e}")
30
+
31
+ if __name__ == "__main__":
32
+ logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')
33
+ simulation = OffensiveSimulation()
34
+ simulation.simulate_attack()
analytics/behavioral_analysis.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def detect_anomalies(user_data):
2
+ anomalies = []
3
+ for data in user_data:
4
+ try:
5
+ if data["activity_level"] > 100:
6
+ anomalies.append(data["user_id"])
7
+ except KeyError:
8
+ print(f"Error: Missing 'activity_level' key in user data: {data}")
9
+ return anomalies
10
+
11
+ if __name__ == "__main__":
12
+ sample_data = [{"user_id": "user1", "activity_level": 120}, {"user_id": "user2", "activity_level": 80}]
13
+ anomalies = detect_anomalies(sample_data)
14
+ print(f"Anomalies Detected: {anomalies}")
analytics/behavioral_analytics.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+
2
+ def detect_behavioral_anomalies(user_data):
3
+ print(f"Analyzing user behavior for anomalies: {user_data}")
4
+ return {"anomalies_detected": True, "details": ["Unusual login times", "High data upload"]}
5
+
6
+ if __name__ == "__main__":
7
+ anomalies = detect_behavioral_anomalies({"user": "john.doe", "activity": "login at 3 AM"})
8
+ print(f"Anomalies: {anomalies}")
ansi-styles/index.d.ts ADDED
@@ -0,0 +1,345 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ declare type CSSColor =
2
+ | 'aliceblue'
3
+ | 'antiquewhite'
4
+ | 'aqua'
5
+ | 'aquamarine'
6
+ | 'azure'
7
+ | 'beige'
8
+ | 'bisque'
9
+ | 'black'
10
+ | 'blanchedalmond'
11
+ | 'blue'
12
+ | 'blueviolet'
13
+ | 'brown'
14
+ | 'burlywood'
15
+ | 'cadetblue'
16
+ | 'chartreuse'
17
+ | 'chocolate'
18
+ | 'coral'
19
+ | 'cornflowerblue'
20
+ | 'cornsilk'
21
+ | 'crimson'
22
+ | 'cyan'
23
+ | 'darkblue'
24
+ | 'darkcyan'
25
+ | 'darkgoldenrod'
26
+ | 'darkgray'
27
+ | 'darkgreen'
28
+ | 'darkgrey'
29
+ | 'darkkhaki'
30
+ | 'darkmagenta'
31
+ | 'darkolivegreen'
32
+ | 'darkorange'
33
+ | 'darkorchid'
34
+ | 'darkred'
35
+ | 'darksalmon'
36
+ | 'darkseagreen'
37
+ | 'darkslateblue'
38
+ | 'darkslategray'
39
+ | 'darkslategrey'
40
+ | 'darkturquoise'
41
+ | 'darkviolet'
42
+ | 'deeppink'
43
+ | 'deepskyblue'
44
+ | 'dimgray'
45
+ | 'dimgrey'
46
+ | 'dodgerblue'
47
+ | 'firebrick'
48
+ | 'floralwhite'
49
+ | 'forestgreen'
50
+ | 'fuchsia'
51
+ | 'gainsboro'
52
+ | 'ghostwhite'
53
+ | 'gold'
54
+ | 'goldenrod'
55
+ | 'gray'
56
+ | 'green'
57
+ | 'greenyellow'
58
+ | 'grey'
59
+ | 'honeydew'
60
+ | 'hotpink'
61
+ | 'indianred'
62
+ | 'indigo'
63
+ | 'ivory'
64
+ | 'khaki'
65
+ | 'lavender'
66
+ | 'lavenderblush'
67
+ | 'lawngreen'
68
+ | 'lemonchiffon'
69
+ | 'lightblue'
70
+ | 'lightcoral'
71
+ | 'lightcyan'
72
+ | 'lightgoldenrodyellow'
73
+ | 'lightgray'
74
+ | 'lightgreen'
75
+ | 'lightgrey'
76
+ | 'lightpink'
77
+ | 'lightsalmon'
78
+ | 'lightseagreen'
79
+ | 'lightskyblue'
80
+ | 'lightslategray'
81
+ | 'lightslategrey'
82
+ | 'lightsteelblue'
83
+ | 'lightyellow'
84
+ | 'lime'
85
+ | 'limegreen'
86
+ | 'linen'
87
+ | 'magenta'
88
+ | 'maroon'
89
+ | 'mediumaquamarine'
90
+ | 'mediumblue'
91
+ | 'mediumorchid'
92
+ | 'mediumpurple'
93
+ | 'mediumseagreen'
94
+ | 'mediumslateblue'
95
+ | 'mediumspringgreen'
96
+ | 'mediumturquoise'
97
+ | 'mediumvioletred'
98
+ | 'midnightblue'
99
+ | 'mintcream'
100
+ | 'mistyrose'
101
+ | 'moccasin'
102
+ | 'navajowhite'
103
+ | 'navy'
104
+ | 'oldlace'
105
+ | 'olive'
106
+ | 'olivedrab'
107
+ | 'orange'
108
+ | 'orangered'
109
+ | 'orchid'
110
+ | 'palegoldenrod'
111
+ | 'palegreen'
112
+ | 'paleturquoise'
113
+ | 'palevioletred'
114
+ | 'papayawhip'
115
+ | 'peachpuff'
116
+ | 'peru'
117
+ | 'pink'
118
+ | 'plum'
119
+ | 'powderblue'
120
+ | 'purple'
121
+ | 'rebeccapurple'
122
+ | 'red'
123
+ | 'rosybrown'
124
+ | 'royalblue'
125
+ | 'saddlebrown'
126
+ | 'salmon'
127
+ | 'sandybrown'
128
+ | 'seagreen'
129
+ | 'seashell'
130
+ | 'sienna'
131
+ | 'silver'
132
+ | 'skyblue'
133
+ | 'slateblue'
134
+ | 'slategray'
135
+ | 'slategrey'
136
+ | 'snow'
137
+ | 'springgreen'
138
+ | 'steelblue'
139
+ | 'tan'
140
+ | 'teal'
141
+ | 'thistle'
142
+ | 'tomato'
143
+ | 'turquoise'
144
+ | 'violet'
145
+ | 'wheat'
146
+ | 'white'
147
+ | 'whitesmoke'
148
+ | 'yellow'
149
+ | 'yellowgreen';
150
+
151
+ declare namespace ansiStyles {
152
+ interface ColorConvert {
153
+ /**
154
+ The RGB color space.
155
+
156
+ @param red - (`0`-`255`)
157
+ @param green - (`0`-`255`)
158
+ @param blue - (`0`-`255`)
159
+ */
160
+ rgb(red: number, green: number, blue: number): string;
161
+
162
+ /**
163
+ The RGB HEX color space.
164
+
165
+ @param hex - A hexadecimal string containing RGB data.
166
+ */
167
+ hex(hex: string): string;
168
+
169
+ /**
170
+ @param keyword - A CSS color name.
171
+ */
172
+ keyword(keyword: CSSColor): string;
173
+
174
+ /**
175
+ The HSL color space.
176
+
177
+ @param hue - (`0`-`360`)
178
+ @param saturation - (`0`-`100`)
179
+ @param lightness - (`0`-`100`)
180
+ */
181
+ hsl(hue: number, saturation: number, lightness: number): string;
182
+
183
+ /**
184
+ The HSV color space.
185
+
186
+ @param hue - (`0`-`360`)
187
+ @param saturation - (`0`-`100`)
188
+ @param value - (`0`-`100`)
189
+ */
190
+ hsv(hue: number, saturation: number, value: number): string;
191
+
192
+ /**
193
+ The HSV color space.
194
+
195
+ @param hue - (`0`-`360`)
196
+ @param whiteness - (`0`-`100`)
197
+ @param blackness - (`0`-`100`)
198
+ */
199
+ hwb(hue: number, whiteness: number, blackness: number): string;
200
+
201
+ /**
202
+ Use a [4-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4-bit) to set text color.
203
+ */
204
+ ansi(ansi: number): string;
205
+
206
+ /**
207
+ Use an [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
208
+ */
209
+ ansi256(ansi: number): string;
210
+ }
211
+
212
+ interface CSPair {
213
+ /**
214
+ The ANSI terminal control sequence for starting this style.
215
+ */
216
+ readonly open: string;
217
+
218
+ /**
219
+ The ANSI terminal control sequence for ending this style.
220
+ */
221
+ readonly close: string;
222
+ }
223
+
224
+ interface ColorBase {
225
+ readonly ansi: ColorConvert;
226
+ readonly ansi256: ColorConvert;
227
+ readonly ansi16m: ColorConvert;
228
+
229
+ /**
230
+ The ANSI terminal control sequence for ending this color.
231
+ */
232
+ readonly close: string;
233
+ }
234
+
235
+ interface Modifier {
236
+ /**
237
+ Resets the current color chain.
238
+ */
239
+ readonly reset: CSPair;
240
+
241
+ /**
242
+ Make text bold.
243
+ */
244
+ readonly bold: CSPair;
245
+
246
+ /**
247
+ Emitting only a small amount of light.
248
+ */
249
+ readonly dim: CSPair;
250
+
251
+ /**
252
+ Make text italic. (Not widely supported)
253
+ */
254
+ readonly italic: CSPair;
255
+
256
+ /**
257
+ Make text underline. (Not widely supported)
258
+ */
259
+ readonly underline: CSPair;
260
+
261
+ /**
262
+ Inverse background and foreground colors.
263
+ */
264
+ readonly inverse: CSPair;
265
+
266
+ /**
267
+ Prints the text, but makes it invisible.
268
+ */
269
+ readonly hidden: CSPair;
270
+
271
+ /**
272
+ Puts a horizontal line through the center of the text. (Not widely supported)
273
+ */
274
+ readonly strikethrough: CSPair;
275
+ }
276
+
277
+ interface ForegroundColor {
278
+ readonly black: CSPair;
279
+ readonly red: CSPair;
280
+ readonly green: CSPair;
281
+ readonly yellow: CSPair;
282
+ readonly blue: CSPair;
283
+ readonly cyan: CSPair;
284
+ readonly magenta: CSPair;
285
+ readonly white: CSPair;
286
+
287
+ /**
288
+ Alias for `blackBright`.
289
+ */
290
+ readonly gray: CSPair;
291
+
292
+ /**
293
+ Alias for `blackBright`.
294
+ */
295
+ readonly grey: CSPair;
296
+
297
+ readonly blackBright: CSPair;
298
+ readonly redBright: CSPair;
299
+ readonly greenBright: CSPair;
300
+ readonly yellowBright: CSPair;
301
+ readonly blueBright: CSPair;
302
+ readonly cyanBright: CSPair;
303
+ readonly magentaBright: CSPair;
304
+ readonly whiteBright: CSPair;
305
+ }
306
+
307
+ interface BackgroundColor {
308
+ readonly bgBlack: CSPair;
309
+ readonly bgRed: CSPair;
310
+ readonly bgGreen: CSPair;
311
+ readonly bgYellow: CSPair;
312
+ readonly bgBlue: CSPair;
313
+ readonly bgCyan: CSPair;
314
+ readonly bgMagenta: CSPair;
315
+ readonly bgWhite: CSPair;
316
+
317
+ /**
318
+ Alias for `bgBlackBright`.
319
+ */
320
+ readonly bgGray: CSPair;
321
+
322
+ /**
323
+ Alias for `bgBlackBright`.
324
+ */
325
+ readonly bgGrey: CSPair;
326
+
327
+ readonly bgBlackBright: CSPair;
328
+ readonly bgRedBright: CSPair;
329
+ readonly bgGreenBright: CSPair;
330
+ readonly bgYellowBright: CSPair;
331
+ readonly bgBlueBright: CSPair;
332
+ readonly bgCyanBright: CSPair;
333
+ readonly bgMagentaBright: CSPair;
334
+ readonly bgWhiteBright: CSPair;
335
+ }
336
+ }
337
+
338
+ declare const ansiStyles: {
339
+ readonly modifier: ansiStyles.Modifier;
340
+ readonly color: ansiStyles.ForegroundColor & ansiStyles.ColorBase;
341
+ readonly bgColor: ansiStyles.BackgroundColor & ansiStyles.ColorBase;
342
+ readonly codes: ReadonlyMap<number, number>;
343
+ } & ansiStyles.BackgroundColor & ansiStyles.ForegroundColor & ansiStyles.Modifier;
344
+
345
+ export = ansiStyles;
ansi-styles/index.js ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ const wrapAnsi16 = (fn, offset) => (...args) => {
4
+ const code = fn(...args);
5
+ return `\u001B[${code + offset}m`;
6
+ };
7
+
8
+ const wrapAnsi256 = (fn, offset) => (...args) => {
9
+ const code = fn(...args);
10
+ return `\u001B[${38 + offset};5;${code}m`;
11
+ };
12
+
13
+ const wrapAnsi16m = (fn, offset) => (...args) => {
14
+ const rgb = fn(...args);
15
+ return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
16
+ };
17
+
18
+ const ansi2ansi = n => n;
19
+ const rgb2rgb = (r, g, b) => [r, g, b];
20
+
21
+ const setLazyProperty = (object, property, get) => {
22
+ Object.defineProperty(object, property, {
23
+ get: () => {
24
+ const value = get();
25
+
26
+ Object.defineProperty(object, property, {
27
+ value,
28
+ enumerable: true,
29
+ configurable: true
30
+ });
31
+
32
+ return value;
33
+ },
34
+ enumerable: true,
35
+ configurable: true
36
+ });
37
+ };
38
+
39
+ /** @type {typeof import('color-convert')} */
40
+ let colorConvert;
41
+ const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
42
+ if (colorConvert === undefined) {
43
+ colorConvert = require('color-convert');
44
+ }
45
+
46
+ const offset = isBackground ? 10 : 0;
47
+ const styles = {};
48
+
49
+ for (const [sourceSpace, suite] of Object.entries(colorConvert)) {
50
+ const name = sourceSpace === 'ansi16' ? 'ansi' : sourceSpace;
51
+ if (sourceSpace === targetSpace) {
52
+ styles[name] = wrap(identity, offset);
53
+ } else if (typeof suite === 'object') {
54
+ styles[name] = wrap(suite[targetSpace], offset);
55
+ }
56
+ }
57
+
58
+ return styles;
59
+ };
60
+
61
+ function assembleStyles() {
62
+ const codes = new Map();
63
+ const styles = {
64
+ modifier: {
65
+ reset: [0, 0],
66
+ // 21 isn't widely supported and 22 does the same thing
67
+ bold: [1, 22],
68
+ dim: [2, 22],
69
+ italic: [3, 23],
70
+ underline: [4, 24],
71
+ inverse: [7, 27],
72
+ hidden: [8, 28],
73
+ strikethrough: [9, 29]
74
+ },
75
+ color: {
76
+ black: [30, 39],
77
+ red: [31, 39],
78
+ green: [32, 39],
79
+ yellow: [33, 39],
80
+ blue: [34, 39],
81
+ magenta: [35, 39],
82
+ cyan: [36, 39],
83
+ white: [37, 39],
84
+
85
+ // Bright color
86
+ blackBright: [90, 39],
87
+ redBright: [91, 39],
88
+ greenBright: [92, 39],
89
+ yellowBright: [93, 39],
90
+ blueBright: [94, 39],
91
+ magentaBright: [95, 39],
92
+ cyanBright: [96, 39],
93
+ whiteBright: [97, 39]
94
+ },
95
+ bgColor: {
96
+ bgBlack: [40, 49],
97
+ bgRed: [41, 49],
98
+ bgGreen: [42, 49],
99
+ bgYellow: [43, 49],
100
+ bgBlue: [44, 49],
101
+ bgMagenta: [45, 49],
102
+ bgCyan: [46, 49],
103
+ bgWhite: [47, 49],
104
+
105
+ // Bright color
106
+ bgBlackBright: [100, 49],
107
+ bgRedBright: [101, 49],
108
+ bgGreenBright: [102, 49],
109
+ bgYellowBright: [103, 49],
110
+ bgBlueBright: [104, 49],
111
+ bgMagentaBright: [105, 49],
112
+ bgCyanBright: [106, 49],
113
+ bgWhiteBright: [107, 49]
114
+ }
115
+ };
116
+
117
+ // Alias bright black as gray (and grey)
118
+ styles.color.gray = styles.color.blackBright;
119
+ styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
120
+ styles.color.grey = styles.color.blackBright;
121
+ styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
122
+
123
+ for (const [groupName, group] of Object.entries(styles)) {
124
+ for (const [styleName, style] of Object.entries(group)) {
125
+ styles[styleName] = {
126
+ open: `\u001B[${style[0]}m`,
127
+ close: `\u001B[${style[1]}m`
128
+ };
129
+
130
+ group[styleName] = styles[styleName];
131
+
132
+ codes.set(style[0], style[1]);
133
+ }
134
+
135
+ Object.defineProperty(styles, groupName, {
136
+ value: group,
137
+ enumerable: false
138
+ });
139
+ }
140
+
141
+ Object.defineProperty(styles, 'codes', {
142
+ value: codes,
143
+ enumerable: false
144
+ });
145
+
146
+ styles.color.close = '\u001B[39m';
147
+ styles.bgColor.close = '\u001B[49m';
148
+
149
+ setLazyProperty(styles.color, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false));
150
+ setLazyProperty(styles.color, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false));
151
+ setLazyProperty(styles.color, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false));
152
+ setLazyProperty(styles.bgColor, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true));
153
+ setLazyProperty(styles.bgColor, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true));
154
+ setLazyProperty(styles.bgColor, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true));
155
+
156
+ return styles;
157
+ }
158
+
159
+ // Make the export immutable
160
+ Object.defineProperty(module, 'exports', {
161
+ enumerable: true,
162
+ get: assembleStyles
163
+ });
164
+
165
+ // Unit tests for ANSI escape code functions
166
+ const assert = require('assert');
167
+
168
+ const styles = assembleStyles();
169
+
170
+ // Test color functions
171
+ assert.strictEqual(styles.color.red.open, '\u001B[31m');
172
+ assert.strictEqual(styles.color.red.close, '\u001B[39m');
173
+ assert.strictEqual(styles.color.green.open, '\u001B[32m');
174
+ assert.strictEqual(styles.color.green.close, '\u001B[39m');
175
+
176
+ // Test background color functions
177
+ assert.strictEqual(styles.bgColor.bgRed.open, '\u001B[41m');
178
+ assert.strictEqual(styles.bgColor.bgRed.close, '\u001B[49m');
179
+ assert.strictEqual(styles.bgColor.bgGreen.open, '\u001B[42m');
180
+ assert.strictEqual(styles.bgColor.bgGreen.close, '\u001B[49m');
181
+
182
+ // Test modifier functions
183
+ assert.strictEqual(styles.modifier.bold.open, '\u001B[1m');
184
+ assert.strictEqual(styles.modifier.bold.close, '\u001B[22m');
185
+ assert.strictEqual(styles.modifier.italic.open, '\u001B[3m');
186
+ assert.strictEqual(styles.modifier.italic.close, '\u001B[23m');
187
+
188
+ console.log('All tests passed!');
ansi-styles/license ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansi-styles/package.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "ansi-styles",
3
+ "version": "4.3.0",
4
+ "description": "ANSI escape codes for styling strings in the terminal",
5
+ "license": "MIT",
6
+ "repository": "chalk/ansi-styles",
7
+ "funding": "https://github.com/chalk/ansi-styles?sponsor=1",
8
+ "author": {
9
+ "name": "Sindre Sorhus",
10
+ "email": "sindresorhus@gmail.com",
11
+ "url": "sindresorhus.com"
12
+ },
13
+ "engines": {
14
+ "node": ">=8"
15
+ },
16
+ "scripts": {
17
+ "test": "xo && ava && tsd",
18
+ "screenshot": "svg-term --command='node screenshot' --out=screenshot.svg --padding=3 --width=55 --height=3 --at=1000 --no-cursor"
19
+ },
20
+ "files": [
21
+ "index.js",
22
+ "index.d.ts"
23
+ ],
24
+ "keywords": [
25
+ "ansi",
26
+ "styles",
27
+ "color",
28
+ "colour",
29
+ "colors",
30
+ "terminal",
31
+ "console",
32
+ "cli",
33
+ "string",
34
+ "tty",
35
+ "escape",
36
+ "formatting",
37
+ "rgb",
38
+ "256",
39
+ "shell",
40
+ "xterm",
41
+ "log",
42
+ "logging",
43
+ "command-line",
44
+ "text"
45
+ ],
46
+ "dependencies": {
47
+ "color-convert": "^2.0.1"
48
+ },
49
+ "devDependencies": {
50
+ "@types/color-convert": "^1.9.0",
51
+ "ava": "^2.3.0",
52
+ "svg-term-cli": "^2.1.1",
53
+ "tsd": "^0.11.0",
54
+ "xo": "^0.25.3"
55
+ }
56
+ }
ansi-styles/readme.md ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ansi-styles [![Build Status](https://travis-ci.org/chalk/ansi-styles.svg?branch=master)](https://travis-ci.org/chalk/ansi-styles)
2
+
3
+ > [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) for styling strings in the terminal
4
+
5
+ You probably want the higher-level [chalk](https://github.com/chalk/chalk) module for styling your strings.
6
+
7
+ <img src="screenshot.svg" width="900">
8
+
9
+ ## Install
10
+
11
+ ```
12
+ $ npm install ansi-styles
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```js
18
+ const style = require('ansi-styles');
19
+
20
+ console.log(`${style.green.open}Hello world!${style.green.close}`);
21
+
22
+
23
+ // Color conversion between 16/256/truecolor
24
+ // NOTE: If conversion goes to 16 colors or 256 colors, the original color
25
+ // may be degraded to fit that color palette. This means terminals
26
+ // that do not support 16 million colors will best-match the
27
+ // original color.
28
+ console.log(style.bgColor.ansi.hsl(120, 80, 72) + 'Hello world!' + style.bgColor.close);
29
+ console.log(style.color.ansi256.rgb(199, 20, 250) + 'Hello world!' + style.color.close);
30
+ console.log(style.color.ansi16m.hex('#abcdef') + 'Hello world!' + style.color.close);
31
+ ```
32
+
33
+ ## API
34
+
35
+ Each style has an `open` and `close` property.
36
+
37
+ ## Styles
38
+
39
+ ### Modifiers
40
+
41
+ - `reset`
42
+ - `bold`
43
+ - `dim`
44
+ - `italic` *(Not widely supported)*
45
+ - `underline`
46
+ - `inverse`
47
+ - `hidden`
48
+ - `strikethrough` *(Not widely supported)*
49
+
50
+ ### Colors
51
+
52
+ - `black`
53
+ - `red`
54
+ - `green`
55
+ - `yellow`
56
+ - `blue`
57
+ - `magenta`
58
+ - `cyan`
59
+ - `white`
60
+ - `blackBright` (alias: `gray`, `grey`)
61
+ - `redBright`
62
+ - `greenBright`
63
+ - `yellowBright`
64
+ - `blueBright`
65
+ - `magentaBright`
66
+ - `cyanBright`
67
+ - `whiteBright`
68
+
69
+ ### Background colors
70
+
71
+ - `bgBlack`
72
+ - `bgRed`
73
+ - `bgGreen`
74
+ - `bgYellow`
75
+ - `bgBlue`
76
+ - `bgMagenta`
77
+ - `bgCyan`
78
+ - `bgWhite`
79
+ - `bgBlackBright` (alias: `bgGray`, `bgGrey`)
80
+ - `bgRedBright`
81
+ - `bgGreenBright`
82
+ - `bgYellowBright`
83
+ - `bgBlueBright`
84
+ - `bgMagentaBright`
85
+ - `bgCyanBright`
86
+ - `bgWhiteBright`
87
+
88
+ ## Advanced usage
89
+
90
+ By default, you get a map of styles, but the styles are also available as groups. They are non-enumerable so they don't show up unless you access them explicitly. This makes it easier to expose only a subset in a higher-level module.
91
+
92
+ - `style.modifier`
93
+ - `style.color`
94
+ - `style.bgColor`
95
+
96
+ ###### Example
97
+
98
+ ```js
99
+ console.log(style.color.green.open);
100
+ ```
101
+
102
+ Raw escape codes (i.e. without the CSI escape prefix `\u001B[` and render mode postfix `m`) are available under `style.codes`, which returns a `Map` with the open codes as keys and close codes as values.
103
+
104
+ ###### Example
105
+
106
+ ```js
107
+ console.log(style.codes.get(36));
108
+ //=> 39
109
+ ```
110
+
111
+ ## [256 / 16 million (TrueColor) support](https://gist.github.com/XVilka/8346728)
112
+
113
+ `ansi-styles` uses the [`color-convert`](https://github.com/Qix-/color-convert) package to allow for converting between various colors and ANSI escapes, with support for 256 and 16 million colors.
114
+
115
+ The following color spaces from `color-convert` are supported:
116
+
117
+ - `rgb`
118
+ - `hex`
119
+ - `keyword`
120
+ - `hsl`
121
+ - `hsv`
122
+ - `hwb`
123
+ - `ansi`
124
+ - `ansi256`
125
+
126
+ To use these, call the associated conversion function with the intended output, for example:
127
+
128
+ ```js
129
+ style.color.ansi.rgb(100, 200, 15); // RGB to 16 color ansi foreground code
130
+ style.bgColor.ansi.rgb(100, 200, 15); // RGB to 16 color ansi background code
131
+
132
+ style.color.ansi256.hsl(120, 100, 60); // HSL to 256 color ansi foreground code
133
+ style.bgColor.ansi256.hsl(120, 100, 60); // HSL to 256 color ansi foreground code
134
+
135
+ style.color.ansi16m.hex('#C0FFEE'); // Hex (RGB) to 16 million color foreground code
136
+ style.bgColor.ansi16m.hex('#C0FFEE'); // Hex (RGB) to 16 million color background code
137
+ ```
138
+
139
+ ## Related
140
+
141
+ - [ansi-escapes](https://github.com/sindresorhus/ansi-escapes) - ANSI escape codes for manipulating the terminal
142
+
143
+ ## Maintainers
144
+
145
+ - [Sindre Sorhus](https://github.com/sindresorhus)
146
+ - [Josh Junon](https://github.com/qix-)
147
+
148
+ ## For enterprise
149
+
150
+ Available as part of the Tidelift Subscription.
151
+
152
+ The maintainers of `ansi-styles` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-ansi-styles?utm_source=npm-ansi-styles&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
app/intelligence/src/analytics/real_ti.groovy ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app/intelligence/src/analytics/real_time_engine.py
2
+
3
+ from typing import Dict, List, Optional
4
+ import asyncio
5
+ import numpy as np
6
+ from datetime import datetime
7
+ import pandas as pd
8
+
9
+ class RealTimeAnalyticsEngine:
10
+ def __init__(self):
11
+ self.data_streams = {}
12
+ self.analytics_queue = asyncio.Queue()
13
+ self.alert_threshold = 0.75
14
+
15
+ async def process_stream(self, stream_id: str, data: Dict):
16
+ """Process incoming data stream in real-time"""
17
+ try:
18
+ # Add timestamp
19
+ data['timestamp'] = datetime.utcnow()
20
+
21
+ # Add to stream buffer
22
+ if stream_id not in self.data_streams:
23
+ self.data_streams[stream_id] = []
24
+ self.data_streams[stream_id].append(data)
25
+
26
+ # Trigger analysis
27
+ await self.analytics_queue.put({
28
+ 'stream_id': stream_id,
29
+ 'data': data
30
+ })
31
+
32
+ # Process analytics queue
33
+ await self.process_analytics_queue()
34
+
35
+ except Exception as e:
36
+ raise Exception(f"Stream processing failed: {str(e)}")
37
+
38
+ async def process_analytics_queue(self):
39
+ """Process queued analytics tasks"""
40
+ while not self.analytics_queue.empty():
41
+ item = await self.analytics_queue.get()
42
+
43
+ # Perform real-time analysis
44
+ analysis_result = await self.analyze_data(
45
+ item['stream_id'],
46
+ item['data']
47
+ )
48
+
49
+ # Check for alerts
50
+ if analysis_result['threat_score'] > self.alert_threshold:
51
+ await self.generate_alert(analysis_result)
52
+
53
+ async def analyze_data(self, stream_id: str, data: Dict) -> Dict:
54
+ """Perform real-time data analysis"""
55
+ try:
56
+ # Get historical data for context
57
+ history = self.data_streams[stream_id][-100:] # Last 100 entries
58
+
59
+ # Calculate metrics
60
+ metrics = {
61
+ 'volume': len(history),
62
+ 'frequency': self.calculate_frequency(history),
63
+ 'pattern_score': self.detect_patterns(history),
64
+ 'anomaly_score': self.detect_anomalies(data, history)
65
+ }
66
+
67
+ # Calculate threat score
68
+ threat_score = self.calculate_threat_score(metrics)
69
+
70
+ return {
71
+ 'stream_id': stream_id,
72
+ 'timestamp': datetime.utcnow(),
73
+ 'metrics': metrics,
74
+ 'threat_score': threat_score,
75
+ 'raw_data': data
76
+ }
77
+
78
+ except Exception as e:
79
+ raise Exception(f"Data analysis failed: {str(e)}")
80
+ }
81
+ }
82
+ )
83
+ })
app_security/app_vulnerability_scanner.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from database.models import DocumentAnalysis
3
+ from sqlalchemy import create_engine
4
+ from sqlalchemy.orm import sessionmaker
5
+ import time
6
+ import logging
7
+
8
+ DATABASE_URL = "sqlite:///document_analysis.db"
9
+ engine = create_engine(DATABASE_URL)
10
+ SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
11
+
12
+ # Configure logging
13
+ logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')
14
+
15
+ def scan_application(app_url):
16
+ print(f"Scanning application for vulnerabilities: {app_url}")
17
+
18
+ # Input validation for app_url
19
+ if not isinstance(app_url, str) or not app_url.startswith("http"):
20
+ logging.error("Invalid app_url provided.")
21
+ return {"vulnerabilities_found": 0, "critical_issues": []}
22
+
23
+ retries = 3
24
+ for attempt in range(retries):
25
+ try:
26
+ session = SessionLocal()
27
+ try:
28
+ response = requests.get(app_url)
29
+ response.raise_for_status()
30
+
31
+ # Simulate a potential SQL injection vulnerability fix
32
+ if "vulnerable_param" in app_url:
33
+ logging.error("Potential SQL injection attempt detected.")
34
+ return {"vulnerabilities_found": 0, "critical_issues": ["Potential SQL Injection attempt detected."]}
35
+
36
+ vulnerabilities = {"vulnerabilities_found": 2, "critical_issues": ["SQL Injection", "XSS"]}
37
+
38
+ # Save scan results to the database
39
+ scan_result = DocumentAnalysis(
40
+ source=app_url,
41
+ title="Vulnerability Scan",
42
+ links=str(vulnerabilities["critical_issues"]),
43
+ error=None
44
+ )
45
+ session.add(scan_result)
46
+ session.commit()
47
+ return vulnerabilities
48
+ except requests.exceptions.HTTPError as http_err:
49
+ logging.error(f"HTTP error occurred: {http_err}")
50
+ scan_result = DocumentAnalysis(
51
+ source=app_url,
52
+ title="Vulnerability Scan",
53
+ links=None,
54
+ error=str(http_err)
55
+ )
56
+ session.add(scan_result)
57
+ session.commit()
58
+ except Exception as err:
59
+ logging.error(f"Other error occurred: {err}")
60
+ scan_result = DocumentAnalysis(
61
+ source=app_url,
62
+ title="Vulnerability Scan",
63
+ links=None,
64
+ error=str(err)
65
+ )
66
+ session.add(scan_result)
67
+ session.commit()
68
+ finally:
69
+ session.close()
70
+ except Exception as db_err:
71
+ logging.error(f"Database connection error: {db_err}")
72
+ if attempt < retries - 1:
73
+ logging.error("Retrying database connection...")
74
+ time.sleep(2)
75
+ else:
76
+ logging.error("Failed to connect to the database after multiple attempts.")
77
+ return {"vulnerabilities_found": 0, "critical_issues": []}
78
+ return {"vulnerabilities_found": 0, "critical_issues": []}
79
+
80
+ def verify_database_connection():
81
+ try:
82
+ session = SessionLocal()
83
+ session.execute('SELECT 1')
84
+ session.close()
85
+ logging.info("Database connection verified.")
86
+ except Exception as e:
87
+ logging.error(f"Database connection verification failed: {e}")
88
+
89
+ if __name__ == "__main__":
90
+ verify_database_connection()
91
+ vulnerabilities = scan_application("http://example.com")
92
+ print(f"Vulnerability Scan Results: {vulnerabilities}")