-
-
Notifications
You must be signed in to change notification settings - Fork 436
/
Copy pathschema.go
4860 lines (3281 loc) · 127 KB
/
schema.go
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package database
var Schema = `
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
--
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: buildparameterinstance; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.buildparameterinstance (
id integer NOT NULL,
build_parameter_id integer NOT NULL,
payload_id integer NOT NULL,
value text DEFAULT ''::text NOT NULL,
enc_key bytea,
dec_key bytea
);
--
-- Name: buildparameterinstance_deckey(public.buildparameterinstance); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.buildparameterinstance_deckey(buildparameterinstance_row public.buildparameterinstance) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT encode(buildparameterinstance_row.dec_key, 'base64')
$$;
--
-- Name: buildparameterinstance_enckey(public.buildparameterinstance); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.buildparameterinstance_enckey(buildparameterinstance_row public.buildparameterinstance) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT encode(buildparameterinstance_row.enc_key, 'base64')
$$;
--
-- Name: c2profileparametersinstance; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.c2profileparametersinstance (
id integer NOT NULL,
c2_profile_parameters_id integer NOT NULL,
c2_profile_id integer NOT NULL,
value text NOT NULL,
enc_key bytea,
dec_key bytea,
payload_id integer,
instance_name text,
operation_id integer,
callback_id integer
);
--
-- Name: c2profileparametersinstance_deckey(public.c2profileparametersinstance); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.c2profileparametersinstance_deckey(c2profileparametersinstance_row public.c2profileparametersinstance) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT encode(c2profileparametersinstance_row.dec_key, 'base64')
$$;
--
-- Name: c2profileparametersinstance_enckey(public.c2profileparametersinstance); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.c2profileparametersinstance_enckey(c2profileparametersinstance_row public.c2profileparametersinstance) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT encode(c2profileparametersinstance_row.enc_key, 'base64')
$$;
--
-- Name: callback; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.callback (
id integer NOT NULL,
display_id integer NOT NULL,
agent_callback_id text NOT NULL,
init_callback timestamp without time zone DEFAULT now() NOT NULL,
last_checkin timestamp without time zone DEFAULT now() NOT NULL,
"user" text DEFAULT ''::text NOT NULL,
host text DEFAULT ''::text NOT NULL,
pid integer DEFAULT 0 NOT NULL,
ip text DEFAULT ''::text NOT NULL,
external_ip text DEFAULT ''::text NOT NULL,
process_name text DEFAULT ''::text NOT NULL,
description text DEFAULT ''::text NOT NULL,
operator_id integer NOT NULL,
active boolean DEFAULT true NOT NULL,
registered_payload_id integer NOT NULL,
integrity_level integer DEFAULT 2 NOT NULL,
locked boolean DEFAULT false NOT NULL,
locked_operator_id integer,
operation_id integer NOT NULL,
crypto_type text DEFAULT ''::text NOT NULL,
dec_key bytea,
enc_key bytea,
os text DEFAULT ''::text NOT NULL,
architecture text DEFAULT ''::text NOT NULL,
domain text DEFAULT ''::text NOT NULL,
extra_info text DEFAULT ''::text NOT NULL,
sleep_info text DEFAULT ''::text NOT NULL,
"timestamp" timestamp without time zone DEFAULT now() NOT NULL
);
--
-- Name: callback_deckey(public.callback); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.callback_deckey(callback_row public.callback) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT encode(callback_row.dec_key, 'base64')
$$;
--
-- Name: callback_enckey(public.callback); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.callback_enckey(callback_row public.callback) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT encode(callback_row.enc_key, 'base64')
$$;
--
-- Name: credential; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.credential (
id integer NOT NULL,
type text DEFAULT 'plaintext'::text NOT NULL,
task_id integer,
account text DEFAULT ''::text NOT NULL,
realm text DEFAULT ''::text NOT NULL,
operation_id integer NOT NULL,
"timestamp" timestamp without time zone DEFAULT now() NOT NULL,
credential bytea DEFAULT '\x'::bytea NOT NULL,
operator_id integer NOT NULL,
comment text DEFAULT ''::text NOT NULL,
deleted boolean DEFAULT false NOT NULL,
metadata text DEFAULT ''::text NOT NULL
);
--
-- Name: credential_credentials(public.credential); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.credential_credentials(credential_row public.credential) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT convert_from(credential_row.credential, 'utf8')
$$;
--
-- Name: current_time(public.callback); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public."current_time"(callback_row public.callback) RETURNS text
LANGUAGE sql STABLE
AS $$
Select Now();
$$;
--
-- Name: default_payload_command_version(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.default_payload_command_version() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
current_version integer;
BEGIN
IF NEW.version IS NULL THEN
SELECT version INTO current_version FROM command WHERE id = NEW.command_id;
NEW.version := current_version;
END IF;
RETURN NEW;
END;
$$;
--
-- Name: filemeta; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.filemeta (
id integer NOT NULL,
agent_file_id text NOT NULL,
total_chunks integer DEFAULT 0 NOT NULL,
chunks_received integer DEFAULT 0 NOT NULL,
chunk_size integer DEFAULT 0 NOT NULL,
task_id integer,
complete boolean DEFAULT false NOT NULL,
path text NOT NULL,
full_remote_path bytea DEFAULT '\x'::bytea NOT NULL,
host text DEFAULT ''::text NOT NULL,
is_payload boolean DEFAULT false NOT NULL,
is_screenshot boolean DEFAULT false NOT NULL,
is_download_from_agent boolean DEFAULT false NOT NULL,
mythictree_id integer,
filename bytea DEFAULT '\x'::bytea NOT NULL,
delete_after_fetch boolean DEFAULT true NOT NULL,
operation_id integer NOT NULL,
"timestamp" timestamp without time zone DEFAULT now() NOT NULL,
deleted boolean DEFAULT false NOT NULL,
operator_id integer NOT NULL,
md5 text DEFAULT ''::text NOT NULL,
sha1 text DEFAULT ''::text NOT NULL,
comment text DEFAULT ''::text NOT NULL
);
--
-- Name: filemeta_filename(public.filemeta); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.filemeta_filename(meta_row public.filemeta) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT encode(meta_row.filename, 'base64')
$$;
--
-- Name: filemeta_filename_utf7(public.filemeta); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.filemeta_filename_utf7(meta_row public.filemeta) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT convert_from(meta_row.filename, 'utf8')
$$;
--
-- Name: filemeta_filename_utf8(public.filemeta); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.filemeta_filename_utf8(meta_row public.filemeta) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT encode(meta_row.filename, 'escape')
$$;
--
-- Name: filemeta_full_remote_path(public.filemeta); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.filemeta_full_remote_path(meta_row public.filemeta) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT encode(meta_row.full_remote_path, 'base64')
$$;
--
-- Name: filemeta_full_remote_path_utf8(public.filemeta); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.filemeta_full_remote_path_utf8(meta_row public.filemeta) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT encode(meta_row.full_remote_path, 'escape')
$$;
--
-- Name: keylog; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.keylog (
id integer NOT NULL,
task_id integer NOT NULL,
keystrokes bytea DEFAULT '\x'::bytea NOT NULL,
"window" text DEFAULT 'UNKNOWN'::text NOT NULL,
"timestamp" timestamp without time zone DEFAULT now() NOT NULL,
operation_id integer NOT NULL,
"user" text DEFAULT 'UNKNOWN'::text NOT NULL
);
--
-- Name: keylog_keystrokes(public.keylog); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.keylog_keystrokes(keylog_row public.keylog) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT convert_from(keylog_row.keystrokes, 'utf8')
$$;
--
-- Name: mythictree; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.mythictree (
id integer NOT NULL,
task_id integer NOT NULL,
"timestamp" timestamp without time zone DEFAULT now() NOT NULL,
operation_id integer NOT NULL,
host text DEFAULT ''::text NOT NULL,
name bytea DEFAULT '\x'::bytea NOT NULL,
parent_path bytea DEFAULT '\x'::bytea NOT NULL,
comment text DEFAULT ''::text NOT NULL,
can_have_children boolean DEFAULT false NOT NULL,
success boolean,
deleted boolean DEFAULT false NOT NULL,
full_path bytea DEFAULT '\x'::bytea NOT NULL,
metadata jsonb DEFAULT jsonb_build_object() NOT NULL,
tree_type text DEFAULT 'file'::text NOT NULL,
os text NOT NULL
);
--
-- Name: mythictree_full_path(public.mythictree); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.mythictree_full_path(fileobj_row public.mythictree) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT convert_from(fileobj_row.full_path, 'utf8')
$$;
--
-- Name: mythictree_name(public.mythictree); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.mythictree_name(fileobj_row public.mythictree) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT convert_from(fileobj_row."name", 'utf8')
$$;
--
-- Name: mythictree_parent_path(public.mythictree); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.mythictree_parent_path(fileobj_row public.mythictree) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT convert_from(fileobj_row.parent_path, 'utf8')
$$;
--
-- Name: new_callback_display_id(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE OR REPLACE FUNCTION public.new_callback_display_id() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
current_max integer;
BEGIN
SELECT GREATEST(0, Max(display_id) )
INTO current_max
FROM callback
WHERE operation_id = NEW.operation_id;
NEW.display_id := current_max + 1;
RETURN NEW;
END;
$$;
--
-- Name: new_task_display_id(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.new_task_display_id() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
current_max integer;
BEGIN
SELECT GREATEST(0, Max(display_id) )
INTO current_max
FROM task
WHERE operation_id = NEW.operation_id;
NEW.display_id := current_max + 1;
RETURN NEW;
END;
$$;
--
-- Name: payload_update_timestamp_on_all_build_updates(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.payload_update_timestamp_on_all_build_updates() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
UPDATE public.payload SET timestamp = NOW() WHERE id=NEW.payload_id;
RETURN NEW;
END;
$$;
--
-- Name: response; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.response (
id integer NOT NULL,
response bytea DEFAULT '\x'::bytea NOT NULL,
"timestamp" timestamp without time zone DEFAULT now() NOT NULL,
task_id integer NOT NULL,
sequence_number integer,
operation_id integer NOT NULL
);
--
-- Name: response(public.response); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.response(response_row public.response) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT encode(response_row.response, 'base64')
$$;
--
-- Name: response_escape(public.response); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.response_escape(response_row public.response) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT encode(response_row.response, 'escape')
$$;
--
-- Name: response_update_task_timestamp(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.response_update_task_timestamp() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
UPDATE public.task SET timestamp=NOW() WHERE id=NEW.task_id;
RETURN NEW;
END;
$$;
--
-- Name: set_current_timestamp(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.set_current_timestamp() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
_new record;
BEGIN
_new := NEW;
_new."timestamp" = NOW();
RETURN _new;
END;
$$;
--
-- Name: tag_update_linked_table(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.tag_update_linked_table() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF (TG_OP = 'DELETE') THEN
IF OLD.task_id IS NOT NULL THEN
UPDATE public.task SET timestamp=Now() WHERE id=OLD.task_id;
END IF;
IF OLD.filemeta_id IS NOT NULL THEN
UPDATE public.filemeta SET timestamp=NOW() WHERE id=OLD.filemeta_id;
END IF;
IF OLD.mythictree_id IS NOT NULL THEN
UPDATE public.mythictree SET timestamp=NOW() WHERE id=OLD.mythictree_id;
END IF;
IF OLD.credential_id IS NOT NULL THEN
UPDATE public.credential SET timestamp=NOW() WHERE id=OLD.credential_id;
END IF;
IF OLD.taskartifact_id IS NOT NULL THEN
UPDATE public.taskartifact SET timestamp=NOW() WHERE id=OLD.taskartifact_id;
END IF;
IF OLD.keylog_id IS NOT NULL THEN
UPDATE public.keylog SET timestamp=NOW() WHERE id=OLD.keylog_id;
END IF;
IF OLD.response_id IS NOT NULL THEN
UPDATE public.response SET timestamp=NOW() WHERE id=OLD.response_id;
END IF;
RETURN OLD;
ELSIF (TG_OP = 'INSERT') THEN
IF NEW.task_id IS NOT NULL THEN
UPDATE public.task SET timestamp=Now() WHERE id=NEW.task_id;
END IF;
IF NEW.filemeta_id IS NOT NULL THEN
UPDATE public.filemeta SET timestamp=NOW() WHERE id=NEW.filemeta_id;
END IF;
IF NEW.mythictree_id IS NOT NULL THEN
UPDATE public.mythictree SET timestamp=NOW() WHERE id=NEW.mythictree_id;
END IF;
IF NEW.credential_id IS NOT NULL THEN
UPDATE public.credential SET timestamp=NOW() WHERE id=NEW.credential_id;
END IF;
IF NEW.taskartifact_id IS NOT NULL THEN
UPDATE public.taskartifact SET timestamp=NOW() WHERE id=NEW.taskartifact_id;
END IF;
IF NEW.keylog_id IS NOT NULL THEN
UPDATE public.keylog SET timestamp=NOW() WHERE id=NEW.keylog_id;
END IF;
IF NEW.response_id IS NOT NULL THEN
UPDATE public.response SET timestamp=NOW() WHERE id=NEW.response_id;
END IF;
RETURN NEW;
END IF;
RETURN NULL;
END;
$$;
--
-- Name: task_update_timestamp_on_all_updates(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.task_update_timestamp_on_all_updates() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW."timestamp" = NOW();
RETURN NEW;
END;
$$;
--
-- Name: taskartifact; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.taskartifact (
id integer NOT NULL,
task_id integer NOT NULL,
"timestamp" timestamp without time zone DEFAULT now() NOT NULL,
artifact bytea DEFAULT '\x'::bytea NOT NULL,
operation_id integer NOT NULL,
host text NOT NULL,
base_artifact text DEFAULT ''::text NOT NULL
);
--
-- Name: taskartifact_artifact_instance(public.taskartifact); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.taskartifact_artifact_instance(taskartifact_row public.taskartifact) RETURNS text
LANGUAGE sql STABLE
AS $$
SELECT convert_from(taskartifact_row.artifact, 'utf8')
$$;
--
-- Name: update_mythictree_timestamp_on_update(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.update_mythictree_timestamp_on_update() RETURNS trigger
LANGUAGE plpgsql
AS $$ BEGIN NEW.timestamp := now(); RETURN NEW; END; $$;
--
-- Name: update_operation_alert_count(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.update_operation_alert_count() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
current_max integer;
BEGIN
SELECT COUNT(*)
INTO current_max
FROM operationeventlog
WHERE operation_id = NEW.operation_id AND resolved=false AND deleted=false AND level='warning';
UPDATE operation SET alert_count = current_max WHERE id = NEW.operation_id;
RETURN NEW;
END;
$$;
--
-- Name: update_task_response_count(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.update_task_response_count() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
current_max integer;
BEGIN
SELECT COUNT(*)
INTO current_max
FROM response
WHERE task_id = NEW.task_id;
UPDATE task SET response_count = current_max WHERE id = NEW.task_id;
RETURN NEW;
END;
$$;
--
-- Name: update_task_timestamp_on_update(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.update_task_timestamp_on_update() RETURNS trigger
LANGUAGE plpgsql
AS $$ BEGIN NEW.timestamp := now(); RETURN NEW; END; $$;
--
-- Name: agentstorage; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.agentstorage (
id integer NOT NULL,
data bytea DEFAULT '\x'::bytea NOT NULL,
unique_id text NOT NULL
);
--
-- Name: agentstorage_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.agentstorage_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: agentstorage_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.agentstorage_id_seq OWNED BY public.agentstorage.id;
--
-- Name: apitokens; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.apitokens (
id integer NOT NULL,
token_type text NOT NULL,
token_value text NOT NULL,
active boolean DEFAULT true NOT NULL,
creation_time timestamp without time zone DEFAULT now() NOT NULL,
operator_id integer NOT NULL
);
--
-- Name: apitokens_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.apitokens_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: apitokens_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.apitokens_id_seq OWNED BY public.apitokens.id;
--
-- Name: attack; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.attack (
id integer NOT NULL,
t_num text NOT NULL,
name text NOT NULL,
os text NOT NULL,
tactic text NOT NULL
);
--
-- Name: attack_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.attack_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: attack_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.attack_id_seq OWNED BY public.attack.id;
--
-- Name: attackcommand; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.attackcommand (
id integer NOT NULL,
attack_id integer NOT NULL,
command_id integer NOT NULL
);
--
-- Name: attackcommand_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.attackcommand_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: attackcommand_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.attackcommand_id_seq OWNED BY public.attackcommand.id;
--
-- Name: attacktask; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.attacktask (
id integer NOT NULL,
attack_id integer NOT NULL,
task_id integer NOT NULL
);
--
-- Name: attacktask_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.attacktask_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: attacktask_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.attacktask_id_seq OWNED BY public.attacktask.id;
--
-- Name: browserscript; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.browserscript (
id integer NOT NULL,
operator_id integer,
script text DEFAULT ''::text NOT NULL,
command_id integer NOT NULL,
payload_type_id integer NOT NULL,
creation_time timestamp without time zone DEFAULT now() NOT NULL,
active boolean DEFAULT true NOT NULL,
author text DEFAULT ''::text NOT NULL,
user_modified boolean DEFAULT false NOT NULL,
container_version text DEFAULT ''::text NOT NULL,
container_version_author text DEFAULT ''::text NOT NULL,
for_new_ui boolean DEFAULT false NOT NULL
);
--
-- Name: browserscript_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.browserscript_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: browserscript_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.browserscript_id_seq OWNED BY public.browserscript.id;
--
-- Name: browserscriptoperation; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.browserscriptoperation (
id integer NOT NULL,
browserscript_id integer NOT NULL,
operation_id integer NOT NULL
);
--
-- Name: browserscriptoperation_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.browserscriptoperation_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: browserscriptoperation_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.browserscriptoperation_id_seq OWNED BY public.browserscriptoperation.id;
--
-- Name: buildparameter; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.buildparameter (
id integer NOT NULL,
name text DEFAULT ''::text NOT NULL,
parameter_type text DEFAULT 'None'::text NOT NULL,
description text DEFAULT ''::text NOT NULL,
payload_type_id integer NOT NULL,
required boolean DEFAULT true NOT NULL,
verifier_regex text DEFAULT ''::text NOT NULL,
deleted boolean DEFAULT false NOT NULL,
default_value text DEFAULT ''::text NOT NULL,
randomize boolean DEFAULT false NOT NULL,
format_string text DEFAULT ''::text NOT NULL,
crypto_type boolean DEFAULT false NOT NULL,
choices jsonb DEFAULT jsonb_build_array() NOT NULL
);
--
-- Name: buildparameter_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.buildparameter_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: buildparameter_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.buildparameter_id_seq OWNED BY public.buildparameter.id;
--
-- Name: buildparameterinstance_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.buildparameterinstance_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: buildparameterinstance_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.buildparameterinstance_id_seq OWNED BY public.buildparameterinstance.id;
--
-- Name: c2profile; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.c2profile (
id integer NOT NULL,
name text NOT NULL,
description text DEFAULT ''::text NOT NULL,
creation_time timestamp without time zone DEFAULT now() NOT NULL,
running boolean DEFAULT false NOT NULL,
container_running boolean DEFAULT false NOT NULL,
author text DEFAULT ''::text NOT NULL,
is_p2p boolean DEFAULT false NOT NULL,
is_server_routed boolean DEFAULT false NOT NULL,
deleted boolean DEFAULT false NOT NULL
);
--
-- Name: c2profile_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.c2profile_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: c2profile_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.c2profile_id_seq OWNED BY public.c2profile.id;
--
-- Name: c2profileparameters; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.c2profileparameters (