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

Fix encoding #124

Merged
merged 4 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix conflicts
  • Loading branch information
Lee Christensen committed Jan 6, 2024
commit af365af0bd5880f2ad59e8289eb7d317730a54dd
29 changes: 24 additions & 5 deletions Seatbelt/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Win32;
using System.Diagnostics.Eventing.Reader;
using System.Threading;
using System.Security.Cryptography;

namespace Seatbelt
{
Expand All @@ -22,28 +23,30 @@ internal class Runtime
private IEnumerable<string> CommandGroups { get; set; }
public bool FilterResults { get; }
public string DelayCommands { get; }
public bool RandomizeOrder { get; }
public string ComputerName { get; } // for remote connections
private string UserName { get; } // for remote connections
private string Password { get; } // for remote connections
private ManagementClass wmiRegProv { get; }

public Runtime(IOutputSink outputSink, IEnumerable<string> commands, IEnumerable<string> commandGroups, bool filter, string delayCommands)
: this(outputSink, commands, commandGroups, filter, delayCommands, "", "", "")
public Runtime(IOutputSink outputSink, IEnumerable<string> commands, IEnumerable<string> commandGroups, bool filter, string delayCommands, bool randomizeOrder)
: this(outputSink, commands, commandGroups, filter, randomizeOrder, delayCommands, "", "", "")
{
}

public Runtime(IOutputSink outputSink, IEnumerable<string> commands, IEnumerable<string> commandGroups, bool filter, string delayCommands, string computerName)
: this(outputSink, commands, commandGroups, filter, delayCommands, computerName, "", "")
public Runtime(IOutputSink outputSink, IEnumerable<string> commands, IEnumerable<string> commandGroups, bool filter, string delayCommands, bool randomizeOrder, string computerName)
: this(outputSink, commands, commandGroups, filter, randomizeOrder, delayCommands, computerName, "", "")
{
}

public Runtime(IOutputSink outputSink, IEnumerable<string> commands, IEnumerable<string> commandGroups, bool filter, string delayCommands, string computerName, string userName, string password)
public Runtime(IOutputSink outputSink, IEnumerable<string> commands, IEnumerable<string> commandGroups, bool filter, bool randomizeOrder, string delayCommands, string computerName, string userName, string password)
{
OutputSink = outputSink;
Commands = commands;
CommandGroups = commandGroups;
FilterResults = filter;
DelayCommands = delayCommands;
RandomizeOrder = randomizeOrder;
ComputerName = computerName;
UserName = userName;
Password = password;
Expand Down Expand Up @@ -352,6 +355,14 @@ private bool ProcessGroup(string command)

var commandsFiltered = toExecute.Where(c => !toExclude.Contains(c)).ToList();

if (RandomizeOrder)
{
OutputSink.WriteHost("[*] Order of the group's commands will be randomize\n");

RNGCryptoServiceProvider random = new RNGCryptoServiceProvider();
commandsFiltered = commandsFiltered.OrderBy(x => Next(random)).ToList();
}

commandsFiltered.ForEach(c =>
{
ExecuteCommand(c, new string[] { });
Expand Down Expand Up @@ -415,6 +426,14 @@ private void ExecuteCommand(CommandBase? command, string[] commandArgs)
OutputSink.WriteError($" [!] Terminating exception running command '{command.Command}': " + e);
}
}

static int Next(RNGCryptoServiceProvider random)
{
byte[] randomInt = new byte[4];
random.GetBytes(randomInt);
return Convert.ToInt32(randomInt[0]);
}

}
}
#nullable enable
1 change: 1 addition & 0 deletions Seatbelt/Seatbelt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public Seatbelt(string[] args)
Options.Commands,
Options.CommandGroups,
Options.FilterResults,
Options.RandomizeOrder,
Options.DelayCommands,
Options.ComputerName,
Options.UserName,
Expand Down
2 changes: 2 additions & 0 deletions Seatbelt/SeatbeltArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public SeatbeltOptions Parse()
{
var quietMode = ParseAndRemoveSwitchArgument("-q");
var filterResults = !ParseAndRemoveSwitchArgument("-Full");
var randomizeOrder = ParseAndRemoveSwitchArgument("-RandomizeOrder");

var commandGroups = ParseAndRemoveKeyValueArgument("-Group");
var outputFile = ParseAndRemoveKeyValueArgument("-OutputFile");
Expand All @@ -35,6 +36,7 @@ public SeatbeltOptions Parse()
outputFile,
filterResults,
quietMode,
randomizeOrder,
delayCommands,
computerName,
userName,
Expand Down
4 changes: 3 additions & 1 deletion Seatbelt/SeatbeltOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ namespace Seatbelt
{
class SeatbeltOptions
{
public SeatbeltOptions(IEnumerable<string> commands, IEnumerable<string> commandGroup, string? outputFile, bool filterResults, bool quietMode, string? delayCommands, string? computerName, string? userName, string? password)
public SeatbeltOptions(IEnumerable<string> commands, IEnumerable<string> commandGroup, string? outputFile, bool filterResults, bool quietMode, bool randomizeOrder, string? delayCommands, string? computerName, string? userName, string? password)
{
Commands = commands;
CommandGroups = commandGroup;
OutputFile = outputFile;
FilterResults = filterResults;
RandomizeOrder = randomizeOrder;
QuietMode = quietMode;
DelayCommands = delayCommands;
ComputerName = computerName;
Expand All @@ -21,6 +22,7 @@ public SeatbeltOptions(IEnumerable<string> commands, IEnumerable<string> command
public IEnumerable<string> CommandGroups { get; set; }
public string? OutputFile { get; set; }
public bool FilterResults { get; set; }
public bool RandomizeOrder { get; set; }
public bool QuietMode { get; set; }
public string? DelayCommands { get; set; }
public string? ComputerName { get; set; }
Expand Down