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

@inspectFile example not working #1646

Closed
Piyushgargcse opened this issue Jan 6, 2018 · 10 comments
Closed

@inspectFile example not working #1646

Piyushgargcse opened this issue Jan 6, 2018 · 10 comments
Assignees
Labels
3.x Related to ModSecurity version 3.x RIP - libmodsecurity
Milestone

Comments

@Piyushgargcse
Copy link

The example you had defined in your documentation is not working
#!/usr/bin/perl

runav.pl

Copyright (c) 2004-2011 Trustwave

This script is an interface between ModSecurity and its

ability to intercept files being uploaded through the

web server, and ClamAV

$CLAMSCAN = "clamscan";

if ($#ARGV != 0) {
print "Usage: runav.pl \n";
exit;
}

my ($FILE) = shift @argv;

$cmd = "$CLAMSCAN --stdout --no-summary $FILE";
$input = $cmd;
$input =~ m/^(.+)/;
$error_message = $1;

$output = "0 Unable to parse clamscan output [$1]";

if ($error_message =~ m/: Empty file.?$/) {
$output = "1 empty file";
}
elsif ($error_message =~ m/: (.+) ERROR$/) {
$output = "0 clamscan: $1";
}
elsif ($error_message =~ m/: (.+) FOUND$/) {
$output = "0 clamscan: $1";
}
elsif ($error_message =~ m/: OK$/) {
$output = "1 clamscan: OK";
}

print "$output\n";

Here you had put a condition that is not taking any parameter so please update your documentation
if ($#ARGV != 0) {
print "Usage: runav.pl \n";
exit;
}

@zimmerle
Copy link
Contributor

zimmerle commented Mar 1, 2018

Hi @Piyushgargcse what leads to believe that this is not working?

@zimmerle zimmerle closed this as completed Mar 1, 2018
@defanator
Copy link
Contributor

May be useful to check: #1610 (comment)

@intelbg
Copy link

intelbg commented Mar 29, 2018

Hello,
We also want and try to implement mod security version3 with NginX 1.12 upload file scanning with clamav according to your documentation with runav.pl which is renamed in our case but it's the same and we are using the following rule:

SecRule FILES_TMPNAMES "@inspectFile /usr/local/bin/pesho.pl"
"phase:2,t:none,block,msg:'Virus found in uploaded file',id:'2222'"

We are seeing that modsecurity creates a temporary file with filename "20180329-113446-152231248681.994854-file-0bn484" in directory "/opt/modsecurity/var/upload", but when the rule 2222 is processed, the "FILES_TMPNAMES" parameter has value "c99.png" which is the real name of the uploaded file. Why FILES_TMPNAMES gives us the real name, and can we inspect the right file?

Here is the complete debug.log from mod security attached.

debug.log.txt

SecUploadKeepFiles is set to on On (In the documentation I read that it should be RelevantOnly but I am not sure if it's only for version 2.9. Please confirm this to me.)

#SecTmpSaveUploadedFiles Off - if this option is ON (I am not sure if it should be on) uploading of any file returns 400 bad request.

Last, but not least I would like to mention that we are familiar with the last commend in the following case and it does not sense:

#1610 (comment)

Please give us complete information which options we need to configure and if the problem with files_tmpnames is the core issue in this case. Thank you in advance.

P.S. I updated with the latest source of modsecurity master branch, because I saw changes to inspect file operator and the problem still exists.

@zimmerle
Copy link
Contributor

Re-opening the issue for further investigation.

@zimmerle zimmerle reopened this Mar 29, 2018
@zimmerle zimmerle added 3.x Related to ModSecurity version 3.x and removed pending feedback labels Mar 29, 2018
@zimmerle zimmerle added this to the v3.0.2 milestone Mar 29, 2018
@wanjidong
Copy link

I have the same problem

@victorhora
Copy link
Contributor

@wanjidong

There was a recent change to fix the behaviour of the operator here. Check if this fixes the issue you're facing.

@wanjidong
Copy link

wanjidong commented Apr 9, 2018

@victorhora Thank you for your reply, but it's not what you said. You can't get FILES_TMPNAMES. My configuration files and log files are as follows.

modsecurity.conf.txt
REQUEST-949-Clamav-Scan.conf.txt
runav.pl.txt
clamav.log
20180409-094128-152323808853.784017.log

ModSecurity version:v3/master 077b182
ModSecurity-nginx version:master owasp-modsecurity/ModSecurity-nginx@6d5f759

@intelbg
Copy link

intelbg commented Apr 17, 2018

Finally, can you please tell me if it's fixed in the latest master?

@victorhora
Copy link
Contributor

Thanks for the feedback @wanjidong and @intelbg.

#1748 should fix this issue. It's being tested in the buildbots now.

Please let us know if it solves your issue.

@zimmerle
Copy link
Contributor

As stated by @victorhora, #1748 fix this. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Related to ModSecurity version 3.x RIP - libmodsecurity
Projects
None yet
Development

No branches or pull requests

6 participants