Overview of sip.inc

Public Variable Summary

Public variables are intended to be accessed by the code that imports this library.

Name Summary
data
port
port

Public Function Summary

Public functions are intended to be called by the code that imports this library.

Name Summary
get_sip_banner
sip_send_recv

Public Variable Details

data

top

port

top

port

top

Public Function Details

get_sip_banner

Named Parameters

port

Code

function get_sip_banner(port) {
    local_var soc, opt, r, banner;
    global_var port;

    if( ! port )
    {
      set_kb_item( name: "nvt_debug_empty/" + get_script_oid(), value:get_script_oid() + "#-#port#-#get_sip_banner" );
      return;
    }

    banner = get_kb_item(strcat("sip/banner/", port));
    if (banner) return banner; 

    if (islocalhost()) soc = open_sock_udp(port);
    else soc = open_priv_sock_udp(sport:5060, dport:port);
    if (!soc) return NULL;

    opt = "OPTIONS sip:openvas@" + get_host_name() + ":" + port + " SIP/2.0" + '\r\n' +
             "Via: SIP/2.0/UDP " + this_host() + ":" + port + '\r\n' +
             "Max-Forwards: 70" + '\r\n' +
             "To: <sip:openvas@" + get_host_name() + ":" + port + ">" + '\r\n' +
             "From: OpenVAS <sip:openvas@" + this_host() + ":" + port + ">;tag=" + rand() + '\r\n' +
             "Call-ID: " + rand() + '\r\n' +
             "CSeq: 63104 OPTIONS" + '\r\n' +
             "Contact: <sip:openvas@" + this_host() + ":" + port + ">" + '\r\n' +
             "Accept: application/sdp" + '\r\n' +
             "Content-Length: 0" + '\r\n\r\n';

    send(socket:soc, data:opt);
    r = recv(socket:soc, length:1024);

    if ("SIP/2.0" >< r && ("Server:" >< r)) {
        banner = egrep(pattern:'^Server:', string:r);
        banner = substr(banner, 8);
    }
    else if ("SIP/2.0" >< r && ("User-Agent" >< r)) {
        banner = egrep(pattern:'^User-Agent', string:r);
        banner = substr(banner, 12);
    }

    if (!isnull(banner)) return banner;
    else return NULL;
}


#--------------------------------------------------------#

		
top

sip_send_recv

Named Parameters

data
port

Code

function sip_send_recv(port, data) {
    local_var ret, soc;
    global_var port, data;

    if( ! port )
    {
      set_kb_item( name: "nvt_debug_empty/" + get_script_oid(), value:get_script_oid() + "#-#port#-#get_sip_banner" );
      return;
    }

    if (islocalhost()) soc = open_sock_udp(port);
    else soc = open_priv_sock_udp(sport:5060, dport:port);
    if (!soc) return NULL;

    if (soc) {
        send(socket:soc, data:data);
        ret = recv(socket:soc, length:1024);
        if (!isnull(ret)) return ret;
    }
    return NULL;
}



		
top