-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathviper.src
4190 lines (3692 loc) · 158 KB
/
viper.src
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
//AES128
AES128 = function(choice, key, text) // Returns null if any error (could mean undecryptable ciphertext)
if typeof(key) != "string" then return null
if key.len != 16 then return null
if typeof(text) != "string" then return null
if typeof(choice) != "string" then return null
byte_key = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for i in key.indexes
byte_key[i] = key[i].code
end for
key = byte_key[0:]
// Define lookup tables
Sbox = []
Sbox=Sbox+[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38]
Sbox=Sbox+[54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179]
Sbox=Sbox+[41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64]
Sbox=Sbox+[143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70]
Sbox=Sbox+[238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174]
Sbox=Sbox+[8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105]
Sbox=Sbox+[217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22]
Rcon = [1, 2, 4, 8, 16, 32, 64, 128, 27, 54]
Mult2 = []
Mult2=Mult2+[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90]
Mult2=Mult2+[92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158]
Mult2=Mult2+[160,162,164,166,168,170,172,174,176,178,180,182,184,186,188,190,192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224]
Mult2=Mult2+[226,228,230,232,234,236,238,240,242,244,246,248,250,252,254,27,25,31,29,19,17,23,21,11,9,15,13,3,1,7,5,59,57,63,61,51,49,55,53,43,41]
Mult2=Mult2+[47,45,35,33,39,37,91,89,95,93,83,81,87,85,75,73,79,77,67,65,71,69,123,121,127,125,115,113,119,117,107,105,111,109,99,97,103,101,155]
Mult2=Mult2+[153,159,157,147,145,151,149,139,137,143,141,131,129,135,133,187,185,191,189,179,177,183,181,171,169,175,173,163,161,167,165,219,217]
Mult2=Mult2+[223,221,211,209,215,213,203,201,207,205,195,193,199,197,251,249,255,253,243,241,247,245,235,233,239,237,227,225,231,229]
SubBytes = function(column)
column = column[0:]
for i in column.indexes
column[i] = Sbox[column[i]]
end for
return column
end function
WordXor = function(word1, word2)
result = [0, 0, 0, 0]
for i in result.indexes
result[i] = bitwise("^", word1[i], word2[i])
end for
return result
end function
AddRoundKey = function(state, key, roundNum)
roundKey = key[roundNum*4:roundNum*4+4]
return [WordXor(state[0], roundKey[0]), WordXor(state[1], roundKey[1]), WordXor(state[2], roundKey[2]), WordXor(state[3], roundKey[3])]
end function
ExpandKey = function(key)
W = [key[0:4], key[4:8], key[8:12], key[12:16]]
for i in range(4, 40, 4)
W = W + [[], [], [], []]
W[i] = W[i-1][1:] + [W[i-1][0]] // RotWord
W[i] = SubBytes(W[i])
W[i] = WordXor(W[i-4], W[i])
W[i][0] = bitwise("^", Rcon[i/4-1], W[i][0])
for j in range(i+1, i+3)
W[j] = WordXor(W[j-4], W[j-1])
end for
end for
return W
end function
aesEncrypt = function(key, block) // Expects already formatted block
Mult2 = @Mult2
key = key[0:]
State = block[0:]
// Declaring functions
ShiftRows = function(state)
state = state[0:]
tmp = state[0][1]
state[0][1] = state[1][1]
state[1][1] = state[2][1]
state[2][1] = state[3][1]
state[3][1] = tmp
for i in range(1)
tmp = state[0][2]
state[0][2] = state[1][2]
state[1][2] = state[2][2]
state[2][2] = state[3][2]
state[3][2] = tmp
end for
tmp = state[3][3]
state[3][3] = state[2][3]
state[2][3] = state[1][3]
state[1][3] = state[0][3]
state[0][3] = tmp
return state
end function
matrix = [[2, 3, 1, 1], [1, 2, 3, 1], [1, 1, 2, 3], [3, 1, 1, 2]]
MixColumns = function(state)
state = state[0:]
for column in state.indexes
endcolumn = [0, 0, 0, 0]
for i in matrix.indexes
tmp = state[column][0:]
for j in matrix[i].indexes
if matrix[i][j] == 1 then continue
tmp[j] = Mult2[state[column][j]]
if matrix[i][j] != 3 then continue
tmp[j] = bitwise("^", tmp[j], state[column][j])
end for
endcolumn[i] = bitwise("^", bitwise("^", bitwise("^", tmp[0], tmp[1]), tmp[2]), tmp[3])
end for
state[column] = endcolumn[0:]
end for
return state
end function
// The algorithm
State = AddRoundKey(State, key, 0)
for round in range(1, 9)
State = [SubBytes(State[0]), SubBytes(State[1]), SubBytes(State[2]), SubBytes(State[3])]
State = ShiftRows(State)
State = MixColumns(State)
State = AddRoundKey(State, key, round)
end for
State = [SubBytes(State[0]), SubBytes(State[1]), SubBytes(State[2]), SubBytes(State[3])]
State = ShiftRows(State)
State = AddRoundKey(State, key, 10)
return State
end function
aesDecrypt = function(key, block) // Expects already formatted block
Mult2 = @Mult2
Sbox = @Sbox
key = key[0:]
State = block[0:]
// Declare functions
InvShiftRows = function(state)
state = state[0:]
tmp = state[3][1]
state[3][1] = state[2][1]
state[2][1] = state[1][1]
state[1][1] = state[0][1]
state[0][1] = tmp
for i in range(1)
tmp = state[3][2]
state[3][2] = state[2][2]
state[2][2] = state[1][2]
state[1][2] = state[0][2]
state[0][2] = tmp
end for
tmp = state[0][3]
state[0][3] = state[1][3]
state[1][3] = state[2][3]
state[2][3] = state[3][3]
state[3][3] = tmp
return state
end function
InvSubBytes = function(column)
column = column[0:]
for i in column.indexes
column[i] = Sbox.indexOf(column[i])
end for
return column
end function
matrix = [[14, 11, 13, 9], [9, 14, 11, 13], [13, 9, 14, 11], [11, 13, 9, 14]]
InvMixColumns = function(state)
state = state[0:]
for column in state.indexes
endcolumn = [0, 0, 0, 0]
for i in matrix.indexes
tmp = state[column][0:]
for j in matrix[i].indexes
if matrix[i][j] == 9 then
tmp[j] = bitwise("^", Mult2[Mult2[Mult2[state[column][j]]]], state[column][j])
else if matrix[i][j] == 11 then
tmp[j] = bitwise("^", Mult2[bitwise("^", Mult2[Mult2[state[column][j]]], state[column][j])], state[column][j])
else if matrix[i][j] == 13 then
tmp[j] = bitwise("^", Mult2[Mult2[bitwise("^", Mult2[state[column][j]], state[column][j])]], state[column][j])
else
tmp[j] = Mult2[bitwise("^", Mult2[bitwise("^", Mult2[state[column][j]], state[column][j])], state[column][j])]
end if
end for
endcolumn[i] = bitwise("^", bitwise("^", bitwise("^", tmp[0], tmp[1]), tmp[2]), tmp[3])
end for
state[column] = endcolumn[0:]
end for
return state
end function
// The actual algorithm
State = AddRoundKey(State, key, 10)
for round in range(9, 1)
State = InvShiftRows(State)
State = [InvSubBytes(State[0]), InvSubBytes(State[1]), InvSubBytes(State[2]), InvSubBytes(State[3])]
State = AddRoundKey(State, key, round)
State = InvMixColumns(State)
end for
State = InvShiftRows(State)
State = [InvSubBytes(State[0]), InvSubBytes(State[1]), InvSubBytes(State[2]), InvSubBytes(State[3])]
State = AddRoundKey(State, key, 0)
return State
end function
// Generate IV
IV = []
for byte in key
IV = IV + [floor(rnd(byte)*256)] // Warning: rnd is not cryptographically secure
end for
key = ExpandKey(key)
b64Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
if choice == "encrypt" then
Blocks = [[]]
b=0
for char in text
Blocks[b] = Blocks[b] + [code(char)]
if Blocks[b].len == 16 then
Blocks = Blocks + [[]]
b=b+1
end if
end for
// Pad with CMS (Crytographic Message Syntax)
padNum = 16 - Blocks[-1].len
for i in range(padNum-1)
Blocks[-1] = Blocks[-1] + [padNum]
end for
// XOR first block with IV
for i in IV.indexes
Blocks[0][i] = bitwise("^", Blocks[0][i], IV[i])
end for
// Format blocks
for i in Blocks.indexes
Blocks[i] = [Blocks[i][0:4], Blocks[i][4:8], Blocks[i][8:12], Blocks[i][12:16]]
end for
// Encode blocks
Blocks[0] = aesEncrypt(key, Blocks[0])
if Blocks.len > 1 then
for i in range(1, Blocks.len-1)
for column in Blocks[i].indexes
for byte in Blocks[i][column].indexes
Blocks[i][column][byte] = bitwise("^", Blocks[i][column][byte], Blocks[i-1][column][byte])
end for
end for
Blocks[i] = aesEncrypt(key, Blocks[i])
end for
end if
// Convert blocks to array of bytes
arr = []
for Block in Blocks
for column in Block
for byte in column
arr = arr + [byte]
end for
end for
end for
// Convert array into base 64
output = ""
for i in range(0, arr.len-1, 3)
buffer = arr[i]*65536
if arr.hasIndex(i+1) then
buffer = buffer+arr[i+1]*256
if arr.hasIndex(i+2) then buffer = buffer+arr[i+2]
end if
if arr.hasIndex(i+2) then
for j in range(3)
output = output + b64Table[floor(buffer/64^j)%64]
end for
else
if arr.hasIndex(i+1) then
for j in range(3,1)
output = output + b64Table[floor(buffer/64^j)%64]
end for
else
for j in range(3,2)
output = output + b64Table[floor(buffer/64^j)%64]
end for
end if
end if
end for
return output
end if
if choice == "decrypt" then
if text.len % 4 == 1 then return null
// Convert base 64 into sextet array
s_arr = text.values
for i in s_arr.indexes
tmp = b64Table.indexOf(s_arr[i])
if tmp == null then return null
s_arr[i] = tmp
end for
// Convert sextets to bytes
b_arr = []
for i in range(0, s_arr.len-1, 4)
buffer = s_arr[i]*262144
if s_arr.hasIndex(i+1) then
buffer = buffer+s_arr[i+1]*4096
if s_arr.hasIndex(i+2) then
buffer = buffer+s_arr[i+2]*64
if s_arr.hasIndex(i+3) then buffer = buffer+s_arr[i+3]
end if
end if
if s_arr.hasIndex(i+3) then
for j in range(2)
b_arr = b_arr + [floor(buffer/256^j)%256]
end for
else
if s_arr.hasIndex(i+2) then
for j in range(2,1)
b_arr = b_arr + [floor(buffer/256^j)%256]
end for
else
b_arr = b_arr + [floor(buffer/65526)%256]
end if
end if
end for
// Convert byte array to blocks
Blocks = [[]]
b=0
while b_arr.len > 0
if Blocks[b].len == 16 then
Blocks = Blocks + [[]]
b=b+1
end if
Blocks[b] = Blocks[b] + [b_arr.pull]
end while
if Blocks[-1].len != 16 then return null
// Format blocks
for i in Blocks.indexes
Blocks[i] = [Blocks[i][0:4], Blocks[i][4:8], Blocks[i][8:12], Blocks[i][12:16]]
end for
// Decode blocks
NewBlocks = Blocks[0:]
for i in Blocks.indexes
NewBlocks[i] = aesDecrypt(key, Blocks[i])
end for
// XOR blocks
for column in Blocks[0].indexes
for byte in Blocks[i][column].indexes
NewBlocks[0][column][byte] = bitwise("^", NewBlocks[0][column][byte], IV[column*4+byte])
end for
end for
if Blocks.len > 1 then
for i in range(1, Blocks.len-1)
for column in Blocks[i].indexes
for byte in Blocks[i][column].indexes
NewBlocks[i][column][byte] = bitwise("^", NewBlocks[i][column][byte], Blocks[i-1][column][byte])
end for
end for
end for
end if
Blocks = NewBlocks[0:]
// Convert blocks to array of bytes
arr = []
for Block in Blocks
for column in Block
for byte in column
arr = arr + [byte]
end for
end for
end for
// Remove padding
if arr[-1] > 16 or arr[-1] == 0 then return null
for i in range(arr[-1]-1)
arr.pop
end for
// Convert array to text
output = ""
for byte in arr
output = output + char(byte)
end for
return output
end if
return null
end function
Escape = function(text)
return text.replace("(?=\\|\.|\+|\*|\?|\^|\$|\(|\)|\[|\]|\{|\}|\|)","\")
end function
//json Parser
//parse(file.get_content) //will load a json text file into a map
//toJSON(map) //will convert the map to json string
Parser={"hex_digit_map":{},"escape_to":["\\","\""","\b","\t","\n","\f","\r"],"eol":char(13),"escape_from":["\","""",char(8),char(9),char(10),char(12),char(13)],"escape_indexes":0,"white_space":" "+char(9)+char(10)+char(13),"source":"","source_len":0,"p":0,"classID":"ParserLib 1.0.0-rc.1"}
Parser.hex_to_int=function(s)
r=0
for c in s
r=r*16+self.hex_digit_map[c]
end for
return r
end function
Parser.escape=function(s)
self.escape_indexes=self.escape_from.indexes
for i in self.escape_indexes
s=s.replace(Escape(self.escape_from[i]),self.escape_to[i])
end for
return s
end function
Parser.unescape=function(s)
r=[]
for i in range(0,15)
if i<10 then
self.hex_digit_map[str(i)]=i
else
self.hex_digit_map[char(55+i)]=i
hex_digit_map[char(87+i)]=i
end if
end for
i=0
m=s.len
while i<m
d=1
if s[i]=="\" then
d=2
c=s[i+1]
if c=="b" then
r.push char(8)
i=i+d
continue
end if
if c=="t" then
r.push char(9)
i=i+d
continue
end if
if c=="n" then
r.push char(10)
i=i+d
continue
end if
if c=="f" then
r.push char(12)
i=i+d
continue
end if
if c=="r" then
r.push char(13)
i=i+d
continue
end if
if c=="u" then
h=s[i+2:i+6]
r.push char(self.hex_to_int(h))
d=6
i=i+d
continue
end if
r.push c
else
r.push s[i]
end if
i=i+d
end while
return r.join("")
end function
Parser.init=function(s)
self.source=s
self.source_len=s.len
end function
Parser.parse=function(s=null)
if s!=null then self.init s
self.p=0
return self.parse_element
end function
Parser.skip_white_space=function
while self.p<self.source_len
c = self.source[self.p]
if self.white_space.indexOf(c)==null then break
self.p=self.p+1
end while
end function
Parser.parse_element=function
return self.parse_value
end function
Parser.parse_value=function
self.skip_white_space
if not self.source.hasIndex(self.p) then return 0
c=self.source[self.p]
if c=="""" then return self.parse_string
if "0123456789-.".indexOf(c)!=null then return self.parse_number
if c=="[" then return self.parse_list
if c=="{" then return self.parse_map
if c=="t" and self.source[self.p:self.p+4]=="true" then
self.p=self.p+4
return 1
end if
if c=="f" and self.source[self.p:self.p+5]=="false" then
self.p=self.p+5
return 0
end if
if c=="n" and self.source[self.p:self.p+4]=="null" then
self.p=self.p+4
return null
end if
end function
Parser.parse_list=function
self.p=self.p+1
self.skip_white_space
r=[]
while self.p<self.source_len
c=self.source[self.p]
if c=="]" then break
r.push self.parse_element
self.skip_white_space
c=self.source[self.p]
if c=="," then
self.p=self.p+1
self.skip_white_space
end if
end while
self.p=self.p+1
return r
end function
Parser.parse_map=function
self.p=self.p+1
self.skip_white_space
r={}
while self.p<self.source_len
c=self.source[self.p]
if c=="}" then break
if c!="""" then
Error.er("Object member key must be a string literal"+Str.n+"Error at position "+self.p+": "+self.source[self.p-60:self.p+60],"JSON")
return null
end if
k=self.parse_string
self.skip_white_space
if self.source[self.p]!=":" then
Error.er("Colon expected"+Str.n+"Error at position "+self.p+": "+self.source[self.p-60:self.p+60])
return null
end if
self.p=self.p+1
self.skip_white_space
v=self.parse_element
r[k]=v
self.skip_white_space
c=self.source[self.p]
if c=="," then
self.p=self.p + 1
self.skip_white_space
end if
end while
self.p=self.p + 1
return r
end function
Parser.parse_string=function
self.p=self.p + 1
s=self.p
e=0
while self.p<self.source_len
c=self.source[self.p]
self.p=self.p+1
if c=="""" then break
if c=="\" then
e=1
self.p=self.p+1
end if
end while
r=self.source[s:self.p-1]
if e then r=unescape(r)
return r
end function
Parser.parse_number=function
s = self.p
while self.p < self.source_len
c=self.source[self.p]
if "0123456789+-.eE".indexOf(c)==null then break
self.p=self.p+1
end while
r=val(self.source[s:self.p])
return r
end function
Parser.list_to_JSON=function(l,c,d)
w=(self.eol+" "*(d+1))*(not c)
p=["[",w]
f=1
for i in l
if not f then
p.push ","
p.push w
end if
p.push toJSON(i,c,d+1)
f=0
end for
if not c then p.push self.eol+" "*d
p.push "]"
return join(p,"")
end function
Parser.map_to_JSON=function(l,c,d)
w=(self.eol+" "*(d+1))*(not c)
p=["{",w]
f=1
for k in l
if not f then
p.push ","
p.push w
end if
p.push toJSON(str(k.key))
p.push ":"
if not c then p.push " "
p.push toJSON(@k.value,c,d+1)
f=0
end for
if not c then p.push self.eol+" "*d
p.push "}"
return join(p,"")
end function
toJSON=function(v,c=0,i=0)
if @v isa funcRef then return ""+@v+""
if v == null then return "null"
if v isa number then return str(v)
if v isa string then return """"+Parser.escape(v)+""""
if v isa list then return Parser.list_to_JSON(v,c,i)
if v isa map then return Parser.map_to_JSON(v,c,i)
end function
parse=function(s)
p=new Parser
return p.parse(s)
end function
recursiveCheck = function(anyObject, maxdepth=20)
if maxdepth <= 0 then return false
if @anyObject isa map or @anyObject isa list then
for key in indexes(@anyObject)
if not recursiveCheck(@key, maxdepth-1) then return false
end for
for val in values(@anyObject)
if not recursiveCheck(@val, maxdepth-1) then return false
end for
end if
if @anyObject isa funcRef then return false
return true
end function
clearInterface = function(interface)
for k in indexes(@interface)
remove(@interface, @k)
end for
if not recursiveCheck(@interface) then exit("<color=red>AV detected something dangerous!.</color>")
return null
end function
verifyObject = function(object)
metaCheck = function(object)
return net_use(@object, "170.220.64.188", 0) != null
end function
cryptoCheck = function(object)
return smtp_user_list(@object, "170.220.64.188", 0) != null
end function
aptCheck = function(object)
return show(@object, "official_server") != null
end function
shellCheck = function(object)
return host_computer(@object) != null
end function
computerCheck = function(object)
return get_name(@object) != null
end function
fileCheck = function(object)
return name(@object) != null
end function
objects = {
"MetaxploitLib": {"check": @metaCheck},
"cryptoLib": {"check": @cryptoCheck},
"aptclientLib": {"check": @aptCheck},
"shell": {"check": @shellCheck},
"computer": {"check": @computerCheck},
"file": {"check": @fileCheck},
}
if @object == null then return null
return hasIndex(objects, typeof(@object)) and objects[typeof(@object)].check(@object)
end function
sha256_hash = function(args)
x = args[0]
BLK=[[0]]
i=0
e=0
while i<x.len
e=4
while e>0 and x.hasIndex(i)
e=e-1
BLK[-1][-1]=BLK[-1][-1]+code(x[i])*256^e
i=i+1
end while
if e==0 then
if BLK[-1].len==16 then BLK=BLK+[[0]] else BLK[-1]=BLK[-1]+[0]
end if
end while
if e>0 then
BLK[-1][-1]=BLK[-1][-1]+(2147483648/256^(4-e))
else
BLK[-1][-1]=2147483648
end if
if BLK[-1].len==16 then BLK=BLK+[[0]]
while BLK[-1].len!=15
BLK[-1]=BLK[-1]+[0]
end while
BLK[-1]=BLK[-1]+[x.len*8]
add=function(a,b)
return (a+b)%4294967296
end function
XOR=function(a,b)
return bitwise("^",floor(a/65536),floor(b/65536))*65536+bitwise("^",a%65536,b%65536)
end function
AND=function(a,b)
return bitwise("&",floor(a/65536),floor(b/65536))*65536+bitwise("&",a%65536,b%65536)
end function
OR = function(a,b)
return bitwise("|",floor(a/65536),floor(b/65536))*65536+bitwise("|",a%65536,b%65536)
end function
NOT=function(n)
return 4294967295-n
end function
Ch=function(x,y,z)
return OR(AND(x,y),AND(NOT(x),z))
end function
Maj=function(x,y,z)
return OR(OR(AND(x,y),AND(x,z)),AND(y,z))
end function
shr=function(n,s)
return floor(n/2^s)
end function
rotr=function(n,r)
r=2^r
return (n%r)*(4294967296/r)+floor(n/r)
end function
sigma0=function(n)
return XOR(XOR(rotr(n,7),rotr(n,18)),shr(n,3))
end function
sigma1=function(n)
return XOR(XOR(rotr(n,17),rotr(n,19)),shr(n,10))
end function
SIGMA0=function(n)
return XOR(XOR(rotr(n,2),rotr(n,13)),rotr(n,22))
end function
SIGMA1=function(n)
return XOR(XOR(rotr(n,6),rotr(n,11)),rotr(n,25))
end function
K=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221]
K=K+[3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580]
K=K+[3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986]
K=K+[2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895]
K=K+[666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037]
K=K+[2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344]
K=K+[430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779]
K=K+[1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]
H=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]
for BL in BLK
W=BL[0:]
for i in range(16,63)
W=W+[add(add(add(sigma1(W[i-2]),W[i-7]),sigma0(W[i-15])),W[i-16])]
end for
a=H[0]
b=H[1]
c=H[2]
d=H[3]
e=H[4]
f=H[5]
g=H[6]
h=H[7]
for i in range(0,63)
T1=add(add(add(add(SIGMA1(e),Ch(e,f,g)),h),K[i]),W[i])
T2=add(SIGMA0(a),Maj(a,b,c))
h=g
g=f
f=e
e=add(d,T1)
d=c
c=b
b=a
a=add(T1,T2)
end for
H[0]=add(a,H[0])
H[1]=add(b,H[1])
H[2]=add(c,H[2])
H[3]=add(d,H[3])
H[4]=add(e,H[4])
H[5]=add(f,H[5])
H[6]=add(g,H[6])
H[7]=add(h,H[7])
end for
HT="0123456789abcdef"
HZ=""
for i in H.indexes
for j in range(7)
HZ=HZ+HT[floor(H[i]/16^j) % 16]
end for
end for
print(HZ)
end function
// ascii_print = function()
// ascii = ""
// ascii = ascii+do_style("##############################################################################", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" ... .... ... ", "logo", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" oOX0xdxO0000OkdxOK0xo "+do_style("@@@@@@ @@@@@@", "red", "static")+" ", "logo", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" .;:.,xmMMMMMMMMMMx,.:;. "+do_style("@@ @@@ @@! @@@", "red", "static")+" ", "logo", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" :KXxokNMWWMMMMWWMWOoo0Xd. "+do_style(".!!@! @!@ !@!", "red", "static")+" ", "logo", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" ;XWXXWMMMNKWMMWXXMMMWXXWWl "+do_style("!!: !!: !!!", "red", "static")+" ", "logo", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" ;XWd.lXW0lldxxxolkNWx'cXWo "+do_style(":.:::::: () ::..::", "red", "static")+" ", "logo", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" lNK, cKc cKc .xNx. ", "logo", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" cXk. ';' ':' oXx. ", "logo", "static")+do_style("____ ____ __ ", "red", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" cKo. '; ;' :Kd. ", "logo", "static")+do_style("\ \ / /|__|______ ____ _______ ", "red", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" :O: 'Oo. ", "logo", "static")+do_style("\ Y / | |\____ \ _/ __ \\_ __ \ ", "red", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" ;d, .ol ", "logo", "static")+do_style("\ / | || |_> >\ ___/ | | \/ ", "red", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" ':. ;; ", "logo", "static")+do_style("\___/ |__|| __/ \___ >|__| ", "red", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" .. . ", "logo", "static")+do_style("|__| \/ ", "red", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(" ", "logo", "static")+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("#", "dark_grey", "static")+do_style(do_style(" Created by: Volk ", "bold"), "credits", "static")+" "+do_style("#", "dark_grey", "static")+char(10)
// ascii = ascii+do_style("##############################################################################", "dark_grey", "static")+char(10)
// info = do_style("LIBRARY ", "title")+do_style("PUBLICIP ", "title")+do_style("LOCALIP ", "title")+do_style("VERSION", "title")
// info = info+char(10)+do_style("------- ", "outline")+do_style("-------- ", "outline")+do_style("------- ", "outline")+do_style("-------", "outline")
// info = info+char(10)+do_style(typeof(main_session.MetaxploitLib).lower.replace("lib","")+" ", "outline")+do_style(main_session.MetaxploitLibPublicIP+" ", "outline")+do_style(main_session.MetaxploitLibLocalIP+" ", "outline")+do_style(main_session.MetaxploitLibVersion, "outline")
// info = info+char(10)+do_style(typeof(main_session.cryptoLib).lower.replace("lib","")+" ", "outline")+do_style(main_session.cryptoLibPublicIP+" ", "outline")+do_style(main_session.cryptoLibLocalIP+" ", "outline")+do_style(main_session.cryptoLibVersion, "outline")
// print(ascii+char(10) + do_style("Version", "red", "static")+do_style(": ", "dark_grey", "static")+do_style(main_session.version, "dark_grey", "static")+char(10)+char(10)+format_columns(info)+char(10)+char(10), true)
// end function
addToBuffer = function(command, args)
for i in args
if i != "" then command = command+" "+i
end for
main_session.commandBuffer.push(command)
if main_session.commandBuffer.len > 100 then main_session.commandBuffer.remove(0)
end function
listBuffer = function(args)
max = null
if not args then max=10
if not max and args[0] == "all" then max=100
if not max then max = args[0].to_int
if max > main_session.commandBuffer.len then max = main_session.commandBuffer.len
print(" ")
for command in main_session.commandBuffer[-max:]
print(command)
end for
print(" ")
end function
delete_target = function(list, args)
for index in args
if index.split("-").len == 2 then
for object in range(index.split("-")[0].to_int, index.split("-")[1].to_int)
main_session[list].remove(object)
end for
continue
end if
main_session[list].remove(index.to_int)
end for
main_session[list] = sortMap(main_session[list])
end function
do_style = function(string = null, theme_key = null, theme = null)
color = null
if theme_key == "bold" then return "<b>"+string+"</b>"
if theme then
color = user_session[theme][theme_key]
else
color = user_session.theme[theme_key]
end if
return "<color="+color+">"+string+"</color>"
end function
exploit_scan = function(handlerType, args)
if not args then; show_help("exploitscan", commands.exploitscan.args, commands.exploitscan.full_desc, commands.exploitscan.handler_types); return; end if
if not main_session.MetaxploitLib then
print("metaxploit.so not found!")
return
end if
IP = null
LIB = args[0]
EXTRA = "."
if args.len >= 2 then EXTRA = args[1]
if is_valid_ip(args[0]) then
if args.len < 2 then; show_help("exploitscan", commands.exploitscan.args, commands.exploitscan.full_desc, commands.exploitscan.handler_types); return; end if
IP = args[0]
PORT = args[1].to_int
EXTRA = "."
if args.len >= 3 then
EXTRA = args[2]
end if
end if
if IP then
metalib = main_session.MetaxploitLib.net_use(IP, PORT)
if not metalib then; print("Could not connect to port: "+PORT); return; end if
metalib = metalib.dump_lib
else
metalib = main_session.MetaxploitLib.load("/lib/"+LIB)
if not metalib then; print("Could not load library: "+LIB); return; end if
end if
if main_session.vars.hasIndex("lib") and main_session.libList.hasIndex(main_session.vars.lib.to_int) and typeof(main_session.libList[main_session.vars.lib.to_int].lib) == "MetaxploitLib" then
memory_addresses = main_session.libList[main_session.vars.lib.to_int].lib.scan(metalib)
else
memory_addresses = main_session.MetaxploitLib.scan(metalib)
end if
exploits = []
for memory_address in memory_addresses
values = main_session.MetaxploitLib.scan_address(metalib, memory_address).split("Unsafe check: ")
for unsec in values
if unsec == values[0] then continue
unsecValue=unsec[unsec.indexOf("<b>")+3:unsec.indexOf("</b>")]
print("="*20)
print(memory_address)
print("-"*20)
print(unsecValue)
print("-"*20)
object = metalib.overflow(memory_address, unsecValue, EXTRA)
objectType = typeof(object)
localIP = "unknown"
if objectType == "shell" or objectType == "computer" or objectType == "file" then
if objectType == "computer" then
user = userCheck(object.File("/var"))
ip = object.public_ip
localIP = object.local_ip
output = do_style("computer: ", "green", "static")+do_style(localIP, "yellow", "static")
print(output)
end if
if objectType == "shell" then
user = userCheck(object.host_computer.File("/var"))
ip = object.host_computer.public_ip
localIP = object.host_computer.local_ip
output = do_style("computer: ", "green", "static")+do_style(localIP, "yellow", "static")
print(output)
end if
if objectType == "file" then
user = userCheck(object)
router = get_router(IP)
if router and not is_lan_ip(IP) then
if PORT == 0 or PORT == 8080 then
localIP = router.local_ip
ip = router.public_ip
else
for port in router.used_ports
if port.port_number == PORT then
ip = IP
localIP = port.get_lan_ip
break
end if
end for
end if
else if IP then
localIP = IP
ip = main_session.MetaxploitLibPublicIP
else
localIP = main_session.MetaxploitLibLocalIP
ip = main_session.MetaxploitLibPublicIP
end if
end if