Last active
May 30, 2019 22:29
-
-
Save krmax44/356a2a9c779236b79f10d975be1806e5 to your computer and use it in GitHub Desktop.
Capture The Flag At UCF - Scripting Repetition solution with Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const net = require('net'); | |
const client = new net.Socket(); | |
const math = require('mathjs'); // requires mathjs package! | |
client.connect(10104, 'ctf.hackucf.org'); | |
client.on('data', data => { | |
const text = data.toString(); | |
const flag = /flag{.*}/gm.exec(text); | |
if (flag) { | |
console.log(); | |
console.log(`We got the flag! The flag is ${flag[0]}`); | |
return client.destroy(); | |
} | |
if (text.includes(' = ')) { | |
const innerMost = eval(text.split('((')[1].split(')')[0]); | |
const inner = eval(innerMost + text.split(')')[1]); | |
const outer = eval(inner + text.split(')')[2].split(' =')[0]); | |
client.write(`${outer}\r\n`); | |
} | |
process.stdout.write('.'); | |
}); | |
const eval = equation => Math.floor(math.eval(equation)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const net = require('net'); | |
const client = new net.Socket(); | |
client.connect(10101, 'ctf.hackucf.org'); | |
client.on('data', data => { | |
const text = data.toString(); | |
const flag = /flag{.*}/gm.exec(text); | |
if (flag) { | |
console.log(); | |
console.log(`We got the flag! The flag is ${flag[0]}`); | |
return client.destroy(); | |
} | |
if (text.includes('Value')) { | |
process.stdout.write('.'); | |
const number = parseInt(text.split('Value')[1].replace(/^\D+/g, '')); | |
client.write(`${number}\r\n`); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const net = require('net'); | |
const client = new net.Socket(); | |
client.connect(10102, 'ctf.hackucf.org'); | |
let firstValue; | |
client.on('data', data => { | |
const text = data.toString(); | |
const flag = /flag{.*}/gm.exec(text); | |
if (flag) { | |
console.log(); | |
console.log(`We got the flag! The flag is ${flag[0]}`); | |
return client.destroy(); | |
} | |
if (text.includes('first value')) { | |
client.write(`${firstValue}\r\n`); | |
} else if (text.includes('Value')) { | |
const number = parseInt(text.split('Value')[1].replace(/^\D+/g, '')); | |
client.write(`${number}\r\n`); | |
if (firstValue === undefined) { | |
firstValue = number; | |
} | |
} | |
process.stdout.write('.'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment