Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

misc/miracle #44

Merged
merged 4 commits into from
Jun 6, 2024
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
15 changes: 15 additions & 0 deletions miracle/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:20.14

RUN apt-get update && apt-get install -y curl gcc wget && apt-get clean && rm -rf /var/lib/apt/lists/* \
&& wget -O ynetd.c https://raw.githubusercontent.com/johnsonjh/ynetd/e6fd08f8f5d0c6b8c18d645957e30ce012536ed4/ynetd.c \
&& echo "ec7509dec7737da54f8b18e1b5ba935d657f9f016c36cfc9ac08f9952373226f ynetd.c" | sha256sum -c \
&& gcc -o ynetd ynetd.c && chmod +x ./ynetd && mv ynetd /usr/local/bin/ynetd && rm ynetd.c \
&& export PATH=$PATH:/usr/local/bin

WORKDIR /app

COPY . /app/

EXPOSE 8898

ENTRYPOINT ["ynetd", "-p", "8898", "node main.js"]
20 changes: 20 additions & 0 deletions miracle/chall.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Miracle
categories:
- misc
value: 50
flag:
file: ./flag.txt
description: |-
You'll need a miracle to get this flag. The server requires you to solve an easy addition problem, but you only
get the flag if the bits magically flip to form another answer.
hints: []
files:
- src: ./main.js
- src: ./eslint.config.mjs
authors:
- Mudasir
visible: true
deploy:
nc:
build: .
expose: 8898/tcp
31 changes: 31 additions & 0 deletions miracle/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import globals from "globals";
import pluginJs from "@eslint/js";


export default [
{files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}},
{languageOptions: { globals: globals.browser }},
pluginJs.configs.recommended,
{
rules: {
"no-unused-vars": "error",
"no-octal": "error",
"for-direction": "error",
"getter-return": "error",
"no-async-promise-executor": "error",
"no-compare-neg-zero": "error",
"no-cond-assign": "error",
"no-constant-condition": "error",
"no-control-regex": "error",
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty": "error",
"no-empty-character-class": "error",
"no-ex-assign": "error",
"no-extra-boolean-cast": "error",
"no-extra-semi": "error",
"no-invalid-regexp": "error",
}
}
];
1 change: 1 addition & 0 deletions miracle/flag.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bcactf{j$_is_W3Ird_?rfuhie4923}
53 changes: 53 additions & 0 deletions miracle/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const readline = require("readline");
const fs = require("fs");

async function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

// thanks chatgpt
function printWithoutNewline(text) {
process.stdout.write(text);
}

function prompt(question) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

return new Promise((resolve) => {
rl.question(question, (answer) => {
rl.close();
resolve(answer);
});
});
}
//end thanks chatgpt

const flag = fs.readFileSync("flag.txt", "utf8");

async function run() {
const name = await prompt("What is your name?\n") ?? "Harry";
const ans = await prompt("What is 55+22?\n") ?? "0";
if (eval("Number(ans)") === 77) {
console.log("Correct!");
console.log("Waiting for bits to flip...");
for (let i = 0; i < 10; i++) {
printWithoutNewline("...");
await sleep(300);
}
console.log("\n");
if (eval(ans) === 63) {
console.log(`You made those bits flip?? You're a wizard ${name}! `);
console.log(`Here's your flag: ${flag}`);
} else {
console.log("You didn't make the bits flip. Too bad ");
}
} else {
console.log("wow you suck at math.");
}
process.exit(1);
}

run();
Loading