diff --git a/Rubeus/Commands/ASREP2Kirbi.cs b/Rubeus/Commands/ASREP2Kirbi.cs index 5f44a5b0..43918340 100644 --- a/Rubeus/Commands/ASREP2Kirbi.cs +++ b/Rubeus/Commands/ASREP2Kirbi.cs @@ -86,7 +86,15 @@ public void Execute(Dictionary arguments) } else if (arguments.ContainsKey("/keyhex")) { - key = Helpers.StringToByteArray(arguments["/keyhex"]); + try + { + key = Helpers.StringToByteArray(arguments["/keyhex"]); + } + catch (ArgumentException ex) + { + Console.WriteLine(String.Format("\r\n[X] {0}\r\n", ex.Message)); + return; + } } else { diff --git a/Rubeus/Commands/Describe.cs b/Rubeus/Commands/Describe.cs index a1e98ff9..886fe450 100755 --- a/Rubeus/Commands/Describe.cs +++ b/Rubeus/Commands/Describe.cs @@ -21,17 +21,23 @@ public void Execute(Dictionary arguments) - if (arguments.ContainsKey("/servicekey")) - { - serviceKey = Helpers.StringToByteArray(arguments["/servicekey"]); - } - if (arguments.ContainsKey("/asrepkey")) - { - asrepKey = Helpers.StringToByteArray(arguments["/asrepkey"]); - } - if (arguments.ContainsKey("/krbkey")) + try { + if (arguments.ContainsKey("/servicekey")) + { + serviceKey = Helpers.StringToByteArray(arguments["/servicekey"]); + } + if (arguments.ContainsKey("/asrepkey")) + { + asrepKey = Helpers.StringToByteArray(arguments["/asrepkey"]); + } + if (arguments.ContainsKey("/krbkey")) + { + krbKey = Helpers.StringToByteArray(arguments["/krbkey"]); + } + } catch (ArgumentException ex) { - krbKey = Helpers.StringToByteArray(arguments["/krbkey"]); + Console.WriteLine(String.Format("\r\n[X] {0}\r\n", ex.Message)); + return; } if (arguments.ContainsKey("/desplaintext")) { diff --git a/Rubeus/Commands/Golden.cs b/Rubeus/Commands/Golden.cs index 1adf2e80..7005d69a 100644 --- a/Rubeus/Commands/Golden.cs +++ b/Rubeus/Commands/Golden.cs @@ -44,6 +44,7 @@ public void Execute(Dictionary arguments) string ldappassword = null; string hash = ""; + byte[] hashBytes = null; Interop.KERB_ETYPE encType = Interop.KERB_ETYPE.subkey_keymaterial; Interop.TicketFlags flags = Interop.TicketFlags.forwardable | Interop.TicketFlags.renewable | Interop.TicketFlags.pre_authent | Interop.TicketFlags.initial; @@ -383,6 +384,18 @@ public void Execute(Dictionary arguments) Console.WriteLine("\r\n[X] You must supply a [/des|/rc4|/aes128|/aes256] hash!\r\n"); return; } + else + { + try + { + hashBytes = Helpers.StringToByteArray(hash); + } + catch (ArgumentException ex) + { + Console.WriteLine(String.Format("\r\n[X] {0}\r\n", ex.Message)); + return; + } + } if (!((encType == Interop.KERB_ETYPE.des_cbc_md5) || (encType == Interop.KERB_ETYPE.rc4_hmac) || (encType == Interop.KERB_ETYPE.aes128_cts_hmac_sha1) || (encType == Interop.KERB_ETYPE.aes256_cts_hmac_sha1))) { @@ -394,7 +407,7 @@ public void Execute(Dictionary arguments) ForgeTickets.ForgeTicket( user, String.Format("krbtgt/{0}", domain), - Helpers.StringToByteArray(hash), + hashBytes, encType, null, Interop.KERB_CHECKSUM_ALGORITHM.KERB_CHECKSUM_HMAC_SHA1_96_AES256, diff --git a/Rubeus/Commands/Silver.cs b/Rubeus/Commands/Silver.cs index 3933e41c..92c56863 100644 --- a/Rubeus/Commands/Silver.cs +++ b/Rubeus/Commands/Silver.cs @@ -45,6 +45,7 @@ public void Execute(Dictionary arguments) string ldappassword = null; string hash = ""; + byte[] hashBytes = null; Interop.KERB_ETYPE encType = Interop.KERB_ETYPE.subkey_keymaterial; byte[] krbKey = null; Interop.KERB_CHECKSUM_ALGORITHM krbEncType = Interop.KERB_CHECKSUM_ALGORITHM.KERB_CHECKSUM_HMAC_SHA1_96_AES256; @@ -445,6 +446,18 @@ public void Execute(Dictionary arguments) Console.WriteLine("\r\n[X] You must supply a [/des|/rc4|/aes128|/aes256] hash!\r\n"); return; } + else + { + try + { + hashBytes = Helpers.StringToByteArray(hash); + } + catch (ArgumentException ex) + { + Console.WriteLine(String.Format("\r\n[X] {0}\r\n", ex.Message)); + return; + } + } if (!String.IsNullOrEmpty(s4uProxyTarget) || !String.IsNullOrEmpty(s4uTransitedServices)) { if (String.IsNullOrEmpty(s4uProxyTarget) || String.IsNullOrEmpty(s4uTransitedServices)) @@ -464,7 +477,7 @@ public void Execute(Dictionary arguments) ForgeTickets.ForgeTicket( user, service, - Helpers.StringToByteArray(hash), + hashBytes, encType, krbKey, krbEncType, diff --git a/Rubeus/lib/Harvest.cs b/Rubeus/lib/Harvest.cs index ba2d8377..065c7668 100755 --- a/Rubeus/lib/Harvest.cs +++ b/Rubeus/lib/Harvest.cs @@ -88,7 +88,8 @@ public void HarvestTicketGrantingTickets() if (collectionStart.AddSeconds(this.runFor) < DateTime.Now) { Console.WriteLine("[*] Completed running for {0} seconds, exiting\r\n", runFor); - System.Environment.Exit(0); + // return will exit Rubeus + return; } } diff --git a/Rubeus/lib/Helpers.cs b/Rubeus/lib/Helpers.cs index a5696dc5..d01ac02a 100755 --- a/Rubeus/lib/Helpers.cs +++ b/Rubeus/lib/Helpers.cs @@ -60,8 +60,7 @@ public static byte[] StringToByteArray(string hex) if ((hex.Length % 16) != 0) { - Console.WriteLine("\r\n[X] Hash must be 16, 32 or 64 characters in length\r\n"); - System.Environment.Exit(1); + throw new ArgumentException("Hash must be 16, 32 or 64 characters in length"); } // yes I know this inefficient