MCPcopy
hub / github.com/bettercap/bettercap / doInjection

Method doInjection

modules/hid/hid_inject.go:93–148  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

91}
92
93func (mod *HIDRecon) doInjection() {
94 mod.writeLock.Lock()
95 defer mod.writeLock.Unlock()
96
97 err, dev, cmds := mod.prepInjection()
98 if err != nil {
99 mod.Error("%v", err)
100 return
101 }
102
103 numFrames := 0
104 szFrames := 0
105 for _, cmd := range cmds {
106 for _, frame := range cmd.Frames {
107 numFrames++
108 szFrames += len(frame.Data)
109 }
110 }
111
112 devType := mod.sniffType
113 if dev != nil {
114 devType = dev.Type.String()
115 }
116
117 mod.Info("sending %d (%s) HID frames to %s (type:%s layout:%s) ...",
118 numFrames,
119 humanize.Bytes(uint64(szFrames)),
120 tui.Bold(mod.sniffAddr),
121 tui.Yellow(devType),
122 tui.Yellow(mod.keyLayout))
123
124 for i, cmd := range cmds {
125 for j, frame := range cmd.Frames {
126 for attempt := 0; attempt < 3; attempt++ {
127 if err := mod.dongle.TransmitPayload(frame.Data, 500, 5); err != nil {
128 if attempt < 2 {
129 mod.Debug("error sending frame #%d of HID command #%d: %v, retrying ...", j, i, err)
130 } else {
131 mod.Error("error sending frame #%d of HID command #%d: %v", j, i, err)
132 }
133 } else {
134 break
135 }
136 }
137
138 if frame.Delay > 0 {
139 mod.Debug("sleeping %dms after frame #%d of command #%d ...", frame.Delay, j, i)
140 time.Sleep(frame.Delay)
141 }
142 }
143 if cmd.Sleep > 0 {
144 mod.Debug("sleeping %dms after command #%d ...", cmd.Sleep, i)
145 time.Sleep(time.Duration(cmd.Sleep) * time.Millisecond)
146 }
147 }
148}

Callers 1

StartMethod · 0.95

Calls 7

prepInjectionMethod · 0.95
LockMethod · 0.80
UnlockMethod · 0.80
ErrorMethod · 0.45
StringMethod · 0.45
InfoMethod · 0.45
DebugMethod · 0.45

Tested by

no test coverage detected