mirror of https://github.com/qwqdanchun/fscan.git
添加功能,跳过某些ip扫描,-hn 192.168.1.1/24
This commit is contained in:
parent
37f53e3f16
commit
dc267a5335
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/shadow1ng/fscan/common"
|
"github.com/shadow1ng/fscan/common"
|
||||||
"net"
|
"net"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -19,22 +20,21 @@ func PortScan(hostslist []string, ports string, timeout int64) []string {
|
||||||
probePorts := common.ParsePort(ports)
|
probePorts := common.ParsePort(ports)
|
||||||
noPorts := common.ParsePort(common.NoPorts)
|
noPorts := common.ParsePort(common.NoPorts)
|
||||||
if len(noPorts) > 0 {
|
if len(noPorts) > 0 {
|
||||||
var tmpPorts []int
|
temp := map[int]struct{}{}
|
||||||
for _, port := range probePorts {
|
for _, port := range probePorts {
|
||||||
var flag bool
|
temp[port] = struct{}{}
|
||||||
nport:
|
|
||||||
for _, noport := range noPorts {
|
|
||||||
if port == noport {
|
|
||||||
flag = true
|
|
||||||
break nport
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, port := range noPorts {
|
||||||
|
delete(temp, port)
|
||||||
}
|
}
|
||||||
if flag {
|
|
||||||
continue
|
var newDatas []int
|
||||||
|
for port, _ := range temp {
|
||||||
|
newDatas = append(newDatas, port)
|
||||||
}
|
}
|
||||||
tmpPorts = append(tmpPorts, port)
|
probePorts = newDatas
|
||||||
}
|
sort.Ints(probePorts)
|
||||||
probePorts = tmpPorts
|
|
||||||
}
|
}
|
||||||
workers := common.Threads
|
workers := common.Threads
|
||||||
Addrs := make(chan Addr, len(hostslist)*len(probePorts))
|
Addrs := make(chan Addr, len(hostslist)*len(probePorts))
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -21,35 +22,54 @@ var ParseIPErr = errors.New(" host parsing error\n" +
|
||||||
"192.168.1.1-192.168.255.255\n" +
|
"192.168.1.1-192.168.255.255\n" +
|
||||||
"192.168.1.1-255")
|
"192.168.1.1-255")
|
||||||
|
|
||||||
func ParseIP(ip string, filename string) (hosts []string, err error) {
|
func ParseIP(ip string, filename string, nohost string) (hosts []string, err error) {
|
||||||
|
|
||||||
if ip != "" {
|
if ip != "" {
|
||||||
hosts, err = ParseIPs(ip)
|
hosts = ParseIPs(ip)
|
||||||
}
|
}
|
||||||
if filename != "" {
|
if filename != "" {
|
||||||
var filehost []string
|
var filehost []string
|
||||||
filehost, _ = Readipfile(filename)
|
filehost, _ = Readipfile(filename)
|
||||||
hosts = append(hosts, filehost...)
|
hosts = append(hosts, filehost...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if nohost != "" {
|
||||||
|
nohosts := ParseIPs(nohost)
|
||||||
|
if len(nohosts) > 0 {
|
||||||
|
temp := map[string]struct{}{}
|
||||||
|
for _, host := range hosts {
|
||||||
|
temp[host] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, host := range nohosts {
|
||||||
|
delete(temp, host)
|
||||||
|
}
|
||||||
|
|
||||||
|
var newDatas []string
|
||||||
|
for host, _ := range temp {
|
||||||
|
newDatas = append(newDatas, host)
|
||||||
|
}
|
||||||
|
hosts = newDatas
|
||||||
|
sort.Strings(hosts)
|
||||||
|
}
|
||||||
|
}
|
||||||
hosts = RemoveDuplicate(hosts)
|
hosts = RemoveDuplicate(hosts)
|
||||||
return hosts, err
|
return hosts, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseIPs(ip string) (hosts []string, err error) {
|
func ParseIPs(ip string) (hosts []string) {
|
||||||
|
var err error
|
||||||
if strings.Contains(ip, ",") {
|
if strings.Contains(ip, ",") {
|
||||||
IPList := strings.Split(ip, ",")
|
IPList := strings.Split(ip, ",")
|
||||||
var ips []string
|
var ips []string
|
||||||
for _, ip := range IPList {
|
for _, ip := range IPList {
|
||||||
ips, err = ParseIPone(ip)
|
ips, err = ParseIPone(ip)
|
||||||
CheckErr(ip, err)
|
|
||||||
hosts = append(hosts, ips...)
|
hosts = append(hosts, ips...)
|
||||||
}
|
}
|
||||||
return hosts, err
|
|
||||||
} else {
|
} else {
|
||||||
hosts, err = ParseIPone(ip)
|
hosts, err = ParseIPone(ip)
|
||||||
CheckErr(ip, err)
|
|
||||||
return hosts, err
|
|
||||||
}
|
}
|
||||||
|
CheckErr(ip, err)
|
||||||
|
return hosts
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseIPone(ip string) ([]string, error) {
|
func ParseIPone(ip string) ([]string, error) {
|
||||||
|
@ -189,8 +209,7 @@ func Readipfile(filename string) ([]string, error) {
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
text := strings.TrimSpace(scanner.Text())
|
text := strings.TrimSpace(scanner.Text())
|
||||||
if text != "" {
|
if text != "" {
|
||||||
host, err := ParseIPs(text)
|
host := ParseIPs(text)
|
||||||
CheckErr(text, err)
|
|
||||||
content = append(content, host...)
|
content = append(content, host...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,7 +217,7 @@ func Readipfile(filename string) ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveDuplicate(old []string) []string {
|
func RemoveDuplicate(old []string) []string {
|
||||||
result := make([]string, 0, len(old))
|
result := []string{}
|
||||||
temp := map[string]struct{}{}
|
temp := map[string]struct{}{}
|
||||||
for _, item := range old {
|
for _, item := range old {
|
||||||
if _, ok := temp[item]; !ok {
|
if _, ok := temp[item]; !ok {
|
||||||
|
|
|
@ -5,8 +5,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParsePort(ports string) []int {
|
func ParsePort(ports string) (scanPorts []int) {
|
||||||
var scanPorts []int
|
if ports == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
slices := strings.Split(ports, ",")
|
slices := strings.Split(ports, ",")
|
||||||
for _, port := range slices {
|
for _, port := range slices {
|
||||||
port = strings.Trim(port, " ")
|
port = strings.Trim(port, " ")
|
||||||
|
@ -39,7 +41,7 @@ func ParsePort(ports string) []int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeDuplicate(old []int) []int {
|
func removeDuplicate(old []int) []int {
|
||||||
result := make([]int, 0, len(old))
|
result := []int{}
|
||||||
temp := map[int]struct{}{}
|
temp := map[int]struct{}{}
|
||||||
for _, item := range old {
|
for _, item := range old {
|
||||||
if _, ok := temp[item]; !ok {
|
if _, ok := temp[item]; !ok {
|
||||||
|
|
|
@ -92,5 +92,6 @@ var (
|
||||||
UrlFile string
|
UrlFile string
|
||||||
Urls []string
|
Urls []string
|
||||||
NoPorts string
|
NoPorts string
|
||||||
|
NoHosts string
|
||||||
SC string
|
SC string
|
||||||
)
|
)
|
||||||
|
|
|
@ -19,6 +19,7 @@ func Banner() {
|
||||||
func Flag(Info *HostInfo) {
|
func Flag(Info *HostInfo) {
|
||||||
Banner()
|
Banner()
|
||||||
flag.StringVar(&Info.Host, "h", "", "IP address of the host you want to scan,for example: 192.168.11.11 | 192.168.11.11-255 | 192.168.11.11,192.168.11.12")
|
flag.StringVar(&Info.Host, "h", "", "IP address of the host you want to scan,for example: 192.168.11.11 | 192.168.11.11-255 | 192.168.11.11,192.168.11.12")
|
||||||
|
flag.StringVar(&NoHosts, "hn", "", "the hosts no scan,as: -hn 192.168.1.1/24")
|
||||||
flag.StringVar(&Info.Ports, "p", DefaultPorts, "Select a port,for example: 22 | 1-65535 | 22,80,3306")
|
flag.StringVar(&Info.Ports, "p", DefaultPorts, "Select a port,for example: 22 | 1-65535 | 22,80,3306")
|
||||||
flag.StringVar(&NoPorts, "pn", "", "the ports no scan,as: -pn 445")
|
flag.StringVar(&NoPorts, "pn", "", "the ports no scan,as: -pn 445")
|
||||||
flag.StringVar(&Info.Command, "c", "", "exec command (ssh)")
|
flag.StringVar(&Info.Command, "c", "", "exec command (ssh)")
|
||||||
|
|
Loading…
Reference in New Issue