Skip to content

Instantly share code, notes, and snippets.

@dommmel
Created January 24, 2014 14:55
Show Gist options
  • Save dommmel/8598775 to your computer and use it in GitHub Desktop.
Save dommmel/8598775 to your computer and use it in GitHub Desktop.
Stripe-CTF Level-1
require 'digest/sha1'
@ctf_username = "user-8lmmcgvw"
def addToLedger
user_in_ledger = false
File.open("LEDGER.txt").each_line do |line|
if line.match(/^#{@ctf_username}:/)
user_in_ledger = true
end
end
unless user_in_ledger
`echo "#{@ctf_username}: 1" >> LEDGER.txt`
end
`git add LEDGER.txt`
end
def reset
`git fetch && git reset --hard origin/master`
addToLedger()
@difficulty = File.read("difficulty.txt").tr("\n","")
@tree = `git write-tree`
@parent = `git rev-parse HEAD`
@timestamp = Time.now.to_i
end
reset()
threadA = Thread.fork do
loop do
remote_sha=`git ls-remote origin -h refs/heads/master 2>/dev/null`.sub("\trefs/heads/master\n","")
local_sha = `git rev-parse HEAD`.sub("\n","")
if remote_sha != local_sha
print "remote_sha: #{remote_sha} != local_sha: #{local_sha}\n\n"
reset()
end
sleep 10
end
end
counter = 0;
loop do
content="tree #{@tree}parent #{@parent}author CTF user <[email protected]> #{@timestamp} +0000
committer CTF user <[email protected]> #{@timestamp} +0000
Give me a Gitcoin
#{counter}"
fix_content = content + "\n"
store = "commit #{fix_content.length}\0#{fix_content}"
sha1 = Digest::SHA1.hexdigest(store)
if sha1 < @difficulty
threadA.kill
print "Mined a Gitcoin with commit: #{sha1}"
`git hash-object -t commit --stdin -w <<< "#{content}"`
`git reset --hard "#{sha1}"`
`git push origin master`
break
end
counter+=1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment