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

Malware scanner #3

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

KosmX
Copy link

@KosmX KosmX commented Jun 11, 2023

What I think the detector/scanner should be.

sorry for typos, mistakes, I'm pretty I made at least 1 typo.

Draft malware scanner
@KosmX KosmX changed the title Malware scanned draft [Draft] Malware scanned draft Jun 11, 2023
@KosmX
Copy link
Author

KosmX commented Jun 11, 2023

I think, we should first code the reference then add new rules, improvements like string rebuilding from byte-array/base64

Update to include dynamic analysis
# Dynamic analysis
A slow but reliable detector looking for jar capabilities, potential malware sign
- run static analysis to filter known threats
Copy link

@Col-E Col-E Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is static analysis mentioned here under the dynamic section?

---

# Dynamic analysis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since static always happens, and dynamic is opt-in depending on usage, I think it'd make more sense for this section to come after the static one

A slow but reliable detector looking for jar capabilities, potential malware sign
- run static analysis to filter known threats
- downloading stuff from the internet (potentially jars, but can be genuine)
Copy link

@Col-E Col-E Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phrasing: We should be detecting the capability to download, but not actually execute any logic. Wording is important to be clear that obvious vectors for abuse are addressed.

- downloading stuff from the internet (potentially jars, but can be genuine)
- zip/jar manipulation.
- able to execute stuff (Runtime.exec())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phrasing: We should make it VERY clear the scanner does not execute stuff, but detects the ability to do so.

- zip/jar manipulation.
- able to execute stuff (Runtime.exec())
- de-obfuscation, static string rebuilding from assets, byte arrays or StringBuilders
Copy link

@Col-E Col-E Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 cents: Deobufuscation isn't technically a necessary component with a tool like SSVM. With that, you can pattern match behaviors and ignore obfuscation entirely.

For example lets say in a static approach you want to look for running some evil-cm:

INVOKESTATIC Runtime.getRuntime()
LDC "evil-cmd"
INVOKEVIRTUAL runtime.exec(String)

This works fine up until you have any kind of obfuscation. Consider string encryption: At that point if you want to keep a static approach you need to support every possible string decryption routine to keep your match logic consistent. That's an impossible ask.

In a dynamic setting using a tool like SSVM you can simulate code execution and peek at calls to Runtime.exec. The string it takes has to be the end-result. So you could in SSVM do:

InstanceClass runtime = vm.getSymbols().java_lang_Runtime();
vm.getInterface().setInvoker(runtime, "exec", "(Ljava/lang/String;)Ljava/io/Process;",
  ctx -> {
    Locals locals = ctx.getLocals();
    String command = ops.toString(locals.loadReference(1));
    if (command.equals("evil-cmd")) {
      String className = ctx.getOwner().getNode().name;
      String methodName = ctx.getMethod().getName();
      String methodDesc = ctx.getMethod().getDesc();
      // method executed with arg deemed malicious, tell detector we found malware here
      sink.markMalware("evil-cmd-detection", className, methodName, methodDesc);
    }
    return Result.CONTINUE;
});

docs/malware-scanner/README.md Show resolved Hide resolved
docs/malware-scanner/README.md Show resolved Hide resolved
KosmX added 2 commits June 12, 2023 21:45
- malware ID
- match ID (I personally want to call it clue ID)

- detection algorithm and interface section separated.
@gdude2002 gdude2002 changed the title [Draft] Malware scanned draft [Draft] Malware scanner draft Jun 19, 2023
@gdude2002 gdude2002 changed the title [Draft] Malware scanner draft Malware scanner draft Jun 19, 2023
@gdude2002 gdude2002 changed the title Malware scanner draft Malware scanner Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants