sip
index
/build/dshell/src/dshell/decoders/voip/sip.py

# Author: MM - https://github.com/1modm
#
# The Session Initiation Protocol (SIP) is the IETF protocol for VOIP and other text and multimedia sessions
# and is a communications protocol for signaling and controlling. 
# SIP is independent from the underlying transport protocol. It runs on the Transmission Control Protocol (TCP), 
# the User Datagram Protocol (UDP) or the Stream Control Transmission Protocol (SCTP)
#
# Rate and codec calculation thanks to https://git.ucd.ie/volte-and-of/voip-pcapy
#
# RFC: https://www.ietf.org/rfc/rfc3261.txt
#
# SIP is a text-based protocol with syntax similar to that of HTTP. 
# There are two different types of SIP messages: requests and responses.
# - Requests initiate a SIP transaction between two SIP entities for establishing, controlling, and terminating sessions. 
# - Responses are send by the user agent server indicating the result of a received request.
#
# - SIP session setup example:
#
#       Alice's  . . . . . . . . . . . . . . . . . . . .  Bob's
#      softphone                                        SIP Phone
#         |                |                |                |
#         |    INVITE F1   |                |                |
#         |--------------->|    INVITE F2   |                |
#         |  100 Trying F3 |--------------->|    INVITE F4   |
#         |<---------------|  100 Trying F5 |--------------->|
#         |                |<-------------- | 180 Ringing F6 |
#         |                | 180 Ringing F7 |<---------------|
#         | 180 Ringing F8 |<---------------|     200 OK F9  |
#         |<---------------|    200 OK F10  |<---------------|
#         |    200 OK F11  |<---------------|                |
#         |<---------------|                |                |
#         |                       ACK F12                    |
#         |------------------------------------------------->|
#         |                   Media Session                  |
#         |<================================================>|
#         |                       BYE F13                    |
#         |<-------------------------------------------------|
#         |                     200 OK F14                   |
#         |------------------------------------------------->|
#         |                                                  |
#

 
Modules
       
colorout
datetime
dpkt
dshell

 
Classes
       
dshell.UDPDecoder(dshell.IPDecoder)
DshellDecoder

 
class DshellDecoder(dshell.UDPDecoder)
    
Method resolution order:
DshellDecoder
dshell.UDPDecoder
dshell.IPDecoder
dshell.Decoder
__builtin__.object

Methods defined here:
__init__(self)
packetHandler(self, udp, data)
preModule(self)

Methods inherited from dshell.UDPDecoder:
IPHandler(self, addr, pkt, ts, **kwargs)
IPv4 dispatch, hands address, UDP payload and packet up to UDP callback
UDP(self, addr, data, pkt, ts=None, **kwargs)
will call self.packetHandler(udp=Packet(),data=data)
(see Packet() for Packet object common attributes)
udp.pkt will contain the raw IP data
data will contain the decoded UDP payload
 
State tracking:
        only if connectionHandler or blobHandler is present
        and packetHandler is not present
 
UDPDecoder will call:
        self.connectionInitHandler(conn=Connection())
                when UDP state is established
                (see Connection() for Connection object attributes)
 
        self.blobHandler(conn=Connection(),blob=Blob())
                when stream direction switches (if following stream)
                blob=(see Blob() objects)
 
        self.connectionHandler(conn=Connection())
                when UDP state is flushed (if following stream)
                state is flushed when stale or when maxblobs is exceeded
                if maxblobs exceeded, current data will go into new connection
 
        self.connectionCloseHandler(conn=Connection())
                when state is discarded (always)

Methods inherited from dshell.IPDecoder:
ipdefrag(self, pkt)
ip fragment reassembly
rawHandler(self, pktlen, pkt, ts, **kwargs)
takes ethernet data and determines if it contains IP or IP6.
defragments IPv4
if 6to4, unencaps the IPv6
If IP/IP6, hands off to IPDecoder via IPHandler()

Data and other attributes inherited from dshell.IPDecoder:
IP_PROTO_MAP = {0: 'IP', 1: 'ICMP', 6: 'TCP', 17: 'UDP', 41: 'IP6', 58: 'ICMP6'}

Methods inherited from dshell.Decoder:
__repr__(self)
__super__(self)
convenience function to get bound instance of superclass
alert(self, *args, **kw)
sends alert to output handler
typically self.alert will be called with the decoded data and the packet/connection info dict last, as follows:
 
self.alert(alert_arg,alert_arg2...,alert_data=value,alert_data2=value2....,**conn/pkt.info())
 
example: self.alert(decoded_data,conn.info(),blob.info()) [blob info overrides conn info]
 
this will pass all information about the decoder, the connection, and the specific event up to the output module
 
if a positional arg is a dict, it updates the kwargs
if an arg is a list, it extends the arg list
else it is appended to the arg list
 
all arguments are optional, at the very least you want to pass the **pkt/conn.info() so all traffic info is available.
 
output modules handle this data as follows:
         - the name of the alerting decoder is available in the "decoder" field
         - all non-keyword arguments will be concatenated into the "data" field
         - keyword arguments, including all provided by .info() will be used to populate matching fields
         - remaining keyword arguments that do not match fields will be represented by "key=value" strings
            concatenated together into the "extra" field
cleanConnectionStore(self)
cleans connection store of all information, flushing out data
cleanup(self, ts)
if cleanup interval expired, close connections not updated in last interval
close(self, conn, ts=None)
for connection based decoders
close and discard the connection object
debug(self, msg)
logs msg at debug level
decode(self, *args, **kw)
# we get the raw output from pcapy as header, data
dump(self, *args, **kw)
write packet data (probably to the PCAP writer if present)
error(self, msg)
logs msg at error level
find(self, addr, state=None)
getASN(self, ip, db=None, notfound='--')
Get ASN associated with an IP.
Requires GeoIP library (geoip2) and data files.
getGeoIP(self, ip, db=None, notfound='--')
Get country code associated with an IP.
Requires GeoIP library (geoip2) and data files.
log(self, msg, level=20)
logs msg at specified level (default of INFO is for -v/--verbose output)
parseArgs(self, args, options={})
called to parse command-line arguments and cli/config file options
if options dict contains 'all' or the decoder name as a key
class members will be updated from value
parseOptions(self, options={})
option keys:values will set class members (self.key=value)
if key is in optiondict
postFile(self)
postModule(self)
postModule is called after capture stops
default postModule, prints basic decoding stats
preFile(self)
stop(self, conn)
stop following connection
handlers will not be called, except for connectionCloseHandler
track(self, addr, data=None, ts=None, offset=None, **kwargs)
connection tracking for TCP and UDP
finds or creates connection based on addr
updates connection with data if provided (using offset to reorder)
tracks timestamps if ts provided
extra args get passed to new connection objects
warn(self, msg)
logs msg at warning level
write(self, obj, **kw)
write session data

Data descriptors inherited from dshell.Decoder:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Data
        dObj = sip udp showpkt=None