Library sip
A SIP library supporting a limited subset of SIP commands and methods
The library currently supports the following methods: * REGISTER, INVITE & OPTIONS
Overview -------- The library consists of the following classes:
o SessionData - Holds session data for the SIP session
o Session - Contains application functionality related to the implemented SIP methods.
o Connection - A class containing code related to socket communication.
o Response - A class containing code for handling SIP responses
o Request - A class containing code for handling SIP requests
o Util - A class containing static utility functions
o SIPAuth - A class containing code related to SIP Authentication
o Helper - A class containing code used as a primary interface by scripts
Author:
| "Patrik Karlsson <patrik@cqure.net>" |
Copyright© Same as Nmap--See http://nmap.org/book/man-legal.html
Source: http://nmap.org/svn/nselib/sip.lua
Functions
| __tostring (self) |
Converts the request to a String suitable to be sent over the socket |
| addHeader (self, name, value) |
Adds a custom header to the request |
| authenticate (self, request, response, authdata) |
Prepares and sends the challenge response authentication to the server |
| calculateResponse (self) |
Calculates the authentication response |
| close (self) |
Disconnects and closes the helper instance |
| close (self) |
Disconnects and closes the helper instance |
| close (self) |
Disconnects and closes the helper instance |
| connect (self) |
Connects the helper instance |
| connect (self) |
Connects the helper instance |
| connect (self) |
Connects the helper instance |
| createResponse (self) |
Creates the complete authentication response |
| exch (self, request) |
Sends a SIP Request and receives the Response |
| get_random_string (length, set) |
Generates a random string of the requested length. |
| getAuthData (self) |
Returns the authentication data from the SIP response |
| getClient (self) |
Retrieves the client ip and port |
| getClient (self) |
Retrieves the client ip and port |
| getCSeq (self) |
Retrieves the current sequence number |
| getDomain (self) |
Retrieves the SIP domain |
| getErrorCode (self) |
Returns the error code from the SIP response |
| getErrorMessage (self) |
Returns the error message returned by the server |
| getHeader (self, name) |
Retrieves a given header value from the response |
| getMethod (self) |
Returns the message method |
| getName (self) |
Retrieves the SIP users full name |
| getPassword (self) |
Retrieves the session password |
| getServer (self) |
Retrieves the server ip and port |
| getServer (self) |
Retrieves the server ip and port |
| getUsername (self) |
Retrieves the username |
| invite (self, uri) |
Attempts to INVITE the user at uri to a call |
| invite (self, uri) |
Attempts to INVITE the user at uri to a call |
| new (self, host, port, options) |
Creates a new instance of the Helper class |
| new (self, host, port, options) |
Creates a new instance of the Helper class |
| new (self, host, port, options) |
Creates a new instance of the Helper class |
| new (self, host, port, options) |
Creates a new instance of the Helper class |
| new (self, host, port, options) |
Creates a new instance of the Helper class |
| new (self, host, port, options) |
Creates a new instance of the Helper class |
| new (self, host, port, options) |
Creates a new instance of the Helper class |
| options (self) |
Sends an option request to the server and handles the response |
| parseChallenge (self) |
Processes and parses a challenge as received from the server |
| recv (self) |
Receives data from the socket |
| register (self, options) |
Register the UAC with the server |
| register (self, options) |
Register the UAC with the server |
| send (self, data) |
Sends the data over the socket |
| setAllow (self, allow) |
Sets the allow header |
| setCallId (self, cid) |
Sets the caller ID information of the SIP request |
| setClient (self, host, port) |
Sets the ip and port of the client |
| setContent (self, content, string) |
Sets the request content data |
| setContentLength (self, len) |
Sets the content-length of the SIP request |
| setContentType (self, t) |
Sets the requests' content type |
| setCredentials (self, username, password) |
Sets the credentials used when performing authentication |
| setCseq (self, seq) |
Sets the sequence number |
| setDomain (self, domain) |
Sets the SIP domain |
| setDomain (self, domain) |
Sets the SIP domain |
| setError (self, code, msg) |
Sets an error |
| setExpires (self, expires) |
Sets the expires header of the SIP request |
| setForwards (self, maxfwd) |
Sets the maximum forwards allowed of this request |
| setMethod (self, method) |
Sets the method used for authentication |
| setMethod (self, method) |
Sets the method used for authentication |
| setName (self, name) |
Sets the SIP users Full Name |
| setPassword (self, password) |
Sets the password used for authentication |
| setPassword (self, password) |
Sets the password used for authentication |
| setProtocol (self, proto) |
Specifies the network protocol being used |
| setProxyAuth (self, auth) |
Sets the proxy authentication data |
| setServer (self, host, port) |
Sets the ip and port of the remote server |
| setSessionData (self, data) |
Sets the sessiondata so that session information may be fetched |
| setSupported (self, supported) |
Sets the supported SIP methods |
| setUA (self, ua) |
Sets the User Agent being used to connect to the SIP server |
| setUri (self, uri) |
Sets the uri used for authentication |
| setUri (self, uri) |
Sets the uri used for authentication |
| setUsername (self, username) |
Sets the username used for authentication |
| setUsername (self, username) |
Sets the username used for authentication |
| setWWWAuth (self, auth) |
Sets the www authentication data |
Functions
- __tostring (self)
-
Converts the request to a String suitable to be sent over the socket
Parameters
- self:
Return value:
ret string containing the complete request for sending over the socket - addHeader (self, name, value)
-
Adds a custom header to the request
Parameters
- self:
- name: string containing the header name
- value: string containing the header value
- authenticate (self, request, response, authdata)
-
Prepares and sends the challenge response authentication to the server
Parameters
- self:
- request: instance of the request object requiring authentication
- response:
- authdata: string containing authentication data
Return values:
- status true on success false on failure
- err string containing an error message if status is false
- calculateResponse (self)
-
Calculates the authentication response
Parameters
- self:
Return value:
reponse string containing the authentication response - close (self)
-
Disconnects and closes the helper instance
Parameters
- self:
- close (self)
-
Disconnects and closes the helper instance
Parameters
- self:
- close (self)
-
Disconnects and closes the helper instance
Parameters
- self:
- connect (self)
-
Connects the helper instance
Parameters
- self:
- connect (self)
-
Connects the helper instance
Parameters
- self:
- connect (self)
-
Connects the helper instance
Parameters
- self:
- createResponse (self)
-
Creates the complete authentication response
Parameters
- self:
Return value:
auth string containing the complete authentication digest - exch (self, request)
-
Sends a SIP Request and receives the Response
Parameters
- self:
- request: instance of Request
Return values:
- status true on success, false on failure
- resp containing a new Response instance err containing error message if status is false
- get_random_string (length, set)
-
Generates a random string of the requested length.
Parameters
- length: (optional) The length of the string to return. Default: 8.
- set: (optional) The set of letters to choose from. Default: upper, lower, numbers, and underscore.
Return value:
The random string. - getAuthData (self)
-
Returns the authentication data from the SIP response
Parameters
- self:
Return value:
auth string containing the raw authentication data - getClient (self)
-
Retrieves the client ip and port
Parameters
- self:
Return values:
- lhost string containing the local ip
- lport number containing the local port
- getClient (self)
-
Retrieves the client ip and port
Parameters
- self:
Return values:
- lhost string containing the local ip
- lport number containing the local port
- getCSeq (self)
-
Retrieves the current sequence number
Parameters
- self:
Return value:
cseq number containing the current sequence number - getDomain (self)
-
Retrieves the SIP domain
Parameters
- self:
Return value:
domain string containing the SIP domain - getErrorCode (self)
-
Returns the error code from the SIP response
Parameters
- self:
Return value:
err number containing the error code - getErrorMessage (self)
-
Returns the error message returned by the server
Parameters
- self:
Return value:
errmsg string containing the error message - getHeader (self, name)
-
Retrieves a given header value from the response
Parameters
- self:
- name: string containing the name of the header
Return value:
value string containing the header value - getMethod (self)
-
Returns the message method
Parameters
- self:
Return value:
method string containing the method - getName (self)
-
Retrieves the SIP users full name
Parameters
- self:
Return value:
name string containing the users full name - getPassword (self)
-
Retrieves the session password
Parameters
- self:
Return value:
pass string containing the session password - getServer (self)
-
Retrieves the server ip and port
Parameters
- self:
Return values:
- rhost string containing the server ip
- rport number containing the server port
- getServer (self)
-
Retrieves the server ip and port
Parameters
- self:
Return values:
- rhost string containing the server ip
- rport number containing the server port
- getUsername (self)
-
Retrieves the username
Parameters
- self:
Return value:
user string containing the sessions username - invite (self, uri)
-
Attempts to INVITE the user at uri to a call
Parameters
- self:
- uri: string containing the sip uri
Return value:
status true on success, false on failure - invite (self, uri)
-
Attempts to INVITE the user at uri to a call
Parameters
- self:
- uri: string containing the sip uri
Return value:
status true on success, false on failure - new (self, host, port, options)
-
Creates a new instance of the Helper class
Parameters
- self:
- host: table containing the remote host
- port: table containing the remote port
- options: table containing any options to pass along to the session (@see Session:new for more details)
Return value:
o containing a new instance of the Helper class - new (self, host, port, options)
-
Creates a new instance of the Helper class
Parameters
- self:
- host: table containing the remote host
- port: table containing the remote port
- options: table containing any options to pass along to the session (@see Session:new for more details)
Return value:
o containing a new instance of the Helper class - new (self, host, port, options)
-
Creates a new instance of the Helper class
Parameters
- self:
- host: table containing the remote host
- port: table containing the remote port
- options: table containing any options to pass along to the session (@see Session:new for more details)
Return value:
o containing a new instance of the Helper class - new (self, host, port, options)
-
Creates a new instance of the Helper class
Parameters
- self:
- host: table containing the remote host
- port: table containing the remote port
- options: table containing any options to pass along to the session (@see Session:new for more details)
Return value:
o containing a new instance of the Helper class - new (self, host, port, options)
-
Creates a new instance of the Helper class
Parameters
- self:
- host: table containing the remote host
- port: table containing the remote port
- options: table containing any options to pass along to the session (@see Session:new for more details)
Return value:
o containing a new instance of the Helper class - new (self, host, port, options)
-
Creates a new instance of the Helper class
Parameters
- self:
- host: table containing the remote host
- port: table containing the remote port
- options: table containing any options to pass along to the session (@see Session:new for more details)
Return value:
o containing a new instance of the Helper class - new (self, host, port, options)
-
Creates a new instance of the Helper class
Parameters
- self:
- host: table containing the remote host
- port: table containing the remote port
- options: table containing any options to pass along to the session (@see Session:new for more details)
Return value:
o containing a new instance of the Helper class - options (self)
-
Sends an option request to the server and handles the response
Parameters
- self:
Return values:
- status true on success, false on failure
- response if status is true, nil else.
- parseChallenge (self)
-
Processes and parses a challenge as received from the server
Parameters
- self:
- recv (self)
-
Receives data from the socket
Parameters
- self:
Return value:
status true on success, false on failure - register (self, options)
-
Register the UAC with the server
Parameters
- self:
- options: table containing zero or more options (@see Session:register for more details)
Return values:
- status true on success, false on failure
- msg containing the error message if status is false
- register (self, options)
-
Register the UAC with the server
Parameters
- self:
- options: table containing zero or more options (@see Session:register for more details)
Return values:
- status true on success, false on failure
- msg containing the error message if status is false
- send (self, data)
-
Sends the data over the socket
Parameters
- self:
- data:
Return value:
status true on success, false on failure - setAllow (self, allow)
-
Sets the allow header
Parameters
- self:
- allow: table containing all of the allowed SIP methods
- setCallId (self, cid)
-
Sets the caller ID information of the SIP request
Parameters
- self:
- cid: string containing the callers id
- setClient (self, host, port)
-
Sets the ip and port of the client
Parameters
- self:
- host: string containing the ip of the client
- port: number containing the port of the client
- setContent (self, content, string)
-
Sets the request content data
Parameters
- self:
- content:
- string: containing the content data
- setContentLength (self, len)
-
Sets the content-length of the SIP request
Parameters
- self:
- len: number containing the length of the actual request
- setContentType (self, t)
-
Sets the requests' content type
Parameters
- self:
- t: string containing the content type
- setCredentials (self, username, password)
-
Sets the credentials used when performing authentication
Parameters
- self:
- username: string containing the username to use for authentication
- password: string containing the password to use for authentication
- setCseq (self, seq)
-
Sets the sequence number
Parameters
- self:
- seq: number containing the sequence number to set
- setDomain (self, domain)
-
Sets the SIP domain
Parameters
- self:
- domain: string containing the domain name
- setDomain (self, domain)
-
Sets the SIP domain
Parameters
- self:
- domain: string containing the domain name
- setError (self, code, msg)
-
Sets an error
Parameters
- self:
- code: number containing the error code
- msg: string containing the error message
- setExpires (self, expires)
-
Sets the expires header of the SIP request
Parameters
- self:
- expires: number containing the expire value
- setForwards (self, maxfwd)
-
Sets the maximum forwards allowed of this request
Parameters
- self:
- maxfwd: number containing the maximum allowed forwards
- setMethod (self, method)
-
Sets the method used for authentication
Parameters
- self:
- method: string containing the method (Usually REGISTER)
- setMethod (self, method)
-
Sets the method used for authentication
Parameters
- self:
- method: string containing the method (Usually REGISTER)
- setName (self, name)
-
Sets the SIP users Full Name
Parameters
- self:
- name: string containing the full name of the user
- setPassword (self, password)
-
Sets the password used for authentication
Parameters
- self:
- password: string containing the password of the user
- setPassword (self, password)
-
Sets the password used for authentication
Parameters
- self:
- password: string containing the password of the user
- setProtocol (self, proto)
-
Specifies the network protocol being used
Parameters
- self:
- proto: should be either "UDP" or "TCP"
- setProxyAuth (self, auth)
-
Sets the proxy authentication data
Parameters
- self:
- auth: string containing properly formatted proxy authentication data
- setServer (self, host, port)
-
Sets the ip and port of the remote server
Parameters
- self:
- host: string containing the ip of the remote server
- port: number containing the port of the remote server
- setSessionData (self, data)
-
Sets the sessiondata so that session information may be fetched
Parameters
- self:
- data: instance of SessionData
- setSupported (self, supported)
-
Sets the supported SIP methods
Parameters
- self:
- supported: string containing the supported methods
- setUA (self, ua)
-
Sets the User Agent being used to connect to the SIP server
Parameters
- self:
- ua: string containing the User-Agent name (defaults to Nmap NSE)
- setUri (self, uri)
-
Sets the uri used for authentication
Parameters
- self:
- uri: string containing the uri (Usually sip:<ip>)
- setUri (self, uri)
-
Sets the uri used for authentication
Parameters
- self:
- uri: string containing the uri (Usually sip:<ip>)
- setUsername (self, username)
-
Sets the username used for authentication
Parameters
- self:
- username: string containing the name of the user
- setUsername (self, username)
-
Sets the username used for authentication
Parameters
- self:
- username: string containing the name of the user
- setWWWAuth (self, auth)
-
Sets the www authentication data
Parameters
- self:
- auth: string containing properly formatted proxy authentication data


