MCPcopy Create free account
hub / github.com/F12FLASH/CTF / MemStorage

Class MemStorage

7.GraphQL Apocalypse/server/storage.ts:13–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11const _0x4a2b = (s: string) => Buffer.from(s, 'base64').toString('utf-8');
12
13export class MemStorage implements IStorage {
14 private readonly _vault = flagVault;
15 private readonly SECRET_ACCESS_CODE_HASH: string;
16 private users: Array<{ id: string; username: string }>;
17 private lastAttemptTime: number = 0;
18 private attemptCount: number = 0;
19 private readonly RATE_LIMIT_WINDOW = 60000;
20 private readonly MAX_ATTEMPTS = 10;
21
22 constructor() {
23 const _ac = _0x4a2b('VFlQRV9DT05GVVNJT05fRVhQTE9JVA==');
24 this.SECRET_ACCESS_CODE_HASH = bcrypt.hashSync(_ac, 10);
25
26 this.users = [
27 { id: "1", username: "admin" },
28 { id: "2", username: "user" },
29 { id: "3", username: "guest" },
30 ];
31 }
32
33 async getFlag(): Promise<string> {
34 return "[REDACTED - Access Denied]";
35 }
36
37 async getUsers(): Promise<Array<{ id: string; username: string }>> {
38 return this.users;
39 }
40
41 async validateAccessCode(inputCode: string): Promise<boolean> {
42 try {
43 const now = Date.now();
44
45 if (now - this.lastAttemptTime > this.RATE_LIMIT_WINDOW) {
46 this.attemptCount = 0;
47 }
48
49 this.attemptCount++;
50 this.lastAttemptTime = now;
51
52 if (this.attemptCount > this.MAX_ATTEMPTS) {
53 await new Promise(resolve => setTimeout(resolve, 3000));
54 }
55
56 const isValid = await bcrypt.compare(inputCode, this.SECRET_ACCESS_CODE_HASH);
57
58 if (isValid) {
59 this.attemptCount = 0;
60 }
61
62 return isValid;
63 } catch (error) {
64 return false;
65 }
66 }
67
68 async unlockSecretData(accessCode: string): Promise<{ flag: string } | null> {
69 const isValid = await this.validateAccessCode(accessCode);
70

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected