Guest User

Untitled

a guest
Mar 1st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. # $Id: http.rb,v 1.2 2006/10/05 01:36:52 koheik Exp $
  2. require 'socket'
  3. $:.unshift(File.dirname(__FILE__) + '/../lib')
  4. require 'net/ntlm'
  5.  
  6. $user = nil
  7. $passwd = nil
  8.  
  9. $host = "www"
  10. $port = 80
  11.  
  12. def header(f, host)
  13. f.print "GET / HTTP/1.1\r\n"
  14. f.print "Host: #{host}\r\n"
  15. f.print "Keep-Alive: 300\r\n"
  16. f.print "Connection: keep-alive\r\n"
  17. end
  18.  
  19. def main
  20.  
  21. s = TCPSocket.new($host, $port)
  22.  
  23. # client -> server
  24. t1 = Net::NTLM::Message::Type1.new()
  25. header(s, $host)
  26. s.print "Authorization: NTLM " + t1.encode64 + "\r\n"
  27. s.print "\r\n"
  28.  
  29. # server -> client
  30. length = 0
  31. while(line = s.gets)
  32.  
  33. if /^WWW-Authenticate: (NTLM|Negotiate) (.+)\r\n/ =~ line
  34. msg = $2
  35. end
  36.  
  37. if /^Content-Length: (\d+)\r\n/ =~ line
  38. length = $1.to_i
  39. end
  40. if /^\r\n/ =~ line
  41. if length > 0
  42. cont = s.read(length)
  43. end
  44. break
  45. end
  46. end
  47. t2 = Net::NTLM::Message.decode64(msg)
  48.  
  49. unless $user and $passwd
  50. target = t2.target_name
  51. target = Net::NTLM::decode_utf16le(target) if t2.has_flag?(:UNICODE)
  52. puts "Target: #{target}"
  53. print "User name: "
  54. ($user = $stdin.readline).chomp!
  55. print "Password: "
  56. ($passwd = $stdin.readline).chomp!
  57. end
  58.  
  59. # client -> server, again
  60. t3 = t2.response({:user => $user, :password => $passwd}, {:ntlmv2 => true})
  61. header(s, $host)
  62. s.print "Authorization: NTLM " + t3.encode64 + "\r\n"
  63. s.print "\r\n"
  64.  
  65. # server -> client
  66. length = 0
  67. while(line = s.gets)
  68.  
  69. if /^WWW-Authenticate: (NTLM|Negotiate) (.+)\r\n/ =~ line
  70. msg = $2
  71. end
  72.  
  73. if /^Content-Length: (\d+)\r\n/ =~ line
  74. length = $1.to_i
  75. end
  76. if /^\r\n/ =~ line
  77. if length > 0
  78. p cont = s.read(length)
  79. end
  80. break
  81. end
  82. end
  83. s.close
  84. end
  85.  
  86. main
Add Comment
Please, Sign In to add comment