Skip to content

Commit 9d7dd8a

Browse files
committed
Add random computer names
Each request will now send a unique computer name with each request. There are 4 different buckets of names to choose from and each is chosen randomly and combined randomly on each function call. Once the computer name is returned the bytes to broadcast are updated. The Makefile has also been updated to include the new computers.go file.
1 parent e29a0b7 commit 9d7dd8a

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
all:
2-
GOOS=windows GOARCH=386 go build -o binaries/respounder-x86.exe respounder.go
3-
GOOS=windows GOARCH=amd64 go build -o binaries/respounder-x64.exe respounder.go
4-
GOOS=linux GOARCH=386 go build -o binaries/respounder-x86 respounder.go
5-
GOOS=linux GOARCH=amd64 go build -o binaries/respounder-x64 respounder.go
6-
GOOS=darwin GOARCH=386 go build -o binaries/respounder-osx respounder.go
7-
GOOS=darwin GOARCH=amd64 go build -o binaries/respounder-osx64 respounder.go
2+
GOOS=windows GOARCH=386 go build -o binaries/respounder-x86.exe respounder.go computernames.go
3+
GOOS=windows GOARCH=amd64 go build -o binaries/respounder-x64.exe respounder.go computernames.go
4+
GOOS=linux GOARCH=386 go build -o binaries/respounder-x86 respounder.go computernames.go
5+
GOOS=linux GOARCH=amd64 go build -o binaries/respounder-x64 respounder.go computernames.go
6+
GOOS=darwin GOARCH=386 go build -o binaries/respounder-osx respounder.go computernames.go
7+
GOOS=darwin GOARCH=amd64 go build -o binaries/respounder-osx64 respounder.go computernames.go

computernames.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"math/rand"
5+
"strings"
6+
)
7+
8+
var (
9+
computerName = []string{"laptop", "workstation", "server"}
10+
firstName = []string{"alice", "bob", "john"}
11+
lastName = []string{"smith", "johnson", "williams"}
12+
jobName = []string{"dev", "qa", "ops", "hr"}
13+
)
14+
15+
func getRandomNumber(length int) int {
16+
return rand.Intn(length)
17+
}
18+
19+
func getComputerName() string {
20+
dstSlice := make([]string, 4)
21+
srcSlice := make([]string, 4)
22+
srcSlice[0] = computerName[getRandomNumber(len(computerName))]
23+
srcSlice[1] = firstName[getRandomNumber(len(firstName))]
24+
srcSlice[2] = lastName[getRandomNumber(len(lastName))]
25+
srcSlice[3] = jobName[getRandomNumber(len(jobName))]
26+
perm := rand.Perm(4)
27+
for i, v := range perm {
28+
dstSlice[v] = srcSlice[i]
29+
}
30+
return strings.Join(dstSlice[:], "")
31+
}

respounder.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
'-'
2525
`
2626

27-
Version = 1.0
27+
Version = 1.1
2828
TimeoutSec = 3
2929
BcastAddr = "224.0.0.252"
3030
LLMNRPort = 5355
@@ -46,6 +46,10 @@ var (
4646
`Creates a debug.log file with a trace of the program`)
4747
)
4848

49+
func init() {
50+
rand.Seed(time.Now().UnixNano())
51+
}
52+
4953
func main() {
5054
initFlags()
5155

@@ -107,14 +111,13 @@ func checkResponderOnInterface(inf net.Interface) map[string]string {
107111
func sendLLMNRProbe(ip net.IP) string {
108112
responderIP := ""
109113
// 2 byte random transaction id eg. 0x8e53
110-
rand.Seed(time.Now().UnixNano())
111-
randomTransactionId := fmt.Sprintf("%04x", rand.Intn(65535))
112-
114+
randomTransactionID := fmt.Sprintf("%04x", rand.Intn(65535))
115+
computerName := getComputerName()
116+
cNameLen := fmt.Sprintf("%2x", len(computerName))
117+
encCName := hex.EncodeToString([]byte(computerName))
113118
// LLMNR request in raw bytes
114-
// TODO: generate a new computer name evertime instead of the
115-
// hardcoded value 'awierdcomputername'
116-
llmnrRequest := randomTransactionId +
117-
"0000000100000000000012617769657264636f6d70757465726e616d650000010001"
119+
llmnrRequest := randomTransactionID +
120+
"00000001000000000000" + cNameLen + encCName + "0000010001"
118121
n, _ := hex.DecodeString(llmnrRequest)
119122

120123
remoteAddr := net.UDPAddr{IP: net.ParseIP(BcastAddr), Port: LLMNRPort}

0 commit comments

Comments
 (0)