[Javanetsim-cvs] IceScan/icesockets ice_rand.h, NONE, 1.1 crawsocket.h, 1.2, 1.3 iceregex.h, 1.5, 1
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2006-12-13 12:59:12
|
Update of /cvsroot/javanetsim/IceScan/icesockets In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv7708/icesockets Modified Files: crawsocket.h iceregex.h Added Files: ice_rand.h Log Message: no message --- NEW FILE: ice_rand.h --- (This appears to be a binary file; contents omitted.) Index: crawsocket.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/icesockets/crawsocket.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** crawsocket.h 30 Nov 2006 12:27:36 -0000 1.2 --- crawsocket.h 13 Dec 2006 12:59:06 -0000 1.3 *************** *** 6,9 **** --- 6,19 ---- #include <netinet/ip.h> #include <netinet/ip_icmp.h> + #define __FAVOR_BSD + #include <netinet/tcp.h> + + struct pseudo_header { + unsigned long s_addr; + unsigned long d_addr; + char zero; + unsigned char protocol; + unsigned short length; + }; class crawsocket : csocket{ *************** *** 89,93 **** } ! int sendto(char *hostname, const void *msg, int len, unsigned int flags){ return csocket::sendto(hostname, 0, msg, len, flags); } --- 99,103 ---- } ! int sendto(const char *hostname, const void *msg, int len, unsigned int flags){ return csocket::sendto(hostname, 0, msg, len, flags); } *************** *** 97,100 **** --- 107,114 ---- } + void nonblock(bool lck){ + csocket::nonblock(lck); + } + bool state(){ return (!sstate) ? true : false; *************** *** 116,120 **** return protocol; } ! }; --- 130,256 ---- return protocol; } ! ! ! int send_tcp_raw( icestring source, icestring destination, unsigned short sport, unsigned short dport, unsigned long seq, ! unsigned long ack, unsigned char flags, unsigned short window, char *data, unsigned short datalen) ! { ! ! ! char packet[sizeof(struct iphdr) + sizeof(struct tcphdr) + datalen]; ! ! struct iphdr *ip = (struct iphdr *) packet; ! struct tcphdr *tcp = (struct tcphdr *) (packet + sizeof(struct iphdr)); ! struct pseudo_header *pseudo = (struct pseudo_header *) (packet + sizeof(struct iphdr) - sizeof(struct pseudo_header)); ! int res; ! char myname[ICEMAXHOSTNAME + 1]; ! ! struct sockaddr_in saddress, daddress; ! int slen, dlen; ! ! slen == make_sockname(saddress, source.c_str(), 0, domain); ! dlen == make_sockname(daddress, destination.c_str(), 0, domain); ! ! bzero(packet, sizeof(iphdr) + sizeof(tcphdr)); ! ! pseudo->s_addr = saddress.sin_addr.s_addr; ! pseudo->d_addr = daddress.sin_addr.s_addr; ! pseudo->protocol = IPPROTO_TCP; ! pseudo->length = htons(sizeof(struct tcphdr) + datalen); ! ! tcp->th_sport = htons(sport); ! tcp->th_dport = htons(dport); ! if (seq) ! tcp->th_seq = htonl(seq); ! //else tcp->th_seq = rand() + rand(); ! ! if (flags & TH_ACK && ack) ! tcp->th_ack = htonl(seq); ! //else if (flags & TH_ACK) ! // tcp->th_ack = rand() + rand(); ! ! tcp->th_off = 5; ! tcp->th_flags = flags; ! ! unsigned short ttl = 121; ! ! if (window) ! tcp->th_win = window; ! else tcp->th_win = htons(1024 * (ttl % 4 + 1)); ! ! tcp->th_sum = in_chksum((unsigned short *)pseudo, sizeof(struct tcphdr) + ! sizeof(struct pseudo_header) + datalen); ! ! bzero(packet, sizeof(struct iphdr)); ! ip->version = 4; ! ip->ihl = 5; ! ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct tcphdr) + datalen); ! ip->id = rand(); ! ip->ttl = ttl; ! ip->protocol = IPPROTO_TCP; ! ip->saddr = saddress.sin_addr.s_addr; ! ip->daddr = daddress.sin_addr.s_addr; ! ip->check = in_chksum((unsigned short *)ip, sizeof(struct iphdr)); ! ! //print_tcppacket(packet,ntohs(ip->tot_len)); ! ! if ((res = sendto(destination.c_str(), packet, ntohs(ip->tot_len), 0)) == -1) ! { ! perror("sendto in send_tcp_raw"); ! return -1; ! } ! ! return res; ! } ! ! static int print_tcppacket(char *packet, int readdata) { ! struct iphdr *ip = (struct iphdr *) packet; ! struct tcphdr *tcp = (struct tcphdr *) (packet + sizeof(struct iphdr)); ! char *data = packet + sizeof(struct iphdr) + sizeof(struct tcphdr); ! int tot_len; ! struct in_addr bullshit, bullshit2; ! char sourcehost[16]; ! int i; ! ! if (!packet) { ! std::cerr << "readtcppacket: packet is NULL!\n"; ! return -1; ! } ! ! bullshit.s_addr = ip->saddr; bullshit2.s_addr = ip->daddr; ! tot_len = ntohs(ip->tot_len); ! strncpy(sourcehost, inet_ntoa(bullshit), 16); ! i = 4 * (ntohs(ip->ihl) + ntohs(tcp->th_off)); ! if (ip->protocol == IPPROTO_TCP){ ! if (ip->frag_off){ ! printf("Packet is fragmented, offset field: %u", ip->frag_off); ! } else { ! printf("TCP packet: %s:%d -> %s:%d (total: %d bytes)\n", sourcehost, ! ntohs(tcp->th_sport), inet_ntoa(bullshit2), ! ntohs(tcp->th_dport), tot_len); ! printf("Flags: "); ! if (!tcp->th_flags) printf("(none)"); ! if (tcp->th_flags & TH_RST) printf("RST "); ! if (tcp->th_flags & TH_SYN) printf("SYN "); ! if (tcp->th_flags & TH_ACK) printf("ACK "); ! if (tcp->th_flags & TH_PUSH) printf("PSH "); ! if (tcp->th_flags & TH_FIN) printf("FIN "); ! if (tcp->th_flags & TH_URG) printf("URG "); ! printf("\n"); ! printf("ttl: %hi ", ip->ttl); ! if (tcp->th_flags & (TH_SYN | TH_ACK)) printf("Seq: %lu\tAck: %lu\n", ! tcp->th_seq, tcp->th_ack); ! else if (tcp->th_flags & TH_SYN) printf("Seq: %lu\n", ntohl(tcp->th_seq)); ! else if (tcp->th_flags & TH_ACK) printf("Ack: %lu\n", ntohl(tcp->th_ack)); ! } ! } ! if (readdata && i < tot_len) { ! printf("Data portion:\n"); ! while(i < tot_len) printf("%2X%c", data[i], (++i%16)? ' ' : '\n'); ! printf("\n"); ! } ! ! return 0; ! } ! }; Index: iceregex.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/icesockets/iceregex.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** iceregex.h 13 Dec 2006 09:08:33 -0000 1.5 --- iceregex.h 13 Dec 2006 12:59:06 -0000 1.6 *************** *** 95,99 **** } ! bool group(int i, char *str, int strsize){ int rc = pcre_copy_substring( subject.c_str(), // Subject that has been successfully matched --- 95,100 ---- } ! bool group(int i, char *str, int strsize){ ! int rc = pcre_copy_substring( subject.c_str(), // Subject that has been successfully matched |