Skip to content
Extraits de code Groupes Projets
Valider af44f2b5 rédigé par Thomas Saquet's avatar Thomas Saquet
Parcourir les fichiers

Merge branch '7-tool-to-pull-the-code-from-another-server-or-push' into 'master'

Tool to auto-upload some files to a remote server

See merge request !19
parents fa9da3dd b8c5f477
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!19Tool to auto-upload some files to a remote server
// Tool to send to rented servers the default binaries from computers
// Note that the utility methods to transfer a file only accepts complete path
// "connect" and "transfer" should be easy reusable for a code pulling tool (issue #7)
imports = {}
imports.temp = {}
imports.utils = {}
imports.utils.ParamLength = function(params)
if params == null then return 0
return params.len
end function
imports.utils.GetParam = function(params, index)
if index < 0 or index >= imports.utils.ParamLength(params) then return null
return params[index]
end function
imports.utils.HasFlag = function(params, short, long)
if imports.utils.ParamLength(params) == 0 then return null
param = params[0]
return param == "-"+short or param == "-"+long
end function
imports.utils.GetProgName = function()
return program_path.split("/")[-1]
end function
imports.network = {}
imports.network.getService = function(port)
if port == 22 then return "ssh"
if port == 21 then return "ftp"
return null
end function
imports.network.connect = function(shell, user, password, ip, port=null, service=null)
if not shell then shell = get_shell
if not port then port = 22
if typeof(port) == "string" then port = port.to_int
if not service then
service = imports.network.getService(port)
if not service then return null
end if
return shell.connect_service(ip, port, user, password, service)
end function
imports.network.transfer = function(shell, origin, dest, upload=true)
if upload then
sourceShell = get_shell
targetShell = shell
else
sourceShell = shell
targetShell = get_shell
end if
if dest[dest.len-2] != "/" then dest = dest + "/"
fileName = origin[path.lastIndexOf("/")+1:]
destPath = dest+fileName
if targetShell.host_computer.File(destPath) != null then return destPath+" already exists"
return sourceShell.scp_upload(origin, dest, targetShell)
end function
imports.file = {}
imports.temp.AddCmd = function(arr, files)
for file in files
arr.push("/bin/"+file)
end for
end function
imports.temp.AddSoft = function(arr, files)
for file in files
arr.push("/usr/bin/"+file+".exe")
end for
end function
imports.file.MISSING = []
imports.temp.AddCmd(imports.file.MISSING,["airmon","aireplay","aircrack","nmap","smtp-user-list","decipher","scanlib","scanrouter"])
imports.temp.AddSoft(imports.file.MISSING,["Map","Manual","AdminMonitor"])
imports.temp = null
//command: colony
length = imports.utils.ParamLength(params)
if length < 3 or length > 5 or imports.utils.HasFlag(params, "h", "help") then exit("<b>Usage: "+imports.utils.GetProgName()+" [user] [password] [ip] [(opt) port] [(opt) service]</b>")
comp = get_shell.host_computer
user = imports.utils.GetParam(params, 0)
password = imports.utils.GetParam(params, 1)
ip = imports.utils.GetParam(params, 2)
port = imports.utils.GetParam(params, 3)
service = imports.utils.GetParam(params, 4)
remote = imports.network.connect(get_shell, user, password, ip, port, service)
if not remote then exit("Can't connect to remote server")
for path in imports.file.MISSING
result = imports.network.transfer(remote, path, path[:path.lastIndexOf("/")], true)
if result != 1 then print(result)
end for
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter