동일한 LAN에 3 개의 랩톱을 연결했습니다.무차별 모드 사용
무릎-1 : 192.168.1.2
무릎-2 : 192.168.1.3
무릎-3 : 192.168.1.4
내가 서버로 무릎-1과는 9333 포트에서 수신 대기했다. 랩 -2는 클라이언트 역할을합니다. netcat을 사용하여 lap2에서 lap1로 데이터를 보냈습니다. lap1에서 pcap을 사용하여 패킷을 캡처 할 수 있습니다. sudo ifconfig eth0 promisc
을 사용하여 무차별 모드를 켰습니다. 또한 pcap_live_open
방법에서는 무차별 모드 플래그를 설정했습니다.
그럼 난 무차별 모드를 해제하고 또한 pcap_live_open
기능. 여전히 패킷을 캡처 할 수 있습니다.
무차별 모드에 대해 봤 거든 장치가 무차별 모드로 인터페이스를 열면 그 네트워크에 연결된 모든 패킷을 캡처 할 수 있다고 추측 할 수 있습니다.
이렇게 이것을 고려해 보면, 저는 랩톱 3을 서버로 사용하고 랩 2는 클라이언트로 남아 있습니다. 위와 같은 절차를 따랐습니다. 나는 랩 - 1에서 pcap 실행 파일을 실행하여 랩 - 3과 랩 -2 사이에서 전송 된 패킷을 캡쳐 할 수 있지만 랩 - 1에서 실행중인 pcap은 무차별 모드로 그렇게 할 수 없다. 모든 3 랩은 동일한 네트워크에 연결됩니다.
누구나 간단한 시나리오에서 무차별 모드를 사용할 수 있습니까?
이것은 내 pcap 코드입니다. 29988은 9333의 반대 (스왑)입니다. 단지 찾고 있습니다.
#include <pcap/pcap.h>
#include <stdint.h>
const u_char *packet;
int main()
{
char *dev = "eth0";
pcap_t *handle;
int j=0;
char errbuf[PCAP_ERRBUF_SIZE];
struct bpf_program fp;
bpf_u_int32 mask;
bpf_u_int32 net;
struct pcap_pkthdr header;
uint8_t *ip_header_len;
uint16_t ip_header_len_val;
uint16_t *port;
/* Find the properties for the device */
while (pcap_lookupnet(dev, &net, &mask, errbuf) == -1) {
printf("Couldn't get netmask for device %s: %s\n", dev, errbuf);
net = 0;
mask = 0;
}
printf("lookedup pcap device: %s\n", dev);
/* Open the session in promiscuous mode */
handle = pcap_open_live(dev, BUFSIZ,1,0, errbuf);
if (handle == NULL) {
printf("Couldn't open device %s: %s\n", dev, errbuf);
}
/* Compile and apply the filter */
if (pcap_compile(handle, &fp, filter_exp, 0, net) == -1) {
printf("Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(handle));
pcap_close(handle);
}
/* if (pcap_setfilter(handle, &fp) == -1) {
printf("Couldn't install filter %s: %s", filter_exp, pcap_geterr(handle));
return(-1);
}
*/
/* Grab a packet */
while ((packet = pcap_next(handle, &header)) != NULL)
{
uint16_t *data_size;
uint16_t size,total_len_val,tcp_header_len_val;
char tdata[128];
uint8_t *data,*tcp_header_len;
uint16_t *total_len;
//ip_proto = (uint8_t *)&packet[9];
ip_header_len = (uint8_t *)&packet[14];
ip_header_len_val = (*ip_header_len) & 0x0F;
ip_header_len_val = ip_header_len_val*4;
// printf("IP header len val:%d\n",ip_header_len_val);
port = (uint16_t *)&packet[14+ip_header_len_val+2];
//printf("port:%d\n",*port);
total_len = (uint16_t *)&packet[14+2];
total_len_val = ((*total_len) >> 8) & 0x00FF;
total_len_val = total_len_val + (((*total_len) << 8) & 0xFF00);
//total_len_val=*total_len;
// printf("tot len val:%d\n",total_len_val);
tcp_header_len = (uint8_t *)&packet[14+ip_header_len_val+12];
tcp_header_len_val = (*tcp_header_len) & 0xF0;
tcp_header_len_val = tcp_header_len_val>>4;
tcp_header_len_val = tcp_header_len_val * 4;
// printf("tcp header len val:%d\n",tcp_header_len_val);
size = (total_len_val- ip_header_len_val) - tcp_header_len_val;
data = (uint8_t *)&packet[14+ip_header_len_val+tcp_header_len_val];
memset(tdata,0,128);
mempcpy(tdata,data,size);
tdata[size]='\0';
if((*port)==29988)
{
printf("Data Packet:%s\n",tdata);
}
}
}
어떻게 연결 되나요? 라우터가있는 경우 올바른 포트로만 패킷을 보낼 수 있으므로 캡처 할 패킷이 lap1에 도착하지 않습니다. 라우터를 통해 –
예. 어떻게 테스트 할 수 있을까요? – user3550166