-
Notifications
You must be signed in to change notification settings - Fork 8
/
msfrpc-cli
executable file
·71 lines (60 loc) · 1.53 KB
/
msfrpc-cli
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
#!/usr/bin/env node
const MsfRpc = require('./lib/msfrpc');
const readline = require('readline');
const Promise = require('bluebird');
const MsgPack5 = require('msgpack5');
const msgpack = MsgPack5();
const URL = require('url');
const usage = `
Usage: msfrpc <URI>
URI example: https://msfUser:123456@localhost:55553
`;
try {
URL.parse(process.argv[2]);
} catch(err) {
console.log(usage);
process.exit();
}
const msfrpc = new MsfRpc(process.argv[2]);
msfrpc.connect().then(() => {
msfrpc.console.create().then((cli) => {
const cliId = cli.id;
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: true
});
const realHistory = rl.history;
function prompt(cli) {
delete rl.history;
rl.history = realHistory;
rl.question(cli.prompt.replace(/[^\x20-\x7E]+/g, ''), (input) => {
input = input.trim();
if(input === 'history') {
console.log(realHistory.join('\n'));
prompt(cli);
} else if(input === 'exit') {
process.exit();
} else {
msfrpc.console.write(cliId, input + '\n').then(() => {
rl.pause();
read();
});
}
});
}
function read() {
rl.history = [];
return msfrpc.console.read(cli.id).then((cli) => {
rl.write(cli.data);
if(cli.busy) {
return Promise.delay(1000).then(read);
} else {
rl.resume();
prompt(cli);
}
});
}
read();
});
});