Skip to content

Commit

Permalink
Added string encryption and other transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
Hippo committed Aug 1, 2020
1 parent dd938cb commit 86d8163
Show file tree
Hide file tree
Showing 17 changed files with 453 additions and 12 deletions.
60 changes: 56 additions & 4 deletions Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,86 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

//TODO: Make documentation for this

// Set input path to jar
var input = "jars/ElseIfChainBool.jar";

// Set export path
var output = "jars/ElseIfChainBool-obf.jar";

// Leave empty if you have JAVA_HOME environment variable set, if not then manually set it to rt.jar
var runtime = "detect";

// Select a dictionary
/**
* Dictionary Types:
* - AlphaNumeric (a-Z | 0-9)
*/
var dictionary = "AlphaNumeric";

// Weather to inline JSR instructions, if you don't know what that is just leave it be
var inlineJSR = true

// Weather to log information about loading/exporting libraries
var logLibraries = false

//Select a list of transformers
/**
* Note: Visit the transformer class itself to get more information about a specific transformer.
* Transformers:
* - BadAnnotation
* - SyntheticBridge (hides code)
* - ReverseJump
* - FakeTryCatches
* - FakeJump
* - ConfusingSwitch
* - JumpRange
* - ClassEntryHider (hides class zip entries)
* - BadAttribute
* - StringEncryption
*/
var transformers = [
"JumpRange"
"StringEncryption"
];

// Add the path to all the library jars your jar depends on
var libraries = [

]

// Add any classes you would like to exclude (not obfuscate), note that this is case sensitive
// Adding "org" here would exclude any class beginning with "org" (including package names, eg org.someone.lib.LibClass)
var exclude = [
]


var FakeTryCatches = {
// The chance it will wrap around an instruction
chance: 80
};

var FakeJump = {
// The chance it will insert a jump
chance: 90
};

var ConfusingSwitch = {
constants: true, chance: 80
// If it will confuse constants
constants: true,
// The chance the switch will be inserted
chance: 80
}

var BadAttribute = {
// If to use bad annotation default attributes
annotation: true,
// If to use bad code attributes
code: true,
// If to use bad module attributes
module: true,
// If to use bad nest host attributes
nest: true
}

var StringEncryption = {
intensity: "light"
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'rip.hippo'
version '1.2.0-SNAPSHOT'
version '1.3.0-SNAPSHOT'

repositories {
mavenCentral()
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/rip/hippo/mosey/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import rip.hippo.mosey.configuration.impl.JavaScriptConfiguration

object Main {



def main(args: Array[String]): Unit = {
try {
val configPath = args.find(arg => arg.startsWith("-config")) match {
Expand Down
18 changes: 17 additions & 1 deletion src/main/scala/rip/hippo/mosey/asm/wrapper/ClassWrapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rip.hippo.mosey.asm.wrapper

import java.util

import org.objectweb.asm.Attribute
import org.objectweb.asm.tree.{AnnotationNode, ClassNode, FieldNode, MethodNode}

import scala.collection.mutable.ListBuffer
Expand All @@ -28,11 +29,26 @@ final class ClassWrapper(classNode: ClassNode) {
classNode.visibleAnnotations.add(annotationNode)
}

def addMethod(methodNode: MethodNode): Unit =
def addMethod(methodNode: MethodNode): MethodWrapper = {
val wrapped = new MethodWrapper(methodNode)
classNode.methods.add(0, methodNode)
methods += wrapped
wrapped
}

def addField(fieldNode: FieldNode): FieldWrapper = {
val wrapped = new FieldWrapper(fieldNode)
classNode.fields.add(0, fieldNode)
fields += wrapped
wrapped
}

def hasModifier(modifier: Int): Boolean = (classNode.access & modifier) != 0

def getAttributes: util.List[Attribute] = classNode.attrs

def createAttributes: Unit = classNode.attrs = new util.ArrayList[Attribute]()

def getName: String = classNode.name

def getSuperName: String = classNode.superName
Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/rip/hippo/mosey/asm/wrapper/FieldWrapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rip.hippo.mosey.asm.wrapper

import java.util

import org.objectweb.asm.Attribute
import org.objectweb.asm.tree.{AnnotationNode, FieldNode}

/**
Expand All @@ -23,4 +24,9 @@ final class FieldWrapper(fieldNode: FieldNode) {
}
fieldNode.visibleAnnotations.add(annotationNode)
}

def getAttributes: util.List[Attribute] = fieldNode.attrs

def createAttributes: Unit = fieldNode.attrs = new util.ArrayList[Attribute]()

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rip.hippo.mosey.asm.wrapper

import java.util

import org.objectweb.asm.Attribute
import org.objectweb.asm.tree.{AnnotationNode, InsnList, MethodNode, TryCatchBlockNode}

/**
Expand All @@ -28,6 +29,10 @@ final class MethodWrapper(methodNode: MethodNode) {

def getTryCatchBlocks: util.List[TryCatchBlockNode] = methodNode.tryCatchBlocks

def getAttributes: util.List[Attribute] = methodNode.attrs

def createAttributes: Unit = methodNode.attrs = new util.ArrayList[Attribute]()

def getMaxLocals: Int = methodNode.maxLocals

def getName: String = methodNode.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import rip.hippo.mosey.dictionary.Dictionary
import rip.hippo.mosey.dictionary.impl.AlphaNumericDictionary
import rip.hippo.mosey.jar.resource.ResourceManager
import rip.hippo.mosey.logger.Logger
import rip.hippo.mosey.transformer.impl.exploits.{ClassEntryHiderTransformer, InvalidJumpRangeTransformer}
import rip.hippo.mosey.transformer.impl.data.StringEncryptionTransformer
import rip.hippo.mosey.transformer.impl.exploits.{BadAttributeTransformer, ClassEntryHiderTransformer, InvalidJumpRangeTransformer}
import rip.hippo.mosey.transformer.impl.flow.{ConfusingSwitchTransformer, FakeJumpTransformer, FakeTryCatchesTransformer, ReverseJumpTransformer}
import rip.hippo.mosey.transformer.impl.misc.{BadAnnotationTransformer, SyntheticBridgeTransformer}

Expand All @@ -29,7 +30,9 @@ final class TransformerManager(configuration: Configuration, resourceManager: Re
"BadAnnotation" -> new BadAnnotationTransformer,
"ConfusingSwitch" -> new ConfusingSwitchTransformer(configuration),
"JumpRange" -> new InvalidJumpRangeTransformer,
"ClassEntryHider" -> new ClassEntryHiderTransformer
"ClassEntryHider" -> new ClassEntryHiderTransformer,
"BadAttribute" -> new BadAttributeTransformer(configuration),
"StringEncryption" -> new StringEncryptionTransformer(configuration, dictionary)
)

private val enabledTransformers = configuration.getTransformers.map(name => transformerMap(name))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package rip.hippo.mosey.transformer.impl.data

import org.objectweb.asm.tree.LdcInsnNode
import rip.hippo.mosey.asm.wrapper.ClassWrapper
import rip.hippo.mosey.configuration.Configuration
import rip.hippo.mosey.dictionary.Dictionary
import rip.hippo.mosey.transformer.Transformer
import rip.hippo.mosey.transformer.impl.data.string.impl.LightStringEncryptionIntensity

/**
* @author Hippo
* @version 1.0.0, 7/31/20
* @since 1.0.0
*
* Well, encrypts strings, nothing more than that eh?
*/
final class StringEncryptionTransformer(configuration: Configuration, val dictionary: Dictionary) extends Transformer {

private val stringEncryptionIntensity = configuration.get("StringEncryption", "intensity").toString.toLowerCase match {
case "light" => new LightStringEncryptionIntensity
case x => throw new IllegalStateException("Could not resolve intensity mode %s".format(x))
}

override def transform(classWrapper: ClassWrapper): Unit = {
val hasStrings = classWrapper.methods.exists(_.getInstructions.toArray.exists(instruction => instruction.isInstanceOf[LdcInsnNode] && instruction.asInstanceOf[LdcInsnNode].cst.isInstanceOf[String]))

if (hasStrings) {
stringEncryptionIntensity.accept(classWrapper, this)

classWrapper.methods.foreach(method =>
method.getInstructions.toArray.foreach {
case ldcInsnNode: LdcInsnNode if ldcInsnNode.cst.isInstanceOf[String] =>
method.getInstructions.insert(ldcInsnNode, stringEncryptionIntensity.encrypt(ldcInsnNode, classWrapper))
method.getInstructions.remove(ldcInsnNode)
case _ =>
}
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package rip.hippo.mosey.transformer.impl.data.string

import org.objectweb.asm.tree.{InsnList, LdcInsnNode}
import rip.hippo.mosey.asm.wrapper.ClassWrapper
import rip.hippo.mosey.transformer.impl.data.StringEncryptionTransformer

/**
* @author Hippo
* @version 1.0.0, 7/31/20
* @since 1.0.0
*/
trait StringEncryptionIntensity {
def accept(classWrapper: ClassWrapper, parent: StringEncryptionTransformer): Unit
def encrypt(ldcInsnNode: LdcInsnNode, classWrapper: ClassWrapper): InsnList
}
Loading

0 comments on commit 86d8163

Please sign in to comment.