Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Rewrite shell script in Go #84

Merged
merged 51 commits into from
Apr 15, 2022
Merged

Rewrite shell script in Go #84

merged 51 commits into from
Apr 15, 2022

Conversation

mdeous
Copy link
Collaborator

@mdeous mdeous commented Mar 24, 2019

This PR is a rewrite in Go of the old and ugly shell script. It adds huge performance improvements, as well as a few enhancements like allowing to exclude common files from the scan, or to set the max filesystem operations per second the application will perform.

It does not pass the CI tests as go get "github.com/hillu/go-yara" seems to fail to compile the module, probably due to the location YARA is installed in, but tests pass on my machine :trollface:. I didn't look much into solving this issue, if you have any ideas feel free to tell me or to add commits to that PR.

This somehow solves #65.

@jvoisin
Copy link
Owner

jvoisin commented Apr 3, 2019

No idea about the CI, it might be a good idea to ask the github.com/hillu/go-yara folks about this.

@jvoisin
Copy link
Owner

jvoisin commented Apr 8, 2019

This is the error, in case anyone wants to give a try at fixing the CI:

dpkg-shlibdeps: error: couldn't find library libyara.so.3 needed by debian/nbs-phpmalwarefinder/usr/bin/phpmalwarefinder (ELF format: 'elf64-x86-64'; RPATH: '')
dpkg-shlibdeps: error: cannot continue due to the error above
Note: libraries are not searched in other binary packages that do not have any shlibs or symbols file.
To help dpkg-shlibdeps find private libraries, you might need to use -l.
dh_shlibdeps: dpkg-shlibdeps -Tdebian/nbs-phpmalwarefinder.substvars debian/nbs-phpmalwarefinder/usr/bin/phpmalwarefinder returned exit code 2
make: *** [binary] Error 2

@mdeous
Copy link
Collaborator Author

mdeous commented Mar 12, 2022

Woohoo!!! @jvoisin I finally managed to fix the CI and have the test suite pass! :D

@mdeous mdeous requested a review from jvoisin March 16, 2022 20:51
.github/workflows/test.yml Show resolved Hide resolved
.github/workflows/test.yml Show resolved Hide resolved
README.md Outdated
```

- Download php-malware-finder `git clone https://github.com/jvoisin/php-malware-finder.git`
- [Install YARA](https://yara.readthedocs.io/en/stable/gettingstarted.html).
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe add a note about installing go as well?

Copy link
Owner

Choose a reason for hiding this comment

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

There is no need to install yara, only libyara

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, I'll add/fix that!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

About libyara, YARA documentation doesn't provide any guidance about installing libyara alone that I could link to, but I can add a note for people installing it using their package manager.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I updated it, lmk what you think

go.mod Show resolved Hide resolved
php-malware-finder/phpmalwarefinder.go Outdated Show resolved Hide resolved
php-malware-finder/phpmalwarefinder.go Outdated Show resolved Hide resolved
php-malware-finder/phpmalwarefinder.go Outdated Show resolved Hide resolved
os.Exit(1)
} else {
if args.Verbose {
fmt.Printf("DEBUG: scan workers: %d\n", args.Workers)
Copy link
Owner

Choose a reason for hiding this comment

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

You might want to use go's logging module, instead of fmt.Printf

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It could be a good idea, having the timestamps could allow to ingest the logs in a SIEM or what not, but then we should probably change some of the output to be more useful as logs (for example the "you should look at these files" header should be turned into a prefix of each finding). Wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I gave it a try, here is what the output looks like:

2022/04/07 22:57:24 [DEBUG] rules directory: /home/mde/Code/php-malware-finder/php-malware-finder
2022/04/07 22:57:24 [DEBUG] excluded file extensions: bz2,yml,exe,rar,md,jpg,svg,zip,yaml,dll,jpeg,gif,xz,7z,tar,bundle,ico,min,txt,gz,map,less,png,coffee,rst,bmp,csv,css,tgz,json,so,bin,js
2022/04/07 22:57:24 [DEBUG] ruleset loaded: /home/mde/Code/php-malware-finder/php-malware-finder/php.yar
2022/04/07 22:57:24 [DEBUG] scan workers: 32
2022/04/07 22:57:24 [DEBUG] target: samples
2022/04/07 22:57:24 [DEBUG] delay between fs ops: 1ns
2022/04/07 22:57:24 [WARNING] match found: samples/artificial/dodgy.php (DodgyPhp)
2022/04/07 22:57:24 [WARNING] match found: samples/classic/ajaxshell.php (DodgyPhp)
2022/04/07 22:57:24 [WARNING] match found: samples/artificial/bypasses.php (ObfuscatedPhp)
[...]
2022/04/07 22:57:24 [WARNING] dangerous file found: samples/real/novahot.php
2022/04/07 22:57:24 [WARNING] dangerous file found: samples/artificial/obfuscated.php
2022/04/07 22:57:24 [WARNING] dangerous file found: samples/classic/simattacker.php
2022/04/07 22:57:24 [DEBUG] scanned 28 files in 145.848134ms

@jvoisin jvoisin merged commit 61126b3 into master Apr 15, 2022
@jvoisin jvoisin deleted the golang branch April 15, 2022 20:02
@mdeous
Copy link
Collaborator Author

mdeous commented Apr 15, 2022

🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants