Develop
[C++] LibTins를 통한 802.11 Packet Sniff
Dork94
2017. 12. 1. 11:32
안녕하세요.
오늘은 LibTins를 통해 암호화된 패킷이 아닌 평문 패킷(OPEN WIFI)에 대한 Sniff 예제를 살펴 보도록 하겠습니다.
#include <iostream> #include <tins/tins.h> #include "printdata.h" using namespace Tins; using namespace std; void usage(); bool chkArgc(int argc); bool foo(PDU& packet) { const TCP& tcp = packet.rfind_pdu<TCP>(); // const TCP* tcp1 = packet.find_pdu<TCP>(); reference find // if(tcp.dport()!=80&&tcp.sport()!=80) return true; //parsing HTTP Packet cout<<"TCP Source Port : "<<tcp.sport()<<endl; cout<<"TCP Destination Port : " << tcp.dport()<<endl; const RawPDU& rawPDU = packet.rfind_pdu<RawPDU>(); if(rawPDU.size()>0){ printByHexData((uint8_t*) rawPDU.payload().data(),rawPDU.size()); cout<<"Payload Size : "<<rawPDU.size()<<endl; } return true; } int main(int argc, char* argv[]) { if(!chkArgc(argc)) exit(1); //init 802.11 Sniffer by Promiscuous Modes SnifferConfiguration config; config.set_filter("port 80"); config.set_promisc_mode(true); Sniffer sniffer(argv[1],config); sniffer.sniff_loop(&foo); return 0; } void usage() { cout<<"Usage : ./IamU <Monitor mode Interface> <Channel>"<<endl; } bool chkArgc(int argc) { if(argc!=3) { usage(); return false; } return true; }
위와 같이 간단하게 패킷 캡처를 진행할 수 있습니다. 암호화된 패킷에 대해서 이전포스팅에 포스팅을 해 두었으니, 필요하신 분은 참조해주시면 됩니다.
감사합니다.