Skip to content

Instantly share code, notes, and snippets.

@indutny indutny/test.js Secret
Last active Dec 16, 2015

Embed
What would you like to do?
var Buffer = require('buffer').Buffer,
net = require('net');
function construct(ciphers) {
function word(num) {
return new Buffer([ num >> 8, num & 0xff ]).toString('hex');
}
ciphers = new Buffer(ciphers, 'hex');
var record_len = 0x9f + ciphers.length;
var handshake_len = 0x9b + ciphers.length;
var cipher_len = ciphers.length;
var chunks = '160301' +
word(record_len) +
'0100' +
word(handshake_len) +
'030251811d4b6df3d56253035ffa2dd1568f7d7ca018e462c779494f15991' +
'dc035a600' + word(cipher_len) +
ciphers.toString('hex') +
'01000072000000260024000021757365722d736572766963652e636f6e646' +
'56e6173746469676974616c2e636f6d000b000403000102000a0034003200' +
'0e000d0019000b000c00180009000a0016001700080006000700140015000' +
'4000500120013000100020003000f001000110023000033740000';
return new Buffer(chunks, 'hex');
}
function extract(str) {
var map = {};
for (var i = 0; i < str.length; i += 4) {
map[str.slice(i, i + 4)] = true;
}
return map;
}
var working_plain = 'c014c00a00390038c00fc0050035c012c00800160013c00d' +
'c003000ac013c00900330032c00ec004002fc011c007c00c' +
'c002000500040015001200090014001100080006000300ff';
var working_set = extract(working_plain);
var failing_set = extract('c014c00ac022c0210039003800880087c00fc00500350084' +
'c012c008c01cc01b00160013c00dc003000ac013c009c01f' +
'c01e00330032009a009900450044c00ec004002f00960041' +
'0007c011c007c00cc0020005000400150012000900140011' +
'00080006000300ff');
function getDiff(a, b) {
return Object.keys(b).filter(function(key) {
return !a.hasOwnProperty(key);
});
}
var diff = getDiff(working_set, failing_set);
diff.sort(function(a, b) {
return Math.random() - 0.5;
});
for (var i = 0; i < diff.length; i++) {
test(diff.slice(0, i).join(''), function() {
});
}
function test(cipher, cb) {
var socket = net.connect(443, '165.193.220.80', function() {
socket.write(construct(working_plain + cipher));
socket.on('data', function(data) {
socket.destroy();
cb(null, false);
});
socket.on('timeout', function() {
console.log(cipher);
socket.destroy();
cb(null, cipher);
});
socket.setTimeout(1000);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.