Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Environment.Exit #163

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Rubeus/Commands/ASREP2Kirbi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ public void Execute(Dictionary<string, string> arguments)
}
else if (arguments.ContainsKey("/keyhex"))
{
key = Helpers.StringToByteArray(arguments["/keyhex"]);
try
{
key = Helpers.StringToByteArray(arguments["/keyhex"]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of putting the try/catch around the single function call, would it not be cleaner to have a higher level try block in Main for ArgumentException?

}
catch (ArgumentException ex)
{
Console.WriteLine(String.Format("\r\n[X] {0}\r\n", ex.Message));
return;
}
}
else
{
Expand Down
26 changes: 16 additions & 10 deletions Rubeus/Commands/Describe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,23 @@ public void Execute(Dictionary<string, string> 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"))
{
Expand Down
15 changes: 14 additions & 1 deletion Rubeus/Commands/Golden.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void Execute(Dictionary<string, string> 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;
Expand Down Expand Up @@ -383,6 +384,18 @@ public void Execute(Dictionary<string, string> arguments)
Console.WriteLine("\r\n[X] You must supply a [/des|/rc4|/aes128|/aes256] hash!\r\n");
return;
}
else
{
try
{
hashBytes = Helpers.StringToByteArray(hash);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comments regarding propagating the exception and catching higher up in Main

}
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)))
{
Expand All @@ -394,7 +407,7 @@ public void Execute(Dictionary<string, string> 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,
Expand Down
15 changes: 14 additions & 1 deletion Rubeus/Commands/Silver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void Execute(Dictionary<string, string> 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;
Expand Down Expand Up @@ -445,6 +446,18 @@ public void Execute(Dictionary<string, string> arguments)
Console.WriteLine("\r\n[X] You must supply a [/des|/rc4|/aes128|/aes256] hash!\r\n");
return;
}
else
{
try
{
hashBytes = Helpers.StringToByteArray(hash);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

}
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))
Expand All @@ -464,7 +477,7 @@ public void Execute(Dictionary<string, string> arguments)
ForgeTickets.ForgeTicket(
user,
service,
Helpers.StringToByteArray(hash),
hashBytes,
encType,
krbKey,
krbEncType,
Expand Down
3 changes: 2 additions & 1 deletion Rubeus/lib/Harvest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
3 changes: 1 addition & 2 deletions Rubeus/lib/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down