Exemple #1
0
  def scan(self, path):
    parser = self.cfg_parser
    ep = parser.get(self.name, "UNIX_SOCKET")

    pyclamd.init_unix_socket(filename=ep)
    if os.path.isdir(path):
      self.scan_dir(path)
    else:
      self.scan_one(path)
    return len(self.results) == 0
    def check_for_virus(data):
        # Writing data to a file for scanning
        path = '/tmp/file_to_scan.txt'
        file_to_scan = open(path, 'w+')
        file_to_scan.write(str(data))
        file_to_scan.close()

        # Initialize pyclamd socket
        pyclamd.init_unix_socket('/tmp/clamd.socket')

        # Scanning file
        virus_found = pyclamd.scan_file(path)

        # Remove the file that was to scan
        os.remove(path)

        return virus_found
	def init_clamd(self, us=None, ns=None):
		self.result = False
		try:
			if us is not None:
				pyclamd.init_unix_socket(us)
			else:
				pyclamd.init_unix_socket()
			self.result = True
		except pyclamd.ScanError:
			try:
				if ns is not None:
					pyclamd.init_network_socket(ns[0], ns[1])
				else:
					pyclamd.init_network_socket()
				self.result = True
			except pyclamd.ScanError:
				raise
def scan_input():
    try:
        (tmp_file, tmp_file_name) = tempfile.mkstemp()
        os.fchmod(tmp_file, 0o644)
        copy_file(0, tmp_file)
        os.close(0)
    except OSError as e:
        syslog.syslog('Temporary file creation failed: \'%s\'\n' % str(e))
        return (None, None, None)

    try:
        pyclamd.init_unix_socket()
        found_virus = pyclamd.scan_file(tmp_file_name)
    except pyclamd.ScanError as e:
        syslog.syslog('Virus scan failed: \'%s\'\n' % str(e))
        return (None, None, None)

    return (tmp_file, tmp_file_name, found_virus)
def scan_input():
	try:
		(tmp_file, tmp_file_name) = tempfile.mkstemp()
		os.fchmod(tmp_file, 0644)
		copy_file(0, tmp_file)
		os.close(0)
	except OSError as e:
		syslog.syslog('Temporary file creation failed: \'%s\'\n' % str(e))
		return (None, None, None)

	try:
		pyclamd.init_unix_socket()
		found_virus = pyclamd.scan_file(tmp_file_name)
	except pyclamd.ScanError as e:
		syslog.syslog('Virus scan failed: \'%s\'\n' % str(e))
		return (None, None, None)

	return (tmp_file, tmp_file_name, found_virus)
 def __init__(self):
     if ANTIVIRUS_CLAMD_UNIX_SOCK:
         pyclamd.init_unix_socket(ANTIVIRUS_CLAMD_UNIX_SOCK)
     else:
         pyclamd.init_network_socket(ANTIVIRUS_CLAMD_HOST,
                                     ANTIVIRUS_CLAMD_PORT)
Exemple #7
0
import pyclamd
import os
from blessings import Terminal

pyclamd.init_unix_socket('/var/run/clamd.scan/clamd.sock')


def av_scan_s3(tmpdir, bucket_name):
	av=[]
	t = Terminal()
	path=os.path.join(tmpdir, bucket_name)
	for subdir, dirs, files in os.walk(path):
		for file in files:
			subdir_path= os.path.join(path, subdir)
			file_path= os.path.join(subdir_path, file)
			av.append(pyclamd.scan_file(file_path))
			av=[x for x in av if x is not None]
			for n in range(len(av)):
                        	index_number= n
				if str(file_path) in av[n]:
					file= file_path
					virus= list(av[n][str(file_path)])
					virus.remove("FOUND")
					virus=str(virus)[2:-2]
					print t.red('Critical !')+ " I found "+virus+ " in the infected file "+file

Exemple #8
0
    def __init__(
            self,
            socket='/var/run/clamav/clamd.ctl'):

        pyclamd.init_unix_socket(socket)
Exemple #9
0
    def __init__(self, socket='/var/run/clamav/clamd.ctl'):

        pyclamd.init_unix_socket(socket)
Exemple #10
0
    group_ex.add_argument('-s', '--socket', metavar="SOCKET", type=str,
                          default="/var/run/clamav/clamd.ctl",
                          help="Socket file to contact clamd")
    group_ex.add_argument('-n', '--network', metavar="HOST:PORT", type=str, action=HostPortAction,
                          default=default_net,
                          help="Host and port to contact clamd, e.g. localhost:3310")
    arguments = parser.parse_args()
    logging.basicConfig(level=max(2 - arguments.verbose_count, 0) * 10)
    return arguments

if __name__ == "__main__":
    args = parse_command_line()

    if args.network == default_net:
        try:
            pyclamd.init_unix_socket(args.socket)
        except:
            pyclamd.init_network_socket(args.network[0], args.network[1])
    else:
        pyclamd.init_network_socket(args.network[0], args.network[1])

    for filename in args.mailfile:
        log.debug("Reading mboxfile {0}".format(filename.name))
        mbox = mailbox.mbox(filename.name)
        log.debug("Loaded mboxfile {0}".format(filename.name))
        if args.clean:
            log.debug("Locking mailbox {0}".format(filename.name))
            mbox.lock()
        try:
            virus_mail = (y for y in (ScanMessage(key, message) for key, message in mbox.iteritems()) if y.signature)
            for v in virus_mail:
Exemple #11
0
#! /usr/bin/env python

import pyclamd

print('pyclamd version: {}'.format(pyclamd.__version__))

pyclamd.init_unix_socket('/var/run/clamav/clamd.ctl')
if pyclamd.ping():
    print('Connection to Unix socket established.')
    print('ClamAV version: {}'.format(pyclamd.version()))

# test scan
result = pyclamd.scan_stream(pyclamd.EICAR)
print('Scan result: {}'.format(result))