Created
January 23, 2014 20:46
-
-
Save iancmyers/8586418 to your computer and use it in GitHub Desktop.
My solution to the Stripe CTF3 level1 challenge. `node work.js`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require('crypto'); | |
var fs = require('fs'); | |
var exec = require('child_process').exec; | |
var async = require('async'); | |
function solve() { | |
async.auto({ | |
reset: function (callback) { | |
exec('git fetch origin && git reset --hard origin/master && (grep -q "user-lceye6qv" LEDGER.txt || echo "user-lceye6qv: 1" >> LEDGER.txt) && git add LEDGER.txt', function (err, stdout) { | |
callback(null, null); | |
}); | |
}, | |
tree: ['reset', function (callback) { | |
exec('git write-tree', function (err, stdout) { | |
callback(null, stdout.trim()); | |
}); | |
}], | |
parent: ['reset', function (callback) { | |
exec('git rev-parse HEAD', function (err, stdout) { | |
callback(null, stdout.trim()); | |
}); | |
}], | |
timestamp: function (callback) { | |
exec('date +%s', function (err, stdout) { | |
callback(null, stdout.trim()); | |
}); | |
}, | |
}, function (err, result) { | |
var counter = Math.floor((Math.random()*10000000)+1); | |
while (++counter) { | |
var shasum = crypto.createHash('sha1'); | |
var body = "tree " + result.tree + "\n" + | |
"parent " + result.parent + "\n" + | |
"author Ian Christian Myers <[email protected]> " + result.timestamp + " -0800\n" + | |
"committer Ian Christian Myers <[email protected]> " + result.timestamp + " -0800\n\n" + | |
"Give me a Gitcoin\n\n" + counter + "\n"; | |
var store = 'commit ' + body.length + "\0" + body; | |
shasum.update(store); | |
var digest = shasum.digest('hex'); | |
if (digest < "000001") { | |
fs.writeFileSync('./commit', body); | |
process.send('Found Gitcoin: ' + digest); | |
exec('git hash-object -t commit -w commit', function (err, stdout, stderr) { | |
var hashObj = stdout.trim(); | |
exec('git reset --hard ' + hashObj + ' && git push origin master', function (err, stdout, stderr) { | |
if (err) { | |
process.send('Starting over.'); | |
solve(); | |
} else { | |
process.send('Success.'); | |
} | |
}); | |
}); | |
break; | |
} | |
} | |
}); | |
} | |
solve(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cp = require('child_process'); | |
var children = []; | |
var count = 100; | |
while (--count) { | |
children[count] = cp.fork('./node-miner'); | |
children[count].on('message', function (data) { | |
console.log(data); | |
}); | |
children[count].on('close', function (code) { | |
console.log('closed'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment