sip

package
v1.47.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package sip is a very basic (and incomplete) implementation of SIP messaging protocol.

Based on the sipgo library, we are only adding some helpers useful in the context of exploitation. For example, we prefer to avoid the complexity of concepts like transactions or dialogs.

References: - https://github.com/emiago/sipgo - https://datatracker.ietf.org/doc/html/rfc3261 - https://datatracker.ietf.org/doc/html/rfc3311 - https://datatracker.ietf.org/doc/html/rfc3581 - https://datatracker.ietf.org/doc/html/rfc3265 - https://datatracker.ietf.org/doc/html/rfc7118

Index

Constants

View Source
const (
	// SIP over UDP message size should be lower than 1300 bytes.
	// https://datatracker.ietf.org/doc/html/rfc3261#section-18.1.1
	UDPMessageLength = 1300

	DefaultMaxForwards        = 70
	DefaultCSeq               = 1
	DefaultInviteContentType  = "application/sdp"
	DefaultMessageContentType = "text/plain"
	DefaultMessageBodyContent = "Hello, this is a test message."
	DefaultInfoContentType    = "application/dtmf-relay"
	DefaultInfoBodyContent    = "Signal=1Signal=1\nDuration=100"
	DefaultExpiresHeader      = 3600
	DefaultRackCSeq           = 1
	DefaultRackInviteCSeq     = 314159
	ContentTypePidf           = "application/pidf+xml"
)

Variables

Default server ports for each transport protocol.

View Source
var GlobalUA string

GlobalUA is the default User-Agent for all SIP go-exploit comms.

Functions

func AddMethodHeaders

func AddMethodHeaders(req *sip.Request, method sip.RequestMethod) bool

Adds generic method-specific headers to a request.

INVITE and MESSAGE ones are handled in the function 'NewRequestBody'.

func IsContactRequired

func IsContactRequired(method sip.RequestMethod) bool

Checks if contact header is required for a method.

func NewDefaultInviteBody

func NewDefaultInviteBody(host, sessid, sessver string) string

Returns a default body for an INVITE request.

Default parameters: - host: "randomIPv4()". - sessid: random digits. - sessver: random digits.

func NewDefaultNotifyBody

func NewDefaultNotifyBody(id, status, contact, ts string) string

Returns a default body for a NOTIFY request.

Default parameters: - id: random letters. - status: "open". - contact: "sip:bob@randomIPv4():5060". - ts: current UTC time in RFC 3339 format.

func NewDefaultPublishBody

func NewDefaultPublishBody(id, status, entity string) string

Returns a default body for a PUBLISH request.

Default parameters: - id: random letters. - status: "open". - entity: "sip:bob@randomIPv4():5060".

func NewRequestBody

func NewRequestBody(method sip.RequestMethod) (string, string)

Returns a valid body and content type header for the given method.

func NewSipRequest

func NewSipRequest(
	method sip.RequestMethod, host string, opts *NewSipRequestOpts,
) (*sip.Request, bool)

Returns a generic well-formed request. Useful to start the communication.

Depending on the method (if not set in 'opts') required headers and body content is automatically added.

func NewViaHeader

func NewViaHeader(opts *NewViaOpts) (*sip.ViaHeader, bool)

Returns a 'Via' header for a SIP request.

func ReadMessageTCP

func ReadMessageTCP(conn net.Conn) (sip.Message, bool)

Returns a SIP message from a TCP connection.

func ReadMessageUDP

func ReadMessageUDP(conn *net.UDPConn) (sip.Message, bool)

Returns a SIP message from a UDP connection using the message length defined in the RFC 3261. https://datatracker.ietf.org/doc/html/rfc3261#section-18.1.1

func SendAndReceiveTCP

func SendAndReceiveTCP(conn net.Conn, req sip.Message) (*sip.Response, bool)

Sends a TCP/TLS message and returns the response.

func SendAndReceiveUDP

func SendAndReceiveUDP(
	conn *net.UDPConn, req sip.Message,
) (*sip.Response, bool)

Sends a UDP message and returns the response.

If 'amount' is set to 0, it will use the recommended size for UDP messages (1300 bytes).

Types

type NewSipRequestOpts

type NewSipRequestOpts struct {
	// Default: 0. The host could be a domain name.
	Port int
	// Default: 'host' function parameter.
	LocalHost string
	// Default: 'Port' property.
	LocalPort int
	// Default: No user set in the request (Via and To headers).
	ToUser string
	// Default: No user set in the request (From header).
	User string
	// Default: No password set in the request (From header).
	Password string
	// Default: UDP.
	Transport TransportType
}

Optional parameters to create a request.

type NewViaOpts

type NewViaOpts struct {
	// Default: "SIP"
	ProtocolName string
	// Default: "2.0"
	ProtocolVersion string
	// Default: "UDP"
	Transport string
	// Default: "localhost"
	Host string
	// Default: 0
	Port int
}

Optional parameters to create a Via header.

type TransportType

type TransportType int

Supported transport protocol.

const (
	UNKNOWN TransportType = iota
	UDP
	TCP
	TLS
	WS
	WSS
)

func (TransportType) String

func (t TransportType) String() string

Directories

Path Synopsis
examples
call command
This example registers an endpoint (user authentication) in a server and starts a call (only the SIP related part).
This example registers an endpoint (user authentication) in a server and starts a call (only the SIP related part).
ping command
This example checks if a UDP server is up.
This example checks if a UDP server is up.
tcp command
This example sends an OPTIONS request over TCP (or TLS).
This example sends an OPTIONS request over TCP (or TLS).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL