Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'winrm-fs'
- # Author: Alamot
- # To upload a file type: UPLOAD local_path remote_path
- # e.g.: PS> UPLOAD myfile.txt C:\temp\myfile.txt
- conn = WinRM::Connection.new(
- endpoint: 'http://127.0.0.1:5985/wsman',
- transport: :negotiate,
- user: 'batman',
- password: 'Zx^#QZX+T!123'
- )
- file_manager = WinRM::FS::FileManager.new(conn)
- class String
- def tokenize
- self.
- split(/\s(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/).
- select {|s| not s.empty? }.
- map {|s| s.gsub(/(^ +)|( +$)|(^["']+)|(["']+$)/,'')}
- end
- end
- command=""
- conn.shell(:powershell) do |shell|
- until command == "exit\n" do
- output = shell.run("-join($id,'PS ',$(whoami),'@',$env:computername,' ',$((gi $pwd).Name),'> ')")
- print(output.output.chomp)
- command = gets
- if command.start_with?('UPLOAD') then
- upload_command = command.tokenize
- print("Uploading " + upload_command[1] + " to " + upload_command[2])
- file_manager.upload(upload_command[1], upload_command[2]) do |bytes_copied, total_bytes, local_path, remote_path|
- puts("#{bytes_copied} bytes of #{total_bytes} bytes copied")
- end
- command = "echo `nOK`n"
- end
- output = shell.run(command) do |stdout, stderr|
- STDOUT.print(stdout)
- STDERR.print(stderr)
- end
- end
- puts("Exiting with code #{output.exitcode}")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement