Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit 1c80378

Browse files
authored
Node icons color bugfix (#171)
1 parent 5ef3ed1 commit 1c80378

File tree

20 files changed

+142
-46
lines changed

20 files changed

+142
-46
lines changed

applications/client/src/store/campaign/campaign.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ export class CampaignStore extends ExtendedModel(() => ({
101101
const parents = Array.from(this.appStore?.graphqlStore.hosts.values() || [], (host) => ({
102102
id: host.id,
103103
name: host.computedName,
104-
className: nodeColor[host.meta[0]?.maybeCurrent?.color || 'default'].className,
104+
className:
105+
nodeColor[
106+
(host.cobaltStrikeServer ? host.server?.meta?.current?.color : host.meta[0]?.maybeCurrent?.color) || 'default'
107+
].className,
105108
shape: host.meta[0]?.maybeCurrent?.shape,
106109
}));
107110
if (nodes.length) {

applications/client/src/store/graphql/BeaconMetaModel.base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { types, prop, tProp, Model, Ref, idProp } from 'mobx-keystone';
77
import { QueryBuilder } from 'mk-gql';
88
import type { BeaconType } from './BeaconTypeEnum';
99
import type { LogEntryModel } from './LogEntryModel';
10+
import type { NodeColors } from './NodeColorsEnum';
1011
import type { Shapes } from './ShapesEnum';
1112

1213
import { LogEntryModelSelector, logEntryModelPrimitives } from './LogEntryModel';
@@ -25,7 +26,7 @@ type Refs = {
2526
export class BeaconMetaModelBase extends Model({
2627
__typename: tProp('BeaconMeta'),
2728
/** The color of the node */
28-
color: prop<string | null>().withSetter(),
29+
color: prop<NodeColors | null>().withSetter(),
2930
/** The time that the last command was run */
3031
endTime: prop<any | null>().withSetter(),
3132
id: prop<string>().withSetter(),

applications/client/src/store/graphql/HostMetaModel.base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { types, prop, tProp, Model, Ref, idProp } from 'mobx-keystone';
77
import { QueryBuilder } from 'mk-gql';
8+
import type { NodeColors } from './NodeColorsEnum';
89
import type { Shapes } from './ShapesEnum';
910

1011
/**
@@ -14,7 +15,7 @@ import type { Shapes } from './ShapesEnum';
1415
export class HostMetaModelBase extends Model({
1516
__typename: tProp('HostMeta'),
1617
/** The color of the node */
17-
color: prop<string | null>().withSetter(),
18+
color: prop<NodeColors | null>().withSetter(),
1819
id: prop<string>().withSetter(),
1920
ip: prop<string | null>().withSetter(),
2021
os: prop<string | null>().withSetter(),
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* This is a mk-gql generated file, don't modify it manually */
2+
/* eslint-disable */
3+
/* tslint:disable */
4+
// @ts-nocheck
5+
import { types, prop, tProp, Model, Ref } from 'mobx-keystone';
6+
7+
/**
8+
* Typescript enum
9+
*/
10+
11+
export enum NodeColors {
12+
default = 'default',
13+
forest = 'forest',
14+
gold = 'gold',
15+
green = 'green',
16+
indigo = 'indigo',
17+
lime = 'lime',
18+
orange = 'orange',
19+
red = 'red',
20+
rose = 'rose',
21+
turquoise = 'turquoise',
22+
vermilion = 'vermilion',
23+
violet = 'violet',
24+
}
25+
26+
/**
27+
* NodeColors
28+
*
29+
* The color of the node
30+
*/
31+
export const NodeColorsEnumType = types.enum(NodeColors);

applications/client/src/store/graphql/RootStore.base.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import type { FileFlag } from './FileFlagEnum';
8787
import type { GenerationType } from './GenerationTypeEnum';
8888
import type { LogType } from './LogTypeEnum';
8989
import type { MitreTechniques } from './MitreTechniquesEnum';
90+
import type { NodeColors } from './NodeColorsEnum';
9091
import type { ParsingStatus } from './ParsingStatusEnum';
9192
import type { ServerDelineationTypes } from './ServerDelineationTypesEnum';
9293
import type { ServerType } from './ServerTypeEnum';
@@ -1184,7 +1185,7 @@ export class RootStoreBase extends ExtendedModel(
11841185
beaconTimeOfDeath?: any;
11851186
beaconType?: BeaconType;
11861187
campaignId: string;
1187-
color?: string;
1188+
color?: NodeColors;
11881189
shape?: Shapes;
11891190
},
11901191
resultSelector:
@@ -1193,7 +1194,7 @@ export class RootStoreBase extends ExtendedModel(
11931194
optimisticUpdate?: () => void
11941195
) {
11951196
return this.mutate<{ updateBeaconMetadata: BeaconModel }>(
1196-
`mutation updateBeaconMetadata($beaconDisplayName: String, $beaconId: String!, $beaconTimeOfDeath: DateTime, $beaconType: BeaconType, $campaignId: String!, $color: String, $shape: Shapes) { updateBeaconMetadata(beaconDisplayName: $beaconDisplayName, beaconId: $beaconId, beaconTimeOfDeath: $beaconTimeOfDeath, beaconType: $beaconType, campaignId: $campaignId, color: $color, shape: $shape) {
1197+
`mutation updateBeaconMetadata($beaconDisplayName: String, $beaconId: String!, $beaconTimeOfDeath: DateTime, $beaconType: BeaconType, $campaignId: String!, $color: NodeColors, $shape: Shapes) { updateBeaconMetadata(beaconDisplayName: $beaconDisplayName, beaconId: $beaconId, beaconTimeOfDeath: $beaconTimeOfDeath, beaconType: $beaconType, campaignId: $campaignId, color: $color, shape: $shape) {
11971198
${typeof resultSelector === 'function' ? resultSelector(BeaconModelSelector).toString() : resultSelector}
11981199
} }`,
11991200
variables,
@@ -1202,14 +1203,14 @@ export class RootStoreBase extends ExtendedModel(
12021203
}
12031204
// Update existing Host Display Name
12041205
@modelAction mutateUpdateHostMetadata(
1205-
variables: { campaignId: string; color?: string; hostDisplayName?: string; hostId: string; shape?: Shapes },
1206+
variables: { campaignId: string; color?: NodeColors; hostDisplayName?: string; hostId: string; shape?: Shapes },
12061207
resultSelector:
12071208
| string
12081209
| ((qb: typeof HostModelSelector) => typeof HostModelSelector) = hostModelPrimitives.toString(),
12091210
optimisticUpdate?: () => void
12101211
) {
12111212
return this.mutate<{ updateHostMetadata: HostModel }>(
1212-
`mutation updateHostMetadata($campaignId: String!, $color: String, $hostDisplayName: String, $hostId: String!, $shape: Shapes) { updateHostMetadata(campaignId: $campaignId, color: $color, hostDisplayName: $hostDisplayName, hostId: $hostId, shape: $shape) {
1213+
`mutation updateHostMetadata($campaignId: String!, $color: NodeColors, $hostDisplayName: String, $hostId: String!, $shape: Shapes) { updateHostMetadata(campaignId: $campaignId, color: $color, hostDisplayName: $hostDisplayName, hostId: $hostId, shape: $shape) {
12131214
${typeof resultSelector === 'function' ? resultSelector(HostModelSelector).toString() : resultSelector}
12141215
} }`,
12151216
variables,
@@ -1220,7 +1221,7 @@ export class RootStoreBase extends ExtendedModel(
12201221
@modelAction mutateUpdateServerMetadata(
12211222
variables: {
12221223
campaignId: string;
1223-
color?: string;
1224+
color?: NodeColors;
12241225
serverDisplayName?: string;
12251226
serverId: string;
12261227
serverType?: ServerType;
@@ -1232,7 +1233,7 @@ export class RootStoreBase extends ExtendedModel(
12321233
optimisticUpdate?: () => void
12331234
) {
12341235
return this.mutate<{ updateServerMetadata: ServerModel }>(
1235-
`mutation updateServerMetadata($campaignId: String!, $color: String, $serverDisplayName: String, $serverId: String!, $serverType: ServerType, $shape: Shapes) { updateServerMetadata(campaignId: $campaignId, color: $color, serverDisplayName: $serverDisplayName, serverId: $serverId, serverType: $serverType, shape: $shape) {
1236+
`mutation updateServerMetadata($campaignId: String!, $color: NodeColors, $serverDisplayName: String, $serverId: String!, $serverType: ServerType, $shape: Shapes) { updateServerMetadata(campaignId: $campaignId, color: $color, serverDisplayName: $serverDisplayName, serverId: $serverId, serverType: $serverType, shape: $shape) {
12361237
${typeof resultSelector === 'function' ? resultSelector(ServerModelSelector).toString() : resultSelector}
12371238
} }`,
12381239
variables,

applications/client/src/store/graphql/ServerMetaModel.base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { types, prop, tProp, Model, Ref, idProp } from 'mobx-keystone';
77
import { QueryBuilder } from 'mk-gql';
8+
import type { NodeColors } from './NodeColorsEnum';
89
import type { ServerType } from './ServerTypeEnum';
910
import type { Shapes } from './ShapesEnum';
1011

@@ -15,7 +16,7 @@ import type { Shapes } from './ShapesEnum';
1516
export class ServerMetaModelBase extends Model({
1617
__typename: tProp('ServerMeta'),
1718
/** The color of the node */
18-
color: prop<string | null>().withSetter(),
19+
color: prop<NodeColors | null>().withSetter(),
1920
id: prop<string>().withSetter(),
2021
shape: prop<Shapes | null>().withSetter(),
2122
type: prop<ServerType>().withSetter(),

applications/client/src/store/graphql/root.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export * from './LinkModel';
2626
export * from './LogEntryModel';
2727
export * from './LogTypeEnum';
2828
export * from './MitreTechniquesEnum';
29+
export * from './NodeColorsEnum';
2930
export * from './NonHidableEntitiesModel';
3031
export * from './OperatorModel';
3132
export * from './ParserInfoModel';

applications/client/src/views/Campaign/Explore/Panels/Beacon/BeaconRow.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,11 @@ export const BeaconRow = observer<BeaconRowProps>(({ beacon, ...props }) => {
126126
{store.settings.momentTz(beacon.maxTime)?.format(dateShortFormat)}
127127
</RowTime>
128128
<RowTitle className={skeletonClass}>
129-
<NodeIcon type="beacon" shape="circle" color="default" />
130-
{/* <NodeIcon type="beacon" shape="triangleUp" color="red" />
131-
<NodeIcon type="beacon" shape="triangleDown" color="rose" />
132-
<NodeIcon type="beacon" shape="diamond" color="indigo" />
133-
<NodeIcon type="beacon" shape="hexagonDown" color="turquoise" />
134-
<NodeIcon type="beacon" shape="square" color="forest" />
135-
<NodeIcon type="beacon" shape="pentagonDown" color="lime" />
136-
<NodeIcon type="beacon" shape="pentagonUp" color="gold" />
137-
<NodeIcon type="beacon" shape="hexagonUp" color="orange" /> */}
129+
<NodeIcon
130+
type="beacon"
131+
shape={beacon.meta?.[0]?.current?.shape || undefined}
132+
color={beacon.meta?.[0]?.current?.color || undefined}
133+
/>
138134
<Txt cy-test="beacon-display-name" normal muted>
139135
{beacon?.computedName || `${beacon.server?.computedName}`}
140136
</Txt>

applications/client/src/views/Campaign/Explore/Panels/Host/HostOrServerRow.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,14 @@ export const HostOrServerRow = observer<HostOrServerRowProps>(({ host, ...props
158158
{host.maxTime ? store.settings.momentTz(host.maxTime)?.format(dateShortFormat) : dateShortPlaceholder}
159159
</RowTime>
160160
<RowTitle>
161-
<NodeIcon type={host.cobaltStrikeServer ? 'server' : 'host'} color="default" />
161+
<NodeIcon
162+
type={host.cobaltStrikeServer ? 'server' : 'host'}
163+
color={
164+
host.cobaltStrikeServer
165+
? host.server?.meta?.current?.color || undefined
166+
: host.meta?.[0]?.current?.color || undefined
167+
}
168+
/>
162169
{host.cobaltStrikeServer && <Txt muted>Server:</Txt>}
163170
<Txt cy-test="hostName" bold={!!host.cobaltStrikeServer}>
164171
{host.computedName}

applications/client/src/views/Campaign/Explore/Panels/Meta/ServerMeta.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ export const ServerMeta = observer((props) => {
8787
}
8888
} else if (args.key === 'color') {
8989
store.campaign.graph?.updateNodeVisual({
90-
nodeId: data.updateServerMetadata.id,
90+
// Safer to use server.serverHost.id instead of data.updateServerMetadata.name, to cover Brute Ratel data nodeId difference at least for now.
91+
nodeId: server?.serverHost?.id || data.updateServerMetadata.name,
9192
className: nodeColor[state.metaDraft.originalData.color].className,
9293
shape: 'hexagonUp',
9394
});

0 commit comments

Comments
 (0)