-
Notifications
You must be signed in to change notification settings - Fork 4
/
victims.groovy
42 lines (38 loc) · 1.21 KB
/
victims.groovy
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
@Grab(group='com.redhat.victims', module='victims-lib', version='1.3.2')
import com.redhat.victims.*
import com.redhat.victims.database.*
import java.security.MessageDigest
import static groovy.io.FileType.FILES
long time = System.currentTimeMillis()
String checksum(File file) {
def digest = MessageDigest.getInstance('SHA1')
file.eachByte(8192) { buffer, length ->
digest.update(buffer, 0, length)
}
new BigInteger(1, digest.digest()).toString(16).padLeft(digest.digestLength << 1, '0')
}
def db = VictimsDB.db()
def cache = new VictimsResultCache()
def dir = new File('./zanata-war/target/zanata/WEB-INF/lib')
dir.traverse(type: FILES) { f ->
String key = checksum(f)
HashSet<String> cves
if (cache.exists(key)) {
cves = cache.get(key)
} else {
ArrayList<VictimsRecord> records = new ArrayList()
VictimsScanner.scan(f.path, records)
records.each { record ->
cves = db.getVulnerabilities(record)
cache.add(key, cves)
}
}
if (!cves.empty) {
System.err.println "$f VULNERABLE! $cves"
} else {
println "$f OK"
}
}
long timeTaken = System.currentTimeMillis() - time
println("Processing took $timeTaken ms.")
return