2023-09-16 16:02:17 +05:30
|
|
|
package smb
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"net"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/praetorian-inc/fingerprintx/pkg/plugins"
|
|
|
|
|
"github.com/praetorian-inc/fingerprintx/pkg/plugins/services/smb"
|
2023-10-17 17:44:13 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
2024-01-18 04:39:15 +05:30
|
|
|
zgrabsmb "github.com/zmap/zgrab2/lib/smb/smb"
|
2023-09-16 16:02:17 +05:30
|
|
|
)
|
|
|
|
|
|
2024-01-18 04:39:15 +05:30
|
|
|
// ==== private helper functions/methods ====
|
|
|
|
|
|
2023-09-16 16:02:17 +05:30
|
|
|
// collectSMBv2Metadata collects metadata for SMBv2 services.
|
2024-03-01 16:10:18 +03:00
|
|
|
// @memo
|
2023-09-16 16:02:17 +05:30
|
|
|
func collectSMBv2Metadata(host string, port int, timeout time.Duration) (*plugins.ServiceSMB, error) {
|
|
|
|
|
if timeout == 0 {
|
|
|
|
|
timeout = 5 * time.Second
|
|
|
|
|
}
|
|
|
|
|
conn, err := protocolstate.Dialer.Dial(context.TODO(), "tcp", net.JoinHostPort(host, fmt.Sprintf("%d", port)))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
|
|
metadata, err := smb.DetectSMBv2(conn, timeout)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return metadata, nil
|
|
|
|
|
}
|
2024-01-18 04:39:15 +05:30
|
|
|
|
|
|
|
|
// getSMBInfo
|
2024-03-01 16:10:18 +03:00
|
|
|
func getSMBInfo(conn net.Conn, setupSession, v1 bool) (*zgrabsmb.SMBLog, error) {
|
2024-01-18 04:39:15 +05:30
|
|
|
_ = conn.SetDeadline(time.Now().Add(10 * time.Second))
|
|
|
|
|
defer func() {
|
|
|
|
|
_ = conn.SetDeadline(time.Time{})
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
result, err := zgrabsmb.GetSMBLog(conn, setupSession, v1, false)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|