⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 portscan.c

📁 Linux snort-2.4.4源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
                ps_proto_update(&scanner->proto[proto_idx],0,1,0,0,0);                scanner->priority_node = 1;            }        }        /*        **  We only get here on the server's response to the intial        **  client connection.        **        **  That's why we use the sp, because that's the port that is        **  open.        */        else if((p->packet_flags & PKT_FROM_SERVER) &&                !(p->packet_flags & PKT_STREAM_EST))        {            if(scanned)                ps_update_open_ports(&scanned->proto[proto_idx], p->sp);                    if(scanner)            {                if(scanner->proto[proto_idx].alerts == PS_ALERT_GENERATED)                    scanner->proto[proto_idx].alerts = PS_ALERT_OPEN_PORT;            }        }    }    /*    **  If we are an icmp unreachable, deal with it here.    */    else if(p->icmph && p->orig_tcph)    {        if(scanned)        {            ps_proto_update(&scanned->proto[proto_idx],0,1,0,0,0);            scanned->priority_node = 1;        }        if(scanner)        {            ps_proto_update(&scanner->proto[proto_idx],0,1,0,0,0);            scanner->priority_node = 1;        }    }    /*    **  If we're none of the above, revert to flow to do some basic    **  processing.  This means that the TCP packet we got is not    **  considered a valid initiator, so we didn't start a stream    **  tracker.    */    else if(flow)    {        if(flow->stats.direction == FROM_INITIATOR)        {            if(scanned)            {                ps_proto_update(&scanned->proto[proto_idx],1,0,                                 p->iph->ip_src.s_addr,p->dp, pkt_time);            }            if(scanner)            {                ps_proto_update(&scanner->proto[proto_idx],1,0,                                 p->iph->ip_dst.s_addr,p->dp, pkt_time);            }        }        else if(flow->stats.direction == FROM_RESPONDER &&                (p->tcph->th_flags & TH_RST))        {            if(scanned)            {                ps_proto_update(&scanned->proto[proto_idx],0,1,0,0,0);                scanned->priority_node = 1;            }            if(scanner)            {                ps_proto_update(&scanner->proto[proto_idx],0,1,0,0,0);                scanner->priority_node = 1;            }        }    }    return 0;}static int ps_tracker_update_ip(PS_PKT *ps_pkt, PS_TRACKER *scanner,        PS_TRACKER *scanned, int proto_idx){    Packet *p;    time_t  pkt_time;    FLOW   *flow;        p = (Packet *)ps_pkt->pkt;    pkt_time = packet_timeofday();    if(p->iph)    {        if(p->icmph)        {            if(p->icmph->type == ICMP_DEST_UNREACH &&               p->icmph->code == ICMP_PROT_UNREACH)            {                if(scanned)                {                    ps_proto_update(&scanned->proto[proto_idx],0,1,0,0,0);                    scanned->priority_node = 1;                }                if(scanner)                {                    ps_proto_update(&scanner->proto[proto_idx],0,1,0,0,0);                    scanner->priority_node = 1;                }            }            return 0;        }        if(p->flow)        {            flow = (FLOW *)p->flow;            if(flow->stats.direction == FROM_INITIATOR)            {                if(scanned)                {                    ps_proto_update(&scanned->proto[proto_idx],1,0,                        p->iph->ip_src.s_addr,(u_short)p->iph->ip_proto, pkt_time);                }                if(scanner)                {                    ps_proto_update(&scanner->proto[proto_idx],1,0,                        p->iph->ip_dst.s_addr,(u_short)p->iph->ip_proto, pkt_time);                }            }            else if(flow->stats.direction == FROM_RESPONDER)            {                if(scanned)                    ps_proto_update(&scanned->proto[proto_idx],-1,0,0,0,0);                if(scanner)                    ps_proto_update(&scanner->proto[proto_idx],-1,0,0,0,0);            }        }    }    return 0;}static int ps_tracker_update_udp(PS_PKT *ps_pkt, PS_TRACKER *scanner,        PS_TRACKER *scanned, int proto_idx){    Packet  *p;    time_t  pkt_time;    FLOW    *flow;        p = (Packet *)ps_pkt->pkt;    pkt_time = packet_timeofday();    if(p->icmph)    {         if(p->icmph->type == ICMP_DEST_UNREACH &&           p->icmph->code == ICMP_PORT_UNREACH)        {            if(scanned)            {                ps_proto_update(&scanned->proto[proto_idx],0,1,0,0,0);                scanned->priority_node = 1;            }            if(scanner)            {                ps_proto_update(&scanner->proto[proto_idx],0,1,0,0,0);                scanner->priority_node = 1;            }        }    }    else if(p->udph)    {        if(p->flow)        {            flow = (FLOW *)p->flow;            if(flow->stats.direction == FROM_INITIATOR)            {                if(scanned)                {                    ps_proto_update(&scanned->proto[proto_idx],1,0,                                     p->iph->ip_src.s_addr,p->dp, pkt_time);                }                if(scanner)                {                    ps_proto_update(&scanner->proto[proto_idx],1,0,                                     p->iph->ip_dst.s_addr,p->dp, pkt_time);                }            }            else if(flow->stats.direction == FROM_RESPONDER)            {                if(scanned)                    ps_proto_update(&scanned->proto[proto_idx],-1,0,0,0,0);                if(scanner)                    ps_proto_update(&scanner->proto[proto_idx],-1,0,0,0,0);            }        }    }    return 0;}static int ps_tracker_update_icmp(PS_PKT *ps_pkt, PS_TRACKER *scanner,        PS_TRACKER *scanned, int proto_idx){    Packet  *p;    time_t  pkt_time;        p = (Packet *)ps_pkt->pkt;    pkt_time = packet_timeofday();    if(p->icmph)    {        switch(p->icmph->type)        {            case ICMP_ECHO:            case ICMP_TIMESTAMP:            case ICMP_ADDRESS:            case ICMP_INFO_REQUEST:                if(scanner)                {                    ps_proto_update(&scanner->proto[proto_idx],1,0,                                     p->iph->ip_dst.s_addr, 0, pkt_time);                }                                break;            case ICMP_DEST_UNREACH:                if(scanner)                {                    ps_proto_update(&scanner->proto[proto_idx],0,1,0,0,0);                    scanner->priority_node = 1;                }                break;            default:                break;        }    }    return 0;}/***  NAME**    ps_tracker_update::*//****  At this point, we should only be looking at tranport protocols**  that we want to.  For instance, if we aren't doing UDP portscans**  then we won't see UDP packets here because they were ignored.****  This is where we evaluate the packet to add/subtract portscan**  tracker values and prioritize a tracker.  We also update the**  time windows.*/static int ps_tracker_update(PS_PKT *ps_pkt, PS_TRACKER *scanner,        PS_TRACKER *scanned){    Packet *p;    int     proto_idx;    int     proto;    p = (Packet *)ps_pkt->pkt;    if(ps_get_proto_index(ps_pkt, &proto_idx, &proto))        return -1;    if(scanner && scanner->proto[proto_idx].alerts)        scanner->proto[proto_idx].alerts = PS_ALERT_GENERATED;    if(scanned && scanned->proto[proto_idx].alerts)        scanned->proto[proto_idx].alerts = PS_ALERT_GENERATED;        switch(proto)    {        case PS_PROTO_TCP:            if(ps_tracker_update_tcp(ps_pkt, scanner, scanned, proto_idx))                return -1;            break;        case PS_PROTO_UDP:            if(ps_tracker_update_udp(ps_pkt, scanner, scanned, proto_idx))                return -1;            break;        case PS_PROTO_ICMP:            if(ps_tracker_update_icmp(ps_pkt, scanner, scanned, proto_idx))                return -1;            break;        case PS_PROTO_IP:            if(ps_tracker_update_ip(ps_pkt, scanner, scanned, proto_idx))                return -1;            break;        default:            return -1;    }    ps_pkt->proto     = proto;    ps_pkt->proto_idx = proto_idx;    return 0;}static int ps_alert_one_to_one(PS_PROTO *scanner, PS_PROTO *scanned,        PS_ALERT_CONF *conf){    if(!conf)        return -1;    /*    **  Let's evaluate the scanned host.    */    if(scanned && !scanned->alerts)    {        if(scanned->priority_count >= conf->priority_count)        {            if(scanned->u_ip_count < conf->u_ip_count &&               scanned->u_port_count >= conf->u_port_count)            {                if(scanner)                {                    if(scanner->priority_count >= conf->priority_count)                    {                        /*                        **  Now let's check to make sure this is one                        **  to one                        */                        scanned->alerts = PS_ALERT_ONE_TO_ONE;                        return 0;                    }                }                else                {                    /*                    **  If there is no scanner, then we do the best we can.                    */                    scanned->alerts = PS_ALERT_ONE_TO_ONE;                    return 0;                }            }        }        if(scanned->connection_count >= conf->connection_count)        {            if(conf->connection_count == 0)                return 0;            if(scanned->u_ip_count < conf->u_ip_count &&               scanned->u_port_count >= conf->u_port_count)            {                scanned->alerts = PS_ALERT_ONE_TO_ONE_FILTERED;                return 0;            }        }    }    return 0;}static int ps_alert_one_to_one_decoy(PS_PROTO *scanner, PS_PROTO *scanned,        PS_ALERT_CONF *conf){    if(!conf)        return -1;    if(scanned && !scanned->alerts)    {        if(scanned->priority_count >= conf->priority_count)        {            if(scanned->u_ip_count >= conf->u_ip_count &&               scanned->u_port_count >= conf->u_port_count)            {                scanned->alerts = PS_ALERT_ONE_TO_ONE_DECOY;                return 0;            }        }        if(scanned->connection_count >= conf->connection_count)        {            if(conf->connection_count == 0)                return 0;            if(scanned->u_ip_count >= conf->u_ip_count &&               scanned->u_port_count >= conf->u_port_count)            {                scanned->alerts = PS_ALERT_ONE_TO_ONE_DECOY_FILTERED;                return 0;            }        }    }    return 0;}static int ps_alert_many_to_one(PS_PROTO *scanner, PS_PROTO *scanned,        PS_ALERT_CONF *conf){    if(!conf)        return -1;    if(scanned && !scanned->alerts)    {        if(scanned->priority_count >= conf->priority_count)        {            if(scanned->u_ip_count <= conf->u_ip_count &&               scanned->u_port_count >= conf->u_port_count)            {                scanned->alerts = PS_ALERT_DISTRIBUTED;                return 0;            }        }        if(scanned->connection_count >= conf->connection_count)        {            if(conf->connection_count == 0)                return 0;            if(scanned->u_ip_count <= conf->u_ip_count &&               scanned->u_port_count >= conf->u_port_count)            {                scanned->alerts = PS_ALERT_DISTRIBUTED_FILTERED;                return 0;            }        }    }                return 0;}static int ps_alert_one_to_many(PS_PROTO *scanner, PS_PROTO *scanned,        PS_ALERT_CONF *conf){    if(!conf)        return -1;    if(scanner && !scanner->alerts)    {        if(scanner->priority_count >= conf->priority_count)        {            if(scanner->u_ip_count >= conf->u_ip_count &&               scanner->u_port_count <= conf->u_port_count)            {                scanner->alerts = PS_ALERT_PORTSWEEP;                return 1;            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -