Skip to content

Commit b240654

Browse files
committed
Added more random options
Merge github.com:ahhh/respounder into add-computernames A random number in a random position will be placed in the getComputerName function. A function to create a random length string between 16 and 32 characters will be created and then filled with either a number or character. These options have been added to the command line options.
2 parents 9d7dd8a + 025fec6 commit b240654

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

computernames.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,45 @@ var (
1010
firstName = []string{"alice", "bob", "john"}
1111
lastName = []string{"smith", "johnson", "williams"}
1212
jobName = []string{"dev", "qa", "ops", "hr"}
13+
alph = []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
14+
num = []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
1315
)
1416

1517
func getRandomNumber(length int) int {
1618
return rand.Intn(length)
1719
}
1820

21+
func getRandomNumberBetween(min, max int) int {
22+
return rand.Intn(max-min) + min
23+
}
24+
1925
func getComputerName() string {
20-
dstSlice := make([]string, 4)
21-
srcSlice := make([]string, 4)
26+
dstSlice := make([]string, 5)
27+
srcSlice := make([]string, 5)
2228
srcSlice[0] = computerName[getRandomNumber(len(computerName))]
2329
srcSlice[1] = firstName[getRandomNumber(len(firstName))]
2430
srcSlice[2] = lastName[getRandomNumber(len(lastName))]
2531
srcSlice[3] = jobName[getRandomNumber(len(jobName))]
26-
perm := rand.Perm(4)
32+
srcSlice[4] = num[getRandomNumber(len(num))]
33+
perm := rand.Perm(5)
2734
for i, v := range perm {
2835
dstSlice[v] = srcSlice[i]
2936
}
3037
return strings.Join(dstSlice[:], "")
3138
}
39+
40+
func randomString() string {
41+
strLen := getRandomNumberBetween(16, 32)
42+
compName := make([]string, strLen)
43+
var numOrStr int
44+
for x := 0; x < strLen; x++ {
45+
numOrStr = getRandomNumber(2)
46+
switch numOrStr {
47+
case 0:
48+
compName[x] = num[getRandomNumber(len(num))]
49+
case 1:
50+
compName[x] = alph[getRandomNumber(len(alph))]
51+
}
52+
}
53+
return strings.Join(compName, "")
54+
}

respounder.go

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ const (
3030
LLMNRPort = 5355
3131
)
3232

33+
const (
34+
def = 0x00
35+
newComp = 0x01
36+
randCom = 0x02
37+
randStr = 0x03
38+
)
39+
3340
var (
3441
// stdout is default output
3542
outFile = os.Stdout
@@ -40,10 +47,18 @@ var (
4047
// argument flags
4148
jsonPtr = flag.Bool("json", false,
4249
`Prints a JSON to STDOUT if a responder is detected on
43-
network. Other text is sent to STDERR`)
50+
network. Other text is sent to STDERR`)
4451

4552
debugPtr = flag.Bool("debug", false,
4653
`Creates a debug.log file with a trace of the program`)
54+
55+
compPtr = flag.String("computername", "aweirdcomputername",
56+
`Overrides the default computer name, requires at least 16 charcter hostname`)
57+
randCompPtr = flag.Bool("rcomputername", false,
58+
`Overrides the default computer name, with a random choice of words`)
59+
randStrPtr = flag.Bool("rstring", false,
60+
`Overrides the default computer name, with a completely random string`)
61+
comNameType byte
4762
)
4863

4964
func init() {
@@ -52,6 +67,17 @@ func init() {
5267

5368
func main() {
5469
initFlags()
70+
flag.Parse()
71+
72+
if *compPtr != "aweirdcomputername" {
73+
comNameType = newComp
74+
} else if *randCompPtr {
75+
comNameType = randCom
76+
} else if *randStrPtr {
77+
comNameType = randStr
78+
} else {
79+
comNameType = def
80+
}
5581

5682
fmt.Fprintln(os.Stderr, Banner)
5783

@@ -109,12 +135,22 @@ func checkResponderOnInterface(inf net.Interface) map[string]string {
109135

110136
// Creates and sends a LLMNR request to the UDP multicast address.
111137
func sendLLMNRProbe(ip net.IP) string {
138+
var cName string
112139
responderIP := ""
113140
// 2 byte random transaction id eg. 0x8e53
114141
randomTransactionID := fmt.Sprintf("%04x", rand.Intn(65535))
115-
computerName := getComputerName()
116-
cNameLen := fmt.Sprintf("%2x", len(computerName))
117-
encCName := hex.EncodeToString([]byte(computerName))
142+
switch comNameType {
143+
case def:
144+
cName = string(*compPtr)
145+
case newComp:
146+
cName = string(*compPtr)
147+
case randCom:
148+
cName = getComputerName()
149+
case randStr:
150+
cName = randomString()
151+
}
152+
cNameLen := fmt.Sprintf("%2x", len(cName))
153+
encCName := hex.EncodeToString([]byte(cName))
118154
// LLMNR request in raw bytes
119155
llmnrRequest := randomTransactionID +
120156
"00000001000000000000" + cNameLen + encCName + "0000010001"
@@ -162,7 +198,7 @@ func getValidIPv4Addr(addrs []net.Addr) net.IP {
162198
func initFlags() {
163199
flag.Usage = func() {
164200
fmt.Fprintf(os.Stderr, "Respounder version %1.1f\n", Version)
165-
fmt.Fprintf(os.Stderr, "Usage: $ respounder [-json] [-debug]")
201+
fmt.Fprintf(os.Stderr, "Usage: $ respounder [-json] [-debug] [-computername anewcomputername! | -rcomputername | -rstring]")
166202
fmt.Fprintf(os.Stderr, "\n\nFlags:\n")
167203
flag.PrintDefaults()
168204
}

0 commit comments

Comments
 (0)