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

Maldet can't scan files/directories with whitespace. VERSION:1.6.4 #354

Open
leooelx opened this issue Jan 26, 2020 · 8 comments
Open

Maldet can't scan files/directories with whitespace. VERSION:1.6.4 #354

leooelx opened this issue Jan 26, 2020 · 8 comments
Assignees
Labels

Comments

@leooelx
Copy link

leooelx commented Jan 26, 2020

I am using Maldet+Clamav+Inotify with monitor mode in a shared directory on Samba,

when I put a malware with no whitespace on name, Maldet can scan and move the file to quarantine, but when I put a file with whitespace on name the log clamscan_log show:

File: PDFXCview - Copy.exe
ERROR: Can't access file /media/raid5/samba/public/PDFXCview

The same error happens with whitespace on a directory name:

FILE: PDFXCview.exe
ERROR: Can't access file /media/raid5/samba/public/new

I tryied to change the filter rule on line 1569 of file internal/functions from:

$tlog $inotify_log inotify | grep -E "CREATE|MODIFY|MOVED_FROM|MOVED_TO" | grep -E -v '/.. ' | awk '{print$1}' | sort | uniq > $monitor_scanlist

to:

$tlog $inotify_log inotify | awk -F"CREATE|MODIFY|MOVED_FROM|MOVED_TO" '{print $1}' | grep -E -v '/.. ' | sort | uniq | sed -r 's/[ $]+/\&/g' | sed 's/.{2}$//' > $monitor_scanlist

clamscan_log:
ERROR: Can't access file /media/raid5/samba/public/PDFXCview\ -\ Copy.exe
AND
ERROR: Can't access file /media/raid5/samba/public/new\ folder/PDFXCview.exe

and to:

$tlog $inotify_log inotify | grep -E "CREATE|MODIFY|MOVED_FROM|MOVED_TO" | grep -E -v '/.. ' | awk -F'(CREATE|MODIFY|MOVED_FROM|MOVED_TO)' '{print $1}' | sort | uniq > $monitor_scanlist

clamscan_log:
ERROR: Can't access file /media/raid5/samba/public/PDFXCview - Copy.exe
AND
ERROR: Can't access file /media/raid5/samba/public/new folder/PDFXCview.exe

When I use the command clamscan -r /media/raid5/samba/public, it found the malwares, even with the whitespaces.

Does anyone know tell me where is the bug?

tnks!

@leooelx
Copy link
Author

leooelx commented Jan 27, 2020

I solved the issue.

Now maldet can scan and quarantine files with whitespaces and files with whitespaces inside directories with whitespaces.

In the line 1569 of file internal/functions we have to set the filter on this way:

$tlog $inotify_log inotify | awk -F"CREATE|MODIFY|MOVED_FROM|MOVED_TO" '{print $1}' | grep -E -v '/.. ' | sort | uniq | sed 's/.{1}$//' > $monitor_scanlist

My thanks to https://github.com/miglinux for helping me to monitor the contents of temporary random files that contained the path and file name.

@rfxn rfxn added the bug label Jan 31, 2020
@rfxn rfxn self-assigned this Jan 31, 2020
@bzed
Copy link

bzed commented Apr 24, 2020

@rfxn well, I think that is a grave enough bug to warrant an immediate fix and release?

@Gazoo
Copy link
Contributor

Gazoo commented Jul 23, 2020

@rfxn any updates on a release to fix this ?

@arafatx
Copy link

arafatx commented Aug 1, 2020

I think he might be busy with some other things. Last commit was April 2019.

@leooelx
Copy link
Author

leooelx commented Aug 29, 2020

I think he might be busy with some other things. Last commit was April 2019.

The issue was solved with my code on the version 1.6.5

Line 1569.
https://github.com/rfxn/linux-malware-detect/blob/master/files/internals/functions

@Gazoo
Copy link
Contributor

Gazoo commented Aug 31, 2020

Thanks for this guys. Happy to see work on 1.6.5 :)

@Gazoo
Copy link
Contributor

Gazoo commented Sep 23, 2020

Think we can get an official 1.6.5 release now?

@danci1973
Copy link

I think the proposed solution needs a few improvements.

  1. You still need to grep 'CREATE|MODIFY|MOVED_FROM|MOVED_TO' from inotify log, otherwise the file list will contain stuff like:
Setting up watches.  Beware: since -r was given, this may take a while!
Watches established.

Basically, anything that's written to the inotify_log is then treated as a file.

  1. awk in this form creates a list of files that end with spaces (at least on CentOS 7.9) and clamdscan can't access these files. I suggest adding spaces to the field separators:

awk -F" CREATE| MODIFY| MOVED_FROM| MOVED_TO"

  1. I don't quite understand the purpose of grep -E -v '/.. ', but in this form it removes all files or directories that start with two characters followed by a space (for example, /var/www/it is just a test would be removed from the list).

  2. What is sed 's/.{1}$//' supposed to do?

  3. I think it would be useful if monitor mode would also use ignore_paths, so my take on it is this:

$tlog $inotify_log inotify | grep -E " CREATE| MODIFY| MOVED_FROM| MOVED_TO" | awk -F" CREATE| MODIFY| MOVED_FROM| MOVED_TO" '{print $1}' | sort -u | grep -vf $ignore_paths> $monitor_scanlist

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

No branches or pull requests

6 participants