fscan/Plugins/scanner.go

113 lines
2.7 KiB
Go
Raw Normal View History

2020-12-29 01:17:10 -08:00
package Plugins
import (
"errors"
"fmt"
2021-02-20 22:52:31 -08:00
"github.com/shadow1ng/fscan/WebScan"
2020-12-29 01:17:10 -08:00
"github.com/shadow1ng/fscan/common"
"reflect"
"strconv"
"strings"
"sync"
)
func Scan(info common.HostInfo) {
2021-03-30 07:30:16 -07:00
fmt.Println("start infoscan")
Hosts, _ := common.ParseIP(info.Host, common.HostFile)
2021-02-20 22:52:31 -08:00
WebScan.Inithttp(common.Pocinfo)
var ch = make(chan struct{}, common.Threads)
2020-12-29 01:17:10 -08:00
var wg = sync.WaitGroup{}
2021-03-04 19:44:21 -08:00
if len(Hosts) > 0 {
if common.IsPing == false {
Hosts = ICMPRun(Hosts, common.Ping)
fmt.Println("icmp alive hosts len is:", len(Hosts))
}
if info.Scantype == "icmp" {
return
}
2021-03-07 18:00:56 -08:00
AlivePorts := PortScan(Hosts, info.Ports, info.Timeout)
2021-03-04 19:44:21 -08:00
if info.Scantype == "portscan" {
return
}
var severports []string //severports := []string{"21","22","135"."445","1433","3306","5432","6379","9200","11211","27017"...}
for _, port := range common.PORTList {
severports = append(severports, strconv.Itoa(port))
}
2021-03-30 07:30:16 -07:00
fmt.Println("start vulscan")
2021-03-04 19:44:21 -08:00
for _, targetIP := range AlivePorts {
info.Host, info.Ports = strings.Split(targetIP, ":")[0], strings.Split(targetIP, ":")[1]
if info.Scantype == "all" {
if info.Ports == "445" { //scan more vul
AddScan("1000001", info, ch, &wg)
AddScan("1000002", info, ch, &wg)
} else if IsContain(severports, info.Ports) {
AddScan(info.Ports, info, ch, &wg)
} else {
AddScan("1000003", info, ch, &wg) //webtitle
}
2020-12-30 05:30:36 -08:00
} else {
2021-04-20 09:13:04 -07:00
port, _ := common.PORTList[info.Scantype]
2021-03-04 19:44:21 -08:00
scantype := strconv.Itoa(port)
AddScan(scantype, info, ch, &wg)
2020-12-29 01:17:10 -08:00
}
}
}
if common.URL != "" {
info.Url = common.URL
AddScan("1000003", info, ch, &wg)
}
if len(common.Urls) > 0 {
for _, url := range common.Urls {
info.Url = url
AddScan("1000003", info, ch, &wg)
}
}
2020-12-29 01:17:10 -08:00
wg.Wait()
2021-04-21 21:06:03 -07:00
common.Logwg.Wait()
2021-03-30 07:30:16 -07:00
close(common.Results)
fmt.Println(fmt.Sprintf("已完成 %v/%v", common.End, common.Num))
2020-12-29 01:17:10 -08:00
}
2021-03-30 03:12:54 -07:00
var Mutex = &sync.Mutex{}
2020-12-29 01:17:10 -08:00
func AddScan(scantype string, info common.HostInfo, ch chan struct{}, wg *sync.WaitGroup) {
wg.Add(1)
go func() {
2021-03-30 03:12:54 -07:00
Mutex.Lock()
common.Num += 1
Mutex.Unlock()
ScanFunc(PluginList, scantype, &info)
2020-12-29 01:17:10 -08:00
wg.Done()
2021-03-30 03:12:54 -07:00
Mutex.Lock()
common.End += 1
Mutex.Unlock()
2020-12-29 01:17:10 -08:00
<-ch
}()
ch <- struct{}{}
}
func ScanFunc(m map[string]interface{}, name string, infos ...interface{}) (result []reflect.Value, err error) {
f := reflect.ValueOf(m[name])
if len(infos) != f.Type().NumIn() {
err = errors.New("The number of infos is not adapted ")
fmt.Println(err.Error())
return result, nil
}
in := make([]reflect.Value, len(infos))
for k, info := range infos {
in[k] = reflect.ValueOf(info)
}
result = f.Call(in)
return result, nil
}
func IsContain(items []string, item string) bool {
for _, eachItem := range items {
if eachItem == item {
return true
}
}
return false
}