diff options
author | n0p <0x90@n0p.cc> | 2018-10-25 23:14:29 +0200 |
---|---|---|
committer | n0p <0x90@n0p.cc> | 2018-10-25 23:14:29 +0200 |
commit | 6814897ce2de08180b6537fcccfb104827e2a131 (patch) | |
tree | cf07de03d5800f8dd6e1c265e6122f8fcb650655 /packer.py | |
download | ForgetfulCommander-6814897ce2de08180b6537fcccfb104827e2a131.tar.gz ForgetfulCommander-6814897ce2de08180b6537fcccfb104827e2a131.zip |
Init.
Diffstat (limited to 'packer.py')
-rw-r--r-- | packer.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/packer.py b/packer.py new file mode 100644 index 0000000..b74a5ac --- /dev/null +++ b/packer.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python2 + +import lief +import os +import subprocess + +subprocess.call(["clang", "-s", "-m32", "-nostdlib", "-nodefaultlibs", "-fPIC", "-Wl,-shared", "entry.c", "-oentry_tmp"]) +subprocess.call(["clang", "-s", "-m32", "-pie", "forgetful_commander.c", "-oforgetful_commander_tmp"]) + +entry = lief.parse("entry_tmp") +forgetful_commander = lief.parse("forgetful_commander_tmp") + +segment_added = forgetful_commander.add(entry.segments[1]) + +forgetful_commander.header.entrypoint = segment_added.physical_address + +# Encrypt exec segment +content = forgetful_commander.segments[3].content + +clr = [0, 0, 0, 0] +flux = [0x78, 0x75, 0x6c, 0x46] +for i in xrange(0, len(content), 4): + tmp = content[i:i+4] + content[i] ^= flux[0] ^ clr[0] + content[i+1] ^= flux[1] ^ clr[1] + content[i+2] ^= flux[2] ^ clr[2] + content[i+3] ^= flux[3] ^ clr[3] + flux.append(flux.pop(0)) + clr = tmp + +forgetful_commander.segments[3].content = content +forgetful_commander.segments[3].add(lief.ELF.SEGMENT_FLAGS.W) + +# Encrypt ro segment +content = forgetful_commander.segments[4].content + +clr = [0, 0, 0, 0] +flux = [0x78, 0x75, 0x6c, 0x46] +for i in xrange(0, len(content), 4): + tmp = content[i:i+4] + content[i] ^= flux[0] ^ clr[0] + content[i+1] ^= flux[1] ^ clr[1] + content[i+2] ^= flux[2] ^ clr[2] + content[i+3] ^= flux[3] ^ clr[3] + flux.append(flux.pop(0)) + clr = tmp + +forgetful_commander.segments[4].content = content +forgetful_commander.segments[4].add(lief.ELF.SEGMENT_FLAGS.W) + +forgetful_commander.write("public/forgetful_commander") + +os.remove("entry_tmp") +os.remove("forgetful_commander_tmp") |