Skip to content

Commit ce38c27

Browse files
committed
mid progress
1 parent b195d81 commit ce38c27

File tree

17 files changed

+177
-151
lines changed

17 files changed

+177
-151
lines changed

public/scripts/debugger.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
async function debugProgram() {
2+
const JSON_DATA = JSON.parse(
3+
document.getElementById('__DATA__').textContent
4+
);
5+
debugger;
6+
const flag = await getFlag(JSON_DATA);
7+
console.log('the flag is', flag);
8+
}
9+
10+
function getURL(json) {
11+
try {
12+
const { a, b, c } = json;
13+
const fromBase64 = atob(a + b + c);
14+
return decodeURIComponent(fromBase64);
15+
} catch (e) {
16+
console.error(
17+
'error with constructing the url. This is unexpected, please contact the creator'
18+
);
19+
return undefined;
20+
}
21+
}
22+
23+
async function getFlag(json) {
24+
const url = getURL(json);
25+
26+
if(!url){
27+
throw new Error('URL error');
28+
}
29+
30+
try {
31+
const fetched = await fetch(url, { method: 'GET' });
32+
const response = await fetched.json();
33+
const { flag } = response;
34+
return 'flag{********}';
35+
} catch (e) {
36+
console.error('error in getFlag()');
37+
console.error(e);
38+
}
39+
}

public/styles/index.css

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
@import './reset.css';
22
@import './utils.css';
33

4-
body{
4+
body {
55
background-color: #303030;
66
font-family: system-ui, serif;
77
color: #e7e7e7;
88
}
99

10-
.gradient-1{
10+
.gradient-1 {
1111
background: linear-gradient(0deg, #e65c00, #f9d423);
1212
}
1313

14-
.gradient-2{
14+
.gradient-2 {
1515
background: linear-gradient(0deg, #d38312, #a83279);;
1616
}
1717

18-
.gradient-3{
18+
.gradient-3 {
19+
background: linear-gradient(to right, #808080, #3fada8);
20+
}
21+
22+
.gradient-4 {
1923
background: linear-gradient(to right, #f806b1, #66ff00);;
2024
}

src/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { InlineStyleController } from '~/controllers/inline-style.controller';
99
import { PreserveLogController } from '~/controllers/preserve-log.controller';
1010
import { NetworkBasicController } from '~/controllers/network-basic.controller';
1111
import { LocalstorageBasicController } from '~/controllers/localstorage-basic.controller';
12+
import { DebuggerController } from './controllers/debugger.controller';
1213

1314
@Module({
1415
controllers: [
@@ -19,6 +20,7 @@ import { LocalstorageBasicController } from '~/controllers/localstorage-basic.co
1920
NetworkBasicController,
2021
SourcesBasicController,
2122
LocalstorageBasicController,
23+
DebuggerController,
2224
],
2325
providers: [AppService],
2426
imports: [

src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const config = {
2727
url: 'level-c231787c',
2828
flag: createFlag('L0calSt0rageIsAwesome'),
2929
}),
30+
debugger: createLevelConfig('CONSOLE_LOG', {
31+
url: 'level-b195d810',
32+
flag: createFlag('D3BUGG3R_M4$T3R'),
33+
}),
3034
},
3135
server: {
3236
port: +envWithDefault<number>('PORT', 3000),
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Controller, Get, Render } from '@nestjs/common';
2+
import config from '~/config';
3+
import { toBase64 } from '~/utils/toBase64';
4+
import { chunkParts } from '~/utils/chunkParts';
5+
6+
const levelConfig = config.levels.debugger;
7+
const FLAG_PARTIALS = 3;
8+
9+
@Controller(levelConfig.url)
10+
export class DebuggerController {
11+
@Get()
12+
@Render('debugger.hbs')
13+
render() {
14+
const encoded = toBase64(encodeURIComponent(`${levelConfig.url}/flag`));
15+
const chunks = chunkParts(encoded, FLAG_PARTIALS);
16+
const flags = Object.fromEntries(
17+
chunks.map((partial, i) => [`flag${i + 1}`, partial])
18+
);
19+
20+
return {
21+
...flags,
22+
};
23+
}
24+
25+
@Get('flag')
26+
getFlag() {
27+
return {
28+
flag: toBase64(levelConfig.flag),
29+
};
30+
}
31+
}

src/controllers/localstorage-basic.controller.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
import { Controller, Get, Render } from '@nestjs/common';
22
import config from '~/config';
3+
import { toBase64 } from '~/utils/toBase64';
4+
import { chunkParts } from '~/utils/chunkParts';
35

46
const levelConfig = config.levels.localStorageBasic;
57
const FLAG_PARTIALS = 5;
8+
69
@Controller(levelConfig.url)
710
export class LocalstorageBasicController {
811
@Get()
912
@Render('localStorage-basic.hbs')
1013
render() {
11-
const encodedFlag = Buffer.from(levelConfig.flag, 'utf8').toString(
12-
'base64'
13-
);
14-
15-
const size = encodedFlag.length / FLAG_PARTIALS;
16-
17-
const flags = Object.fromEntries(
18-
new Array(FLAG_PARTIALS)
19-
.fill(null)
20-
.map((_, i) => [
21-
`flag${i + 1}`,
22-
encodedFlag.slice(i * size, (i + 1) * size),
23-
])
14+
const encodedFlag = toBase64(levelConfig.flag);
15+
const chunks = chunkParts(encodedFlag, FLAG_PARTIALS);
16+
const flags = chunks.reduce(
17+
(acc, curr, index) => ({
18+
...acc,
19+
[`flag${index + 1}`]: curr,
20+
}),
21+
{}
2422
);
2523

2624
return {

src/logic/aes.spec.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/logic/aes.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/logic/flagEncryption.spec.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/logic/flagEncryption.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)