[C++] LibTins를 통한 802.11 Decrypt(무선패킷 복호화 하기)
오늘은 802.11 패킷을 LibTIns를 통해 복호화 하는 간단한 예제를 알아보도록 하겠습니다.
LibTins에 대한 기초적인 예시가 많이 존재하지 않으므로, 알아가는것을 차츰차츰 포스팅 하도록 하겠습니다.
#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);
auto decrypt_proxy = Crypto::make_wpa2_decrypter_proxy(&foo);
decrypt_proxy.decrypter().add_ap_data("dorkdork","HanBin");
return 0;
}
void usage()
{
cout<<"Usage : ./IamU <Monitor mode Interface> <Channel>"<<endl;
}
bool chkArgc(int argc)
{
if(argc!=3)
{
usage();
return false;
}
return true;
}
먼저 Sniffer객체를 이용해 Sniff할 장치를 지정하고, config 객체를 이용해 필터 및 설정을 할 수 있습니다.
그리고 decrypt_proxy 객체를 이용해 패킷이 수신되면 Decrypt를 진행합니다.
이때, 객체의 해당 Password(dorkdork) 및 SSID(HanBin)을 주어야 정상적으로 Decrypt가 진행되므로 알고 있어야 합니다(LibTIns는 패스워드 크래킹을 지원하지 않습니다).
패킷이 수신되고 정상적으로 패킷이 복호화가 되면 지정해준 함수(foo)로 가서 원하는 프로세스를 동작 시킬 수 있으며, 이때 패킷은 PDU의 형태로 지정됩니다.
그리고 foo함수에서 보시는 바와 같이 간단하게 패킷을 parsing하여 이용할 수 있습니다.
위의 예제는 80번 포트의 패킷을 수신(Decrypt)하여 포트를 출력하고 뒤의 데이터가 있다면 해당 데이터를 출력 하는 프로그램입니다.
위의 printByHexData는 제가 작성한 외부 함수(printdata.h)이므로 혼동없으시길 바랍니다. 해당 함수는 아래의 포스팅을 참조하시길 바랍니다.
2017/09/22 - [Develop] - 16진수로 값 출력 및 mac address 출력하기 (C++)