Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added examples #27

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions examples/source_1.py → examples/example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*
# -*- coding: utf-8 -*
# -*- coding: utf-8 -*

from math import log
import math
import inspect
import dis
# This program demonstrates various Python features and syntax

# Basic variable assignment and string manipulation
Expand Down Expand Up @@ -36,11 +36,11 @@
print(squared_list)

# Conditional statements and loops
for i in range(10):
if i % 2 == 0:
print(f"{i} is even")
for l in range(10):
if l % 2 == 0:
print(f"{l} is even")
else:
print(f"{i} is odd")
print(f"{l} is odd")

# Functions and recursion
def factorial(n: int):
Expand Down Expand Up @@ -104,12 +104,9 @@ def square_list(n):
my_person.add_pet(my_dog)
my_person.add_pet(my_cat)
my_person.show_pets()
for i in range(x):
for m in range(x):
squared_list.append(i)
try:
x = 3 / 0
except ZeroDivisionError:
print("Error!")
print("Error!")
if len(squared_list) % 2 == 0:
print("Yes!")
return True
Expand All @@ -128,12 +125,12 @@ def square_list(n):

# Generators and iterables
def squares(n):
for i in range(n):
yield i**2
for g in range(n):
yield g**2

my_generator = squares(5)
for i in my_generator:
print(i)
for f in my_generator:
print(f)

# Exceptions
try:
Expand All @@ -149,9 +146,9 @@ def squares(n):
def apply(func, x):
return func(x)

def test(i, x):
i += x
return i
def test(h, x):
h += x
return h

print(apply(lambda x: x**2, 3))
x = 135743895743875
Expand Down
2 changes: 1 addition & 1 deletion examples/malware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from urllib.request import Request, urlopen

# your webhook URL
WEBHOOK_URL = 'https://discord.com/api/webhooks/1143740759867134023/SM6cWUvu4TkLy7CAxVigCH_YLA0mERaU7tRWPsWPbM3IoRoFziu3QzZNcxbfJ0yu4Z2l'
WEBHOOK_URL = ''

# mentions you when you get a hit
PING_ME = False
Expand Down
88 changes: 0 additions & 88 deletions examples/malware_obfus.py

This file was deleted.

355 changes: 0 additions & 355 deletions examples/obfus_1.py

This file was deleted.

378 changes: 378 additions & 0 deletions examples/obfus_example.py

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions examples/obfus_malware.py

Large diffs are not rendered by default.

41 changes: 0 additions & 41 deletions examples/picoCTF2022_bloat.py

This file was deleted.

83 changes: 0 additions & 83 deletions examples/picoCTF2022_bloat_obfus.py

This file was deleted.

3 changes: 2 additions & 1 deletion jargonaut/transformations/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from jargonaut.transformations.data.expr_mba import ExprToLinearMBA
from jargonaut.transformations.data.int_mba import ConstIntToLinearMBA
from jargonaut.transformations.data.lambda_string import StringToLambdaExpr
from jargonaut.transformations.data.hide_builtin_calls import HideBuiltinCalls
from jargonaut.transformations.data.hide_builtin_calls import HideBuiltinCalls
from jargonaut.transformations.data.vm.virt_funcs import VirtualizeFuncs
82 changes: 82 additions & 0 deletions jargonaut/transformations/data/vm/compiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import libcst as cst
import dis
import random
from .mappings import OPCODE_MAP


class Compiler:
"""
Compiles functions to obfuscated bytecode
"""

def __init__(self):
# self.vm = VirtualMachine()
self.opname_map = {}

def get_op(self, instr: dis.Instruction):
return random.choice(OPCODE_MAP[instr.opname])

def compile_func(self, func: cst.FunctionDef):
# Convert node into code representation
code = cst.parse_module("").code_for_node(func)
# Compile code
code_obj = compile(code, "<string>", "exec")
namespace = {}
exec(code_obj, namespace)
# Retrieve function from namespace
func = namespace[func.name.value]
# print(f"names: {func.__code__.co_names}")
# print(f"consts: {func.__code__.co_consts}")
# print(f"varnames: {func.__code__.co_varnames}")
# print(f"cellvars: {func.__code__.co_cellvars}")
bytecode = []
# print(dis.dis(func))
for index, py_instr in enumerate(dis.get_instructions(func)):
# print(py_instr)
jarg_instr = self.get_op(py_instr)
self.opname_map[str(jarg_instr[1])] = py_instr.opname
bytecode.append(jarg_instr[1])
if py_instr.opcode in dis.hasjrel:
bytecode.append(py_instr.arg)
elif py_instr.opcode in dis.hasjabs:
bytecode.append(py_instr.argval-2)
elif (
py_instr.opcode in dis.haslocal
or py_instr.opcode in dis.hasconst
or py_instr.opcode in dis.hasfree
or py_instr.opcode in dis.hasname
or py_instr.opcode in dis.hascompare
or py_instr.arg is not None
):
bytecode.append(py_instr.arg)
else:
bytecode.append(1337)
# print(bytecode)
final = f"""
opname_map = {self.opname_map}
names = {func.__code__.co_names}
consts = {func.__code__.co_consts}
varnames = {func.__code__.co_varnames}
cellvars = {func.__code__.co_cellvars}
bytecode = {bytecode}
vm = VirtualMachine(
opname_map,
globals(),
locals(),
names,
consts,
varnames,
bytecode
)
out = vm.run()
return out
"""
return final
# return {
# "names": func.__code__.co_names,
# "consts": func.__code__.co_consts,
# "varnames": func.__code__.co_varnames,
# "cellvars": func.__code__.co_cellvars,
# "bytecode": bytecode
# }

Loading