mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
The FCS-at-end flag was being ignored in RadioTap. Added beacon display example.
This commit is contained in:
@@ -1,26 +1,25 @@
|
||||
CXX=@CXX@
|
||||
CXXFLAGS=-c -Wall @CXXFLAGS@
|
||||
LDFLAGS=-lpcap -ltins -lpthread
|
||||
SOURCES=arpspoofing.cpp portscan.cpp
|
||||
CXXFLAGS=-Wall @CXXFLAGS@
|
||||
LDFLAGS=-ltins
|
||||
EXECUTABLES=arpspoof portscan traceroute beacon_display
|
||||
|
||||
OBJECTS=$(SOURCES:.cpp=.o)
|
||||
INCLUDE=
|
||||
EXECUTABLES=arpspoof portscan traceroute
|
||||
|
||||
all: $(SOURCES) $(EXECUTABLES)
|
||||
all: $(EXECUTABLES)
|
||||
|
||||
compile: $(OBJECTS)
|
||||
|
||||
recompile: clean all
|
||||
|
||||
arpspoof: arpspoofing.o
|
||||
$(CXX) arpspoofing.o $(LDFLAGS) -o arpspoof
|
||||
arpspoof:
|
||||
$(CXX) arpspoofing.cpp -o arpspoofing $(CXXFLAGS) $(LDFLAGS)
|
||||
|
||||
portscan: portscan.o
|
||||
$(CXX) portscan.o $(LDFLAGS) -o portscan
|
||||
beacon_display:
|
||||
$(CXX) beacon_display.cpp -o beacon_display $(CXXFLAGS) $(LDFLAGS)
|
||||
|
||||
portscan:
|
||||
$(CXX) portscan.cpp -o portscan $(CXXFLAGS) $(LDFLAGS) -lpthread
|
||||
|
||||
traceroute:
|
||||
$(CXX) traceroute.cpp -o traceroute -std=c++0x -Wall $(LDFLAGS)
|
||||
$(CXX) traceroute.cpp -o traceroute -std=c++0x $(CXXFLAGS) $(LDFLAGS)
|
||||
|
||||
.cpp.o:
|
||||
$(CXX) $(CXXFLAGS) $(INCLUDE) $< -o $@
|
||||
|
||||
49
examples/beacon_display.cpp
Normal file
49
examples/beacon_display.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <tins/tins.h>
|
||||
|
||||
using namespace Tins;
|
||||
|
||||
class BeaconSniffer {
|
||||
public:
|
||||
void run(const std::string &iface);
|
||||
private:
|
||||
typedef Dot11::address_type address_type;
|
||||
typedef std::map<address_type, std::string> ssids_type;
|
||||
|
||||
bool callback(PDU &pdu);
|
||||
|
||||
ssids_type ssids;
|
||||
};
|
||||
|
||||
void BeaconSniffer::run(const std::string &iface) {
|
||||
Sniffer sniffer(iface, 1500, true, "type mgt subtype beacon");
|
||||
sniffer.sniff_loop(make_sniffer_handler(this, &BeaconSniffer::callback));
|
||||
}
|
||||
|
||||
bool BeaconSniffer::callback(PDU &pdu) {
|
||||
Dot11Beacon *beacon = pdu.find_pdu<Dot11Beacon>();
|
||||
if(beacon && !beacon->from_ds() && !beacon->to_ds()) {
|
||||
address_type addr = beacon->addr2();
|
||||
ssids_type::iterator it = ssids.find(addr);
|
||||
if(it == ssids.end()) {
|
||||
try {
|
||||
it = ssids.insert(std::make_pair(addr, beacon->ssid())).first;
|
||||
std::cout << it->first << " - " << it->second << std::endl;
|
||||
}
|
||||
catch(std::runtime_error&) {
|
||||
// no ssid, just ignore it.
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::string interface = "wlan0";
|
||||
if(argc == 2)
|
||||
interface = argv[1];
|
||||
BeaconSniffer sniffer;
|
||||
sniffer.run(interface);
|
||||
}
|
||||
@@ -189,7 +189,7 @@ namespace Tins {
|
||||
T *find_pdu(PDUType type = T::pdu_flag) {
|
||||
PDU *pdu = this;
|
||||
while(pdu) {
|
||||
if(pdu->pdu_type() == type)
|
||||
if(pdu->matches_flag(type))
|
||||
return static_cast<T*>(pdu);
|
||||
pdu = pdu->inner_pdu();
|
||||
}
|
||||
|
||||
@@ -115,7 +115,14 @@ Tins::RadioTap::RadioTap(const uint8_t *buffer, uint32_t total_sz)
|
||||
buffer += sizeof(_rx_flags);
|
||||
total_sz -= sizeof(_rx_flags);
|
||||
}
|
||||
if(total_sz)
|
||||
if((flags() & FCS) != 0) {
|
||||
if(total_sz <= 4)
|
||||
throw std::runtime_error(msg);
|
||||
else {
|
||||
total_sz -= sizeof(uint32_t);
|
||||
}
|
||||
}
|
||||
if(total_sz)
|
||||
inner_pdu(Dot11::from_bytes(buffer, total_sz));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user