Skip to content

Instantly share code, notes, and snippets.

@ebrandel
Last active January 6, 2017 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebrandel/03b97de06a95095a51d84638108e839c to your computer and use it in GitHub Desktop.
Save ebrandel/03b97de06a95095a51d84638108e839c to your computer and use it in GitHub Desktop.
brute-forcing a keygen
var fs = require("fs");
var command = "";
var realSecret = "Z5ELZYDJ2ZSTXMXCEIQLETFWS25AGZVWOGTEDUEOWB4JFALL5RAQ";
var epochEndTime = 1475280000; // 10/1/2016 0:0:0 GMT
var epochTime = 1476575999 // start here and move backwards - 10/15/2016 23:59:59 GMT
const execSync = require('child_process').execSync;
// We're going backwards in time
while (epochTime > epochEndTime) {
// javascript time is in ms, so multiply * 1000
var dateString = date2str(new Date(epochTime * 1000), "yyyy-MM-dd hh:mm:ss");
command = 'LD_PRELOAD=/usr/lib/i386-linux-gnu/faketime/libfaketime.so.1 FAKETIME="' + dateString + '" ./keygen -g -k 559018485 -o 559018485-mst.key';
code = execSync(command);
var buf = fs.readFileSync('559018485.key', "utf8");
var secret = buf.split("secret=")[1];
if (secret.includes(realSecret)) {
console.log("we got it!", epochTime, secret);
process.exit();
}
// Just providing some progress to the screen
// so we know things are still going
if (i % 1000 === 0) {
console.log(i, dateString);
}
epochTime--;
}
function date2str(x, y) {
var z = {
M: x.getMonth() + 1,
d: x.getDate(),
h: x.getHours(),
m: x.getMinutes(),
s: x.getSeconds()
};
y = y.replace(/(M+|d+|h+|m+|s+)/g, function(v) {
return ((v.length > 1 ? "0" : "") + eval('z.' + v.slice(-1))).slice(-2)
});
return y.replace(/(y+)/g, function(v) {
return x.getFullYear().toString().slice(-v.length)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment