Created
November 19, 2015 04:46
-
-
Save teknogeek/51744307d544354b2e10 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/local/bin/python | |
# -*- coding: utf-8 -*- | |
def main(one, two, three, four, five, six, seven, eight): | |
#b[o]ol + li[s]t = "os" | |
#need this so to import os | |
os = True.__class__.__name__[one] + [].__class__.__name__[two] | |
#[wr]apper_descriptor + tuple[ite]rator = "write" | |
#need this to do os.write | |
write = ().__class__.__eq__.__class__.__name__[:two] + ().__iter__().__class__.__name__[five:eight] | |
#line number table which ends up as "" since it's anonymous | |
#need an empty string for deobfuscateString | |
emptyString = (lambda: _).func_code.co_lnotab | |
def obfuscateString(word): | |
codes = [ord(c) for c in word] | |
# string obfuscation | |
# ============================ | |
# | |
# L−1 | |
# ∑ c[n] * (256^n) | |
# n=0 | |
# | |
# L = string length | |
# c[n] = ASCII code for nth character in string | |
num = sum(codes[i] * (256 ** i) for i in xrange(len(codes))) | |
return num | |
def deobfuscateString(num): | |
if num: | |
return chr(num % 256) + deobfuscateString(num // 256) | |
else: | |
return emptyString #"" | |
helloWorldNum = obfuscateString("Hello World!\n") | |
print "os: '{0}' (type: {1})".format(os, os.__class__.__name__) | |
print "write: '{0}' (type: {1})".format(write, write.__class__.__name__) | |
print "emptyString: '{0}' (type: {1})".format(emptyString, emptyString.__class__.__name__) | |
print "helloWorldNum: {0}".format(helloWorldNum) | |
#that number is far too plain, let's convert it into some bit shifted mumbo jumbo, shall we? | |
from math import ceil, log | |
def convertToBitShifted(num, depth=0): | |
result = "" | |
while num: | |
base = shift = 0 | |
diff = num | |
span = int(ceil(log(abs(num), 1.5))) + (16 >> depth) | |
for test_base in xrange(span): | |
for test_shift in xrange(span): | |
test_diff = abs(num) - (test_base << test_shift) | |
if abs(test_diff) < abs(diff): | |
diff = test_diff | |
base = test_base | |
shift = test_shift | |
if result: | |
result += " + " if num > 0 else " - " | |
elif num < 0: | |
base = -base | |
if shift == 0: | |
result += encodeBitShifted(base, depth) | |
else: | |
result += "(%s << %s)" % (encodeBitShifted(base, depth), | |
encodeBitShifted(shift, depth)) | |
num = diff if num > 0 else -diff | |
return result | |
def encodeBitShifted(num, depth): | |
numL = ["one", "two", "three", "four", "five", "six", "seven", "eight"] | |
if num <= 8: | |
#so that eval will use our 1-8 variables in main() | |
return numL[num - 1] | |
return "(" + convertToBitShifted(num, depth + 1) + ")" | |
newHelloWorldNum = convertToBitShifted(helloWorldNum) | |
print "newHelloWorldNum: {0}".format(newHelloWorldNum) | |
print "eval(newHelloWorldNum): {0}".format(eval(newHelloWorldNum)) | |
#and finally | |
print "\ndun...\n\nduNN.....\n\nDUNNNNN!!!!\n\nFinal Output jesus christ what have we done:" | |
getattr(__import__(os), write)(one, deobfuscateString(eval(newHelloWorldNum))) | |
def getNumList(L): | |
if L: | |
#really there's zero local variables because _ is not defined anywhere so it's assumed as a global | |
zero = (lambda: _).func_code.co_nlocals | |
#likewise, _ is now defined so it's really got one local variable | |
one = (lambda _: _).func_code.co_nlocals | |
#this gets number of arguments for each function in a list of functions recursively | |
return [L[zero].func_code.co_argcount] + getNumList(L[one:]) | |
else: | |
return [] | |
if __name__ == "__main__": | |
#for our 1-8 list for number arguments | |
funcs = ( | |
lambda one: one, | |
lambda one, two: one, | |
lambda one, two, three: one, | |
lambda one, two, three, four: one, | |
lambda one, two, three, four, five: one, | |
lambda one, two, three, four, five, six: one, | |
lambda one, two, three, four, five, six, seven: one, | |
lambda one, two, three, four, five, six, seven, eight: one | |
) | |
oneThroughEight = getNumList(funcs) #[1, 2, 3, 4, 5, 6, 7, 8] | |
print "oneThroughEight: {0}".format(oneThroughEight) | |
main(*oneThroughEight) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment