优化ip段处理模块、端口扫描模块。

This commit is contained in:
shadow1ng
2020-12-03 23:20:39 +08:00
parent b00a5d4403
commit 818102a814
4 changed files with 9 additions and 24 deletions
+1
View File
@@ -78,6 +78,7 @@ func isping(ip string) bool {
if err != nil { if err != nil {
return false return false
} }
defer conn.Close()
_, err = conn.Write(buffer.Bytes()) _, err = conn.Write(buffer.Bytes())
if err != nil { if err != nil {
return false return false
+5 -21
View File
@@ -35,12 +35,9 @@ func ParsePort(ports string) []int {
return scanPorts return scanPorts
} }
func ProbeHosts(host string, ports <-chan int, respondingHosts chan<- string, done chan<- bool, model string, adjustedTimeout int) { func ProbeHosts(host string, ports <-chan int, respondingHosts chan<- string, done chan<- bool, adjustedTimeout int) {
Timeout := time.Duration(adjustedTimeout) * time.Second
for port := range ports { for port := range ports {
start := time.Now()
con, err := net.DialTimeout("tcp4", fmt.Sprintf("%s:%d", host, port), time.Duration(adjustedTimeout)*time.Second) con, err := net.DialTimeout("tcp4", fmt.Sprintf("%s:%d", host, port), time.Duration(adjustedTimeout)*time.Second)
duration := time.Now().Sub(start)
if err == nil { if err == nil {
defer con.Close() defer con.Close()
address := host + ":" + strconv.Itoa(port) address := host + ":" + strconv.Itoa(port)
@@ -48,21 +45,17 @@ func ProbeHosts(host string, ports <-chan int, respondingHosts chan<- string, do
common.LogSuccess(result) common.LogSuccess(result)
respondingHosts <- address respondingHosts <- address
} }
if duration < Timeout {
difference := Timeout - duration
Timeout = Timeout - (difference / 2)
}
} }
done <- true done <- true
} }
func ScanAllports(address string, probePorts []int, threads int, timeout time.Duration, model string, adjustedTimeout int) ([]string, error) { func ScanAllports(address string, probePorts []int, threads int, adjustedTimeout int) ([]string, error) {
ports := make(chan int, 20) ports := make(chan int, 20)
results := make(chan string, 10) results := make(chan string, 10)
done := make(chan bool, threads) done := make(chan bool, threads)
for worker := 0; worker < threads; worker++ { for worker := 0; worker < threads; worker++ {
go ProbeHosts(address, ports, results, done, model, adjustedTimeout) go ProbeHosts(address, ports, results, done, adjustedTimeout)
} }
for _, port := range probePorts { for _, port := range probePorts {
@@ -80,13 +73,11 @@ func ScanAllports(address string, probePorts []int, threads int, timeout time.Du
if threads == 0 { if threads == 0 {
return responses, nil return responses, nil
} }
case <-time.After(timeout):
return responses, nil
} }
} }
} }
func TCPportScan(hostslist []string, ports string, model string, timeout int) ([]string, []string) { func TCPportScan(hostslist []string, ports string, timeout int) ([]string, []string) {
var AliveAddress []string var AliveAddress []string
var aliveHosts []string var aliveHosts []string
probePorts := ParsePort(ports) probePorts := ParsePort(ports)
@@ -119,18 +110,12 @@ func TCPportScan(hostslist []string, ports string, model string, timeout int) ([
var wg sync.WaitGroup var wg sync.WaitGroup
mutex := &sync.Mutex{} mutex := &sync.Mutex{}
limiter := make(chan struct{}, lm) limiter := make(chan struct{}, lm)
aliveHost := make(chan string, lm/2)
go func() {
for s := range aliveHost {
fmt.Println(s)
}
}()
for _, host := range hostslist { for _, host := range hostslist {
wg.Add(1) wg.Add(1)
limiter <- struct{}{} limiter <- struct{}{}
go func(host string) { go func(host string) {
defer wg.Done() defer wg.Done()
if aliveAdd, err := ScanAllports(host, probePorts, thread, 5*time.Second, model, timeout); err == nil && len(aliveAdd) > 0 { if aliveAdd, err := ScanAllports(host, probePorts, thread, timeout); err == nil && len(aliveAdd) > 0 {
mutex.Lock() mutex.Lock()
aliveHosts = append(aliveHosts, host) aliveHosts = append(aliveHosts, host)
for _, addr := range aliveAdd { for _, addr := range aliveAdd {
@@ -142,6 +127,5 @@ func TCPportScan(hostslist []string, ports string, model string, timeout int) ([
}(host) }(host)
} }
wg.Wait() wg.Wait()
close(aliveHost)
return aliveHosts, AliveAddress return aliveHosts, AliveAddress
} }
+1 -1
View File
@@ -40,7 +40,7 @@ func Scan(info common.HostInfo) {
Hosts = ICMPRun(Hosts, info.IcmpThreads, info.Ping) Hosts = ICMPRun(Hosts, info.IcmpThreads, info.Ping)
fmt.Println("icmp alive hosts len is:", len(Hosts)) fmt.Println("icmp alive hosts len is:", len(Hosts))
} }
_, AlivePorts := TCPportScan(Hosts, info.Ports, "icmp", 3) //return AliveHosts,AlivePorts _, AlivePorts := TCPportScan(Hosts, info.Ports, 3) //return AliveHosts,AlivePorts
var severports []string //severports := []string{"21","22","135"."445","1433","3306","5432","6379","9200","11211","27017"...} var severports []string //severports := []string{"21","22","135"."445","1433","3306","5432","6379","9200","11211","27017"...}
for _, port := range common.PORTList { for _, port := range common.PORTList {
severports = append(severports, strconv.Itoa(port)) severports = append(severports, strconv.Itoa(port))
+1 -1
View File
@@ -14,7 +14,7 @@
因为用习惯了f-scrack,习惯一条命令跑完所有模块,省去一个个模块单独调用的时间,当然我附加了-m 指定模块的功能。 因为用习惯了f-scrack,习惯一条命令跑完所有模块,省去一个个模块单独调用的时间,当然我附加了-m 指定模块的功能。
## 最近更新 ## 最近更新
[+] 2020/12/03 优化ip段处理模块,新增支持192.168.1.1-192.168.255.255 [+] 2020/12/03 优化ip段处理模块、icmp、端口扫描模块。新增支持192.168.1.1-192.168.255.255。
[+] 2020/11/17 增加-ping 参数,作用是存活探测模块用ping代替icmp发包。 [+] 2020/11/17 增加-ping 参数,作用是存活探测模块用ping代替icmp发包。
[+] 2020/11/17 增加WebScan模块,新增shiro简单识别。https访问时,跳过证书认证。将服务模块和web模块的超时分开,增加-wt 参数(WebTimeout)。 [+] 2020/11/17 增加WebScan模块,新增shiro简单识别。https访问时,跳过证书认证。将服务模块和web模块的超时分开,增加-wt 参数(WebTimeout)。
[+] 2020/11/16 对icmp模块进行优化,增加-it 参数(IcmpThreads),默认11000,适合扫B段 [+] 2020/11/16 对icmp模块进行优化,增加-it 参数(IcmpThreads),默认11000,适合扫B段