Beacon Packet에서 SSID 추출
Packet 구조
Monitor mode를 통해 얻은 Beacon 패킷의 구조는 아래와 같다.

각각의 프레임이 담고 있는 정보를 대강 정리해 보면,
RadioTap
- 무선 신호의 주파수
- 신호 세기 정보 (dbm)
- 안테나 정보
- Etc…
802.11 Beacon Frame
- Type 정보 ( beacon인지 probe인지 등…)
- Source, Destination Mac address 정보
- Etc…
802.11 Wireless LAN
- 802.11b/g/n 등 지원가능한 전송방식 종류
- 암호화 종류 및 지원 여부
- SSID
- channel
- 지원 가능한 속도 (Mbit/s)
- WPS 지원 여부
- Etc…
SSID 추출
802.11 Wireless LAN에서 빨간색 네모 표시된 “53 41 4d 53 55 4e 47” 부분이 SSID 이다. (위치: 74byte)
그리고 앞에 파란색으로 네모 표시된 “07“은 SSID 의 길이 정보로 해당 길이 만큼 SSID 정보를 읽으면 된다. (위치: 73byte)
Source Code
간단한 SSID 출력 프로그램
#include <cstdio> #include <pcap.h> enum{CMD, INF}; void procPacket(u_char *arg, const struct pcap_pkthdr *h, const u_char *p) { int len; len = 0; u_int8_t ssid_len = *(p+73); // SSID length 정보의 위치 for(int i=0; i < ssid_len; i++){ // SSID length만큼 읽어드림 printf("%c", *(p+74+i)); } printf("\n"); return; } int main(int argc, char *argv[]){ pcap_t *handle; char *dev = argv[INF]; char errbuf[PCAP_ERRBUF_SIZE]; struct bpf_program fp; handle = pcap_open_live(dev, BUFSIZ, 0, 100, errbuf); if(NULL == handle){ printf("%s", errbuf); return 1; } if(-1 == pcap_compile(handle, &fp, "type mgt subtype beacon",0,PCAP_NETMASK_UNKNOWN)){ printf("compile error\n"); return 1; } if (pcap_setfilter(handle, &fp) == -1){ printf("setfilter error\n"); return 1; } pcap_loop(handle, -1, procPacket, NULL); }
사용된 함수별 참고 포스트