/*th a FIN flag and pass it through a raw socket. * * Thamer Al-Herbish shadows@whitefang.com */ #include #include #include #include #include #include #include #if defined(LINUX) #include #include #else #include #include #endif #include #include #include #include int main(int argc,char *argv[]) { unsigned char packet[ #if !defined(LINUX) sizeof(struct ip) + #else /* LINUX */ sizeof(struct iphdr) + #endif /* LINUX */ sizeof(struct tcphdr)]; struct sockaddr_in mysocket; unsigned short sport, dport; struct in_addr saddr, daddr; struct tcphdr *tcp; unsigned long seq, ack; int sockd, on = 1; if(argc < 5) { fprintf(stderr,"usage: %s source_port source_address dest_port dest_address\n", argv[0]); exit(1); } sport = (unsigned short)atoi(argv[1]); saddr.s_addr = inet_addr(argv[2]); dport = (unsigned short)atoi(argv[3]); daddr.s_addr = inet_addr(argv[4]); if((sockd = socket(AF_INET,SOCK_RAW,IPPROTO_RAW)) < 0) { perror("socket"); exit(1); } if(setsockopt(sockd,IPPROTO_IP,IP_HDRINCL,(char *)&on,sizeof(on)) < 0) { perror("setsockopt"); exit(1); } /* Very bad random sequence number generator */ srand(getpid()); seq = rand()%time(NULL); ack = rand()%time(NULL); ip_gen(packet,IPPROTO_TCP,saddr,daddr,sizeof(packet)); #if !defined(LINUX) tcp = (struct tcphdr *)(packet + sizeof(struct ip)); tcp_gen((char *)tcp,sport,dport,seq,ack); #if !defined(SOLARIS_CKSUM_BUG) tcp->th_sum = trans_check(IPPROTO_TCP,(char *)tcp, sizeof(struct tcphdr), saddr, daddr); #else /* SOLARIS_CKSUM_BUG */ tcp->th_sum = sizeof(struct tcphdr); #endif /* SOLARIS_CKSUM_BUG */ #else /* LINUX */ tcp = (struct tcphdr *)(packet + sizeof(struct iphdr)); tcp_gen((char *)tcp,sport,dport,seq,ack); #if !defined(SOLARIS_CKSUM_BUG) tcp->check = trans_check(IPPROTO_TCP,(char *)tcp, sizeof(struct tcphdr), saddr, daddr); #else /* SOLARIS_CKSUM_BUG */ tcp->check = sizeof(struct tcphdr); #endif /* SOLARIS_CKSUM_BUG */ #endif /* LINUX */ memset(&mysocket,'\0',sizeof(mysocket)); mysocket.sin_family = AF_INET; mysocket.sin_port = htons(dport); mysocket.sin_addr = daddr; if(sendto(sockd,&packet,sizeof(packet),0x0,(struct sockaddr *)&mysocket, sizeof(mysocket)) != sizeof(packet)) { perror("sendto"); exit(1); } exit(0); }