mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-25 20:51:52 +08:00
fix: resolve recent service scan regressions
This commit is contained in:
@@ -3,10 +3,59 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/shadow1ng/fscan/common"
|
||||
)
|
||||
|
||||
func TestVNCDisableBruteOnlyChecksUnauthenticatedAccess(t *testing.T) {
|
||||
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer listener.Close()
|
||||
|
||||
var connections atomic.Int32
|
||||
go func() {
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
connections.Add(1)
|
||||
_ = conn.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
host, portText, err := net.SplitHostPort(listener.Addr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
port, err := strconv.Atoi(portText)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cfg := common.NewConfig()
|
||||
cfg.DisableBrute = true
|
||||
session := common.NewScanSession(cfg, common.NewState(), &common.FlagVars{})
|
||||
result := NewVNCPlugin().Scan(context.Background(), &common.HostInfo{Host: host, Port: port}, session)
|
||||
if result == nil || !result.Success || result.Service != "vnc" {
|
||||
t.Fatalf("Scan() = %#v, want identified VNC service", result)
|
||||
}
|
||||
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
if got := connections.Load(); got != 1 {
|
||||
t.Fatalf("connections = %d, want one unauthenticated-access check and no password attempts", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClassifyVNCErrorType(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user