if (o.debugging) error("Whacked packet to port %lu passed to posportupdate with state %s (%d)\n", current->portno, statenum2str(current->state), current->state);
log_write(LOG_STDOUT, "Strange packet from port %d:\n", ntohs(tcp->th_sport));
readtcppacket((unsigned char *)ip, bytes);
}
current = NULL;
continue;
}
current = &scan[portlookup[newport]];
for(i=0; i < 3; i++) {
if (MOD_DIFF(sequences[i],ntohl(tcp->th_ack)) < 5)
break;
}
if (i < 3) trynum = i;
else {
if (o.debugging)
log_write(LOG_STDOUT, "Strange ACK number from target: %lX\n", (unsigned long) ntohl(tcp->th_ack));
trynum = (current->trynum == 0)? 0 : -1;
}
if (current->trynum < trynum) {
if (o.debugging)
error("Received SYN packet implying trynum %d from port %hu even though that port is only on trynum %d (could be from an earlier round)", trynum, newport, current->trynum);
trynum = -1;
}
if (scantype == SYN_SCAN) {
if (tcp->th_flags & TH_RST) {
newstate = PORT_CLOSED;
} else if ((tcp->th_flags & (TH_SYN|TH_ACK)) == (TH_SYN|TH_ACK)) {
newstate = PORT_OPEN;
} else {
if (o.debugging)
error("Received response to SYN scan with unexpected tcp flags: %d\n", tcp->th_flags);
continue;
}
}
else if (scantype == WINDOW_SCAN) {
if (tcp->th_flags & TH_RST) {
if (tcp->th_win) {
newstate = PORT_OPEN;
} else {
newstate = PORT_CLOSED;
}
} else {
if (o.debugging)
error("Received response to WINDOW scan with unexpected tcp flags: %d\n", tcp->th_flags);
continue;
}
}
else if (scantype == ACK_SCAN) {
if (tcp->th_flags & TH_RST) {
newstate = PORT_UNFIREWALLED;
} else {
if (o.debugging)
error("Received response to ACK scan with unexpected tcp flags: %d\n", tcp->th_flags);
continue;
}
} else {
fatal("Unknown scan type!#$!@#$ passed to get_syn_results! Please notify fyodor@insecure.org");
snprintf(filter, sizeof(filter), "(icmp and dst host %s) or (tcp and src host %s and dst host %s)", inet_ntoa(target->source_ip), p, inet_ntoa(target->source_ip));
log_write(LOG_STDOUT, "RPC Scan giving up on port %hu proto %d due to repeated lack of response\n", rsi.rpc_current_port->portno, rsi.rpc_current_port->proto);
snprintf(filter, sizeof(filter), "(icmp and dst host %s) or (tcp and src host %s and dst host %s and ( dst port %d or dst port %d))", inet_ntoa(target->source_ip), p, inet_ntoa(target->source_ip), o.magic_port , o.magic_port + 1);