Skip to content

Commit ae76726

Browse files
committed
mid progress, added more levels
1 parent 220b145 commit ae76726

File tree

14 files changed

+199
-40
lines changed

14 files changed

+199
-40
lines changed

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,74 @@ Get familiar with your browser by solving CTF only with your devtools
55
** Supports all common browsers
66

77
**Fuck IE don't even try!
8+
9+
# Development
10+
11+
Here is a quick guide to develop more levels
12+
13+
## Creating A new Level
14+
15+
### Create a new Page
16+
17+
Create a new `.hbs` file in `pages` (e.g. `my-level.hbs`)
18+
**\*use `!` + `Tab` to generate basic HTML structure, or copy-paste another `.hbs` file**
19+
20+
example for body content in a level:
21+
22+
```handlebars
23+
<div>
24+
the flag is {{flag}}
25+
</div>
26+
```
27+
28+
`{{flag}}` serves as a placeholder for data injection from the server
29+
30+
### Create Level Configuration
31+
32+
add to `config.ts` the following:
33+
34+
```typescript
35+
export default {
36+
levels: {
37+
/* {... Other levels}*/
38+
myLevel: createLevelConfig('MY_LEVEL', {
39+
url: 'level-123456',
40+
flag: createFlag('myFl4G')
41+
})
42+
}
43+
}
44+
```
45+
46+
NOTE: don't copy-paste like an idiot, you might delete other levels by accident.
47+
48+
### Create a new Controller
49+
50+
```bash
51+
$ nest g co myLevel controllers --flat
52+
```
53+
54+
This command will create a new `my-level.controller.ts` file inside `controllers/` directory. `--flat` means it will not
55+
create a `my-level/` directory too.
56+
57+
To create a route that displays content, add `@Get()` to specify your request method, and `@Render` to specify which page you want to render
58+
59+
```typescript
60+
import config from '~/config';
61+
62+
const levelConfig = config.levels.myLevel
63+
64+
@Controller(levelConfig.url)
65+
export class MyLevelController {
66+
@Get()
67+
@Render('my-level.hbs')
68+
render() {
69+
//this defines the variables for my-level.hbs
70+
return {
71+
flag: levelConfig.flag,
72+
};
73+
}
74+
}
75+
```
76+
77+
to add more routes just learn `nestjs`, and put them inside the relevant controller.
78+

public/styles/index.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ body{
77
color: #e7e7e7;
88
}
99

10-
.gradient1{
10+
.gradient-1{
1111
background: linear-gradient(0deg, #e65c00, #f9d423);
1212
}
13+
14+
.gradient-2{
15+
background: linear-gradient(0deg, #d38312, #a83279);;
16+
}

src/app.module.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1+
import * as path from 'path';
12
import { Module } from '@nestjs/common';
23
import { AppController } from './app.controller';
34
import { AppService } from './app.service';
4-
import { LevelsModule } from './levels.module';
55
import { ServeStaticModule } from '@nestjs/serve-static';
6-
import * as path from 'path';
6+
import { SourcesBasicController } from './controllers/sources-basic.controller';
7+
import { BasicController } from '~/controllers/basic.controller';
8+
import { InlineStyleController } from '~/controllers/inline-style.controller';
9+
import { PreserveLogController } from '~/controllers/preserve-log.controller';
10+
import { NetworkBasicController } from '~/controllers/network-basic.controller';
711

812
@Module({
9-
controllers: [AppController],
13+
controllers: [
14+
AppController,
15+
BasicController,
16+
InlineStyleController,
17+
PreserveLogController,
18+
NetworkBasicController,
19+
SourcesBasicController,
20+
],
1021
providers: [AppService],
1122
imports: [
12-
LevelsModule,
1323
ServeStaticModule.forRoot({
1424
serveRoot: '/public',
1525
rootPath: path.join(__dirname, '..', 'public'),

src/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ export default {
2626
url: 'level-ce5ed9ff',
2727
flag: createFlag('Y0uG0tM3'),
2828
}),
29+
networkBasic: createLevelConfig('NETWORK_BASIC', {
30+
url: 'level-99606d6a',
31+
flag: createFlag('N3tW0rkB4S1CS'),
32+
}),
33+
sourcesBasic: createLevelConfig('SOURCES_BASIC', {
34+
url: 'level-9ad478b3',
35+
flag: createFlag('Y0ureAW1zardHarry'),
36+
}),
2937
},
3038
server: {
3139
port: envWithDefault<number>('PORT', 3000),

src/controllers/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Controller, Get, Render } from '@nestjs/common';
2+
import config from '~/config';
3+
4+
const levelConfig = config.levels.networkBasic;
5+
const flagRoute = 'flag';
6+
@Controller(levelConfig.url)
7+
export class NetworkBasicController {
8+
@Get()
9+
@Render('network-basic.hbs')
10+
render() {
11+
return {
12+
flagUrl: `${levelConfig.url}/${flagRoute}`,
13+
};
14+
}
15+
16+
@Get(flagRoute)
17+
getFlag() {
18+
const flag = levelConfig.flag;
19+
return { flag };
20+
}
21+
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Controller, Get, Render } from '@nestjs/common';
1+
import { Controller, Get, Header, HttpCode, Render } from '@nestjs/common';
22
import config from '~/config';
33

44
const levelConfig = config.levels.preserveLog;
5+
const flagRoute = 'flag';
56

67
@Controller(levelConfig.url)
78
export class PreserveLogController {
@@ -10,14 +11,13 @@ export class PreserveLogController {
1011
render() {
1112
return {
1213
flag: levelConfig.flag,
13-
flagUrl: `${levelConfig.url}/flag`,
14+
flagUrl: `${levelConfig.url}/${flagRoute}`,
1415
};
1516
}
1617

17-
@Get('/flag')
18-
getFlag() {
19-
return {
20-
flag: levelConfig.flag,
21-
};
22-
}
18+
@Get(flagRoute)
19+
@HttpCode(200)
20+
@Header('X-Flag', levelConfig.flag)
21+
// eslint-disable-next-line @typescript-eslint/no-empty-function
22+
getFlag() {}
2323
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {
2+
Controller,
3+
Get,
4+
Header,
5+
HttpCode,
6+
HttpStatus,
7+
Render,
8+
} from '@nestjs/common';
9+
import config from '~/config';
10+
11+
const levelConfig = config.levels.sourcesBasic;
12+
const cssFileName = 'flag-file.css';
13+
14+
@Controller(levelConfig.url)
15+
export class SourcesBasicController {
16+
@Get()
17+
@Render('sources-basic.hbs')
18+
render() {
19+
return {
20+
cssFilePath: `${levelConfig.url}/${cssFileName}`,
21+
};
22+
}
23+
24+
@Get(cssFileName)
25+
@Header('Content-Type', 'text/css; charset=UTF-8')
26+
getFile() {
27+
return `
28+
/* ${levelConfig.flag} */
29+
body{
30+
background: crimson;
31+
}
32+
`;
33+
}
34+
}

src/levels.module.ts

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

src/pages/basic.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
77
<meta http-equiv="X-UA-Compatible" content="ie=edge">
88
<link rel="stylesheet" href="/public/styles/index.css">
9-
<title>Document</title>
9+
<title>Devtools CTF</title>
1010
</head>
1111
<body class="center full-size">
1212
<!--{{flag}}-->
13-
<h1 class="gradient-text gradient1">Where is the flag?</h1>
13+
<h1 class="gradient-text gradient-1">Where is the flag?</h1>
1414
<span>Press F12 to open devtools</span>
1515
</body>
1616
</html>

0 commit comments

Comments
 (0)