diff options
author | Nat Lasseter <user@4574.co.uk> | 2025-02-19 17:05:26 +0000 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2025-02-19 17:05:26 +0000 |
commit | e160be0ebd55a130d37129714d340726882aac07 (patch) | |
tree | c1c515ec01fa0d445c92f8a5583db2098f6430eb /4.1/kinit.rb | |
parent | b50766d496010bf2856dac88d97c236cf5944ae6 (diff) |
[4.1] Started
Diffstat (limited to '4.1/kinit.rb')
-rwxr-xr-x | 4.1/kinit.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/4.1/kinit.rb b/4.1/kinit.rb new file mode 100755 index 0000000..5174839 --- /dev/null +++ b/4.1/kinit.rb @@ -0,0 +1,36 @@ +#!/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) +eticket = [response.body].pack("H*").unpack("C*").pack("c*") + +cipher = OpenSSL::Cipher::AES.new(256, :CBC).decrypt +cipher.key = Digest::SHA2.digest(pw) +begin + ticket = cipher.update(eticket) + cipher.final + File.open(".keytab", ?w) do |f| + f.puts "_TGS:#{ticket}" + end +rescue OpenSSL::Cipher::CipherError + puts "Invalid password?" +end |