2023-04-06 08:27:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-04-06 09:35:59 +00:00
|
|
|
"time"
|
2023-04-06 08:27:37 +00:00
|
|
|
|
|
|
|
clamav "git.cyber.gent/friedkiwi/go-clamav"
|
|
|
|
)
|
|
|
|
|
2023-04-06 09:35:59 +00:00
|
|
|
func banner() {
|
|
|
|
fmt.Println(" _ \n _ __ ___ __ _| |___ ___ __ _ _ __ \n| '_ ` _ \\ / _` | / __|/ __/ _` | '_ \\ \n| | | | | | (_| | \\__ \\ (_| (_| | | | |\n|_| |_| |_|\\__,_|_|___/\\___\\__,_|_| |_|\n ")
|
|
|
|
fmt.Println("malscan v0.1 microservice")
|
|
|
|
fmt.Println("")
|
|
|
|
}
|
|
|
|
|
2023-04-06 08:27:37 +00:00
|
|
|
func main() {
|
2023-04-06 09:35:59 +00:00
|
|
|
|
|
|
|
banner()
|
|
|
|
// start freshclam goroutine
|
|
|
|
go freshclam_update()
|
|
|
|
|
2023-04-06 08:27:37 +00:00
|
|
|
// new clamav instance
|
|
|
|
c := new(clamav.Clamav)
|
|
|
|
err := c.Init(clamav.SCAN_OPTIONS{
|
|
|
|
General: 0,
|
|
|
|
Parse: clamav.CL_SCAN_PARSE_ARCHIVE | clamav.CL_SCAN_PARSE_ELF,
|
|
|
|
Heuristic: 0,
|
|
|
|
Mail: 0,
|
|
|
|
Dev: 0,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// free clamav memory
|
|
|
|
defer c.Free()
|
|
|
|
|
|
|
|
// load db
|
|
|
|
signo, err := c.LoadDB("/usr/local/share/clamav", uint(clamav.CL_DB_DIRECTORY))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
fmt.Println("db load succeed:", signo)
|
|
|
|
|
|
|
|
// compile engine
|
|
|
|
err = c.CompileEngine()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.EngineSetNum(clamav.CL_ENGINE_MAX_SCANSIZE, 1024*1024*40)
|
|
|
|
c.EngineSetNum(clamav.CL_ENGINE_MAX_SCANTIME, 9000)
|
|
|
|
// fmt.Println(c.EngineGetNum(clamav.CL_ENGINE_MAX_SCANSIZE))
|
|
|
|
|
|
|
|
// scan
|
|
|
|
scanned, virusName, ret := c.ScanFile("/bin/bash")
|
|
|
|
fmt.Println(scanned, virusName, ret)
|
2023-04-06 09:35:59 +00:00
|
|
|
|
|
|
|
// loop forever.
|
|
|
|
for {
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
2023-04-06 08:27:37 +00:00
|
|
|
}
|