Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/shadow-decoys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Shadow terminals

These public simulations distract casual route probing and offer small CTFs. They are not an authentication layer, an intrusion detector, or a substitute for the real admin's session checks.

| Route | Experience |
| --- | --- |
| `/admin` | Fake PIN console |
| `/administrator` | Fake system administration login |
| `/wp-admin` | Fake content administration login (no WordPress installed) |
| `/cpanel` | Fake hosting login (no cPanel installed) |
| `/admin/login` | Fake operator login |
| `/dashboard/login` | Fake dashboard login |
| `/b1kr4m-5h4d0w` | Five-lock cipher CTF |
| `/admin/access` | Alternate entrance to cipher CTF |
| `/admin/backup` | Three-lock archive CTF |
| `/root` | Three-lock signal CTF |

Login inputs remain only in React memory and are cleared immediately when submitted. No login requests, database writes, credential storage, or real admin imports are involved. The timer is cleaned up when leaving a page.

CTF verification accepts only a recognized track, integer level, and answer up to 128 characters. Answers stay in the server route. Completion returns fictional flags and never sets an admin cookie or redirects to the real login. Flags are game rewards, not proof of identity; players can inspect or probe the public verifier.

The verifier has a bounded 2,048-entry per-instance throttle (20 attempts per minute) with expired-entry cleanup and Retry-After responses. This is best-effort on Vercel; it is not a globally coordinated rate limit. Responses are not cached. Decoy pages have noindex/nofollow metadata and headers without advertising the route inventory in robots.txt.

No new packages, database schema changes, or environment variables are required.
6 changes: 6 additions & 0 deletions src/app/admin/access/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { CryptoPuzzle } from '@/components/crypto-puzzle';
import { ShadowShell, shadowMetadata } from '@/components/shadow-shell';
export const metadata = shadowMetadata;
export default function Page() {
return <ShadowShell label="Recovery terminal"><CryptoPuzzle track="cipher" /></ShadowShell>;
}
6 changes: 6 additions & 0 deletions src/app/admin/backup/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { CryptoPuzzle } from '@/components/crypto-puzzle';
import { ShadowShell, shadowMetadata } from '@/components/shadow-shell';
export const metadata = shadowMetadata;
export default function Page() {
return <ShadowShell label="Recovery terminal"><CryptoPuzzle track="archive" /></ShadowShell>;
}
6 changes: 6 additions & 0 deletions src/app/admin/login/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DecoyLogin } from '@/components/decoy-login';
import { ShadowShell, shadowMetadata } from '@/components/shadow-shell';
export const metadata = shadowMetadata;
export default function Page() {
return <ShadowShell label="Restricted access"><DecoyLogin title="Operator sign-in" code="OPS-05" /></ShadowShell>;
}
25 changes: 4 additions & 21 deletions src/app/admin/page.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
'use client';

import Link from 'next/link';
import { Terminal } from 'lucide-react';
import { DeadEndPinForm } from '@/components/dead-end-pin-form';

/** Decoy login — it never grants access and ships none of the real admin code. */
import { DecoyLogin } from '@/components/decoy-login';
import { ShadowShell, shadowMetadata } from '@/components/shadow-shell';
export const metadata = shadowMetadata;
export default function AdminPage() {
return (
<div className="grid-cross flex min-h-screen flex-col items-center justify-center p-4 pt-20 sm:p-8 sm:pt-20 md:p-12 md:pt-24">
<header className="absolute top-4 left-4">
<Link href="/" className="flex items-center space-x-2 text-muted-foreground hover:text-primary transition-colors">
<Terminal className="h-5 w-5" />
<span className="font-code text-sm">/home</span>
</Link>
</header>

<div className="w-full max-w-4xl">
<DeadEndPinForm onSuccess={() => {}} />
</div>
</div>
);
return <ShadowShell label="Restricted access"><DecoyLogin pinOnly /></ShadowShell>;
}
6 changes: 6 additions & 0 deletions src/app/administrator/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DecoyLogin } from '@/components/decoy-login';
import { ShadowShell, shadowMetadata } from '@/components/shadow-shell';
export const metadata = shadowMetadata;
export default function Page() {
return <ShadowShell label="Restricted access"><DecoyLogin title="System administration" code="SYS-02" /></ShadowShell>;
}
52 changes: 52 additions & 0 deletions src/app/api/ctf/verify/__tests__/route.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/** @jest-environment node */
import { NextRequest } from 'next/server';
import { POST } from '../route';
import { SHADOW_TRACKS } from '@/lib/shadow-challenges';

let client = 0;
const request = (body: unknown, ip = `test-${++client}`) => new NextRequest('https://example.com/api/ctf/verify', { method: 'POST', headers: { 'x-forwarded-for': ip }, body: JSON.stringify(body) });
const rot = (text: string, shift: number) => text.replace(/[a-z]/g, (c) => String.fromCharCode((c.charCodeAt(0) - 97 + shift + 26) % 26 + 97));

test('every displayed cipher is solvable and completion never issues admin access', async () => {
const cipher = SHADOW_TRACKS.cipher.puzzles;
const archive = SHADOW_TRACKS.archive.puzzles;
const signal = SHADOW_TRACKS.signal.puzzles;
const decoded = {
cipher: [rot(cipher[0].cipher, 13), Buffer.from(cipher[1].cipher, 'base64').toString(), Buffer.from(cipher[2].cipher, 'hex').toString(), rot(cipher[3].cipher, -3), cipher[4].cipher.split(' ').map((b) => String.fromCharCode(parseInt(b, 2))).join('')],
archive: [decodeURIComponent(archive[0].cipher), archive[1].cipher.split('').reverse().join(''), Buffer.from(Buffer.from(archive[2].cipher, 'base64').toString(), 'hex').toString()],
signal: [signal[0].cipher.split(' ').map((c) => ({ '.-.': 'r', '---': 'o', '-': 't' })[c]).join(''), signal[1].cipher.split(' ').map((b) => String.fromCharCode(Number(b))).join(''), signal[2].cipher.replace(/[a-z]/g, (c) => String.fromCharCode(219 - c.charCodeAt(0)))],
};
for (const [track, answers] of Object.entries(decoded)) {
for (const [index, answer] of answers.entries()) {
const response = await POST(request({ track, level: index + 1, answer: ` ${answer.toUpperCase()} ` }));
expect(response.status).toBe(200);
const result = await response.json();
expect(result.correct).toBe(true);
expect(result.isLastLevel).toBe(index === answers.length - 1);
expect(Boolean(result.flag)).toBe(index === answers.length - 1);
expect(response.headers.has('set-cookie')).toBe(false);
expect(response.headers.has('location')).toBe(false);
expect(result).not.toHaveProperty('redirect');
}
}
});

test('wrong answers disclose no flags and malformed levels are rejected', async () => {
expect(await (await POST(request({ level: 5, answer: 'admin' }))).json()).toEqual({ correct: false, isLastLevel: true });
for (const body of [null, {}, { level: 1.5, answer: 'shadow' }, { track: 'other', level: 1, answer: 'x' }, { level: 99, answer: 'x' }, { level: 1, answer: 'x'.repeat(129) }]) {
expect((await POST(request(body))).status).toBe(400);
}
expect((await POST(request({ level: 1, answer: 'x'.repeat(3000) }))).status).toBe(413);
});

test('attempt limit returns retry instructions and expires', async () => {
const clock = jest.spyOn(Date, 'now').mockReturnValue(2000000000000);
try {
for (let i = 0; i < 20; i++) expect((await POST(request({ level: 1, answer: 'x' }, 'limited'))).status).toBe(200);
const blocked = await POST(request({ level: 1, answer: 'shadow' }, 'limited'));
expect(blocked.status).toBe(429);
expect(blocked.headers.get('retry-after')).toBe('60');
clock.mockReturnValue(2000000060001);
expect((await POST(request({ level: 1, answer: 'shadow' }, 'limited'))).status).toBe(200);
} finally { clock.mockRestore(); }
});
86 changes: 37 additions & 49 deletions src/app/api/ctf/verify/route.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,44 @@
import { NextRequest, NextResponse } from 'next/server';

// Puzzles with server-side solutions (never exposed to client)
const PUZZLES = [
{ level: 1, solution: "admin" },
{ level: 2, solution: "admin" },
{ level: 3, solution: "admin" },
{ level: 4, solution: "admin" },
{ level: 5, solution: "admin" },
];

// Rate limiting for puzzle attempts
const puzzleAttempts = new Map<string, { count: number; resetTime: number }>();
const MAX_PUZZLE_ATTEMPTS = 20; // per minute
const WINDOW_MS = 60 * 1000;
import { z } from 'zod';
import { SHADOW_TRACKS } from '@/lib/shadow-challenges';

const solutions = {
cipher: ['shadow', 'crow', 'genjutsu', 'cipher', 'escape'],
archive: ['vault', 'archive', 'echo'],
signal: ['root', 'spectre', 'trail'],
} as const;
const flags = { cipher: 'BIKRAM{the_shadow_was_a_decoy}', archive: 'BIKRAM{no_secrets_in_the_archive}', signal: 'BIKRAM{root_of_an_illusion}' };
const schema = z.object({
track: z.enum(['cipher', 'archive', 'signal']).default('cipher'),
level: z.number().int().min(1),
answer: z.string().trim().min(1).max(128),
});
// Best-effort per-instance abuse control, not an authentication boundary.
const attempts = new Map<string, { count: number; until: number }>();
const WINDOW_MS = 60000;
const MAX_KEYS = 2048;

export async function POST(request: NextRequest) {
const now = Date.now();
for (const [key, entry] of attempts) if (entry.until <= now) attempts.delete(key);
const ip = (request.headers.get('x-forwarded-for')?.split(',')[0]?.trim() || 'unknown').slice(0, 100);
const entry = attempts.get(ip);
if ((entry && entry.count >= 20) || (!entry && attempts.size >= MAX_KEYS)) {
return NextResponse.json({ error: 'Too many attempts. Wait one minute and retry.' }, { status: 429, headers: { 'Retry-After': '60', 'Cache-Control': 'no-store' } });
}
attempts.set(ip, { count: (entry?.count || 0) + 1, until: entry?.until || now + WINDOW_MS });
try {
const clientIP = request.headers.get('x-forwarded-for')?.split(',')[0]?.trim() || 'unknown';
const now = Date.now();

// Rate limiting
const entry = puzzleAttempts.get(clientIP);
if (entry && now < entry.resetTime) {
if (entry.count >= MAX_PUZZLE_ATTEMPTS) {
return NextResponse.json(
{ error: 'Too many attempts. Please wait.' },
{ status: 429 }
);
}
entry.count++;
} else {
puzzleAttempts.set(clientIP, { count: 1, resetTime: now + WINDOW_MS });
}

const { level, answer } = await request.json();

if (typeof level !== 'number' || level < 1 || level > PUZZLES.length) {
return NextResponse.json({ error: 'Invalid level' }, { status: 400 });
}

if (typeof answer !== 'string' || !answer.trim()) {
return NextResponse.json({ error: 'Answer is required' }, { status: 400 });
}

const puzzle = PUZZLES[level - 1];
const isCorrect = answer.toLowerCase().trim() === puzzle.solution;

return NextResponse.json({
correct: isCorrect,
isLastLevel: level === PUZZLES.length,
});
const text = await request.text();
if (new TextEncoder().encode(text).length > 2048) return NextResponse.json({ error: 'Answer payload too large.' }, { status: 413 });
const parsed = schema.safeParse(JSON.parse(text));
if (!parsed.success) return NextResponse.json({ error: 'Provide a valid track, integer level and answer (up to 128 characters).' }, { status: 400 });
const { track, level, answer } = parsed.data;
if (level > SHADOW_TRACKS[track].puzzles.length) return NextResponse.json({ error: 'Invalid level.' }, { status: 400 });
const correct = answer.toLowerCase() === solutions[track][level - 1];
const isLastLevel = level === solutions[track].length;
// No sessions, credentials, redirects or database writes: these are game flags only.
return NextResponse.json({ correct, isLastLevel, ...(correct && isLastLevel ? { flag: flags[track] } : {}) }, { headers: { 'Cache-Control': 'no-store' } });
} catch {
return NextResponse.json({ error: 'Bad request' }, { status: 400 });
return NextResponse.json({ error: 'Malformed challenge request.' }, { status: 400 });
}
}
48 changes: 4 additions & 44 deletions src/app/b1kr4m-5h4d0w/page.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,6 @@
'use client';

import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { CryptoPuzzle } from '@/components/crypto-puzzle';
import Link from 'next/link';
import { Terminal, Lock } from 'lucide-react';

export default function BikramShadowAccessPage() {
const [isAuthenticated, setIsAuthenticated] = useState(false);
const router = useRouter();

const handlePuzzleSuccess = () => {
setIsAuthenticated(true);
// Redirect to bikram page for PIN authentication after puzzle completion
router.push('/bikram');
};

if (isAuthenticated) {
return null; // Will redirect to /bikram
}

return (
<div className="grid-cross flex min-h-screen flex-col items-center justify-center p-4 pt-20 sm:p-8 md:p-12 bg-gradient-to-br from-background via-background to-primary/10">
<header className="absolute top-4 left-4">
<Link href="/" className="flex items-center space-x-2 text-muted-foreground hover:text-primary transition-colors">
<Terminal className="h-5 w-5" />
<span className="font-code text-sm">/home</span>
</Link>
</header>

<div className="w-full max-w-4xl">
<CryptoPuzzle onSuccess={handlePuzzleSuccess} />
</div>

<footer className="absolute bottom-4 right-4 text-xs text-muted-foreground/50 font-mono">
<div className="flex items-center gap-2">
<Lock className="h-3 w-3" />
<span>b1kr4m-5h4d0w</span>
</div>
</footer>
</div>
);
import { ShadowShell, shadowMetadata } from '@/components/shadow-shell';
export const metadata = shadowMetadata;
export default function ShadowPage() {
return <ShadowShell label="Shadow protocol"><CryptoPuzzle /></ShadowShell>;
}


6 changes: 6 additions & 0 deletions src/app/cpanel/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DecoyLogin } from '@/components/decoy-login';
import { ShadowShell, shadowMetadata } from '@/components/shadow-shell';
export const metadata = shadowMetadata;
export default function Page() {
return <ShadowShell label="Restricted access"><DecoyLogin title="Hosting control" code="HST-04" /></ShadowShell>;
}
6 changes: 6 additions & 0 deletions src/app/dashboard/login/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DecoyLogin } from '@/components/decoy-login';
import { ShadowShell, shadowMetadata } from '@/components/shadow-shell';
export const metadata = shadowMetadata;
export default function Page() {
return <ShadowShell label="Restricted access"><DecoyLogin title="Dashboard access" code="DSH-06" /></ShadowShell>;
}
6 changes: 6 additions & 0 deletions src/app/root/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { CryptoPuzzle } from '@/components/crypto-puzzle';
import { ShadowShell, shadowMetadata } from '@/components/shadow-shell';
export const metadata = shadowMetadata;
export default function Page() {
return <ShadowShell label="Recovery terminal"><CryptoPuzzle track="signal" /></ShadowShell>;
}
6 changes: 6 additions & 0 deletions src/app/wp-admin/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DecoyLogin } from '@/components/decoy-login';
import { ShadowShell, shadowMetadata } from '@/components/shadow-shell';
export const metadata = shadowMetadata;
export default function Page() {
return <ShadowShell label="Restricted access"><DecoyLogin title="Content administration" code="CMS-03" /></ShadowShell>;
}
39 changes: 39 additions & 0 deletions src/components/__tests__/crypto-puzzle.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { CryptoPuzzle } from '../crypto-puzzle';
jest.mock('lucide-react', () => ({ Eye: () => null, Flag: () => null, Lock: () => null, RotateCcw: () => null }));
const originalFetch = global.fetch;
afterEach(() => { global.fetch = originalFetch; });

test('progress begins at zero, advances, and ends with a game flag instead of an admin link', async () => {
global.fetch = jest.fn().mockImplementation(async (_url, options) => {
const { level } = JSON.parse(options.body);
return { ok: true, json: async () => ({ correct: true, isLastLevel: level === 3, ...(level === 3 ? { flag: 'BIKRAM{no_secrets_in_the_archive}' } : {}) }) };
});
render(<CryptoPuzzle track="archive" />);
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuenow', '0');
for (let level = 1; level <= 3; level++) {
fireEvent.change(screen.getByLabelText('Decoded answer'), { target: { value: 'test' } });
fireEvent.click(screen.getByRole('button', { name: '>_ Verify' }));
await waitFor(() => expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuenow', String(level)));
}
expect(screen.getByText('BIKRAM{no_secrets_in_the_archive}')).toBeVisible();
expect(document.querySelector('a[href="/bikram"]')).toBeNull();
expect(screen.getByRole('link', { name: 'Follow another signal →' })).toHaveAttribute('href', '/root');
fireEvent.click(screen.getByRole('button', { name: 'Restart sequence' }));
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuenow', '0');
});

test('wrong answers reveal a clue after three tries and a network error keeps the same lock', async () => {
global.fetch = jest.fn().mockResolvedValue({ ok: true, json: async () => ({ correct: false }) });
render(<CryptoPuzzle />);
for (let count = 1; count <= 3; count++) {
fireEvent.change(screen.getByLabelText('Decoded answer'), { target: { value: 'wrong' } });
fireEvent.click(screen.getByRole('button', { name: '>_ Verify' }));
await waitFor(() => expect(screen.getByText(`ATTEMPTS // ${count}`)).toBeVisible());
}
expect(screen.getByRole('button', { name: 'Hide clue' })).toHaveAttribute('aria-expanded', 'true');
jest.mocked(global.fetch).mockRejectedValueOnce(new Error('offline'));
fireEvent.click(screen.getByRole('button', { name: '>_ Verify' }));
await waitFor(() => expect(screen.getByRole('status')).toHaveTextContent('Uplink interrupted'));
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuenow', '0');
});
32 changes: 32 additions & 0 deletions src/components/__tests__/decoy-login.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { render, screen, fireEvent, act } from '@testing-library/react';
import { DecoyLogin } from '../decoy-login';
jest.mock('lucide-react', () => ({ Lock: () => null, Terminal: () => null }));

test('decoy discards entered values, denies access, and makes no network request', () => {
jest.useFakeTimers();
const originalFetch = global.fetch;
global.fetch = jest.fn();
try {
render(<DecoyLogin />);
fireEvent.change(screen.getByLabelText('Operator ID'), { target: { value: 'test-user' } });
fireEvent.change(screen.getByLabelText('Password'), { target: { value: 'disposable-test-input' } });
fireEvent.click(screen.getByRole('button', { name: '>_ Authenticate' }));
expect(screen.getByLabelText('Password')).toHaveValue('');
expect(screen.getByLabelText('Operator ID')).toHaveValue('');
act(() => jest.advanceTimersByTime(1100));
expect(screen.getByRole('status')).toHaveTextContent('Access denied');
expect(global.fetch).not.toHaveBeenCalled();
} finally { global.fetch = originalFetch; jest.useRealTimers(); }
});

test('PIN-only decoy remains usable and clears its timer when leaving', () => {
jest.useFakeTimers();
try {
const { unmount } = render(<DecoyLogin pinOnly />);
expect(screen.queryByLabelText('Operator ID')).not.toBeInTheDocument();
fireEvent.change(screen.getByLabelText('PIN'), { target: { value: '123456' } });
fireEvent.click(screen.getByRole('button', { name: '>_ Authenticate' }));
unmount();
expect(jest.getTimerCount()).toBe(0);
} finally { jest.useRealTimers(); }
});
Loading
Loading