-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (60 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import readlinePromise from 'readline-promise';
import { stdin, stdout } from 'node:process';
import axios from 'axios';
import phpServer from 'php-server';
const colors = {
reset: '\x1b[0m',
red: '\x1b[31m',
green: '\x1b[32m',
blue: '\x1b[34m',
cyan: '\x1b[36m',
yellow: '\x1b[33m',
magenta: '\x1b[35m',
}
const colorize =(text, color)=> color + text + colors.reset;
const readline = readlinePromise.default;
const readlineInterface = readline.createInterface({
input: stdin,
output: stdout,
termina: true,
});
const server = await phpServer({
port: parseInt(process.argv[2]) || 8000,
router: './aes.php',
});
console.log(colorize(
`PHP server started on ${server.url}`,
colors.yellow));
process.on('exit', ()=> {
readlineInterface.close();
server.stop();
});
const RESULT_PADDER = '----------------';
const BIT_SIZES = [128, 192, 256];
const guessHistory = [];
const encryptedString = await readlineInterface.questionAsync(
'\nEncrypted string: ');
const serverUrl = new URL(server.url);
serverUrl.searchParams.set('string', encryptedString);
for (;;) {
const guess = await readlineInterface.questionAsync(
colorize('\n[GUESS] ', colors.cyan));
if (!guess) {
console.log(
colorize('Tried:', colors.yellow),
guessHistory.sort().join(colorize(', ', colors.yellow)) )
continue;
}
serverUrl.searchParams.set('key', guess);
guessHistory.push(guess);
for (const bits of BIT_SIZES) {
serverUrl.searchParams.set('bits', bits);
const response = await axios.get(serverUrl.toString());
if (response.data) {
console.log(colorize(
`${RESULT_PADDER} ${bits}bit key ${RESULT_PADDER}`,
colors.green));
console.log(response.data);
}
}
}