larsch / ocra

One-Click Ruby Application Builder
http://ocra.rubyforge.org/
833 stars 84 forks source link

Truncation/Parsing error using ocra #103

Closed lmayorga1980 closed 9 years ago

lmayorga1980 commented 9 years ago

Ruby: 2.1.5 Ocra: 1.3.5 Winrm: 1.3.4

I am trying to using the WinRM Ruby Gem with the following POC example:

example.rb


require 'winrm'

exit (0) if ARGV.size.eql?(0)

host = ARGV[0]
cmd  = ARGV[1]

puts host
puts cmd

endpoint = "http://#{host}:5985/wsman"

puts endpoint 

begin

winrm = WinRM::WinRMWebService.new(endpoint, :plaintext, :user => '<SOME_USER>', :pass => '<SOME_PWD>', :basic_auth_only => false)

puts winrm.inspect

winrm.cmd("#{cmd}") do |stdout, stderr|
    STDOUT.print stdout
      STDERR.print stderr
end 

rescue Exception => e

  puts e.inspect
  puts e.backtrace
end

When I execute ruby example.rb <hostname> "powershell get-host" it works normally but after compiling using ocra ocra --console example.rb it seems to fail with a #<WinRM::WinRMAuthorizationError: WinRM::WinRMAuthorizationError>

It could be that ocra is changing something on the fly?

sneal commented 9 years ago

I'd enable logging for the winrm gem and for Windows. You can enable winrm gem logging by setting the WINRM_LOG env var to debug.

lmayorga1980 commented 9 years ago

It seems that after reviewing using the WINRM_LOG=true I was able to see the XML request which is NOT different from both executions but with ocra i get the following error.


#<WinRM::WinRMAuthorizationError: WinRM::WinRMAuthorizationError>
C:/Users/lmo0/AppData/Local/Temp/ocrA804.tmp/lib/ruby/gems/2.1.0/gems/winrm-1.3.
4/lib/winrm/http/response_handler.rb:57:in `raise_if_auth_error'
C:/Users/lmo0/AppData/Local/Temp/ocrA804.tmp/lib/ruby/gems/2.1.0/gems/winrm-1.3.
4/lib/winrm/http/response_handler.rb:50:in `raise_if_error'
C:/Users/lmo0/AppData/Local/Temp/ocrA804.tmp/lib/ruby/gems/2.1.0/gems/winrm-1.3.
4/lib/winrm/http/response_handler.rb:35:in `parse_to_xml'
C:/Users/lmo0/AppData/Local/Temp/ocrA804.tmp/lib/ruby/gems/2.1.0/gems/winrm-1.3.
4/lib/winrm/http/transport.rb:50:in `send_request'
C:/Users/lmo0/AppData/Local/Temp/ocrA804.tmp/lib/ruby/gems/2.1.0/gems/winrm-1.3.
4/lib/winrm/winrm_service.rb:430:in `send_message'
C:/Users/lmo0/AppData/Local/Temp/ocrA804.tmp/lib/ruby/gems/2.1.0/gems/winrm-1.3.
4/lib/winrm/winrm_service.rb:126:in `open_shell'
C:/Users/lmo0/AppData/Local/Temp/ocrA804.tmp/lib/ruby/gems/2.1.0/gems/winrm-1.3.
4/lib/winrm/winrm_service.rb:299:in `run_cmd'
C:/Users/lmo0/AppData/Local/Temp/ocrA804.tmp/src/exec-host.rb:21:in `<main>'
lmayorga1980 commented 9 years ago

Ok. The following command fixed my issue.

ocra --quiet --console script.rb --output rmq.exe --no-enc --gem-all