Skip to content

Commit

Permalink
Fix ImplantTemplate becomes null on GruntTable
Browse files Browse the repository at this point in the history
  • Loading branch information
cobbr committed Sep 7, 2020
1 parent 93eddf4 commit 1cb750a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix profile bug when HttpGetResponse differs from HttpPostResponse
- Fix TaskKill display bug
- Fix token impersonation issues
- Fix ImplantTemplate becomes null on GruntTable

## [v0.6] - 2020-08-04
### Added
Expand Down
2 changes: 2 additions & 0 deletions Covenant/Components/Grunts/GruntCommandCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
if (this.GruntCommand.CommandOutput != null && this.GruntCommand.CommandOutput.Id == commandOutput.Id)
{
this.GruntCommand = await Service.GetGruntCommand(this.GruntCommandId);
Service.DisposeContext();
this.GruntCommand.CommandOutput ??= await Service.GetCommandOutput(this.GruntCommand.CommandOutputId);
Service.DisposeContext();
await this.InvokeAsync(() => this.StateHasChanged());
Expand All @@ -110,6 +111,7 @@
if (this.GruntCommandId == gruntCommand.Id)
{
this.GruntCommand = await Service.GetGruntCommand(this.GruntCommandId);
Service.DisposeContext();
this.GruntCommand.CommandOutput ??= await Service.GetCommandOutput(this.GruntCommand.CommandOutputId);
Service.DisposeContext();
await this.InvokeAsync(() => this.StateHasChanged());
Expand Down
15 changes: 10 additions & 5 deletions Covenant/Components/Grunts/GruntIndex.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
<TabbedTerminals @ref="TabbedTerminals" @bind-TerminalGrunts="TerminalGrunts" OnRemoveTerminal="OnRemoveTerminal"/>

@code {
[Parameter]
public List<Grunt> Grunts { get; set; }
[Parameter]
public List<Grunt> Grunts { get; set; }
private List<Grunt> UnfilteredGrunts { get; set; }

private TabbedTerminals TabbedTerminals { get; set; }
Expand Down Expand Up @@ -82,21 +82,26 @@
}
}

private void OnEditGrunt(object sender, Grunt grunt)
private async void OnEditGrunt(object sender, Grunt grunt)
{
if (grunt.ImplantTemplate == null)
{
grunt.ImplantTemplate = await Service.GetImplantTemplate(grunt.ImplantTemplateId);
Service.DisposeContext();
}
bool inDisplayedGrunts = this.Grunts.Any(G => G.Id == grunt.Id);
if (inDisplayedGrunts)
{
this.Grunts[this.Grunts.FindIndex(G => G.Id == grunt.Id)] = grunt;
this.InvokeAsync(() => this.StateHasChanged());
await this.InvokeAsync(() => this.StateHasChanged());
}
if (this.UnfilteredGrunts.Any(G => G.Id == grunt.Id))
{
this.UnfilteredGrunts[this.UnfilteredGrunts.FindIndex(G => G.Id == grunt.Id)] = grunt;
if (!inDisplayedGrunts && (!this.Hidden || grunt.Status != GruntStatus.Hidden) && grunt.Status != GruntStatus.Uninitialized)
{
this.FilterGrunts();
this.InvokeAsync(() => this.StateHasChanged());
await this.InvokeAsync(() => this.StateHasChanged());
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions Covenant/Components/Grunts/GruntTable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<SortableTableHeader TItem="Grunt" TItem2="string" GetSortableProperty="(grunt) => grunt.Note">
<HeaderContent>Note</HeaderContent>
</SortableTableHeader>
<SortableTableHeader TItem="Grunt" TItem2="string" GetSortableProperty="(grunt) => grunt.ImplantTemplate.Name">
<SortableTableHeader TItem="Grunt" TItem2="string" GetSortableProperty="(grunt) => grunt.ImplantTemplate?.Name">
<HeaderContent>Template</HeaderContent>
</SortableTableHeader>
</TableHeader>
Expand All @@ -66,7 +66,7 @@
<td @attributes="InputAttributes">@grunt.LastCheckIn</td>
<td @attributes="InputAttributes">@grunt.Status</td>
<td @attributes="InputAttributes">@grunt.Note</td>
<td @attributes="InputAttributes">@grunt.ImplantTemplate.Name</td>
<td @attributes="InputAttributes">@grunt.ImplantTemplate?.Name</td>
</tr>
</TableRow>
<ButtonTray>@ButtonTray</ButtonTray>
Expand Down Expand Up @@ -103,6 +103,7 @@
protected async override Task OnInitializedAsync()
{
this.Grunts = this.Grunts ?? (await Service.GetGrunts()).ToList();
Service.DisposeContext();
}

private string GetGruntStatusOpacity(GruntStatus s)
Expand All @@ -120,7 +121,7 @@
{
return SearchTerm == string.Empty ||
grunt.Name.Contains(SearchTerm, StringComparison.CurrentCultureIgnoreCase) ||
grunt.ImplantTemplate.Name.Contains(SearchTerm, StringComparison.CurrentCultureIgnoreCase) ||
(grunt.ImplantTemplate != null && grunt.ImplantTemplate.Name.Contains(SearchTerm, StringComparison.CurrentCultureIgnoreCase)) ||
grunt.Hostname.Contains(SearchTerm, StringComparison.CurrentCultureIgnoreCase) ||
grunt.UserName.Contains(SearchTerm, StringComparison.CurrentCultureIgnoreCase) ||
grunt.Status.ToString().Contains(SearchTerm, StringComparison.CurrentCultureIgnoreCase) ||
Expand Down

0 comments on commit 1cb750a

Please sign in to comment.