_LINKI

GreyHack - SpyShell by LINKI

Apr 21st, 2019
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.76 KB | None | 0 0
  1. if params.len != 2 then exit("<b>Example: <i>spyshell</i> [IP] [LAN IP]</b>")
  2. ip = params[0]
  3. lanIP = params[1]
  4.  
  5. //BaseClass//
  6. ftpShell = { }
  7. ftpShell.ctor = function(userPC, target, workdir = "/")
  8.     self.userPC = userPC
  9.     self.target = target
  10.     self.workdir = workdir
  11.     self.localWorkdir = parent_path(program_path)
  12.     self.localDownloads = self.localWorkdir + "/Downloads"
  13.     self.unloadStore = self.localDownloads + "/" + ip
  14. end function
  15. //Functions//
  16. ftpShell.help = function()
  17.     print("<b>[Help]</b>\n|(*) - maybe not work, req root or write access\n|exit\n|ps\n|(*)useradd\n|(*)userdel\n|(*)passwd\n|cat\n|(*)chmod\n|decipher/dec\n|download/get (use cat)\n|pwd\n|ls\n|cd\n|(*)rm\n|(*)mkdir\n|(*)touch\n|(*)mv\n|(*)cp")
  18. end function
  19. ftpShell.com_ps = function()
  20.     print(format_columns(self.target.show_procs))
  21. end function
  22. ftpShell.com_pwd = function()
  23.     print(self.workdir)
  24. end function
  25. ftpShell.absPath = function(path)
  26.     if path.len > 1 and path[path.len - 1] == "/" then path = path[0:path.len - 1]
  27.     if path[0] == "/" then return path
  28.     if path == ".." then return parent_path(self.workdir)
  29.     if self.workdir == "/" then return self.workdir + path
  30.     return self.workdir + "/" + path
  31. end function
  32. ftpShell.getWorkDir = function()
  33.     return self.target.File(self.workdir)
  34. end function
  35. ftpShell.findObject = function(path, out = true)
  36.     obj = self.target.File(path)
  37.     if obj == null then
  38.         if out then print("Not found object - '" + path + "'")
  39.         return false
  40.     end if
  41.     return obj
  42. end function
  43. ftpShell.findFolder = function(path, out = true)
  44.     dir = self.findObject(path, false)
  45.     if not dir or not dir.is_folder then
  46.         if out then print("Not found folder - '" + path + "'")
  47.         return false
  48.     end if
  49.     return dir
  50. end function
  51. ftpShell.findFile = function(path, out = true)
  52.     file = self.findObject(path, false)
  53.     if not file or file.is_folder then
  54.         if out then print("Not found file - '" + path + "'")
  55.         return false
  56.     end if
  57.     return file
  58. end function
  59. ftpShell.existObject = function(path)
  60.     obj = self.target.File(path)
  61.     if obj == null then return false
  62.     return true
  63. end function
  64. ftpShell.existFolder = function(path)
  65.     folder = self.target.File(path)
  66.     if folder == null or not folder.is_folder then return false
  67.     return true
  68. end function
  69. ftpShell.existFile = function(path)
  70.     file = self.target.File(path)
  71.     if file == null or file.is_folder then return false
  72.     return true
  73. end function
  74. ftpShell.com_ls = function(args)
  75.     dirPath = self.workdir
  76.     if args != null and args.len > 0 then dirPath = self.absPath(args[0])
  77.    
  78.     dir = self.findFolder(dirPath)
  79.     if not dir then return
  80.    
  81.     out = ""
  82.     subObjects = dir.get_folders + dir.get_files
  83.     for object in subObjects
  84.         out = out + object.permissions + " " + object.owner + " " + object.size + " " + object.name + "\n"
  85.     end for
  86.    
  87.     print(format_columns(out))
  88. end function
  89. ftpShell.com_cd = function(args)
  90.     dirPath = "/root"
  91.     if args != null and args.len > 0 then dirPath = self.absPath(args[0])
  92.    
  93.     dir = self.findFolder(dirPath)
  94.     if not dir then return
  95.    
  96.     self.workdir = dirPath
  97. end function
  98. ftpShell.com_rm = function(args)
  99.     if args == null or args.len == 0 then
  100.         print(command_info("rm_usage"))
  101.         return
  102.     end if
  103.    
  104.     count = 0
  105.     for arg in args
  106.         if arg == "*" then
  107.             dir = self.getWorkDir()
  108.             objs = dir.get_folders + dir.get_files
  109.             count = count + objs.len
  110.             for obj in objs
  111.                 print("Deleted - " + obj.path)
  112.                 obj.delete()
  113.             end for
  114.         else
  115.             obj = self.findObject(self.absPath(arg))
  116.             if not obj then continue
  117.            
  118.             count = count + 1
  119.             print("Deleted - " + obj.path)
  120.             obj.delete()
  121.         end if
  122.     end for
  123.     print("<i>(i)Deleted " + count + " objects</i>")
  124. end function
  125. ftpShell.com_mkdir = function(args)
  126.     if args == null or args.len == 0 then
  127.         print(command_info("mkdir_usage"))
  128.         return
  129.     end if
  130.    
  131.     count = 0
  132.     for arg in args
  133.         arg = self.absPath(arg)
  134.         argSplited = arg.split("/")
  135.         name = argSplited[argSplited.len - 1]
  136.         dirPath = parent_path(arg)
  137.        
  138.         dir = self.findFolder(dirPath)
  139.         if not dir then continue
  140.        
  141.         self.target.create_folder(dir.path, name)
  142.         count = count + 1
  143.         print("Created folder - " + arg)
  144.     end for
  145.     print("<i>(i)Created " + count + " folders</i>")
  146. end function
  147. ftpShell.com_touch = function(args)
  148.     if args == null or args.len == 0 then
  149.         print(command_info("touch_usage"))
  150.         return
  151.     end if
  152.    
  153.     count = 0
  154.     for arg in args
  155.         arg = self.absPath(arg)
  156.         argSplited = arg.split("/")
  157.         name = argSplited[argSplited.len - 1]
  158.         dirPath = parent_path(arg)
  159.        
  160.         dir = self.findFolder(dirPath)
  161.         if not dir then continue
  162.        
  163.         self.target.touch(dir.path, name)
  164.         count = count + 1
  165.         print("Created file - " + arg)
  166.     end for
  167.     print("<i>(i)Created " + count + " files</i>")
  168. end function
  169. ftpShell.com_mv = function(args)
  170.     if args == null or args.len != 2 then
  171.         print(command_info("mv_usage"))
  172.         return
  173.     end if
  174.     origFile = self.absPath(args[0])
  175.     dirPath = self.absPath(args[1])
  176.    
  177.     file = self.findFile(origFile)
  178.     if not file then return
  179.    
  180.     newName = file.name
  181.     if not self.existFolder(dirPath) then
  182.         newName = dirPath.split("/").pop
  183.         dirPath = parent_path(dirPath)
  184.     end if
  185.    
  186.     file.move(dirPath, newName)
  187.     print("<i>(i)File - '" + origFile + "' moved to '" + dirPath + "/" + newName + "'</i>" )
  188. end function
  189. ftpShell.com_cp = function(args)
  190.     if args == null or args.len != 2 then
  191.         print(command_info("cp_usage"))
  192.         return
  193.     end if
  194.     origFile = self.absPath(args[0])
  195.     dirPath = self.absPath(args[1])
  196.    
  197.     file = self.findFile(origFile)
  198.     if not file then return
  199.    
  200.     newName = file.name
  201.     if not self.existFolder(dirPath) then
  202.         newName = dirPath.split("/").pop
  203.         dirPath = parent_path(dirPath)
  204.     end if
  205.    
  206.     file.copy(dirPath, newName)
  207.     print("<i>(i)File - '" + origFile + "' copyed to '" + dirPath + "/" + newName + "'</i>" )
  208. end function
  209. ftpShell.com_useradd = function(args)
  210.     if args == null or args.len != 2 then
  211.         print(command_info("useradd_usage"))
  212.         return
  213.     end if
  214.     user = args[0]
  215.     pass = args[1]
  216.     if self.target.create_user(user, pass) then
  217.         print("<i>(i)User '" + user + "' created</i>")
  218.         return
  219.     end if
  220.     print("<i>Could not create user :/</i>")
  221. end function
  222. ftpShell.com_userdel = function(args)
  223.     if args == null or args.len < 1 then
  224.         print(command_info("userdel_usage"))
  225.         return
  226.     end if
  227.  
  228.     rec = false
  229.     if args.len == 1 then
  230.         user = args[0]
  231.     else
  232.         if args[0] == "-r" then rec = true
  233.         user = args[1]
  234.     end if
  235.  
  236.     if self.target.create_user(user, rec) then
  237.         print("<i>(i)User '" + user + "' deleted</i>")
  238.         return
  239.     end if
  240.     print("<i>Could not delete user :/</i>")
  241. end function
  242. ftpShell.com_passwd = function(args)
  243.     if args == null or args.len != 2 then
  244.         print("<b>Example:</b> passwd [user] [new password]")
  245.         return
  246.     end if
  247.     user = args[0]
  248.     pass = args[1]
  249.     if self.target.create_user(user, pass) then
  250.         print("<i>(i)Password for '" + user + "' changed</i>")
  251.         return
  252.     end if
  253.     print("<i>Could not change password :/</i>")
  254. end function
  255. ftpShell.com_cat = function(args)
  256.     if args == null or args.len == 0 then
  257.         print(command_info("cat_usage"))
  258.         return
  259.     end if
  260.    
  261.     count = 0
  262.     for arg in args
  263.         arg = self.absPath(arg)
  264.         file = self.findFile(arg)
  265.         if not file then continue
  266.        
  267.         content = file.content
  268.         if content == null then
  269.             print("Cannot read file - '" + arg + "'")
  270.         else
  271.             print("<b>[Content - </b><i>'" + arg + "'</i><b>]</b>")
  272.             print(content)
  273.             count = count + 1
  274.         end if
  275.     end for
  276.     print("<i>(i)Read " + count + " files</i>")
  277. end function
  278. ftpShell.com_chmod = function(args)
  279.     if args == null or args.len < 2 then
  280.         print(command_info("chmod_usage"))
  281.         return
  282.     end if
  283.     rec = false
  284.     if args[0] == "-R" or args[0] == "-r" then
  285.         rec = true
  286.         perm = args[1]
  287.         args.remove(0)
  288.     else
  289.         perm = args[0]
  290.     end if
  291.     args.remove(0)
  292.    
  293.     count = 0
  294.     for arg in args
  295.         arg = self.absPath(arg)
  296.         obj = self.findObject(arg)
  297.         if not obj then continue
  298.        
  299.         obj.chmod(perm, rec)
  300.         print("Object - '" + arg + "' chmoded")
  301.         count = count + 1
  302.     end for
  303.     print("<i>(i)Chmoded '" + count + "' objects</i>")
  304. end function
  305. ftpShell.rmLocalFile = function(path)
  306.     file = self.userPC.File(path)
  307.     if file == null then return
  308.    
  309.     file.delete()
  310. end function
  311. ftpShell.unloadFile = function(file, prev = null, out = true)
  312.     if file.content == null then return false
  313.     if prev == null then
  314.         path = self.unloadStore
  315.     else
  316.         path = prev
  317.     end if
  318.    
  319.     self.userPC.touch(path, file.name)
  320.     localFile = self.userPC.File(path + "/" + file.name)
  321.     localFile.set_content(file.content)
  322.     if out then print("<i>File '" + file.path + "' saved to '" + localFile.path + "'</i>")
  323.     return localFile.path
  324. end function
  325. ftpShell.unloadFolder = function(folder, prev = null, out = true)
  326.     if prev == null then
  327.         path = self.unloadStore
  328.     else
  329.         path = prev
  330.     end if
  331.  
  332.     self.userPC.create_folder(path, folder.name)
  333.     createdPath = path + "/" + folder.name
  334.     if out then print("<i>Created folder - " + createdPath + "</i>")
  335.    
  336.     folders = folder.get_folders
  337.     files = folder.get_files
  338.     for f in folders
  339.         self.unloadFolder(f, createdPath)
  340.     end for
  341.     for file in folder.get_files
  342.         self.unloadFile(file, createdPath)
  343.     end for
  344.     return true
  345. end function
  346. ftpShell.unloadObject = function(obj)
  347.     if obj.is_folder then
  348.         return self.unloadFolder(obj)
  349.     else
  350.         return self.unloadFile(obj)
  351.     end if
  352. end function
  353. ftpShell.checkLocalStore = function()
  354.     if self.userPC.File(self.localWorkdir) == null then
  355.         self.userPC.create_folder(parent_path(self.localWorkdir), self.localWorkdir.split("/").pop)
  356.     end if
  357.     if self.userPC.File(self.localDownloads) == null then
  358.         self.userPC.create_folder(parent_path(self.localDownloads), self.localDownloads.split("/").pop)
  359.     end if
  360.     if self.userPC.File(self.unloadStore) == null then
  361.         self.userPC.create_folder(parent_path(self.unloadStore), self.unloadStore.split("/").pop)
  362.     end if
  363. end function
  364. ftpShell.com_download = function(args)
  365.     if args == null or args.len == 0 then
  366.         print("<b>Example:</b> download/get [path1] [path2] ...")
  367.         return
  368.     end if
  369.    
  370.     self.checkLocalStore()
  371.    
  372.     countFolders = 0
  373.     countFiles = 0
  374.     for arg in args
  375.         arg = self.absPath(arg)
  376.         obj = self.findObject(arg)
  377.         if not obj then return
  378.        
  379.         if obj.is_folder then
  380.             self.unloadFolder(obj)
  381.             countFolders = countFolders + 1
  382.         else
  383.             self.unloadFile(obj)
  384.             countFiles = countFiles + 1
  385.         end if
  386.     end for
  387.     print("<i>(i)Downloaded " + countFolders + " folders</i>")
  388.     print("<i>(i)Downloaded " + countFiles + " files</i>")
  389. end function
  390. ftpShell.com_decipher = function(args)
  391.     if args == null or args.len == 0 then
  392.         print("<b>Example:</b> [path1] [path2] ...")
  393.         return
  394.     end if
  395.    
  396.     crypto = include_lib("crypto")
  397.     if not crypto then exit("<b><i>Crypto.so</i> not found!</b>")
  398.    
  399.     out = "FILE DECRYPTED\n"
  400.     for arg in args
  401.         arg = self.absPath(arg)
  402.         file = self.findFile(arg)
  403.         if not file then continue
  404.         tempPath = self.unloadFile(file, null, false)
  405.         if not tempPath then continue
  406.        
  407.         out = out + arg + " " + crypto.decipher(tempPath) + "\n"
  408.         self.rmLocalFile(tempPath)
  409.     end for
  410.    
  411.     print(format_columns(out))
  412. end function
  413. ftpShell.runShell = function()
  414.     print("<i>(i)Hided ftp-shell opened</i>")
  415.     isExit = false
  416.     input = ""
  417.     cmd = ""
  418.     args = []
  419.     while not isExit
  420.         input = user_input(ip + ":" + self.workdir + "> ")
  421.         args = input.split(" ")
  422.         if args.len < 1 then continue
  423.         cmd = args[0]
  424.         args.remove(0)
  425.        
  426.         if cmd == "exit" then
  427.             isExit = true
  428.         else if cmd == "help" then
  429.             self.help()
  430.         else if cmd == "ps" then
  431.             self.com_ps()
  432.         else if cmd == "useradd" then
  433.             self.com_useradd(args)
  434.         else if cmd == "userdel" then
  435.             self.com_userdel(args)
  436.         else if cmd == "passwd" then
  437.             self.com_passwd(args)
  438.         else if cmd == "cat" then
  439.             self.com_cat(args)
  440.         else if cmd == "chmod" then
  441.             self.com_chmod(args)
  442.         else if cmd == "download" or cmd == "get" then
  443.             self.com_download(args)
  444.         else if cmd == "decipher" or cmd == "dec" then
  445.             self.com_decipher(args)
  446.         else if cmd == "pwd" then
  447.             self.com_pwd()
  448.         else if cmd == "ls" then
  449.             self.com_ls(args)
  450.         else if cmd == "cd" then
  451.             self.com_cd(args)
  452.         else if cmd == "rm" then
  453.             self.com_rm(args)
  454.         else if cmd == "mkdir" then
  455.             self.com_mkdir(args)
  456.         else if cmd == "touch" then
  457.             self.com_touch(args)
  458.         else if cmd == "mv" then
  459.             self.com_mv(args)
  460.         else if cmd == "cp" then
  461.             self.com_cp(args)
  462.         else
  463.             print("Command not found")
  464.         end if
  465.     end while
  466.     print("<i>(i)Hided ftp-shell closed</i>")
  467. end function
  468.  
  469. userShell = get_shell()
  470. userPC = userShell.host_computer()
  471.  
  472. print("<b><i>SpyShell</i></b>")
  473.  
  474. router = get_router(ip)
  475. if not router then exit("<b>Host not found :/</b>")
  476. target = router.get_computer(lanIP)
  477. if not target then exit("<b>LAN Host not found :(</b>")
  478.  
  479. print("<i>Connected - <b>OK</b></i>")
  480. print()
  481.  
  482. ftpShell.ctor(userPC, target)
  483. ftpShell.runShell()
  484.  
  485. print()
  486. print("<b><i>SpyShell</i></b>")
  487. print("<b><i>By LINKI :)</i></b>")
Add Comment
Please, Sign In to add comment