티스토리 뷰
<main.cpp>
#include "packet.h"
char *packet = "\x00\x50\x56\xef\x84\x60\x00\x0c\x29\x19\xdc\xd4\x08\x00\x45\x00\x01\x76\xe9\x63\x40\x00\x40\x06\x83\xf8\xc0\xa8\x38\x81\xaf\xd5\x23\x27\x9c\x5e\x00\x50\x47\x44\x67\x41\x5a\x26\x4a\xd2\x50\x18\x72\x10\xcd\x8e\x00\x00\x47\x45\x54\x20\x2f\x20\x48\x54\x54\x50\x2f\x31\x2e\x31\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x74\x65\x73\x74\x2e\x67\x69\x6c\x67\x69\x6c\x2e\x6e\x65\x74\x0d\x0a\x55\x73\x65\x72\x2d\x41\x67\x65\x6e\x74\x3a\x20\x4d\x6f\x7a\x69\x6c\x6c\x61\x2f\x35\x2e\x30\x20\x28\x58\x31\x31\x3b\x20\x55\x62\x75\x6e\x74\x75\x3b\x20\x4c\x69\x6e\x75\x78\x20\x78\x38\x36\x5f\x36\x34\x3b\x20\x72\x76\x3a\x36\x35\x2e\x30\x29\x20\x47\x65\x63\x6b\x6f\x2f\x32\x30\x31\x30\x30\x31\x30\x31\x20\x46\x69\x72\x65\x66\x6f\x78\x2f\x36\x35\x2e\x30\x0d\x0a\x41\x63\x63\x65\x70\x74\x3a\x20\x74\x65\x78\x74\x2f\x68\x74\x6d\x6c\x2c\x61\x70\x70\x6c\x69\x63\x61\x74\x69\x6f\x6e\x2f\x78\x68\x74\x6d\x6c\x2b\x78\x6d\x6c\x2c\x61\x70\x70\x6c\x69\x63\x61\x74\x69\x6f\x6e\x2f\x78\x6d\x6c\x3b\x71\x3d\x30\x2e\x39\x2c\x69\x6d\x61\x67\x65\x2f\x77\x65\x62\x70\x2c\x2a\x2f\x2a\x3b\x71\x3d\x30\x2e\x38\x0d\x0a\x41\x63\x63\x65\x70\x74\x2d\x4c\x61\x6e\x67\x75\x61\x67\x65\x3a\x20\x65\x6e\x2d\x55\x53\x2c\x65\x6e\x3b\x71\x3d\x30\x2e\x35\x0d\x0a\x41\x63\x63\x65\x70\x74\x2d\x45\x6e\x63\x6f\x64\x69\x6e\x67\x3a\x20\x67\x7a\x69\x70\x2c\x20\x64\x65\x66\x6c\x61\x74\x65\x0d\x0a\x43\x6f\x6e\x6e\x65\x63\x74\x69\x6f\x6e\x3a\x20\x6b\x65\x65\x70\x2d\x61\x6c\x69\x76\x65\x0d\x0a\x55\x70\x67\x72\x61\x64\x65\x2d\x49\x6e\x73\x65\x63\x75\x72\x65\x2d\x52\x65\x71\x75\x65\x73\x74\x73\x3a\x20\x31\x0d\x0a\x0d\x0a";
int main() {
macprint(packet);
ipprint(packet);
tcpprint(packet);
httpprint(packet);
}
<packet.cpp>
#include "packet.h"
void ipprint(char *p)
{
uint8_t dst_ip[4] = {p[30], p[31], p[32], p[33]};
printf("dip: %d.%d.%d.%d\n", dst_ip[0],dst_ip[1],dst_ip[2],dst_ip[3]);
uint8_t src_ip[4] ={p[26], p[27], p[28], p[29]};
printf("sip: %d.%d.%d.%d\n", src_ip[0],src_ip[1],src_ip[2],src_ip[3]);
}
void macprint(char *p)
{
uint8_t dst_mac[6] = {p[0],p[1],p[2],p[3],p[4],p[5]};
printf("dmac : %02X: %X: %02X: %X: %X: %X\n", dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4],dst_mac[5]);
uint8_t src_mac[6] = { p[6],p[7],p[8],p[9],p[10],p[11] };
printf("smac : %02X: %02X: %02X: %X: %X: %X\n", src_mac[0], src_mac[1], src_mac[2], src_mac[3], src_mac[4], src_mac[5]);
}
void tcpprint(char *p)
{
uint8_t dst_port[2] = {p[36], p[37]};
printf("dip: %d\n", (dst_port[0]<<8)+dst_port[1]);
uint8_t src_port[2] ={p[34], p[35]};
printf("sip: %d\n", (src_port[0]<<8)+src_port[1]);
}
void httpprint(char *p)
{
uint8_t http[16] = {p[54],p[55],p[56],p[57],p[58],p[59],p[60],p[61],p[62],p[63],p[64],p[65],p[66],p[67],p[68],p[69]};
printf("http : %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", http[0], http[1], http[2], http[3], http[4], http[5], http[6], http[7], http[8], http[9], http[10], http[11], http[12], http[13], http[14], http[15]);
}
<packet.h>
#include <iostream>
#include <string.h>
using namespace std;
#include <stdio.h>
#include <stdint.h>
void ipprint(char *p);
void macprint(char *p);
void tcpprint(char *p);
void httpprint(char *p);
<test.pro>
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp \
packet.cpp
HEADERS += \
packet.h \
packet.h
고정된 패킷을 각각 mac, ip, tcp, http로 출력했습니다.
'네트워크 공부 > 공부' 카테고리의 다른 글
aireplay-ng를 사용한 deauth attack (1) | 2022.07.21 |
---|---|
무선 네트워트 패킷 수집 (2) | 2022.07.21 |
cain abel 툴을 이용한 arp spoofing 실습 방법 (3) | 2020.07.28 |
OSI 7계층 (쉽게 외워볼까..?) (5) | 2019.06.24 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday