Skip to content

Commit

Permalink
Added IP obfuscation option. Idea and code from @vysec
Browse files Browse the repository at this point in the history
  • Loading branch information
capnspacehook committed Jul 14, 2018
1 parent 93e2ed2 commit a9ebd5c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bin/shellpop
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@ def main():
encoders.add_argument("--urlencode", action="store_true", required=False,
help="Encode the command in URL encoding.")

# Obfuscation options
obfuscation = parser.add_argument_group("Obfuscation Options")
obfuscation.add_argument("--ipfuscate", action="store_true", required=False, help="Obfuscate IP address.")
obfuscation.add_argument("--obfuscate-small", action="store_true", default=False, required=False, help="Obfuscated \
command will be as small as possible.")

# Use handler if possible.
parser.add_argument("--handler", action="store_true", help="Use handler, if possible.", default=False,
required=False)
Expand Down Expand Up @@ -664,6 +670,9 @@ def main():
if args.host in [str(x) for x in netifaces.interfaces()]:
args.host = str(netifaces.ifaddresses(args.host)[2][0]["addr"]) # translate iface name to ipv4

if args.ipfuscate:
args.host = ipfuscate(args.host, args.obfuscate_small)

if args.xor is True:
args.xor = randint(0, 255)
else:
Expand Down
1 change: 1 addition & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from bind import *
from reverse import *
from encoders import *
from obfuscators import *
from classes import *
from handlers import *
from stagers import *
Expand Down
63 changes: 63 additions & 0 deletions src/obfuscators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import os

def ipfuscate(ip, smallIP):
"""
Obfuscate an IP address by converting it to decimal, hex,
octal, or a combination of the three.
Code borrowed from @vysecurity (https://github.com/vysec/IPFuscator)
Implemented by @capnspacehook
"""
parts = ip.split('.')

if not smallIP:
ip = randomBaseIPgen(parts, smallIP)

else:
type = ord(os.urandom(1)) % 4
decimal = int(parts[0]) * 16777216 + int(parts[1]) * 65536 + int(parts[2]) * 256 + int(parts[3])

if type == 0:
ip = decimal
elif type == 1:
ip = hex(decimal)
elif type == 2:
ip = oct(decimal)
else:
ip = randomBaseIPgen(parts, smallIP)

return str(ip)

def randomBaseIPgen(parts, smallIP):
"""
Used by ipfuscate(), returns an obfuscated IP with random bases.
Code borrowed from @vysecurity (https://github.com/vysec/IPFuscator)
Implemented by @capnspacehook
"""

hexParts = []
octParts = []

for i in parts:
hexParts.append(hex(int(i)))
octParts.append(oct(int(i)))

randBaseIP = ""
for i in range(0,4):
val = ord(os.urandom(1)) % 3
if val == 0:
# dec
randBaseIP += parts[i] + '.'
elif val == 1:
# hex
if not smallIP:
randBaseIP += hexParts[i].replace('0x', '0x' + '0' * (ord(os.urandom(1)) % 31)) + '.'
else:
randBaseIP += hexParts[i] + '.'
else:
# oct
if not smallIP:
randBaseIP += '0' * (ord(os.urandom(1)) % 31) + octParts[i] + '.'
else:
randBaseIP += octParts[i] + '.'

return randBaseIP[:-1]

0 comments on commit a9ebd5c

Please sign in to comment.