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

Segfault caused when Java classfiles are scanned as Mach-O files in Yara 4.0.1 and 4.0.2 #1317

Closed
melina-delgado opened this issue Jul 2, 2020 · 1 comment

Comments

@melina-delgado
Copy link

melina-delgado commented Jul 2, 2020

Yara version: 4.0.2, 4.0.1

Hello everyone,

A neat thing I recently learned is that Java classfiles have the same file magic as Mach-O Fat binaries. This means that the Yara macho module will try to parse Java classfiles as Mach-O files. This is the culprit line https://github.com/VirusTotal/yara/blob/master/libyara/modules/macho/macho.c#L1349

The following I have found just by stepping through gdb.

For most class files, when we enter the macho_parse_fat_file function, we do not enter macho_parse_file function here: https://github.com/VirusTotal/yara/blob/master/libyara/modules/macho/macho.c#L701

However, for a few, we do. This is because we do not enter this line: https://github.com/VirusTotal/yara/blob/master/libyara/modules/macho/macho.c#L694 . So, it enters the macho_parse_file function and we hit a segfault in line 555 of macho.c . I see that the reserved variable doesn't seem to be used so there might be some other bugs in the macho.c file.

gdb_yara_402_error

I have attached a sample rule and sample Java classfile in a zipfile that replicates the issue.
yara_402_bug_zip.zip

@melina-delgado melina-delgado changed the title Segfault caused when Java classfiles are scanned as Mach-O files in Yara 4.0.2 Segfault caused when Java classfiles are scanned as Mach-O files in Yara 4.0.1 and 4.0.2 Jul 2, 2020
plusvic added a commit that referenced this issue Jul 8, 2020
@plusvic
Copy link
Member

plusvic commented Jul 8, 2020

Fixed in 510f366

@plusvic plusvic closed this as completed Jul 8, 2020
tarterp pushed a commit to mandiant/yara that referenced this issue Mar 31, 2022
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

2 participants