fscan/Plugins/scanner.go

132 lines
3.6 KiB
Go
Raw Normal View History

2020-12-29 01:17:10 -08:00
package Plugins
import (
"fmt"
2023-08-03 21:37:55 -07:00
"example.com/fxscan/WebScan/lib"
"example.com/fxscan/common"
2020-12-29 01:17:10 -08:00
"reflect"
"strconv"
"strings"
"sync"
)
func Scan(info common.HostInfo) {
2021-03-30 07:30:16 -07:00
fmt.Println("start infoscan")
2021-11-30 23:22:48 -08:00
Hosts, err := common.ParseIP(info.Host, common.HostFile, common.NoHosts)
if err != nil {
fmt.Println("len(hosts)==0", err)
return
}
lib.Inithttp(common.Pocinfo)
var ch = make(chan struct{}, common.Threads)
2020-12-29 01:17:10 -08:00
var wg = sync.WaitGroup{}
2022-08-15 20:18:09 -07:00
web := strconv.Itoa(common.PORTList["web"])
ms17010 := strconv.Itoa(common.PORTList["ms17010"])
if len(Hosts) > 0 || len(common.HostPort) > 0 {
2022-08-16 00:10:09 -07:00
if common.NoPing == false && len(Hosts) > 0 {
Hosts = CheckLive(Hosts, common.Ping)
fmt.Println("[*] Icmp alive hosts len is:", len(Hosts))
2021-03-04 19:44:21 -08:00
}
2022-07-03 08:41:39 -07:00
if common.Scantype == "icmp" {
common.LogWG.Wait()
2021-03-04 19:44:21 -08:00
return
}
2022-08-15 20:18:09 -07:00
common.GC()
var AlivePorts []string
if common.Scantype == "webonly" || common.Scantype == "webpoc" {
AlivePorts = NoPortScan(Hosts, info.Ports)
} else if common.Scantype == "hostname" {
info.Ports = "139"
AlivePorts = NoPortScan(Hosts, info.Ports)
} else if len(Hosts) > 0 {
2022-07-03 08:41:39 -07:00
AlivePorts = PortScan(Hosts, info.Ports, common.Timeout)
fmt.Println("[*] alive ports len is:", len(AlivePorts))
2022-07-03 08:41:39 -07:00
if common.Scantype == "portscan" {
common.LogWG.Wait()
return
}
2021-03-04 19:44:21 -08:00
}
if len(common.HostPort) > 0 {
AlivePorts = append(AlivePorts, common.HostPort...)
AlivePorts = common.RemoveDuplicate(AlivePorts)
common.HostPort = nil
fmt.Println("[*] AlivePorts len is:", len(AlivePorts))
}
2022-08-15 20:18:09 -07:00
common.GC()
2021-03-04 19:44:21 -08:00
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]
2022-07-03 08:41:39 -07:00
if common.Scantype == "all" || common.Scantype == "main" {
switch {
case info.Ports == "135":
AddScan(info.Ports, info, &ch, &wg) //findnet
if common.IsWmi {
AddScan("1000005", info, &ch, &wg) //wmiexec
}
case info.Ports == "445":
2022-08-15 20:18:09 -07:00
AddScan(ms17010, info, &ch, &wg) //ms17010
//AddScan(info.Ports, info, ch, &wg) //smb
//AddScan("1000002", info, ch, &wg) //smbghost
case info.Ports == "9000":
2022-08-15 20:18:09 -07:00
AddScan(web, info, &ch, &wg) //http
AddScan(info.Ports, info, &ch, &wg) //fcgiscan
case IsContain(severports, info.Ports):
2022-08-15 20:18:09 -07:00
AddScan(info.Ports, info, &ch, &wg) //plugins scan
default:
2022-08-15 20:18:09 -07:00
AddScan(web, info, &ch, &wg) //webtitle
2021-03-04 19:44:21 -08:00
}
2020-12-30 05:30:36 -08:00
} else {
2022-08-15 20:18:09 -07:00
scantype := strconv.Itoa(common.PORTList[common.Scantype])
AddScan(scantype, info, &ch, &wg)
2020-12-29 01:17:10 -08:00
}
}
}
2022-08-15 20:18:09 -07:00
common.GC()
for _, url := range common.Urls {
info.Url = url
2022-08-15 20:18:09 -07:00
AddScan(web, info, &ch, &wg)
}
2022-08-15 20:18:09 -07:00
common.GC()
2020-12-29 01:17:10 -08:00
wg.Wait()
2021-05-05 20:37:29 -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{}
2022-08-15 20:18:09 -07:00
func AddScan(scantype string, info common.HostInfo, ch *chan struct{}, wg *sync.WaitGroup) {
*ch <- struct{}{}
2020-12-29 01:17:10 -08:00
wg.Add(1)
go func() {
2021-03-30 03:12:54 -07:00
Mutex.Lock()
common.Num += 1
Mutex.Unlock()
2022-08-15 20:18:09 -07:00
ScanFunc(&scantype, &info)
2021-03-30 03:12:54 -07:00
Mutex.Lock()
common.End += 1
Mutex.Unlock()
2022-05-12 02:56:32 -07:00
wg.Done()
2022-08-15 20:18:09 -07:00
<-*ch
2020-12-29 01:17:10 -08:00
}()
}
2022-08-15 20:18:09 -07:00
func ScanFunc(name *string, info *common.HostInfo) {
f := reflect.ValueOf(PluginList[*name])
in := []reflect.Value{reflect.ValueOf(info)}
f.Call(in)
2020-12-29 01:17:10 -08:00
}
func IsContain(items []string, item string) bool {
for _, eachItem := range items {
if eachItem == item {
return true
}
}
return false
}