fscan/Plugins/scanner.go

135 lines
3.7 KiB
Go
Raw Normal View History

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