fscan/Plugins/findnet.go

85 lines
1.9 KiB
Go
Raw Normal View History

2020-12-29 01:17:10 -08:00
package Plugins
import (
"bytes"
"encoding/hex"
"fmt"
2023-08-03 21:37:55 -07:00
"example.com/fxscan/common"
2020-12-29 01:17:10 -08:00
"strings"
"time"
)
var (
bufferV1, _ = hex.DecodeString("05000b03100000004800000001000000b810b810000000000100000000000100c4fefc9960521b10bbcb00aa0021347a00000000045d888aeb1cc9119fe808002b10486002000000")
bufferV2, _ = hex.DecodeString("050000031000000018000000010000000000000000000500")
bufferV3, _ = hex.DecodeString("0900ffff0000")
)
func Findnet(info *common.HostInfo) error {
err := FindnetScan(info)
return err
}
func FindnetScan(info *common.HostInfo) error {
2021-04-20 09:13:04 -07:00
realhost := fmt.Sprintf("%s:%v", info.Host, 135)
2022-07-03 08:41:39 -07:00
conn, err := common.WrapperTcpWithTimeout("tcp", realhost, time.Duration(common.Timeout)*time.Second)
2021-09-10 05:32:51 -07:00
defer func() {
if conn != nil {
2021-09-10 05:32:51 -07:00
conn.Close()
}
}()
2020-12-29 01:17:10 -08:00
if err != nil {
return err
}
2022-07-03 08:41:39 -07:00
err = conn.SetDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second))
2020-12-29 01:17:10 -08:00
if err != nil {
return err
}
_, err = conn.Write(bufferV1)
if err != nil {
return err
}
reply := make([]byte, 4096)
_, err = conn.Read(reply)
if err != nil {
return err
}
_, err = conn.Write(bufferV2)
if err != nil {
return err
}
if n, err := conn.Read(reply); err != nil || n < 42 {
return err
}
text := reply[42:]
flag := true
for i := 0; i < len(text)-5; i++ {
if bytes.Equal(text[i:i+6], bufferV3) {
text = text[:i-4]
flag = false
break
}
}
if flag {
return err
}
err = read(text, info.Host)
return err
}
func read(text []byte, host string) error {
encodedStr := hex.EncodeToString(text)
hostnames := strings.Replace(encodedStr, "0700", "", -1)
hostname := strings.Split(hostnames, "000000")
result := "[*] NetInfo:\n[*]" + host
2020-12-29 01:17:10 -08:00
for i := 0; i < len(hostname); i++ {
hostname[i] = strings.Replace(hostname[i], "00", "", -1)
host, err := hex.DecodeString(hostname[i])
if err != nil {
return err
}
result += "\n [->]" + string(host)
}
common.LogSuccess(result)
return nil
}