diff --git a/TeamFiltration/TeamFiltration/Handlers/TeamsHandler.cs b/TeamFiltration/TeamFiltration/Handlers/TeamsHandler.cs index f17f283..450d771 100644 --- a/TeamFiltration/TeamFiltration/Handlers/TeamsHandler.cs +++ b/TeamFiltration/TeamFiltration/Handlers/TeamsHandler.cs @@ -165,70 +165,68 @@ public async Task GetWorkingWithList(string tenantId) failedResp: //TODO:Add logic to select FireProx endpoint based on current location - var enumUserReq = await _teamsClient.GetAsync(enumUserUrl + $"{TeamsRegion}/beta/users/{username}/externalsearchv3"); - - if (enumUserReq.IsSuccessStatusCode) { //We got an 200 OK response var userResp = await enumUserReq.Content.ReadAsStringAsync(); + //Indication of valid JSOn response if (userResp.Contains("tenantId")) { //get the object - List responeObject = JsonConvert.DeserializeObject>(userResp); + List usersFoundObject = JsonConvert.DeserializeObject>(userResp); //Any size - if (responeObject.Count() > 0) + if (usersFoundObject.Count() > 0) { + foreach (var responeObject in usersFoundObject) + { - if ( - //Check that the TenantID is not null - responeObject.FirstOrDefault().tenantId != null - - //Check that the coExistenceMode is not Unknown - && !responeObject.FirstOrDefault().featureSettings.coExistenceMode.Equals("Unknown") - //Check that the Display != Equals email. - && !responeObject.FirstOrDefault().displayName.Equals(username) + if ( + //Check that the TenantID is not null + responeObject.tenantId != null - //Check that the UPN matches the email your are looking for - && responeObject.FirstOrDefault().userPrincipalName.ToLower().Equals(username.ToLower()) - ) - { + //Check that the coExistenceMode is not Unknown + && !responeObject.featureSettings.coExistenceMode.Equals("Unknown") - try + //Check that the Display != Equals email OR that the UPN = userPrincipalName + && (!responeObject.displayName.Equals(username) || responeObject.userPrincipalName.ToLower().Equals(username.ToLower()))) { - //Check the user presence - HttpResponseMessage getUserPresence = await _teamsClient.PollyPostAsync( - $"https://presence.teams.microsoft.com/v1/presence/getpresence/", + try + { - new StringContent( - "[{ \"mri\":\"" + responeObject.FirstOrDefault().mri + "\"}]" - , Encoding.UTF8 - , "application/json" - ) - ); + //Check the user presence + HttpResponseMessage getUserPresence = await _teamsClient.PollyPostAsync( + $"https://presence.teams.microsoft.com/v1/presence/getpresence/", + new StringContent( + "[{ \"mri\":\"" + responeObject.mri + "\"}]" + , Encoding.UTF8 + , "application/json" + ) + ); - var getPresenceObject = JsonConvert.DeserializeObject>(await getUserPresence.Content.ReadAsStringAsync()); - if (getPresenceObject.FirstOrDefault()?.presence?.calendarData?.isOutOfOffice != null) - { - Outofofficenote = getPresenceObject.FirstOrDefault()?.presence?.calendarData.outOfOfficeNote; + var getPresenceObject = JsonConvert.DeserializeObject>(await getUserPresence.Content.ReadAsStringAsync()); + + if (getPresenceObject.FirstOrDefault()?.presence?.calendarData?.isOutOfOffice != null) + { + Outofofficenote = getPresenceObject.FirstOrDefault()?.presence?.calendarData.outOfOfficeNote; + } } - } - catch (Exception ex) - { + catch (Exception ex) + { - } + } - return (true, responeObject.FirstOrDefault().objectId, responeObject.FirstOrDefault(), Outofofficenote); + return (true, responeObject.objectId, responeObject, Outofofficenote); + } } } } @@ -237,8 +235,13 @@ public async Task GetWorkingWithList(string tenantId) } else if (enumUserReq.StatusCode.Equals(HttpStatusCode.Forbidden)) { - //As of 24.04.2023 - Seems like MS have patched this. - return (false, "", null, null); + //We got an 200 OK response + var userResp = await enumUserReq.Content.ReadAsStringAsync(); + + if (userResp.Equals("{\"errorCode\":\"Forbidden\"}")) + //As of 24.04.2023 - Seems like MS have patched this. + //return (false, "", null, null); + return (true, "", null, null); } else if (enumUserReq.StatusCode.Equals(HttpStatusCode.InternalServerError)) { diff --git a/TeamFiltration/TeamFiltration/Modules/Exfiltrate.cs b/TeamFiltration/TeamFiltration/Modules/Exfiltrate.cs index 82609b3..050233f 100644 --- a/TeamFiltration/TeamFiltration/Modules/Exfiltrate.cs +++ b/TeamFiltration/TeamFiltration/Modules/Exfiltrate.cs @@ -1684,7 +1684,20 @@ await filteredUserPrincipalNames.ParallelForEachAsync( async upn => { if (logDb) - _databaseHandler.WriteValidAcc(new ValidAccount() { Username = upn.userPrincipalName.Trim().ToLower(), Id = Helpers.Generic.StringToGUID(upn.userPrincipalName.Trim().ToLower()).ToString() }); + try + { + _databaseHandler.WriteValidAcc(new ValidAccount() + { + Username = upn.userPrincipalName.Trim().ToLower(), + Id = Helpers.Generic.StringToGUID(upn.userPrincipalName.Trim().ToLower()).ToString() + }); + } + catch (Exception ex) + { + + + } + }, maxDegreeOfParallelism: 700); }