-
Notifications
You must be signed in to change notification settings - Fork 1
/
SimpleClamAVscan.py
79 lines (66 loc) · 2.13 KB
/
SimpleClamAVscan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import sys, dircache, os
import pyclamav
from HTMLParser import HTMLParser, HTMLParseError
import urllib2
############################################################################
class Parse(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.span_flag = False
self.td_flag = False
def handle_starttag(self, tag, attrs):
if tag == 'span':
self.span_flag = True
if tag == 'td':
self.td_flag = True
def handle_data(self, data):
if self.span_flag:
self.span = data
self.span_flag = False
if self.td_flag:
self.td = data
self.td_flag = False
############################################################################
############################################################################
def scanfile(file):
try:
ret = pyclamav.scanfile(file)
except ValueError, e:
print '[*]ValueError :', e, '("'+file+'")'
return None
except TypeError, e:
print '[*]TyperError :', e, '("'+file+'")'
return None
else:
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], ' !!!!'
url = 'http://totalhash.com/search/av:' + ret[1]
response = urllib2.urlopen(url)
html = Parse()
html.feed(response.read())
html.close()
print '%s - %s' % (url, html.span)
print "____________________________"
return False
############################################################################
############################################################################
if __name__ == '__main__':
if len(sys.argv)>1:
dirlisting=dircache.listdir(sys.argv[1])
if dirlisting!=[]:
for file in dirlisting:
scanfile(file)
else:
scanfile(sys.argv[1])
else:
dirlisting=dircache.listdir('./')
if dirlisting!=[]:
for file in dirlisting:
scanfile(file)
#######################################################################