mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 04:59:25 -07:00
new: hid.sniff will now hexdump sniffed payloads (closes #490)
This commit is contained in:
parent
73710ba7d3
commit
ee8fe972e0
4 changed files with 23 additions and 7 deletions
|
@ -32,6 +32,7 @@ type HIDRecon struct {
|
||||||
sniffType string
|
sniffType string
|
||||||
pingPayload []byte
|
pingPayload []byte
|
||||||
inSniffMode bool
|
inSniffMode bool
|
||||||
|
sniffSilent bool
|
||||||
inPromMode bool
|
inPromMode bool
|
||||||
inInjectMode bool
|
inInjectMode bool
|
||||||
keyLayout string
|
keyLayout string
|
||||||
|
@ -58,6 +59,7 @@ func NewHIDRecon(s *session.Session) *HIDRecon {
|
||||||
inSniffMode: false,
|
inSniffMode: false,
|
||||||
inPromMode: false,
|
inPromMode: false,
|
||||||
inInjectMode: false,
|
inInjectMode: false,
|
||||||
|
sniffSilent: true,
|
||||||
pingPayload: []byte{0x0f, 0x0f, 0x0f, 0x0f},
|
pingPayload: []byte{0x0f, 0x0f, 0x0f, 0x0f},
|
||||||
keyLayout: "US",
|
keyLayout: "US",
|
||||||
scriptPath: "",
|
scriptPath: "",
|
||||||
|
@ -85,7 +87,7 @@ func NewHIDRecon(s *session.Session) *HIDRecon {
|
||||||
sniff := session.NewModuleHandler("hid.sniff ADDRESS", `(?i)^hid\.sniff ([a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}|clear)$`,
|
sniff := session.NewModuleHandler("hid.sniff ADDRESS", `(?i)^hid\.sniff ([a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}|clear)$`,
|
||||||
"Start sniffing a specific ADDRESS in order to collect payloads, use 'clear' to stop collecting.",
|
"Start sniffing a specific ADDRESS in order to collect payloads, use 'clear' to stop collecting.",
|
||||||
func(args []string) error {
|
func(args []string) error {
|
||||||
return mod.setSniffMode(args[0])
|
return mod.setSniffMode(args[0], false)
|
||||||
})
|
})
|
||||||
|
|
||||||
sniff.Complete("hid.sniff", s.HIDCompleter)
|
sniff.Complete("hid.sniff", s.HIDCompleter)
|
||||||
|
|
|
@ -18,7 +18,7 @@ func (mod *HIDRecon) isInjecting() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mod *HIDRecon) setInjectionMode(address string) error {
|
func (mod *HIDRecon) setInjectionMode(address string) error {
|
||||||
if err := mod.setSniffMode(address); err != nil {
|
if err := mod.setSniffMode(address, true); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if address == "clear" {
|
} else if address == "clear" {
|
||||||
mod.inInjectMode = false
|
mod.inInjectMode = false
|
||||||
|
|
|
@ -42,11 +42,13 @@ func (mod *HIDRecon) onDeviceDetected(buf []byte) {
|
||||||
if isNew, dev := mod.Session.HID.AddIfNew(addr, mod.channel, payload); isNew {
|
if isNew, dev := mod.Session.HID.AddIfNew(addr, mod.channel, payload); isNew {
|
||||||
// sniff for a while in order to detect the device type
|
// sniff for a while in order to detect the device type
|
||||||
go func() {
|
go func() {
|
||||||
if err := mod.setSniffMode(dev.Address); err == nil {
|
prevSilent := mod.sniffSilent
|
||||||
|
|
||||||
|
if err := mod.setSniffMode(dev.Address, true); err == nil {
|
||||||
mod.Debug("detecting device type ...")
|
mod.Debug("detecting device type ...")
|
||||||
defer func() {
|
defer func() {
|
||||||
mod.sniffLock.Unlock()
|
mod.sniffLock.Unlock()
|
||||||
mod.setSniffMode("clear")
|
mod.setSniffMode("clear", prevSilent)
|
||||||
}()
|
}()
|
||||||
// make sure nobody can sniff to another
|
// make sure nobody can sniff to another
|
||||||
// address until we're not done here...
|
// address until we're not done here...
|
||||||
|
|
|
@ -3,12 +3,15 @@
|
||||||
package hid
|
package hid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bettercap/bettercap/network"
|
"github.com/bettercap/bettercap/network"
|
||||||
|
|
||||||
"github.com/bettercap/nrf24"
|
"github.com/bettercap/nrf24"
|
||||||
|
|
||||||
|
"github.com/evilsocket/islazy/str"
|
||||||
"github.com/evilsocket/islazy/tui"
|
"github.com/evilsocket/islazy/tui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,7 +19,7 @@ func (mod *HIDRecon) isSniffing() bool {
|
||||||
return mod.sniffAddrRaw != nil
|
return mod.sniffAddrRaw != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mod *HIDRecon) setSniffMode(mode string) error {
|
func (mod *HIDRecon) setSniffMode(mode string, silent bool) error {
|
||||||
if !mod.Running() {
|
if !mod.Running() {
|
||||||
return fmt.Errorf("please turn hid.recon on")
|
return fmt.Errorf("please turn hid.recon on")
|
||||||
}
|
}
|
||||||
|
@ -24,11 +27,13 @@ func (mod *HIDRecon) setSniffMode(mode string) error {
|
||||||
mod.sniffLock.Lock()
|
mod.sniffLock.Lock()
|
||||||
defer mod.sniffLock.Unlock()
|
defer mod.sniffLock.Unlock()
|
||||||
|
|
||||||
|
mod.sniffSilent = silent
|
||||||
mod.inSniffMode = false
|
mod.inSniffMode = false
|
||||||
if mode == "clear" {
|
if mode == "clear" {
|
||||||
mod.Debug("restoring recon mode")
|
mod.Debug("restoring recon mode")
|
||||||
mod.sniffAddrRaw = nil
|
mod.sniffAddrRaw = nil
|
||||||
mod.sniffAddr = ""
|
mod.sniffAddr = ""
|
||||||
|
mod.sniffSilent = true
|
||||||
} else {
|
} else {
|
||||||
if err, raw := nrf24.ConvertAddress(mode); err != nil {
|
if err, raw := nrf24.ConvertAddress(mode); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -73,13 +78,20 @@ func (mod *HIDRecon) doPing() {
|
||||||
func (mod *HIDRecon) onSniffedBuffer(buf []byte) {
|
func (mod *HIDRecon) onSniffedBuffer(buf []byte) {
|
||||||
if sz := len(buf); sz > 0 && buf[0] == 0x00 {
|
if sz := len(buf); sz > 0 && buf[0] == 0x00 {
|
||||||
buf = buf[1:]
|
buf = buf[1:]
|
||||||
mod.Debug("sniffed payload %x for %s", buf, mod.sniffAddr)
|
lf := mod.Info
|
||||||
|
if mod.sniffSilent {
|
||||||
|
lf = mod.Debug
|
||||||
|
}
|
||||||
|
lf("payload for %s : %s", tui.Bold(mod.sniffAddr), str.Trim(hex.Dump(buf)))
|
||||||
if dev, found := mod.Session.HID.Get(mod.sniffAddr); found {
|
if dev, found := mod.Session.HID.Get(mod.sniffAddr); found {
|
||||||
dev.LastSeen = time.Now()
|
dev.LastSeen = time.Now()
|
||||||
dev.AddPayload(buf)
|
dev.AddPayload(buf)
|
||||||
dev.AddChannel(mod.channel)
|
dev.AddChannel(mod.channel)
|
||||||
} else {
|
} else {
|
||||||
mod.Warning("got a payload for unknown device %s", mod.sniffAddr)
|
if lf = mod.Warning; mod.sniffSilent == false {
|
||||||
|
lf = mod.Debug
|
||||||
|
}
|
||||||
|
lf("got a payload for unknown device %s", mod.sniffAddr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue