Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bored-engineer/242f637f0b395681e2627eca790826a9 to your computer and use it in GitHub Desktop.
Save bored-engineer/242f637f0b395681e2627eca790826a9 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
#
# This tool is only used to "decrypt" the github enterprise source code.
#
# Run in the /data directory of the instance.
require "zlib"
KEY = "This obfuscation is intended to discourage GitHub Enterprise customers "+
"from making modifications to the VM. We know this 'encryption' is easily broken. "
class String
def unescape
buffer = []
mode = 0
tmp = ""
# https://github.com/ruby/ruby/blob/trunk/doc/syntax/literals.rdoc#strings
sequences = {
"a" => 7,
"b" => 8,
"t" => 9,
"n" => 10,
"v" => 11,
"f" => 12,
"r" => 13,
"e" => 27,
"s" => 32,
"\"" => 34,
"#" => 35,
"\\" => 92,
"{" => 123,
"}" => 125,
}
self.chars.each do |c|
if mode == 0
if c == "\\"
mode = 1
tmp = ""
else
buffer << c.ord
end
else
tmp << c
if tmp[0] == "x"
if tmp.length == 3
buffer << tmp[1..2].hex
mode = 0
tmp = ""
next
else
next
end
end
if tmp.length == 1 && sequences[tmp]
buffer << sequences[tmp]
mode = 0
tmp = ""
next
end
raise "Unknown sequences: \"\\#{tmp}\""
end
end
buffer.pack("C*")
end
def decrypt
i, plaintext = 0, ''
Zlib::Inflate.inflate(self).each_byte do |c|
plaintext << (c ^ KEY[i%KEY.length].ord).chr
i += 1
end
plaintext
end
end
Dir.glob("**/*.rb").each do |file|
next if File.directory?(file)
next if not File.exists?(file)
header = "__ruby_concealer__ \""
len = header.length
File.open(file, "r+") do |fh|
if fh.read(len) == header
puts file
ciphertext = fh.read[0..-1].unescape
plaintext = ciphertext.decrypt
fh.truncate(0)
fh.rewind
fh.write(plaintext)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment