def scanfile(): try: clear() print "If output is (1,'Example mal') it means its a virus, if is 0 its not!" askfile = str(raw_input("Enter the file which you want to scan?: ")) import pyclamav print pyclamav.scanfile(askfile) raw_input("Press Enter") mains() except: print ValueError mains()
def handle_uploaded_file(f): global last_md5 filename = str(f) md5str = '' destination = open("uploadfile/" + filename, 'w') for chunk in f.chunks(): destination.write(chunk) destination.close() #scan this file import pyclamav print 'scanning...' scanret = pyclamav.scanfile("uploadfile/" + filename) if scanret[0]: #if 1, virus scanresult = 'n' else: scanresult = 'y' #if or not virus try: #save to database p = white_list(fileID = last_md5, status = scanresult) p.save() except Exception as e: print "[*]error!" print e print scanret if scanresult == 'y': return "healthy file" else: return "virus"
def handle_uploaded_file(f): global last_md5 filename = str(f) md5str = '' destination = open("uploadfile/" + filename, 'w') for chunk in f.chunks(): destination.write(chunk) destination.close() #scan this file import pyclamav print 'scanning...' scanret = pyclamav.scanfile("uploadfile/" + filename) if scanret[0]: #if 1, virus scanresult = 'n' else: scanresult = 'y' #if or not virus try: #save to database p = white_list(fileID=last_md5, status=scanresult) p.save() except Exception as e: print "[*]error!" print e print scanret if scanresult == 'y': return "healthy file" else: return "virus"
def scanfile(file): try: ret = pyclamav.scanfile(file) except ValueError, e: print '[*]ValueError :', e, '("'+file+'")' return None
def scanfile(file): ret = pyclamav.scanfile(file) if ret[0]==0: print "____________________________" print "[*]", file, 'is not infected.......' print "____________________________" return True elif ret[0]==1: print "____________________________" print '[*]', file, 'is infected with', ret[1], ' !!!!' print "____________________________" return False
def clean(self, *args, **kwargs): # ValidatedFileField.clean will check the MIME type from the # http headers and by peeking in the file data = super(RWValidatedFileField, self).clean(*args, **kwargs) file = data.file # next scan with pyclamav tmpfile = file.file.name has_virus, virus_name = pyclamav.scanfile(tmpfile) if has_virus: fn = file.name raise forms.ValidationError( 'The file %s you uploaded appears to contain a virus or be' 'malware (%s).' % (fn, virus_name)) return data
def run(self): try: for parent,dirnames,filenames in os.walk(self.userdir): self.allcount = len(filenames) for filename in filenames: #输出文件信息 ret = [] tmp = {} print "scan file:" + os.path.join(parent,filename) ret = pyclamav.scanfile(os.path.join(parent,filename)) if ret[0]!=0: tmp['file'] = os.path.join(parent,filename) tmp['virusinfo'] = ret[1:] self.result.append(tmp) self.dangercount = self.dangercount + 1 self.count = self.count + 1 except Exception,e: print e
def clean(self, *args, **kwargs): # ValidatedFileField.clean will check the MIME type from the # http headers and by peeking in the file data = super(RWValidatedFileField, self).clean(*args, **kwargs) file = data.file # next scan with pyclamav tmpfile = file.file.name has_virus, virus_name = pyclamav.scanfile(tmpfile) if has_virus: fn = file.name raise forms.ValidationError( 'The file %s you uploaded appears to contain a virus or be' 'malware (%s).' % (fn, virus_name) ) return data
def scan_file(self, filepath): found, virus = pyclamav.scanfile(filepath) return found, virus
def scanMessage(bodyFile, controlFileList): try: avresult = pyclamav.scanfile(bodyFile) except Exception, e: return "430 " + str(e)