aboutsummaryrefslogtreecommitdiff
path: root/5.1/kinit.rb
diff options
context:
space:
mode:
Diffstat (limited to '5.1/kinit.rb')
-rwxr-xr-x5.1/kinit.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/5.1/kinit.rb b/5.1/kinit.rb
new file mode 100755
index 0000000..9c77eec
--- /dev/null
+++ b/5.1/kinit.rb
@@ -0,0 +1,37 @@
+#!/usr/bin/env ruby
+
+require 'io/console'
+require 'json'
+require 'net/http'
+require 'openssl'
+require 'uri'
+
+uri = URI.parse("http://localhost:4567/login")
+
+header = {'Content-Type': 'text/json'}
+
+print "Username: "; un = gets.strip
+print "Password: "; pw = STDIN.noecho(&:gets).strip; puts
+
+login = {
+ "username": un
+}
+
+http = Net::HTTP.new(uri.host, uri.port)
+request = Net::HTTP::Post.new(uri.request_uri, header)
+request.body = login.to_json
+
+response = http.request(request)
+eanc, tgt = response.body.split(?,)
+eanc = [eanc].pack("H*").unpack("C*").pack("c*")
+
+cipher = OpenSSL::Cipher::AES.new(256, :CBC).decrypt
+cipher.key = Digest::SHA2.digest(pw)
+begin
+ anc = cipher.update(eanc) + cipher.final
+ File.open(".keytab", ?w) do |f|
+ f.puts "_TGS,#{anc},#{tgt}"
+ end
+rescue OpenSSL::Cipher::CipherError
+ puts "Invalid password?"
+end