Skip to content

Commit

Permalink
Merge branch 'develop' into internal-error
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpect authored May 17, 2024
2 parents 2a759ed + 4a7522a commit bad4dde
Show file tree
Hide file tree
Showing 31 changed files with 1,148 additions and 13 deletions.
Binary file added challenges_sample/knock/knock.tar.gz
Binary file not shown.
15 changes: 15 additions & 0 deletions challenges_sample/knock/knock/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:17.4.0-buster-slim

RUN mkdir -p /app

WORKDIR /app

COPY package.json .

RUN yarn

COPY . .

USER node

CMD ["node", "index.js"]
26 changes: 26 additions & 0 deletions challenges_sample/knock/knock/challenge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: knock-knock
author: BrownieInMotion
description: |-
Knock knock? Who's there? Another pastebin!!
${link_main_0}
flag: dice{1_d00r_y0u_d00r_w3_a11_d00r_f0r_1_d00r}

provide:
- ./index.js
- ./Dockerfile

containers:
main:
build: .
ports:
- 3000
environment:
FLAG: "dice{1_d00r_y0u_d00r_w3_a11_d00r_f0r_1_d00r}"

expose:
main:
- target: 3000
http: knock-knock
healthContent: Create Paste
62 changes: 62 additions & 0 deletions challenges_sample/knock/knock/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const crypto = require('crypto');

class Database {
constructor() {
this.notes = [];
this.secret = `secret-${crypto.randomUUID}`;
}

createNote({ data }) {
const id = this.notes.length;
this.notes.push(data);
return {
id,
token: this.generateToken(id),
};
}

getNote({ id, token }) {
if (token !== this.generateToken(id)) return { error: 'invalid token' };
if (id >= this.notes.length) return { error: 'note not found' };
return { data: this.notes[id] };
}

generateToken(id) {
return crypto
.createHmac('sha256', this.secret)
.update(id.toString())
.digest('hex');
}
}

const db = new Database();
db.createNote({ data: process.env.FLAG });

const express = require('express');
const app = express();

app.use(express.urlencoded({ extended: false }));
app.use(express.static('public'));

app.post('/create', (req, res) => {
const data = req.body.data ?? 'no data provided.';
const { id, token } = db.createNote({ data: data.toString() });
res.redirect(`/note?id=${id}&token=${token}`);
});

app.get('/note', (req, res) => {
const { id, token } = req.query;
const note = db.getNote({
id: parseInt(id ?? '-1'),
token: (token ?? '').toString(),
});
if (note.error) {
res.send(note.error);
} else {
res.send(note.data);
}
});

app.listen(3000, () => {
console.log('listening on port 3000');
});
9 changes: 9 additions & 0 deletions challenges_sample/knock/knock/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "knock-knock",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"express": "^4.17.2"
}
}
45 changes: 45 additions & 0 deletions challenges_sample/knock/knock/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<style>
* {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Helvetica Neue', sans-serif;
box-sizing: border-box;
}

html,
body {
margin: 0;
}

.container {
padding: 2rem;
width: 90%;
max-width: 900px;
margin: auto;
}

input:not([type='submit']) {
width: 100%;
padding: 8px;
margin: 8px 0;
}

textarea {
width: 100%;
padding: 8px;
margin: 8px 0;
resize: vertical;
font-family: monospace;
}

input[type='submit'] {
margin-bottom: 16px;
}
</style>

<div class="container">
<h1>Create Paste</h1>
<form method="POST" action="/create">
<textarea name="data"></textarea>
<input type="submit" value="Create" />
</form>
</div>
Loading

0 comments on commit bad4dde

Please sign in to comment.