forked from mahocitrus/rocShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrocShellWithAPI.gs
More file actions
1033 lines (1021 loc) · 44.9 KB
/
rocShellWithAPI.gs
File metadata and controls
1033 lines (1021 loc) · 44.9 KB
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
clear_screen //if you dont like screen to be cleared remove this line
{"ver":"1.0.5", "api":true} //release. today is huge.
import_code("/root/cloudExploitAPI") //This is for cloud exploit base in multiplayer.
local = {}
local.shell = get_shell
local.computer = get_shell.host_computer
local.folder = local.computer.File(current_path)
local.router = get_router
local.user = active_user
local.lanIp = get_shell.host_computer.local_ip
local.publicIp = get_router.public_ip
if not local.computer.is_network_active then print("No internet access.")
aptclient = include_lib(current_path + "/aptclient.so")
if not aptclient then aptclient = include_lib("/lib/aptclient.so")
if not aptclient then print("missing lib apiclient.so in lib or current path")
blockchain = include_lib(current_path + "/blockchain.so")
if not blockchain then blockchain = include_lib("/lib/blockchain.so")
if not blockchain then print("missing lib blockchain.so in lib or current path")
crypto = include_lib(current_path + "/crypto.so")
if not crypto then crypto = include_lib("/lib/crypto.so")
if not crypto then print("missing lib crypto.so in lib or current path")
metaxploit = include_lib(current_path + "/metaxploit.so")
if not metaxploit then metaxploit = include_lib("/lib/metaxploit.so")
if not metaxploit then print("missing lib metaxploit.so in lib or current path")
current = {}
current.obj = local.shell
current.computer = function
if typeof(current.obj) == "shell" then return current.obj.host_computer
if typeof(current.obj) == "computer" then return current.obj
return null
end function
current.router = local.router
current.folder = local.folder
current.user = local.user
current.lanIp = local.lanIp
current.publicIp = function
return current.router.public_ip
end function
libs = {}
libs.absolutePath = function(rPath, cPath) //current path + relative path = absolute path
if rPath.len == 0 then return print("invalid path.")
if rPath[0] == "/" then return rPath
if cPath.len == 0 then return print("invalid path.")
if not cPath[0] == "/" then return print("invalid path.")
if not cPath[-1] == "/" then cPath = cPath + "/"
absPath = cPath + rPath
while absPath.len > 1 and absPath[-1] == "/"
absPath = absPath[:-1]
end while
return absPath
end function
libs.changeDir = function(toPath, fileObject) //go to another dir
if not fileObject then fileObject = globals.current.folder
while fileObject.parent
fileObject = fileObject.parent
end while
if toPath.len == 0 then return print("File not found.")
while (toPath.len > 1) and (toPath[-1] == "/") //trim end "/"
toPath = toPath[:-1]
end while
while (toPath.len > 1) and (toPath[0] == "/") //trim start "/"
toPath = toPath[1:]
end while
if toPath == "/" then return fileObject
toPath = toPath.split("/")
for p in toPath
found = false
for f in fileObject.get_folders
if not f.name == p then continue
found = true
fileObject = f
break
end for
if not found then return print("Folder not found.")
end for
if not fileObject.is_folder then return print("Folder not found.")
return fileObject
end function
libs.getFile = function(toPath, fileObject) //changeDir only support folder but this works for both
if not fileObject then fileObject = globals.current.folder
while fileObject.parent
fileObject = fileObject.parent
end while
if toPath.len == 0 then return print("File not found.")
while (toPath.len > 1) and (toPath[-1] == "/") //trim end "/"
toPath = toPath[:-1]
end while
while (toPath.len > 1) and (toPath[0] == "/") //trim start "/"
toPath = toPath[1:]
end while
if toPath == "/" then return fileObject
toPath = toPath.split("/")
for i in toPath.indexes
found = false
if i == (toPath.len - 1) then
for f in fileObject.get_folders + fileObject.get_files
if not f.name == toPath[i] then continue
return f
end for
return print("File not found")
end if
for f in fileObject.get_folders
if not f.name == toPath[i] then continue
found = true
fileObject = f
break
end for
if not found then return print("File not found.")
end for
return fileObject
end function
libs.allFiles = function(fileObject) //list all file object under a dir
if not fileObject then
fileObject = globals.current.folder
while fileObject.parent
fileObject = fileObject.parent
end while
end if
files = [fileObject] + fileObject.get_folders + fileObject.get_files
i = 0
while i < files.len
if files[i].is_folder then files = files + files[i].get_folders + files[i].get_files
i = i + 1
if i > 200 then break //prevent huge file system
end while
return files
end function
libs.find = function(fileName, fileObject) //find files under a dir
founded = []
files = self.allFiles(fileObject)
for file in files
if lower(file.name).indexOf(lower(fileName)) != null then founded = founded + [file]
end for
return founded
end function
libs.toFile = function(anyObject)
if typeof(anyObject) == "shell" then return anyObject.host_computer.File("/")
if typeof(anyObject) == "computer" then return anyObject.File("/")
if typeof(anyObject) == "file" then
while anyObject.parent
anyObject = anyObject.parent
end while
return anyObject
end if
return null
end function
libs.checkAccess = function(fileObject) //check perm for npc machine
if not typeof(fileObject) == "file" then return null
while fileObject.parent
fileObject = fileObject.parent
end while
homeFolder = null
for folder in fileObject.get_folders
if folder.name == "root" then
if folder.has_permission("w") and folder.has_permission("r") and folder.has_permission("x") then return "root"
end if
if folder.name == "home" then
homeFolder = folder
end if
end for
if not homeFolder then return "guest"
for folder in homeFolder.get_folders
if folder.name == "guest" then continue
if folder.has_permission("w") and folder.has_permission("r") and folder.has_permission("x") then return folder.name
end for
return "guest"
end function
libs.corruptLog = function(fileObject) //corrupt system log by copy the smallest file to that dir
if not fileObject then fileObject = current.folder
while fileObject.parent
fileObject = fileObject.parent
end while
files = self.allFiles(fileObject)
toCopy = null
for file in files
if (not file.is_folder) and file.has_permission("r") then
if not toCopy then toCopy = file
if val(file.size) < val(toCopy.size) then toCopy = file
end if
end for
if not toCopy then return print("No file to overwrite log! try using ""touch"".")
logFile = null
for file in files
if not file.path == "/var/system.log" then continue
logFile = file
break
end for
if not logFile then return print("log file not found!")
tryDelete = logFile.delete
if tryDelete == "" then print("Log file deleted.") else return print("Error: " + deleteLogFile)
tryCopy = toCopy.copy("/var", "system.log")
if tryCopy == true then return print("All steps done. Log cleared.")
return print(tryCopy)
end function
libs.fileSize = function(bytes) //translate byte to kb and mb
bytes = bytes.to_int
i = 0
units = ["B","KB","MB","GB","TB","PT"]
while bytes > 1024
bytes = bytes / 1024
i = i + 1
end while
return round(bytes, 2) + units[i]
end function
libs.scanLib = function(metaLib, metaxploit)
if not metaLib then return null
if not metaxploit then metaxploit = globals.metaxploit
ret = {}
ret.lib_name = metaLib.lib_name
ret.version = metaLib.version
ret.memorys = {}
memorys = metaxploit.scan(metaLib)
for memory in memorys
addresses = metaxploit.scan_address(metaLib, memory).split("Unsafe check:")
ret.memorys[memory] = []
for address in addresses
if address == addresses[0] then continue
value = address[address.indexOf("<b>")+3:address.indexOf("</b>")]
value = value.replace("\n", "")
ret.memorys[memory] = ret.memorys[memory] + [value]
end for
end for
return ret
end function
libs.typeofFile = function(fileObject)
if not typeof(fileObject) == "file" then return null
if fileObject.is_folder then return "fld"
if fileObject.is_binary then return "bin"
return "txt"
end function
computerCommands = {}
computerCommands["ps"] = {"name":"ps", "description":"List processes running.", "args":""}
computerCommands["ps"]["run"] = function(args)
computer = current.computer
procs = computer.show_procs
procs = procs.split("\n")
output = ""
for proc in procs
val = proc.split(" ")
if val[0] == "USER" then continue
output = output + "\n" + "[" + val[0] + "] (" + val[1] + ") " + val[4] + " " + "CPU: [" + val[2] + "] " + "MEM: [" + val[3] + "]"
end for
return print(format_columns(output) + "\n")
end function
computerCommands["kill"] = {"name":"kill", "description":"Kill a process.", "args":"[PID]"}
computerCommands["kill"]["run"] = function(args)
if args.len < 1 then return print("Usage: kill [PID]")
PID = args[0].to_int
if typeof(PID) != "number" then return print("The PID must be a number.")
computer = current.computer
output = computer.close_program(PID) //close PID
if output == true then return print("Process " + PID + " closed")
if output then return print(output)
return print("Process " + PID + " not found")
end function
computerCommands["touch"] = {"name":"touch", "description":"Create a text file.", "args":"[file_path]"}
computerCommands["touch"]["run"] = function(args)
if args.len < 1 then return print("Usage: touch [file_name]")
path = libs.absolutePath(args[0], current.folder.path)
if path == null then return print("path not found")
parent = parent_path(path)
name = path.split("/")[-1]
doTouch = current.computer.touch(parent, name)
if doTouch == true then return print("Done.")
print(doTouch)
return print("Failed.")
end function
computerCommands["mkdir"] = {"name":"mkdir", "description":"Create a empty folder.", "args":"[folder_path]"}
computerCommands["mkdir"]["run"] = function(args)
if args.len < 1 then return print("Usage: mkdir [folder_path]")
path = libs.absolutePath(args[0], current.folder.path)
if path == null then return print("path not found")
parent = parent_path(path)
name = path.split("/")[-1]
doMkdir = current.computer.create_folder(parent, name)
if doMkdir == true then return print("Done.")
print(doMkdir)
return print("Failed.")
end function
computerCommands["netinfo"] = {"name":"netinfo", "description":"Display net info", "args":""}
computerCommands["netinfo"]["run"] = function(args)
computer = current.computer
print(computer.public_ip)
print(computer.local_ip)
print(computer.active_net_card)
if computer.active_net_card == "WIFI" then
netcards = computer.network_devices
for netcard in netcards.split(char(10))
interface = netcard.split(" ")[0]
print(interface)
for wifi in computer.wifi_networks(interface)
print(wifi)
end for
end for
end if
return null
end function
computerCommands["wifi"] = {"name":"wifi", "description":"Connect Wifi.", "args":"[device] [bssid] [essid] [password]"}
computerCommands["wifi"]["run"] = function(args)
if args.len < 3 then return print("Usage: wifi [device] [bssid] [essid] [password]")
computer = current.computer
return print(computer.connect_wifi(args[0], args[1], args[2], args[3]))
end function
shellCommands = {}
shellCommands["shell"] = {"name":"shell", "description":"Starts terminal. Watch out for active traces.", "args":"[PID]"}
shellCommands["shell"]["run"] = function(args)
return current.obj.start_terminal
end function
shellCommands["ssh"] = {"name":"ssh", "description":"Connect to a ssh service. I hate ftp.", "args":"[user@password] [ip] [(opt) port]"}
shellCommands["ssh"]["run"] = function(args)
if args.len < 2 then return print("usage: ssh [user@password] [ip] [(opt) port]")
sshUser = args[0].split("@")[0]
sshPass = args[0].split("@")[1]
sshIp = args[1]
if args.len > 2 then port = args[2].to_int else port = 22
if not port isa number then return print("Invalid port.")
localShell = current.obj
remoteShell = localShell.connect_service(sshIp, port, sshUser, sshPass, "ssh")
if not typeof(remoteShell) == "shell" then
print(remoteShell)
return print("Connection failed.")
end if
if sshUser == "root" then homePath = "/root" else homePath = "/home/" + sshUser
globals.current.obj = remoteShell
globals.current.folder = remoteShell.host_computer.File(homePath)
globals.current.user = sshUser
if not is_lan_ip(sshIp) then globals.current.router = get_router(sshIp)
globals.current.lanIp = remoteShell.host_computer.local_ip
return print("Connected.")
end function
shellCommands["up"] = {"name":"up", "description":"Upload a file. Only take absolute path.", "args":"[local_file_path] [remote_path]"}
shellCommands["up"]["run"] = function(args)
if args.len < 2 then return print("Usage: up [local_file_path] [remote_path].")
localShell = local.shell
remoteShell = current.obj
pathFrom = args[0]
pathTo = args[1]
fileFrom = globals.local.computer.File(pathFrom) //get file
folderTo = globals.current.obj.host_computer.File(pathTo) //get folder
if not folderTo then return print("Remote directory not found.") //check if folder exists
if not folderTo.is_folder then return print("Remote directory not found.") //check if folder exists
if not fileFrom then return print("Local file not found: " + pathFrom) //not found print error msg
print("Uploading file: " + fileFrom.name + " to: " + pathTo) //found print target path
upload = localShell.scp(pathFrom, pathTo, remoteShell) //func call as upload
if not typeof(upload) == "string" then return print("File uploaded successfully.")
return print(upload)
end function
shellCommands["dl"] = {"name":"dl", "description":"download a file.", "args":"[remote_file_path] [local_path]"}
shellCommands["dl"]["run"] = function(args)
localShell = local.shell
remoteShell = current.obj
if args.len < 2 then return print("Usage: dl [remote_file_path] [local_path].")
pathFrom = args[0]
pathTo = args[1]
fileFrom = globals.current.obj.host_computer.File(pathFrom)//get file
folderTo = globals.local.computer.File(pathTo) //get folder
if not folderTo then return print("Local directory not found.") //check if folder exists
if not folderTo.is_folder then return print("Local directory not found.") //check if folder exists
if not fileFrom then return print("Remote file not found: " + pathFrom) //not found print error msg
print("Downloading file: " + fileFrom.name + " to: " + pathTo) //found print target path
download = remoteShell.scp(pathFrom, pathTo, localShell) //func call as download
if not typeof(download) == "string" then return print("File uploaded successfully.")
return print(download)
end function
shellCommands["run"] = {"name":"run", "description":"Execute a program.", "args":"[path] [(opt) params]"}
shellCommands["run"]["run"] = function(args)
if args.len < 1 then return print("Program not found")
return current.obj.launch(args[0], args[1:].join(" "))
end function
shellCommands["ping"] = {"name":"ping", "description":"Ping a ip.", "args":"[ip]"}
shellCommands["ping"]["run"] = function(args)
if args.len < 1 then return print("Invalid ip.")
result = current.obj.ping(params[0])
if result then
if typeof(result) == "string" then
print(result)
else
print("Ping successful")
end if
else
print("ip unreachable");
end if
return true
end function
shellCommands["build"] = {"name":"build", "description":"Compile a program.", "args":"[source_path] [to_path] [(opt) allow_import]"}
shellCommands["build"]["run"] = function(args)
if args.len < 2 then return print("Path invalid.")
allowedImport = false
if args.len > 2 then
if (args[2].lower == "true") or (args[2].to_int == 1) then allowedImport = true
end if
return print(current.obj.build(args[0], args[1], allowedImport))
end function
commands = {}
commands["re"] = {"name":"re", "description":"Remote attack.", "args":"[ip] [port] [(opt) injectArg]"}
commands["re"]["run"] = function(args)
if args.len < 2 then return print("Usage: re [ip] [port] [(opt) injectArg]")
targetIp = args[0]
if not is_valid_ip(targetIp) then targetIp = nslookup(targetIp)
if not is_valid_ip(targetIp) then return print("Invalid ip.")
targetPort = args[1].to_int
if args.len > 2 then injectArg = args[2] else injectArg = ""
netSession = metaxploit.net_use(targetIp, targetPort)
netSession = metaxploit.net_use(targetIp, targetPort) //this extra line is for some game mechanics
if not netSession then return print("Unable to make net session.")
metaLib = netSession.dump_lib
if not metaLib then return print("Unable to dump lib.")
forceLocal = false
while true
exploits = queryExploit(metaLib.lib_name, metaLib.version) //Request exploit from cloud database API
//exploits = libs.scanLib(metaLib, metaxploit) //This is the full local version.
if (not exploits) or forceLocal then
exploits = remoteScan(targetIp, targetPort) //Scan for exploit and send to cloud database thru API
forceLocal = true
end if
if not exploits then return print("Unable to scan for exploits.")
results = []
for e in exploits.memorys
for value in e.value
object = metaLib.overflow(e.key, value, injectArg)
if (typeof(object) != "shell") and (typeof(object) != "computer") and (typeof(object) != "file") then continue
result = {"object":object, "user":libs.checkAccess(libs.toFile(object)), "addr":e.key, "valn":value}
results = results + [result]
end for
end for
toPrint = ""
for i in results.indexes
toPrint = toPrint + str(i + 1) + ". " + results[i].user + ":" + typeof(results[i].object) + " " + results[i].addr + " " + results[i].valn + char(10)
end for
if not forceLocal then
print("Perform a force local scan may find more exploits.")
print("Enter ""f"" to do a local scan.")
end if
print(format_columns(toPrint))
select = user_input("Select> ").to_int
if not typeof(select) == "number" then
if not lower(select) == "f" then return null
if forceLocal then return null
forceLocal = true
continue
end if
if select > results.len then return null
if select < 1 then return null
select = select - 1
globals.current.obj = results[select].object
if not is_lan_ip(targetIp) then globals.current.router = get_router(targetIp)
globals.current.folder = libs.toFile(results[select].object)
globals.current.user = results[select].user
if targetPort == 0 then
if is_lan_ip(injectArg) then //first we guess the ip, if the injected string is a lan ip, we assume it is that.
globals.current.lanIp = injectArg //this may not be correct.
if libs.getFile("/lib/kernel_router.so", current.folder) then globals.current.lanIp = current.router.local_ip //if we find router kernel we set ip to router
else
globals.current.lanIp = current.router.local_ip //if the injected string is not a lan ip, the correct lan ip must be the router lan ip.
end if
if current.computer then globals.current.lanIp = current.computer.local_ip //if we have a shell or a computer, we set the ip to the correct one.
else
if is_lan_ip(targetIp) then globals.current.lanIp = targetIp else globals.current.lanIp = current.router.ping_port(targetPort).get_lan_ip //this may not be correct. TODO
end if
return null
end while
end function
commands["lo"] = {"name":"lo", "description":"Local attack.", "args":"[lib_path] [(opt) injectArg]"}
commands["lo"]["run"] = function(args)
if args.len < 1 then return print("Usage: lo [lib_path] [(opt) injectArg]")
targetPath = args[0]
if args.len > 1 then injectArg = args[1] else injectArg = ""
metaLib = metaxploit.load(targetPath)
if not metaLib then return print("Unable to load lib.")
forceLocal = false
while true
exploits = queryExploit(metaLib.lib_name, metaLib.version) //Request exploit from cloud database API
//exploits = libs.scanLib(metaLib, metaxploit) //This is the full local version.
if (not exploits) or forceLocal then
exploits = localScan(targetPath) //Scan for exploit and send to cloud database thru API
forceLocal = true
end if
if not exploits then return print("Unable to scan for exploits.")
results = []
for e in exploits.memorys
for value in e.value
object = metaLib.overflow(e.key, value, injectArg)
if (typeof(object) != "shell") and (typeof(object) != "computer") and (typeof(object) != "file") then continue
result = {"object":object, "user":libs.checkAccess(libs.toFile(object)), "addr":e.key, "valn":value}
results = results + [result]
end for
end for
toPrint = ""
for i in results.indexes
toPrint = toPrint + str(i + 1) + ". " + results[i].user + ":" + typeof(results[i].object) + " " + results[i].addr + " " + results[i].valn + char(10)
end for
if not forceLocal then
print("Perform a force local scan may find more exploits.")
print("Enter ""f"" to do a local scan.")
end if
print(format_columns(toPrint))
select = user_input("Select> ").to_int
if not typeof(select) == "number" then
if forceLocal then return null
if not lower(select) == "f" then return null
forceLocal = true
continue
end if
if select > results.len then return null
if select < 1 then return null
select = select - 1
globals.current.obj = results[select].object
globals.current.folder = libs.toFile(results[select].object)
globals.current.user = results[select].user
return null
end while
end function
commands["nmap"] = {"name":"nmap", "description":"Scan a ip or a domain.", "args":"[ip/domain]"}
commands["nmap"]["run"] = function(args) //thanks to Nameless for this awesome nmap. I am too lazy to write a new one. It is MIT licensed anyway.
if args.len < 1 then return print("Invalid ip.")
targetIp = args[0]
if not is_valid_ip(targetIp) then targetIp = nslookup(targetIp)
if not is_valid_ip(targetIp) then return print("Invalid ip.")
if is_lan_ip(targetIp) then //this is a huge if else statement i know sorry too lazy to change
router = current.router
lanPorts = router.device_ports(targetIp)
publicPorts = router.used_ports
print("\nLocal Machine at " + targetIp)
if lanPorts.len == 0 then print("| | --> No local ports detected.")
for lanPort in lanPorts
s = "| |"
if lanPort.is_closed then
s = s + "-X-> "
else
s = s + "---> "
end if
s = s + ":" + lanPort.port_number + " "
s = s + router.port_info(lanPort)
for publicPort in publicPorts
iPort = router.ping_port(publicPort.port_number)
if iPort.port_number == lanPort.port_number and iPort.get_lan_ip == targetIp then
s = s + "-->" + " External Address: " + router.public_ip + ":" + publicPort.port_number
end if
end for
print(s)
end for
if not router.kernel_version then
print("Warning: kernel_router.so not found")
else
print("kernel_router.so version: " + router.kernel_version) //print router version
end if
print("|\n|---> " + router.essid_name + " (" + router.bssid_name + ")")
print(" Public IP: " + router.public_ip + " Private IP: " + router.local_ip)
print(whois(router.public_ip))
firewall_rules = router.firewall_rules
if typeof(firewall_rules) == "string" then return print(firewall_rules)
print("\nScanning firewall rules...\n")
if firewall_rules.len == 0 then return print("No rules found.")
info = "ACTION PORT SOURCE_IP DESTINATION_IP"
for rules in firewall_rules
info = info + "\n" + rules
end for
print(format_columns(info) + "\n")
else
router = get_router(targetIp)
publicPorts = router.used_ports
print("\n" + router.essid_name + " (" + router.bssid_name + ")")
print("Public IP: " + router.public_ip + " Private IP: " + router.local_ip)
print(whois(router.public_ip))
portFwds = []
blankPorts = []
for publicPort in publicPorts
lanPort = router.ping_port(publicPort.port_number)
if lanPort then portFwds.push({"external":publicPort, "internal":lanPort})
arrows = "--->"
arrows2 = " ---> "
if publicPort.is_closed then arrows = "-X->"
if not router.ping_port(publicPort.port_number) then
arrows2 = " ---> ? "
else if router.ping_port(publicPort.port_number) and router.ping_port(publicPort.port_number).is_closed then
arrows2 = " -X-> "
end if
print(" | |"+arrows+" :" + publicPort.port_number + " " + router.port_info(publicPort).split(" ")[0] + " " + router.port_info(publicPort).split(" ")[1] +arrows2 + publicPort.get_lan_ip)
end for
if not router.devices_lan_ip then
print(" |-> No local machines detected.")
else
for lanMachine in router.devices_lan_ip
print(" |-> Machine at " + lanMachine + "")
vbar = "|"
if router.devices_lan_ip.indexOf(lanMachine) == (router.devices_lan_ip.len - 1) then vbar = " "
if not router.device_ports(lanMachine) then
print(" " + vbar + " |--> No ports detected.")
else
for port in router.device_ports(lanMachine)
arrows = "-->"
if port.is_closed then arrows = "-X>"
toPrint = " " + vbar + " |" + arrows + " :" + port.port_number + " " + router.port_info(port).split(" ")[0] + " " + router.port_info(port).split(" ")[1]
for portFwd in portFwds
if port.get_lan_ip == portFwd.internal.get_lan_ip and port.port_number == portFwd.internal.port_number then toPrint = toPrint + " ---> external port " + portFwd.external.port_number
end for
print(toPrint)
end for
end if
end for
end if
if not router.kernel_version then
print("Warning: kernel_router.so not found")
else
print("kernel_router.so version: " + router.kernel_version) //print router version
end if
firewall_rules = router.firewall_rules
if typeof(firewall_rules) == "string" then return print(firewall_rules)
print("\nScanning firewall rules...\n")
if firewall_rules.len == 0 then return print("No rules found.")
info = "ACTION PORT SOURCE_IP DESTINATION_IP"
for rules in firewall_rules
info = info + "\n" + rules
end for
print(format_columns(info) + "\n")
end if
end function
commands["cd"] = {"name":"cd", "description":"Moves to a different directory.", "args":"[(opt) path]"}
commands["cd"]["run"] = function(args)
if args.len < 1 then
if current.user == "root" then toPath = "/root" else toPath = "/home/" + current.user
else
if args[0] == "." then return null
if args[0] == ".." then
if current.folder.parent then globals.current.folder = current.folder.parent
return null
end if
toPath = libs.absolutePath(args[0], current.folder.path)
if not toPath then return null
end if
folderObj = current.folder
while folderObj.parent
folderObj = folderObj.parent
end while
toFolder = libs.changeDir(toPath, folderObj)
if not typeof(toFolder) == "file" then
if args.len < 1 then globals.current.folder = folderObj else print("No such directory.")
return null
end if
if not toFolder.is_folder then return print("No such directory.")
globals.current.folder = toFolder
return true
end function
commands["ls"] = {"name":"ls", "description":"List all files.", "args":"[(opt) path]"}
commands["ls"]["run"] = function(args)
if args.len == 0 then toPath = current.folder.path else toPath = libs.absolutePath(args[0], current.folder.path)
if not toPath then return print("No such directory.")
folderObj = current.folder
while folderObj.parent
folderObj = folderObj.parent
end while
toFolder = libs.changeDir(toPath, folderObj)
if not typeof(toFolder) == "file" then return print("No such directory.")
if not toFolder.is_folder then return print("No such directory.")
subFiles = toFolder.get_folders + toFolder.get_files
subFiles.sort
output = "<b>NAME TYPE +WRX FILE_SIZE PERMISSIONS OWNER GROUP</b>"
for subFile in subFiles
nameFile = subFile.name.replace(" ","_")
permission = subFile.permissions
owner = subFile.owner
size = subFile.size
group = subFile.group
type = "txt"
if subFile.is_binary == 1 then type = "bin"
if subFile.is_folder == 1 then type = "fld"
WRX = ""
if subFile.has_permission("w") then WRX = WRX + "w" else WRX = WRX + "-"
if subFile.has_permission("r") then WRX = WRX + "r" else WRX = WRX + "-"
if subFile.has_permission("x") then WRX = WRX + "x" else WRX = WRX + "-"
output = output + "\n" + subFile + ">" + nameFile + " [" + type + "] [" + WRX + "] [" + libs.fileSize(size) + "] [" + permission + "] [" + owner + "] [" + group + "]"
end for
print(format_columns(output))
return print("\n")
end function
commands["help"] = {"name":"help", "description":"List all commands.", "args":""}
commands["help"]["run"] = function(args)
output = "\n" + typeof(current.obj) + " commands:" + "\n"
for command in commands
commandData = command.value
output = output + char(9) + commandData.name + " " + commandData.args.trim + " -> " + commandData.description + "\n"
end for
if typeof(current.obj) == "computer" or typeof(current.obj) == "shell" then
for command in computerCommands
commandData = command.value
output = output + char(9) + commandData.name + " " + commandData.args.trim + " -> " + commandData.description + "\n"
end for
if typeof(current.obj) == "shell" then
for command in shellCommands
commandData = command.value
output = output + char(9) + commandData.name + " " + commandData.args.trim + " -> " + commandData.description + "\n"
end for
end if
end if
return print(output)
end function
commands["valn"] = {"name":"valn", "description":"List file with vulnerable permission.", "args":""}
commands["valn"]["run"] = function(args)
allFiles = libs.allFiles
files = []
for file in allFiles
if file.has_permission("r") or file.has_permission("w") or file.has_permission("x") then
files = files + [libs.typeofFile(file) + " " + file.path + " " + file.permissions]
end if
end for
output = files.sort.join("\n")
return print(output)
end function
commands["text"] = {"name":"text", "description":"Text Editor. Will clear screen to display text.", "args":"[path_to_text]"}
commands["text"]["run"] = function(args)
if args.len < 1 then return print("Invalid arguments!")
pathText = libs.absolutePath(args[0], current.folder.path)
if not pathText then return print("File not found.")
textFile = libs.getFile(pathText)
if not textFile then return print("File not found.")
if textFile.is_binary or textFile.is_folder then return print("File not text.")
text = textFile.get_content
lines = text.split(char(10))
while true
clear_screen
for i in lines.indexes
line = "<color=orange>" + str(i + 1) + "</color>" + char(9)
line = line + lines[i]
print(line)
end for
print("x: save and exit, s: save, q: exit, i: insert, m: modify, r: remove")
option = user_input("> ", false, true)
if option.lower == "s" or option.lower == "x" then textFile.set_content(lines.join(char(10)))
if option.lower == "q" or option.lower == "x" then break
if option.lower == "i" then
print("specify line number, c to cancel.")
lineNum = user_input("> ").to_int
newText = user_input("input text:" + char(10))
if not lineNum isa number then continue
if lineNum >= lines.len then lineNum = lines.len
if lineNum < 0 then lineNum = 0
lines = lines[:lineNum] + [newText] + lines[lineNum:]
continue
end if
if option.lower == "m" then
print("specify line number, c to cancel.")
lineNum = user_input("> ").to_int
newText = user_input("input text:" + char(10))
if not lineNum isa number then continue
if lineNum > lines.len then lineNum = lines.len
if lineNum < 1 then lineNum = 1
lines[lineNum - 1] = newText
continue
end if
if option.lower == "r" then
print("specify line number, c to cancel.")
lineNum = user_input("> ").to_int
if not lineNum isa number then continue
if lineNum < 1 or lineNum > lines.len then continue
if lines.len == 1 then
lines[0] = ""
continue
end if
lines = lines[:lineNum - 1] + lines[lineNum:]
continue
end if
end while
return print("Done.")
end function
commands["find"] = {"name":"find", "description":"Find a file with its name.", "args":"[file]"}
commands["find"]["run"] = function(args)
if args.len < 1 then return print("Usage: find [file]")
fileName = args[0]
files = libs.find(fileName)
output = []
for file in files
output = output + [libs.typeofFile(file) + " " + file.path]
end for
output = output.sort.join("\n")
return print(output)
end function
commands["cat"] = {"name":"cat", "description":"Prints a file.", "args":"[file]"}
commands["cat"]["run"] = function(args)
if args.len < 1 then return print("No file specified.")
folderObj = current.folder
while folderObj.parent
folderObj = folderObj.parent
end while
toPath = libs.absolutePath(args[0], current.folder.path)
if not toPath then return print("No file specified.")
toPrint = libs.getFile(toPath, folderObj)
if not typeof(toPrint) == "file" then return print("File not found: " + toPath)
if not toPrint.has_permission("r") then return print("Permission denied.") //check perm
if toPrint.is_binary or toPrint.is_folder then return print("File not text file.")
return print(toPrint.get_content)
end function
commands["chmod"] = {"name":"chmod", "description":"Change permission for a file.", "args":"[(opt) -R] [ugo+/-rwx] [path]"}
commands["chmod"]["run"] = function(args)
folderObj = current.folder
while folderObj.parent
folderObj = folderObj.parent
end while
if args.len == 2 then
toPath = libs.absolutePath(args[1], current.folder.path)
isRecursive = false
perm = args[0]
else if args.len == 3 then
toPath = libs.absolutePath(args[2], current.folder.path)
isRecursive = true
perm = args[1]
else
return print("Usage: chmod [(opt) -R] [ugo+-rwx] [path]")
end if
if not toPath then return print("No file specified.")
toChmod = libs.getFile(toPath, folderObj)
if not typeof(toChmod) == "file" then return print("File not found: " + toPath)
users = []
if perm.indexOf("u") != null then users.push("u")
if perm.indexOf("g") != null then users.push("g")
if perm.indexOf("o") != null then users.push("o")
if perm.indexOf("+") != null and perm.indexOf("-") == null then
action = "+"
else if perm.indexOf("+") == null and perm.indexOf("-") != null then
action = "-"
else
return print("Invalid permission.")
end if
perms = ""
if perm.indexOf("r") != null then perms = perms + "r"
if perm.indexOf("w") != null then perms = perms + "w"
if perm.indexOf("w") != null then perms = perms + "x"
doChmod = 2
for user in users
doChmod = toChmod.chmod(user + action + perms, isRecursive)
end for
if doChmod and doChmod != 2 then return print(doChmod)
return print("Done.")
end function
commands["chgrp"] = {"name":"chgrp", "description":"Change group for a file.", "args":"[(opt) -R] [group] [path]"}
commands["chgrp"]["run"] = function(args)
folderObj = current.folder
while folderObj.parent
folderObj = folderObj.parent
end while
if args.len == 2 then
toPath = libs.absolutePath(args[1], current.folder.path)
isRecursive = false
grp = args[0]
else if args.len == 3 then
toPath = libs.absolutePath(args[2], current.folder.path)
isRecursive = true
grp = args[1]
else
return print("Usage: chgrp [(opt) -R] [group] [path]")
end if
if not toPath then return print("No file specified.")
toChgrp = libs.getFile(toPath, folderObj)
if not typeof(toChgrp) == "file" then return print("File not found: " + toPath)
doChgrp = toChgrp.set_group(grp, isRecursive)
if doChgrp then return print(doChgrp)
return print("Done.")
end function
commands["chown"] = {"name":"chown", "description":"Change owner for a file.", "args":"[(opt) -R] [owner] [path]"}
commands["chown"]["run"] = function(args)
folderObj = current.folder
while folderObj.parent
folderObj = folderObj.parent
end while
if args.len == 2 then
toPath = libs.absolutePath(args[1], current.folder.path)
isRecursive = false
user = args[0]
else if args.len == 3 then
toPath = libs.absolutePath(args[2], current.folder.path)
isRecursive = true
user = args[1]
else
return print("Usage: chown [(opt) -R] [owner] [path]")
end if
if not toPath then return print("No file specified.")
toChown = libs.getFile(toPath, folderObj)
if not typeof(toChown) == "file" then return print("File not found: " + toPath)
doChown = toChown.set_owner(user, isRecursive)
if doChown then return print(doChown)
return print("Done.")
end function
commands["cp"] = {"name":"cp", "description":"Copy file.", "args":"[path_from] [path_to]"}
commands["cp"]["run"] = function(args)
if args.len < 2 then return print("Usage: cp [path_from] [path_to].")
folderObj = current.folder
while folderObj.parent
folderObj = folderObj.parent
end while
fromPath = libs.absolutePath(args[0], current.folder.path)
toPath = libs.absolutePath(args[1], current.folder.path)
if (not fromPath) or (not toPath) then return print("No file specified.")
toCopy = libs.getFile(fromPath, folderObj)
if not typeof(toCopy) == "file" then return print("File not found: " + toPath)
paths = toPath.split("/")
toPathList = []
for path in paths
if path then toPathList.push(path) //empty string eval to false
end for
if not toPathList.len then return print("No file specified.")
newName = toPathList[-1]
if toPathList.len == 1 then toPath = "/" else toPath = "/" + toPathList[:-1].join("/")
doCopy = toCopy.copy(toPath, newName)
if doCopy then return print(doCopy)
return print("Done.")
end function
commands["mv"] = {"name":"mv", "description":"Move file.", "args":"[path_from] [path_to]"}
commands["mv"]["run"] = function(args)
if args.len < 2 then return print("Usage: mv [path_from] [path_to].")
folderObj = current.folder
while folderObj.parent
folderObj = folderObj.parent
end while
fromPath = libs.absolutePath(args[0], current.folder.path)
toPath = libs.absolutePath(args[1], current.folder.path)
if (not fromPath) or (not toPath) then return print("No file specified.")
toMove = libs.getFile(fromPath, folderObj)
if not typeof(toMove) == "file" then return print("File not found: " + toPath)
paths = toPath.split("/")
toPathList = []
for path in paths
if path then toPathList.push(path) //empty string eval to false
end for
if not toPathList.len then return print("No file specified.")
newName = toPathList[-1]
if toPathList.len == 1 then toPath = "/" else toPath = "/" + toPathList[:-1].join("/")
doMove = toMove.move(toPath, newName)
if doMove then return print(doMove)
return print("Done.")
end function
commands["rm"] = {"name":"rm", "description":"Delete file.", "args":"[file]"}
commands["rm"]["run"] = function(args)
if args.len < 1 then return print("No file specified.")
folderObj = current.folder
while folderObj.parent
folderObj = folderObj.parent
end while
toPath = libs.absolutePath(args[0], current.folder.path)
if not toPath then return print("No file specified.")
toDelete = libs.getFile(toPath, folderObj)
if not typeof(toDelete) == "file" then return print("File not found: " + toPath)
if not toDelete.has_permission("w") then return print("Permission denied.") //check perm
toDelete.delete //delete file
return print("File deleted.") //output
end function
commands["hash"] = {"name":"hash", "description":"Reverse hash. Split multiple lines with commas or line breaks.", "args":"[hash]"}
commands["hash"]["run"] = function(args)
if not crypto then return print("Error: crypto.so not loaded!")
if args.len != 1 then return print("Invalid arguments!")
hashes = []
passes = args[0]
passes = passes.split(char(10))
for i in passes.indexes
passes[i] = passes[i].split(",")
for j in passes[i].indexes
passes[i][j] = passes[i][j].split(";")
for k in passes[i][j].indexes
hashes = hashes + [passes[i][j][k]]
end for
end for
end for
for hsh in hashes
hsh = hsh.split(":")
if hsh.len > 0 then arg = hsh[0]
if hsh.len > 1 then arg = hsh[1]
ret = crypto.decipher(arg)
if hsh.len > 1 then ret = hsh[0] + ":" + ret
print(ret)
end for
return print("All hash done.")
end function
commands["clog"] = {"name":"clog", "description":"Clear log.", "args":""}
commands["clog"]["run"] = function(args)
tryClearLog = libs.corruptLog(current.folder)
if not tryClearLog then return print("Failed.")
return print("Done.")
end function
commands["local"] = {"name":"local", "description":"Get back to local.", "args":""}
commands["local"]["run"] = function(args)
globals.current.obj = local.shell
globals.current.router = local.router
globals.current.folder = local.folder
globals.current.user = local.user
globals.current.lanIp = local.lanIp
return null
end function
commands["clear"] = {"name":"clear", "description":"Clear screen.", "args":""}
commands["clear"]["run"] = function(args)
return clear_screen
end function