-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add more "hacking detected" messages. One will be picked by random instead of always using the same one. * Instead of posting the "hacking detected" message immediately after login, post it after a set period of time based on the hacker's skill level. * On hacker login API call return the seconds until detection, so that a progress bar can be shown in the frontend.
- Loading branch information
Showing
11 changed files
with
179 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,4 +75,3 @@ export function initState(state: Record<string, unknown>) { | |
} | ||
|
||
export default store; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { SkillLevels } from '@/utils/groups'; | ||
import { z } from 'zod'; | ||
|
||
export const Stores = { | ||
HackerDetectionTimes: 'hacker_detection_times', | ||
} as const; | ||
|
||
export const HackerDetectionTimes = z.object({ | ||
type: z.literal('misc'), | ||
id: z.literal(Stores.HackerDetectionTimes), | ||
detection_times: z.object({ | ||
[SkillLevels.Novice]: z.number().min(0).int(), | ||
[SkillLevels.Master]: z.number().min(0).int(), | ||
[SkillLevels.Expert]: z.number().min(0).int(), | ||
}), | ||
}); | ||
export type HackerDetectionTimes = z.infer<typeof HackerDetectionTimes>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export const SkillLevels = { | ||
Novice: 'skill:novice', | ||
Master: 'skill:master', | ||
Expert: 'skill:expert', | ||
} as const; | ||
export type SkillLevel = typeof SkillLevels[keyof typeof SkillLevels]; | ||
|
||
export function getHighestSkillLevel(person: unknown): SkillLevel { | ||
if (typeof person !== 'object' || person === null || !('groups' in person)) { | ||
return SkillLevels.Novice; | ||
} | ||
|
||
// Dumb hack to work around Bookshelf models returning relations in a dumb way | ||
const { groups }: { groups: string[] } = JSON.parse(JSON.stringify(person)); | ||
|
||
if (!Array.isArray(groups)) { | ||
return SkillLevels.Novice; | ||
} | ||
const skillLevels = groups.filter((group: string) => typeof group === 'string' && group.startsWith('skill:')); | ||
if (skillLevels.length === 0) { | ||
return SkillLevels.Novice; | ||
} | ||
|
||
if (skillLevels.includes(SkillLevels.Expert)) return SkillLevels.Expert; | ||
if (skillLevels.includes(SkillLevels.Master)) return SkillLevels.Master; | ||
return SkillLevels.Novice; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { getPath } from '@/store/store'; | ||
import { SkillLevels, getHighestSkillLevel } from './groups'; | ||
import { Duration } from './time'; | ||
import { HackerDetectionTimes, Stores } from '@/store/types'; | ||
import { logger } from '@/logger'; | ||
|
||
const hackingIntrustionDetectionMessages = [ | ||
'Intrusion detection system has detected malicious activity', | ||
'System has detected unusual network patterns', | ||
'Unusual activity recognized within the system', | ||
'System analysis reveals potential illicit entry', | ||
'Inconsistent data patterns suggest possible intrusion', | ||
'System surveillance notes suspicious activity', | ||
'Potential intrusion detected by the system\'s defense mechanism', | ||
'Cyber defense system has detected irregular activity', | ||
'Unusual system access patterns detected', | ||
'Abnormal network behavior suggests possible intrusion', | ||
'Inconsistent network patterns hinting at potential breach', | ||
'System reports unusual activity, possible intrusion', | ||
'System has detected a potential security breach', | ||
'System\'s defense mechanism notes potential intrusion', | ||
'System analysis records irregular access patterns', | ||
'Network surveillance system detects potential malicious activity', | ||
]; | ||
|
||
export const getRandomHackingIntrustionDetectionMessage = () => { | ||
const randomIndex = Math.floor(Math.random() * hackingIntrustionDetectionMessages.length); | ||
return hackingIntrustionDetectionMessages[randomIndex]; | ||
}; | ||
|
||
export const getHackingDetectionTime = async (hackerPerson: unknown): Promise<number> => { | ||
const skillLevel = getHighestSkillLevel(hackerPerson); | ||
const detectionTimesBlob = await getPath(['data', 'misc', Stores.HackerDetectionTimes]); | ||
const detectionTimes = HackerDetectionTimes.safeParse(detectionTimesBlob); | ||
if (!detectionTimes.success) { | ||
logger.error('Failed to parse detection times blob, returning 1min', detectionTimesBlob); | ||
return Duration.minutes(1); | ||
} | ||
|
||
switch (skillLevel) { | ||
case SkillLevels.Expert: | ||
return detectionTimes.data.detection_times[SkillLevels.Expert]; | ||
case SkillLevels.Master: | ||
return detectionTimes.data.detection_times[SkillLevels.Master]; | ||
case SkillLevels.Novice: | ||
return detectionTimes.data.detection_times[SkillLevels.Novice]; | ||
default: | ||
return Duration.minutes(1); | ||
} | ||
}; |