package Plugins import ( "bytes" "fmt" "time" "example.com/fxscan/common" ) const ( pkt = "\x00" + // session "\x00\x00\xc0" + // legth "\xfeSMB@\x00" + // protocol //[MS-SMB2]: SMB2 NEGOTIATE Request //https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/e14db7ff-763a-4263-8b10-0c3944f52fc5 "\x00\x00" + "\x00\x00" + "\x00\x00" + "\x00\x00" + "\x1f\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + // [MS-SMB2]: SMB2 NEGOTIATE_CONTEXT // https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/15332256-522e-4a53-8cd7-0bd17678a2f7 "$\x00" + "\x08\x00" + "\x01\x00" + "\x00\x00" + "\x7f\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "x\x00" + "\x00\x00" + "\x02\x00" + "\x00\x00" + "\x02\x02" + "\x10\x02" + "\x22\x02" + "$\x02" + "\x00\x03" + "\x02\x03" + "\x10\x03" + "\x11\x03" + "\x00\x00\x00\x00" + // [MS-SMB2]: SMB2_PREAUTH_INTEGRITY_CAPABILITIES // https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/5a07bd66-4734-4af8-abcf-5a44ff7ee0e5 "\x01\x00" + "&\x00" + "\x00\x00\x00\x00" + "\x01\x00" + "\x20\x00" + "\x01\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00" + // [MS-SMB2]: SMB2_COMPRESSION_CAPABILITIES // https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/78e0c942-ab41-472b-b117-4a95ebe88271 "\x03\x00" + "\x0e\x00" + "\x00\x00\x00\x00" + "\x01\x00" + //CompressionAlgorithmCount "\x00\x00" + "\x01\x00\x00\x00" + "\x01\x00" + //LZNT1 "\x00\x00" + "\x00\x00\x00\x00" ) func SmbGhost(info *common.HostInfo) error { if common.IsBrute { return nil } err := SmbGhostScan(info) return err } func SmbGhostScan(info *common.HostInfo) error { ip, port, timeout := info.Host, 445, time.Duration(common.Timeout)*time.Second addr := fmt.Sprintf("%s:%v", info.Host, port) conn, err := common.WrapperTcpWithTimeout("tcp", addr, timeout) defer func() { if conn != nil { conn.Close() } }() if err != nil { return err } _, err = conn.Write([]byte(pkt)) if err != nil { return err } buff := make([]byte, 1024) err = conn.SetReadDeadline(time.Now().Add(timeout)) n, err := conn.Read(buff) if err != nil { return err } if bytes.Contains(buff[:n], []byte("Public")) == true { result := fmt.Sprintf("[+] %v CVE-2020-0796 SmbGhost Vulnerable", ip) common.LogSuccess(result) } return err }