misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
evilsocket 2018-03-13 15:22:03 +01:00
parent d6b9aa7b7f
commit 38d08e4db6
No known key found for this signature in database
GPG key ID: 1564D7F30393A456

View file

@ -11,16 +11,32 @@ import (
"github.com/google/gopacket/layers" "github.com/google/gopacket/layers"
) )
func NewDot11Beacon(bssid net.HardwareAddr, ssid string, seq uint16) (error, []byte) { type Dot11EncryptionType int
const (
Dot11Open Dot11EncryptionType = iota
Dot11Wep
Dot11WpaTKIP
Dot11WpaAES
)
type Dot11BeaconConfig struct {
SSID string
BSSID net.HardwareAddr
Channel int
Encryption Dot11EncryptionType
}
func NewDot11Beacon(conf Dot11BeaconConfig) (error, []byte) {
// TODO: still very incomplete // TODO: still very incomplete
return packets.Serialize( return packets.Serialize(
&layers.RadioTap{}, &layers.RadioTap{},
&layers.Dot11{ &layers.Dot11{
Address1: network.BroadcastHw, Address1: network.BroadcastHw,
Address2: bssid, Address2: conf.BSSID,
Address3: bssid, Address3: conf.BSSID,
Type: layers.Dot11TypeMgmtBeacon, Type: layers.Dot11TypeMgmtBeacon,
SequenceNumber: seq, // not sure this needs to be a specific value SequenceNumber: 0, // not sure this needs to be a specific value
}, },
&layers.Dot11MgmtBeacon{ &layers.Dot11MgmtBeacon{
Timestamp: uint64(time.Now().Second()), // not sure Timestamp: uint64(time.Now().Second()), // not sure
@ -29,8 +45,8 @@ func NewDot11Beacon(bssid net.HardwareAddr, ssid string, seq uint16) (error, []b
}, },
&layers.Dot11InformationElement{ &layers.Dot11InformationElement{
ID: layers.Dot11InformationElementIDSSID, ID: layers.Dot11InformationElementIDSSID,
Length: uint8(len(ssid) & 0xff), Length: uint8(len(conf.SSID) & 0xff),
Info: []byte(ssid), Info: []byte(conf.SSID),
}, },
// TODO: Rates n stuff ... // TODO: Rates n stuff ...
&layers.Dot11InformationElement{ &layers.Dot11InformationElement{
@ -50,7 +66,14 @@ func (w *WiFiModule) sendBeaconPacket(counter int) {
w.writes.Add(1) w.writes.Add(1)
defer w.writes.Done() defer w.writes.Done()
if err, pkt := NewDot11Beacon(w.Session.Interface.HW, "Prova", uint16(counter)); err != nil { conf := Dot11BeaconConfig{
SSID: "Prova",
BSSID: w.Session.Interface.HW,
Channel: 1,
Encryption: Dot11Open,
}
if err, pkt := NewDot11Beacon(conf); err != nil {
log.Error("Could not create beacon packet: %s", err) log.Error("Could not create beacon packet: %s", err)
} else { } else {
w.injectPacket(pkt) w.injectPacket(pkt)