Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. require 'winrm-fs'
  2.  
  3. # Author: Alamot
  4. # To upload a file type: UPLOAD local_path remote_path
  5. # e.g.: PS> UPLOAD myfile.txt C:\temp\myfile.txt
  6.  
  7. conn = WinRM::Connection.new(
  8. endpoint: 'http://127.0.0.1:5985/wsman',
  9. transport: :negotiate,
  10. user: 'batman',
  11. password: 'Zx^#QZX+T!123'
  12.  
  13.  
  14. )
  15.  
  16. file_manager = WinRM::FS::FileManager.new(conn)
  17.  
  18.  
  19. class String
  20. def tokenize
  21. self.
  22. split(/\s(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/).
  23. select {|s| not s.empty? }.
  24. map {|s| s.gsub(/(^ +)|( +$)|(^["']+)|(["']+$)/,'')}
  25. end
  26. end
  27.  
  28.  
  29. command=""
  30.  
  31. conn.shell(:powershell) do |shell|
  32. until command == "exit\n" do
  33. output = shell.run("-join($id,'PS ',$(whoami),'@',$env:computername,' ',$((gi $pwd).Name),'> ')")
  34. print(output.output.chomp)
  35. command = gets
  36. if command.start_with?('UPLOAD') then
  37. upload_command = command.tokenize
  38. print("Uploading " + upload_command[1] + " to " + upload_command[2])
  39. file_manager.upload(upload_command[1], upload_command[2]) do |bytes_copied, total_bytes, local_path, remote_path|
  40. puts("#{bytes_copied} bytes of #{total_bytes} bytes copied")
  41. end
  42. command = "echo `nOK`n"
  43. end
  44.  
  45. output = shell.run(command) do |stdout, stderr|
  46. STDOUT.print(stdout)
  47. STDERR.print(stderr)
  48. end
  49. end
  50. puts("Exiting with code #{output.exitcode}")
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement