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

Microsoft flags YaraX compiled binary as Trojan malware #200

Closed
Benji377 opened this issue Sep 19, 2024 · 5 comments
Closed

Microsoft flags YaraX compiled binary as Trojan malware #200

Benji377 opened this issue Sep 19, 2024 · 5 comments

Comments

@Benji377
Copy link

Benji377 commented Sep 19, 2024

Intro

I have a public repo where I build YARA rules using a Python script, the binary is then uploaded to a release and later downloaded by our application. The application uses the binary to scan files.

Problem

The issue is, that once we download the binary from the release page, Microsoft Windows Defender immediately deletes it and reports it as a Trojan. Has anybody had the same issue?
Here is an extract of how the binary is built:

...
# Iterate through the rules folder and retrieve each yar file in the folder and subfolders
rules_folder = 'rules'
for root, dirs, files in os.walk(rules_folder):
    for file in files:
        if file.endswith('.yar'):
            # Get the content of the file as string
            with open(os.path.join(root, file), 'r') as rule_file:
                content = rule_file.readlines()
                # Add the rule to the compiler
                try:
                    compiler.add_source(''.join(content))
                    number_of_rules += 1
                except Exception as e:
                    error_rules.append(file)
                    print(f'Error compiling {file}: {e}')

# Compile the rules
rules = compiler.build()

# Save the compiled rules into a binary file
with open('rulepirus.yarac', 'wb') as write_file:
    rules.serialize_into(write_file)
...

Links

@GamingGuy003
Copy link

GamingGuy003 commented Sep 19, 2024

Co Programmer of OP here. This has been happening for multiple yara-x versions including the latest one, so it does not seem to be version specific

@plusvic
Copy link
Member

plusvic commented Sep 19, 2024

This may happen because compiled rules include a WebAssembly module in compiled form, and Microsoft Windows Defender may consider that suspicious. I'll investigate.

@plusvic
Copy link
Member

plusvic commented Sep 19, 2024

However, I strongly suggest you to reconsider the distribution of YARA rules in binary form to your users. Using compiled YARA rules from third-parties is highly discouraged because it constitutes a security risk. Bear in mind that compiled YARA rules contain executable code, therefore they can be manipulated to execute malicious payloads.

Also, compiled YARA rules at this moment are guaranteed to run in the same platform that was used for compiling. You if you compile them in 64-bits Linux, you must use them in 64-bits Linux, they won't work on Windows or macOS. You will also encounter issues when compiling the rules with some version of YARA and trying o use it with some other version.

The bottom line is that compiled rules are a mechanism for avoiding the re-compilation of large sets of rules, but assuming that you are compiling the rules yourself and that you are not using it in cross-platform environment. They are not intended to be used as a mechanism for distributing closed-source YARA rules.

@GamingGuy003
Copy link

Thank you, this is quite useful information. I was unaware of the cross platform limitations. We will attempt to implement compilation on the client instead of pre compiling the rules in that case. This however still leaves the issue with storing the compiled rules, as we partially target low performance devices and compilation might be quite slow on those. If you find anything about why Defender tags the rules or how we could circumvent that we would be really grateful!

@plusvic
Copy link
Member

plusvic commented Sep 20, 2024

After #202 I think that Microsoft Windows Defender should not flag the compiled rules anymore. It also solved the issue with compiled rules that are platform-specific. Still, distributing compiled rules is highly discourage unless you implement some signature mechanism that validates that compiled rules come from a trusted source without alteration.

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

No branches or pull requests

3 participants