Skip to content

Commit

Permalink
Merge pull request #77 from sdslabs/unzip_pipeline
Browse files Browse the repository at this point in the history
Implement challenge.tar.gz unzip pipeline
  • Loading branch information
ashpect authored Oct 8, 2023
2 parents ed80063 + b2b3760 commit 3b3c2e1
Show file tree
Hide file tree
Showing 20 changed files with 864 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
knock flag getter
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
knock flag setter
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
knock challenge checker
Binary file added challenge_template/knock/knock.tar.gz
Binary file not shown.
15 changes: 15 additions & 0 deletions challenge_template/knock/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 challenge_template/knock/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 challenge_template/knock/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 challenge_template/knock/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 challenge_template/knock/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 3b3c2e1

Please sign in to comment.