Skip to content

Commit d86e6d3

Browse files
author
Code Express
committed
First commit ;)
1 parent 8f53ce3 commit d86e6d3

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212

1313
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
1414
.glide/
15+
16+
# log files
17+
*.log

respounder.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package main
2+
3+
import (
4+
"encoding/hex"
5+
"fmt"
6+
"math/rand"
7+
"net"
8+
"os"
9+
"strings"
10+
"time"
11+
)
12+
13+
const (
14+
banner = `
15+
16+
.´/
17+
/ ( .----------------.
18+
[ ]░░░░░░░░░░░|// RESPOUNDER //|
19+
) ( '----------------'` + "\n" +
20+
" '-' \n"
21+
22+
timeoutSec = 3
23+
)
24+
25+
func main() {
26+
fmt.Fprintln(os.Stderr, banner)
27+
28+
interfaces, _ := net.Interfaces()
29+
for _, inf := range interfaces {
30+
checkResponderOnInterface(inf)
31+
}
32+
}
33+
34+
func checkResponderOnInterface(inf net.Interface) string {
35+
json := ""
36+
addrs, _ := inf.Addrs()
37+
if len(addrs) > 0 {
38+
ip := addrs[0].(*net.IPNet).IP
39+
if ip.String() != "127.0.0.1" {
40+
fmt.Printf("%-10s Sending probe from %s...\t", "["+inf.Name+"]", ip)
41+
responderAddr := sendLLMNRProbe(ip)
42+
if responderAddr != "" {
43+
fmt.Printf("responder detected at %s\n", responderAddr)
44+
} else {
45+
fmt.Println("responder not detected")
46+
}
47+
}
48+
}
49+
return json
50+
}
51+
52+
// Creates and sends a LLMNR request to the UDP multicast address.
53+
func sendLLMNRProbe(ip net.IP) string {
54+
responderIP := ""
55+
// 2 byte random transaction id eg. 0x8e53
56+
rand.Seed(time.Now().UnixNano())
57+
randomTransactionId := fmt.Sprintf("%04x", rand.Intn(65535))
58+
59+
// LLMNR request in raw bytes
60+
// TODO: generate a new computer name evertime instead of the
61+
// hardcoded value 'awierdcomputername'
62+
llmnrRequest := randomTransactionId +
63+
"0000000100000000000012617769657264636f6d70757465726e616d650000010001"
64+
n, _ := hex.DecodeString(llmnrRequest)
65+
66+
remoteAddr := net.UDPAddr{IP: net.ParseIP("224.0.0.252"), Port: 5355}
67+
68+
conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: ip})
69+
if err != nil {
70+
fmt.Println("Couldn't bind to a UDP interface. Bailing out!")
71+
}
72+
73+
defer conn.Close()
74+
_, _ = conn.WriteToUDP(n, &remoteAddr)
75+
76+
conn.SetReadDeadline(time.Now().Add(timeoutSec * time.Second))
77+
buffer := make([]byte, 1024)
78+
_, clientIP, err := conn.ReadFromUDP(buffer)
79+
if err == nil { // no timeout (or any other) error
80+
responderIP = strings.Split(clientIP.String(), ":")[0]
81+
}
82+
return responderIP
83+
}

0 commit comments

Comments
 (0)