<commit_before>﻿using Syfuhs.Security.Kerberos;
using Syfuhs.Security.Kerberos.Aes;
using Syfuhs.Security.Kerberos.Crypto;
using System;
using System.IO;
using System.Linq;
using System.Text;

namespace KerbTester
{
    class Program
    {
        static void Main(string[] args)
        {
            AESKerberosConfiguration.Register();

            if (args.Length < 3)
            {
                ShowHelp();
                return;
            }

            try
            {
                string raw = "";

                switch (args[2])
                {
                    case "aes":
                    case "aes256":
                        raw = "<KEY>;
                        break;
                    case "aes128":
                        raw = "<KEY>;
                        break;
                    case "rc4":
                        raw = "YIIJRgYGKwYBBQUCoIIJOjCCCTagMDAuBgkqhkiC9xIBAgIGCSqGSIb3EgECAgYKKwYBBAGCNwICHgYKKwYBBAGCNwICCqKCCQAEggj8YIII+AYJKoZIhvcSAQICAQBuggjnMIII46ADAgEFoQMCAQ6iBwMFACAAAACjggdaYYIHVjCCB1KgAwIBBaEaGxhJREVOVElUWUlOVEVSVkVOVElPTi5DT02iLTAroAMCAQKhJDAiGwRIVFRQGxphYWRnLndpbmRvd3MubmV0Lm5zYXRjLm5ldKOCBv4wggb6oAMCARehAwIBA6KCBuwEggboqofMyb1XmwRUn6UqLhEZjjh2mQBaWwIBEYAyneJNi+qXsNcCTAqdXirSMl/RMnClcDvqv1qI2sa7xG1l3VraOlu+pB3Z1xANWIkgPW6RRkQOZl2yNQ4RrZ9ZrDRGnE7ZTSeGZgGUCkANheImRBVVmFUKZfOl9ztDp/dRy6oltYXt8bbvJF2GcSAYOY/QYjmP5qqvQzpr615AA2zjrtQdQxbACKnRplfI3bVMuFzXYHX5nrVW+xs3wNjo20y8T8gXRSJuOZgnCZE86iqUuklRNgP5FSbfMJtgKtyorxUW1XMUAplA8UQS85L95B4gQxQYvWg4hteIIleadn+AmwyrpZjRqZ3Tgy8bXtNjebrNR1X8e821vi/99jrTbR4XgrrGH5aKFlGWCuZhRPUFxpuuFN7rBIIrCsiE6bq9uUDnzcdsUzLhcm3w+0JG7/G8ubVJr7imhrSngW60J2c11HQO5+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B0ycXiY396pVGM5E7C51yA4z0WxmjDeg1ZsHSNCyoTjkJqRPz9yXLYB1nMtKaClrGlkmOlEN5HbWsN12yqQ6XfxCKgXk3s0XkF9wVHk9r9XipkGjo5VKPIOLWCycd+kTRwpPHLngz3/1Y3nupKLysUKr6ffYZHc6RLFBkDvLtnBIlYtXfNq4tOxs7jexo9ZwN/BOOtC+uvcKFVYCMQ=";
                        break;
                    case "spnego":
                        raw = "YIGeBgYrBgEFBQKggZMwgZCgGjAYBgorBgEEAYI3AgIeBgorBgEEAYI3AgIKonIEcE5FR09FWFRTAAAAAAAAAABgAAAAcAAAAAPx046cicVOngxMfxUsCsEIMeUM39SSXP1N9DuDVIU3IFosQ3eWTsKOPdfTNWD4SAAAAAAAAAAAYAAAAAEAAAAAAAAAAAAAAMNbiTClcBVAolAmCpGQrZA=";
                        break;
                    default:
                        raw = args[1];
                        break;
                }

                KeyTable keytab;

                if (args[0] == "keytab")
                {
                    keytab = new KeyTable(File.ReadAllBytes("sample.keytab"));
                }
                else
                {
                    keytab = new KeyTable(new KerberosKey(args[0], host: args[1]));
                }

                var validator = new KerberosValidator(keytab)
                {
                    Logger = W
                };

                var authenticator = new KerberosAuthenticator(validator);

                if (args.Contains("novalidate"))
                {
                    validator.ValidateAfterDecrypt = ValidationAction.Replay;
                }

                var identity = authenticator.Authenticate(raw);

                if (identity == null)
                {
                    W("Identity could not be decrypted");

                    return;
                }

                foreach (var c in identity.Claims)
                {
                    W($"{c.Type}: {c.Value}");
                }
            }
            catch (Exception ex)
            {
                W(ex.Message);
            }

            ;
        }

        private static void W(string w)
        {
            Console.WriteLine(w);
        }

        private static void ShowHelp()
        {
            W("");
            W(" Usage:   KerbTester.exe <key> <host> [aes|aes256|rc4] [request] [novalidate]");
            W("");
            W(" Example: KerbTester.exe P@ssw0rd! server01 YIIHCAYGKw... novalidate");
            W("");
            W(" ================================================");
            W("");
            W("    key          The key (password) of the SPN this request is targeting");
            W("    host         The samAccountName of the SPN this request is targeting (used for salt generation)");
            W("    aes          Process a sample AES 256 encrypted token");
            W("    aes128       Process a sample AES 128 encrypted token");
            W("    rc4          Process a sample RC4 encrypted token");
            W("    request      Process kerberos request in a base64 encoding");
            W("    novalidate   Do not validate token");
            W("");
        }

        private static byte[] MD4(byte[] key)
        {
            return new MD4().ComputeHash(key);
        }

        private static byte[] MD4(string password)
        {
            return MD4(Encoding.Unicode.GetBytes(password));
        }
    }
}
<commit_msg>Added claims to the AES ticket<commit_after>﻿using Syfuhs.Security.Kerberos;
using Syfuhs.Security.Kerberos.Aes;
using Syfuhs.Security.Kerberos.Crypto;
using System;
using System.IO;
using System.Linq;
using System.Text;

namespace KerbTester
{
    class Program
    {
        static void Main(string[] args)
        {
            AESKerberosConfiguration.Register();

            if (args.Length < 3)
            {
                ShowHelp();
                return;
            }

            try
            {
                string raw = "";

                switch (args[2])
                {
                    case "aes":
                    case "aes256":
                        raw = "<KEY>";
                        break;
                    case "aes128":
                        raw = "<KEY>;
                        break;
                    case "rc4":
                        raw = "<KEY>;
                        break;
                    case "spnego":
                        raw = "<KEY>;
                        break;
                    default:
                        raw = args[1];
                        break;
                }

                KeyTable keytab;

                if (args[0] == "keytab")
                {
                    keytab = new KeyTable(File.ReadAllBytes("sample.keytab"));
                }
                else
                {
                    keytab = new KeyTable(new KerberosKey(args[0], host: args[1]));
                }

                var validator = new KerberosValidator(keytab)
                {
                    Logger = W
                };

                var authenticator = new KerberosAuthenticator(validator);

                if (args.Contains("novalidate"))
                {
                    validator.ValidateAfterDecrypt = ValidationAction.Replay;
                }

                var identity = authenticator.Authenticate(raw);

                if (identity == null)
                {
                    W("Identity could not be decrypted");

                    return;
                }

                foreach (var c in identity.Claims)
                {
                    W($"{c.Type}: {c.Value}");
                }
            }
            catch (Exception ex)
            {
                W(ex.Message);
            }

            ;
        }

        private static void W(string w)
        {
            Console.WriteLine(w);
        }

        private static void ShowHelp()
        {
            W("");
            W(" Usage:   KerbTester.exe <key> <host> [aes|aes256|rc4] [request] [novalidate]");
            W("");
            W(" Example: KerbTester.exe P@ssw0rd! server01 YIIHCAYGKw... novalidate");
            W("");
            W(" ================================================");
            W("");
            W("    key          The key (password) of the SPN this request is targeting");
            W("    host         The samAccountName of the SPN this request is targeting (used for salt generation)");
            W("    aes          Process a sample AES 256 encrypted token");
            W("    aes128       Process a sample AES 128 encrypted token");
            W("    rc4          Process a sample RC4 encrypted token");
            W("    request      Process kerberos request in a base64 encoding");
            W("    novalidate   Do not validate token");
            W("");
        }

        private static byte[] MD4(byte[] key)
        {
            return new MD4().ComputeHash(key);
        }

        private static byte[] MD4(string password)
        {
            return MD4(Encoding.Unicode.GetBytes(password));
        }
    }
}

{'fraction_non_alphanumeric': 0.08156226696495153, 'fraction_numerical': 0.050335570469798654, 'mean_word_length': 1.8926934483688325, 'pattern_counts': {'":': 10, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4485545', 'n_tokens_mistral': 4636, 'n_tokens_neox': 4232, 'n_words': 455}