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