in src/jndi_deobfuscate/jndi_deobfuscate.py [0:0]
def _transform_replace_upper_and_lower_methods(input_string: str) -> str:
"""Given a string with Java lookup features using either upper() or lower() modifiers,
deobfuscate the string by replacing those features with the appropriate text.
"""
if input_string:
result = re.search(SIMPLE_UPPER_LOWER_MODIFIER_REGEX_PATTERN, input_string)
if result:
full_variable = result.group(1) # ${lower:TEXT_TO_LOWER}
modifier = result.group(2) # lower/upper
text_to_modify = result.group(3) # TEXT_TO_LOWER
if modifier.lower() == "lower":
modified_text = text_to_modify.lower()
elif modifier.lower() == "upper":
modified_text = text_to_modify.upper()
else:
logger.debug(
f"Upper/lower found unknown modifier: {modifier} in string {full_variable}"
)
output_string = input_string.replace(full_variable, modified_text)
return output_string
else:
return input_string