Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure in executing Winrm command from remote Ubuntu server 16.04 to remote Windows R2 2012 server #271

Open
atharva-infiverve opened this issue May 24, 2017 · 5 comments

Comments

@atharva-infiverve
Copy link
Contributor

atharva-infiverve commented May 24, 2017

Hi
We are using winrm 2.1.1 with Jruby 9.1.1.0. We are executing some basic powershell commands as well as command-line commands in negotiate as transport mode from a remote Ubuntu server(16.04 LTS) to Windows R2 2012 server were winrm is configured.Below is the code snippet which we are using:

require 'winrm'
opts = {
  endpoint: 'http://someurl.com:5985/wsman',
  transport: :negotiate,
  user: 'Administrator',
  password: 'mypassword'
}
conn = WinRM::Connection.new(opts)
conn.logger.level = :debug
conn.shell(:powershell) do |shell|
  output = shell.run('$PSVersionTable') do |stdout, stderr|
    STDOUT.print stdout
    STDERR.print stderr
  end
  puts "The script exited with exit code #{output.exitcode}"
end

When we are executing the above code we are simply getting connection time out while executing the commands (for both powershell and cmd commands). We are not getting any specific error logs, so we are stuck and unable to debug the root cause.

We have also traced the network packets using Wireshark Tool and we are getting following logs -

Case 1 . Failure in executing command via ubuntu server to Windows server
a. 72.251.240.36 -Ubuntu server
b. 10.0.37.104 Windows R2 2012 server where winrm is configured

winrm-source-destination-failure

Case 2 . Success in executing the command via ubuntu server to Windows server
a. 72.251.240.36 -Ubuntu server
b. 10.0.37.104 Windows R2 2012 server where winrm is configured

winrmrequest-source-destination-success

Please Note: While executing the above code snippet command or any other commands as well , out of 10 times,only 2 times the commands gets executed successfully through the same ubuntu server(72.251.240.36) on the same Windows server(10.0.37.104) .Rest of the time we get a timeout.

Thanks in advance !!
Do let us know if you need any more details.

@mwrock
Copy link
Member

mwrock commented May 25, 2017

Looks like the problem is in the authentication. From what I recall, you were having issues with jruby and the NTLM gem and had a PR in flight that was never merged. I just added a commit to your former PR and made a new PR #272 . Can you give the change in that PR a try?

@atharva-infiverve
Copy link
Contributor Author

Hi,
Yes I will surely try with the change in that PR. But the issue #271 which I raised is something different other then just an authentication problem, I suspect that, as I am able to do handshake once or twice with the Winrm server but after third or fourth request it fails to execute the commands.

@mwrock
Copy link
Member

mwrock commented May 25, 2017

Do you have access to a non jruby environment. I'd be curious to see if we can isolate jruby as being the likely culprit. Wherever the problem is I highly suspect it to be inside of rubyntlm since the last thing we see on the wire is the challenge response and the ball is in rubyntlm's court to return credentials. I just dont have any jruby environment to validate.

@atharva-infiverve
Copy link
Contributor Author

Hi ,
Thanks alot for your suggestion, as suggested by you we tried to execute the same code snippet in non jruby environment , and it is working fine every time executing the same code on the respective Windows R2 2012 server.In jruby environment it is working intermittently ,like out of 10 times we execute, 2 times it is working fine and rest of the time it is giving timeout. Can you just guide us in which direction we can debug this issue? Thanks in advance!

@mwrock
Copy link
Member

mwrock commented May 26, 2017

I think the hang is occuring somewhere in the init_auth method https://github.com/WinRb/WinRM/blob/master/lib/winrm/http/transport.rb#L212. or in thre rubyntlm gem code it calls. I'd drop in tracing code or use pry to determine exactly what call is hanging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants