Skip to content

Commit

Permalink
Correct detection of proper ICMP/6 replies, make isn from replay mode…
Browse files Browse the repository at this point in the history
… fix more general.
  • Loading branch information
John E committed Jun 4, 2012
1 parent 1bb8b80 commit b9c6722
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions constants.h
Expand Up @@ -44,6 +44,7 @@
*/
#define MINIMUM_PACKET_SIZE 68
#define DEFAULT_SRCPORT 44129
#define ICMP_ID 34254

/* Save time typing/screen real estate. */
#define SIZEOF_ICMP6 sizeof( struct icmp6_hdr )
Expand Down
4 changes: 2 additions & 2 deletions packets.c
Expand Up @@ -129,7 +129,7 @@ void *append_icmp_ping( void *buf, unsigned short payload_length )
icmph->icmp_type = ICMP_ECHO;
icmph->icmp_code = 0;
icmph->icmp_cksum = 0;
icmph->icmp_id = htons( (unsigned short) rand() );
icmph->icmp_id = htons( ICMP_ID );
icmph->icmp_seq = htons( 1 );
memset( (char *) icmph + SIZEOF_PING, 0x01, payload_length );

Expand All @@ -143,7 +143,7 @@ void *append_icmp6_ping( void *buf, unsigned short payload_length )
icmp6h->icmp6_type = ICMP6_ECHO_REQUEST;
icmp6h->icmp6_code = 0;
icmp6h->icmp6_cksum = 0;
icmp6h->icmp6_id = htons( (unsigned short) rand() );
icmp6h->icmp6_id = htons( ICMP_ID );
icmp6h->icmp6_seq = htons( 1 );
memset( (char *) icmp6h + SIZEOF_ICMP6, 0x01, payload_length );

Expand Down
12 changes: 6 additions & 6 deletions synfrag.c
Expand Up @@ -684,13 +684,13 @@ int get_isn_for_replay( char *interface, char *srcip, char *dstip, unsigned shor
tcph = (struct tcphdr *) print_a_packet( (char *) packet_buf, r, IPPROTO_TCP );
if ( !tcph ) return 0;
printf( "\nLooks good, sending replay.\n\n" );
*isn = ntohl( tcph->th_seq );
*isn = tcph->th_seq;
*srcport = ntohs( tcph->th_sport );
free( packet_buf );
return 1;
}

int check_received_packet( int buf_len, char *packet_buf, enum TEST_TYPE test_type, unsigned short srcport ) {
int check_received_packet( int buf_len, char *packet_buf, enum TEST_TYPE test_type ) {
struct ether_header *received_packet_data = (struct ether_header *) packet_buf;
struct tcphdr *tcph;
struct icmp *icmph;
Expand All @@ -701,11 +701,11 @@ int check_received_packet( int buf_len, char *packet_buf, enum TEST_TYPE test_ty
if ( IS_TEST_IPV4( test_type ) && IS_TEST_ICMP( test_type ) ) {
icmph = (struct icmp *) print_a_packet( (char *) received_packet_data, buf_len, IPPROTO_ICMP );
if ( !icmph ) return 0;
if ( icmph->icmp_type == ICMP_ECHOREPLY && icmph->icmp_id == htons( srcport ) ) return 1;
if ( icmph->icmp_type == ICMP_ECHOREPLY && icmph->icmp_id == htons( ICMP_ID ) ) return 1;
} else if ( IS_TEST_IPV6( test_type ) && IS_TEST_ICMP( test_type ) ) {
icmp6h = (struct icmp6_hdr *) print_a_packet( (char *) received_packet_data, buf_len, IPPROTO_ICMPV6 );
if ( !icmp6h ) return 0;
if ( icmp6h->icmp6_type == ICMP6_ECHO_REPLY && icmp6h->icmp6_id == htons( srcport ) ) return 1;
if ( icmp6h->icmp6_type == ICMP6_ECHO_REPLY && icmp6h->icmp6_id == htons( ICMP_ID ) ) return 1;
} else { /* Assume pcap picked the right address family for our packet. */
tcph = (struct tcphdr *) print_a_packet( (char *) received_packet_data, buf_len, IPPROTO_TCP );
if ( !tcph ) return 0;
Expand Down Expand Up @@ -1142,7 +1142,7 @@ void do_ipv6_frag_nomore_tcp( char *interface, char *srcip, char *dstip, char *s
next = append_ethernet( ethh, srcmac, dstmac, ETHERTYPE_IPV6 );
next = append_ipv6( next, srcip, dstip, IPPROTO_FRAGMENT, SIZEOF_FRAG + SIZEOF_TCP );
next = append_frag_last( next, IPPROTO_TCP, 0, fragid );
append_tcp_syn( next, srcport, dstport, htonl( isn ) );
append_tcp_syn( next, srcport, dstport, isn );
calc_checksum( ip6h, IPPROTO_TCP, SIZEOF_TCP );

synfrag_send( ethh, packet_size );
Expand Down Expand Up @@ -1457,7 +1457,7 @@ int main( int argc, char **argv )

r = harvest_pcap_listener( &packet_buf );
if ( !r ) errx( 1, "Test failed, no response before time out (%li seconds).\n", receive_timeout );
if ( check_received_packet( r, packet_buf, test_type, srcport ) ) {
if ( check_received_packet( r, packet_buf, test_type ) ) {
printf( "\nTest was successful.\n" );
free( packet_buf );
return 0;
Expand Down

0 comments on commit b9c6722

Please sign in to comment.