Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
c70ec9ad9d | |||
![]() |
9b95e8d983 | ||
![]() |
e329a754f7 | ||
![]() |
0235c63026 | ||
![]() |
e59b76e462 | ||
![]() |
4d114889a5 | ||
![]() |
bc02105dfa | ||
![]() |
70d0a9948e |
4 changed files with 126 additions and 4 deletions
2
README.md
Normal file
2
README.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# this is NOT for scraping public IPs
|
||||||
|
i had like zero clue that it was a legal gray zone in europe so like i suggest you do NOT use it on public ips
|
21
compile.sh
Normal file
21
compile.sh
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Existing builds
|
||||||
|
GOOS=darwin GOARCH=arm64 go build -o bin/portscraper_OSX_ARM64 main.go
|
||||||
|
GOOS=darwin GOARCH=amd64 go build -o bin/portscraper_OSX_X64 main.go
|
||||||
|
GOOS=windows GOARCH=amd64 go build -o bin/portscraper_WIN_X64_86.exe main.go
|
||||||
|
GOOS=windows GOARCH=386 go build -o bin/portscraper_WIN_X86.exe main.go
|
||||||
|
GOOS=freebsd GOARCH=amd64 go build -o bin/portscraper_FREEBSD_X64 main.go
|
||||||
|
GOOS=freebsd GOARCH=386 go build -o bin/portscraper_FREEBSD_X32 main.go
|
||||||
|
GOOS=freebsd GOARCH=arm64 go build -o bin/portscraper_FREEBSD_ARM64 main.go
|
||||||
|
GOOS=linux GOARCH=386 go build -o bin/portscraper_LINUX_X32 main.go
|
||||||
|
GOOS=linux GOARCH=amd64 go build -o bin/portscraper_LINUX_X64 main.go
|
||||||
|
GOOS=linux GOARCH=arm64 go build -o bin/portscraper_LINUX_ARM64 main.go
|
||||||
|
GOOS=linux GOARCH=arm go build -o bin/portscraper_LINUX_ARM main.go
|
||||||
|
GOOS=linux GOARCH=mipsle go build -o bin/portscraper_LINUX_MIPSLE main.go
|
||||||
|
GOOS=linux GOARCH=mips go build -o bin/portscraper_LINUX_MIPS main.go
|
||||||
|
|
||||||
|
# my stupid fucking router GL.iNet GL-E750
|
||||||
|
GOOS=linux GOARCH=mips GOMIPS=softfloat CGO_ENABLED=0 go build \
|
||||||
|
-ldflags="-s -w -extldflags '-static'" \
|
||||||
|
-o bin/portscraper_LINUX_MIPS_SOFT main.go
|
106
main.go
106
main.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
@ -20,7 +21,7 @@ type OpenPort struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
const batchSize = 255
|
const batchSize = 255
|
||||||
|
var minecraftServers []string
|
||||||
var (
|
var (
|
||||||
printMutex sync.Mutex
|
printMutex sync.Mutex
|
||||||
fileLock sync.Mutex
|
fileLock sync.Mutex
|
||||||
|
@ -103,6 +104,86 @@ func identifyServiceAndOS(ip string, port int) string {
|
||||||
return ""
|
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) {
|
func scanPort(ip string, port int, wg *sync.WaitGroup) {
|
||||||
printStatusLine(ip, fmt.Sprintf("scanning port %d...", port))
|
printStatusLine(ip, fmt.Sprintf("scanning port %d...", port))
|
||||||
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), 500*time.Millisecond)
|
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], ".")
|
hostname = strings.TrimSuffix(host[0], ".")
|
||||||
}
|
}
|
||||||
fingerprint := identifyServiceAndOS(ip, port)
|
fingerprint := identifyServiceAndOS(ip, port)
|
||||||
|
if port == 25565 {
|
||||||
|
minecraftServers = append(minecraftServers, ip)
|
||||||
|
}
|
||||||
openPortsLock.Lock()
|
openPortsLock.Lock()
|
||||||
openPorts = append(openPorts, OpenPort{ip, port, hostname, fingerprint})
|
openPorts = append(openPorts, OpenPort{ip, port, hostname, fingerprint})
|
||||||
line := fmt.Sprintf(" - %s : port %d open - hostname: %s", ip, port, hostname)
|
line := fmt.Sprintf(" - %s : port %d open - hostname: %s", ip, port, hostname)
|
||||||
|
@ -262,11 +345,26 @@ func main() {
|
||||||
fmt.Println("\n--------------------------------------------------")
|
fmt.Println("\n--------------------------------------------------")
|
||||||
fmt.Println("scan done at:", time.Now())
|
fmt.Println("scan done at:", time.Now())
|
||||||
fmt.Println("--------------------------------------------------")
|
fmt.Println("--------------------------------------------------")
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(openPorts) == 0 {
|
if len(openPorts) == 0 {
|
||||||
summaryFile.WriteString("no open ports found.\n")
|
summaryFile.WriteString("no open ports found.\n")
|
||||||
} else {
|
} else {
|
||||||
summaryFile.WriteString("[+] scan summary: open ports found with fingerprints\n")
|
summaryFile.WriteString("[+] scan summary: open ports found with fingerprints above\n")
|
||||||
|
summaryFile.WriteString(fmt.Sprintf("[+] scanned %s to %s\n[+] ports %d to %d\n[+] %d scanned\n[+] %d hits\n", ipParts[0], ipParts[1], portStart, portEnd, len(ipList), len(openPorts)))
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
fmt.Println("[+] scan summary written to summary.txt")
|
fmt.Println("[+] scan summary written to summary.txt")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
"143": {"name": "IMAP"},
|
"143": {"name": "IMAP"},
|
||||||
"161": {"name": "SNMP"},
|
"161": {"name": "SNMP"},
|
||||||
"445": {"name": "SMB (Windows File Sharing)"},
|
"445": {"name": "SMB (Windows File Sharing)"},
|
||||||
|
"443": {"name": "HTTPS"},
|
||||||
"1433": {"name": "MSSQL"},
|
"1433": {"name": "MSSQL"},
|
||||||
"1521": {"name": "Oracle DB"},
|
"1521": {"name": "Oracle DB"},
|
||||||
"3306": {"name": "MySQL"},
|
"3306": {"name": "MySQL"},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue