From bc02105dfa9d23495d4e1293df073b70696cc67b Mon Sep 17 00:00:00 2001 From: WhatDidYouExpect <89535984+WhatDidYouExpect@users.noreply.github.com> Date: Sat, 26 Jul 2025 21:09:11 +0200 Subject: [PATCH] simple compile script so i dont have to type it out each time --- compile.sh | 3 ++ main.go | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 compile.sh diff --git a/compile.sh b/compile.sh new file mode 100644 index 0000000..5f996bd --- /dev/null +++ b/compile.sh @@ -0,0 +1,3 @@ +#!/bin/sh +go build -o portscraper main.go +GOOS=windows GOARCH=amd64 go build -o portscraper.exe main.go diff --git a/main.go b/main.go index 7b30be3..a151d5f 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "bytes" "encoding/json" "fmt" "net" @@ -20,7 +21,7 @@ type OpenPort struct { } const batchSize = 255 - +var minecraftServers []string var ( printMutex sync.Mutex fileLock sync.Mutex @@ -103,6 +104,86 @@ func identifyServiceAndOS(ip string, port int) string { return "" } +func queryMinecraftServer(ip string, port int) string { + conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), 3*time.Second) + if err != nil { + return "" + } + defer conn.Close() + writeVarInt := func(val int) []byte { + var out []byte + for { + temp := byte(val & 0x7F) + val >>= 7 + if val != 0 { + temp |= 0x80 + } + out = append(out, temp) + if val == 0 { + break + } + } + return out + } + + protocolVersion := 754 + serverAddr := ip + state := 1 + // so confusing for me i actually had to comment stuff + var payload []byte + payload = append(payload, 0x00) // fackin packet ID for handshake + payload = append(payload, writeVarInt(protocolVersion)...) // protocol version + payload = append(payload, writeVarInt(len(serverAddr))...) // address length + payload = append(payload, []byte(serverAddr)...) // address + payload = append(payload, byte(port>>8), byte(port&0xFF)) // port + payload = append(payload, byte(state)) // next state: status + + packet := append(writeVarInt(len(payload)), payload...) // full packet = length + payload + conn.Write(packet) // send handshake + conn.Write([]byte{0x01, 0x00}) // send status request + + conn.SetReadDeadline(time.Now().Add(3 * time.Second)) + buf := make([]byte, 4096) + n, err := conn.Read(buf) + if err != nil || n == 0 { + return "" + } + + start := bytes.IndexByte(buf, '{') + if start == -1 { + return "" + } + jsonData := string(buf[start:n]) + + var status struct { + Version struct { + Name string `json:"name"` + } `json:"version"` + Description interface{} `json:"description"` + Players struct { + Online int `json:"online"` + Max int `json:"max"` + } `json:"players"` + } + + if err := json.Unmarshal([]byte(jsonData), &status); err != nil { + return "" + } + + desc := "" + switch v := status.Description.(type) { + case string: + desc = v + case map[string]interface{}: + if text, ok := v["text"].(string); ok { + desc = text + } + } + + return fmt.Sprintf("%s | %d/%d players | %s", status.Version.Name, status.Players.Online, status.Players.Max, desc) +} + + func scanPort(ip string, port int, wg *sync.WaitGroup) { printStatusLine(ip, fmt.Sprintf("scanning port %d...", port)) conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), 500*time.Millisecond) @@ -114,7 +195,9 @@ func scanPort(ip string, port int, wg *sync.WaitGroup) { hostname = strings.TrimSuffix(host[0], ".") } fingerprint := identifyServiceAndOS(ip, port) - + if port == 25565 { + minecraftServers = append(minecraftServers, ip) + } openPortsLock.Lock() openPorts = append(openPorts, OpenPort{ip, port, hostname, fingerprint}) line := fmt.Sprintf(" - %s : port %d open - hostname: %s", ip, port, hostname) @@ -269,4 +352,16 @@ func main() { summaryFile.WriteString("[+] scan summary: open ports found with fingerprints\n") } fmt.Println("[+] scan summary written to summary.txt") + if len(minecraftServers) > 0 { + safePrintln("[*] querying Minecraft servers on port 25565...") + for _, ip := range minecraftServers { + status := queryMinecraftServer(ip, 25565) + if status != "" { + safePrintln("[MC] Server at", ip, "responded.") + summaryFile.WriteString("[MC] " + ip + ":25565 " + status + "\n") + } else { + summaryFile.WriteString("[MC] " + ip + ":25565 no response or malformed\n") + } + } + } }