SlideShare a Scribd company logo
1 of 30
Download to read offline
STUN
Studying the STUN protocol
Giacomo Vacca, @giavac
STUN: Session Traversal Utilities for NAT
RFC 5389 (8489)
"[STUN] can be used by an endpoint to determine the IP address and port allocated
to it by a NAT. It can also be used to check connectivity between two endpoints, and
as a keep-alive protocol to maintain NAT bindings."
Combination with other protocols:
- Connectivity checks: ICE (RFC 8845)
- Relay: TURN (RFC 5766, 8656) 2
Main characteristics
- Extensible packet format
- Several transport protocols
- Two forms of authentication
3
STUN “usages”
A “usage” defines:
- When STUN messages get sent
- Optional Attributes to include
- What server is used
- The authentication mechanism
ICE (RFC 8445), SIP OUTBOUND (RFC 5626) and NAT Behaviour Discovery (RFC
5780) are all “STUN usages” and are “complete NAT traversal solutions”.
A STUN extension may define new methods, attributes or response codes. 4
STUN operations
STUN is a client-server protocol.
STUN defines 2 types of transactions:
1. Request/Response
2. Indication
Request/Response: client sends a
request, server sends a response.
Indication: either client or server sends
an indication, without the need for a
response.
A 96-bit transaction ID is required.
5
STUN messages
All STUN messages start with a fixed header with:
- Method (e.g. Binding)
- Class (Request, Success Response, Error Response or Indication)
- Transaction ID (96-bit number)
After the header there are zero or more Attributes (in the form of
Type-Length-Value). Attributes can be required (“comprehension-required”) or
optional (“comprehension-optional”).
Attributes are always padded to a multiple of 4 Bytes. Optional: FINGERPRINT 6
STUN header
Binary, network order, big endian.
20 Bytes header + 0 or more Attributes.
The header contains:
- Message Type (16 bits)
- Message Length (16 bits)
- Magic Cookie (32 bits)
- Transaction ID (96 bits)
Message Type: First 2 most significant
bits: 00, Class (Request, Success
Response, Error Response, Indication),
Method.
7
The Magic Cookie
0x2112A442
0010 0001 0001 0010 1010 0100 0100 0010
It’s used to further distinguish a STUN packet from other types, and to XOR the transport addresses.
8
Transport Addresses
A Transport Address is the combination of an IP address and port, e.g. 172.17.0.3:44567
Reflexive Transport Address: A Transport Address learned by a STUN client, identifying that client as
seen by another host or network, typically a STUN server. e.g. “What’s my public IP and port?”
Provided in MAPPED-ADDRESS or XOR-MAPPED-ADDRESS attributes in STUN responses.
ç
9
STUN Binding method 1/2
Used in Request/Response transactions: to determine what binding a STUN
server has allocated for the client, and keep the binding alive.
Used in Indication transactions: to keep the binding alive.
In Request/Response transactions, a STUN client sends a “Binding Request” to
the STUN server. The STUN server replies with a “Binding Success Response”,
containing an attribute called XOR-MAPPED-ADDRESS, which value is the XOR’d
source transport address, as seen by the STUN server. In this way the STUN
client learns its Reflexive Transport Address allocated by the outermost NAT. 10
STUN Binding method 2/2
11
STUN mechanisms (optional procedures)
- DNS discovery
- Redirection to an alternate server
- A fingerprint attribute for demultiplexing
- 2 authentication and message integrity exchanges (username, password,
message-integrity)
- long-term credentials (pre-provisioned credentials)
- short-term credentials (out-of-band method before STUN exchange,
credentials expire quickly; e.g. ICE)
12
Authentication and message integrity
- long-term credentials (pre-provisioned credentials with digest authentication)
- Server replies with ERROR-CODE 401, REALM and NONCE (for replay protection)
- Client sends request again, with USERNAME, REALM, NONCE and the computed
MESSAGE-INTEGRITY
- Indications cannot be challenged so cannot use this method
- short-term credentials (out-of-band method before STUN, credentials expire; e.g. ICE)
- Authentication requires USERNAME and MESSAGE-INTEGRITY Attributes.
- Responses contain the MESSAGE-INTEGRITY Attribute.
Errors: 401 (unauthorized, failed authentication), 400 (bad request, missing attributes), 438 (stale nonce)
13
Multiplexing
STUN Messages can be multiplexed with other protocols, e.g. with RTP.
14
Sending Requests or Indications over UDP
Requests can be retransmitted until a Response is received. Exponential backoff
with RTO (Retransmission TimeOut)
Indications are not retransmitted and so are not reliable.
15
Sending Requests or Indications over TCP or
TLS-over-TCP
The STUN client opens a TCP connection to the STUN server.
TLS:
- Minimum TLS_RSA_WITH_AES_128_CBC_SHA ciphersuite
- The client SHOULD verify the server certificate
- The client MUST verify the server identity
The STUN server should not close TCP connections (nor open connections
towards the client).
16
Sending Responses (Success or Error)
The Method is the same as the Request. Class is either “Success Response” or “Error Response”.
For Success Response to Binding method:
- The server adds a XOR-MAPPED-ADDRESS Attribute with source Transport Address.
For Error Response:
- The server adds an ERROR-CODE Attribute.
- Add the authentication Attributes if applicable (e.g. error 401)
- Add other applicable Attributes (e.g. UNKNOWN-ATTRIBUTES for error 420)
17
DNS discovery
SRV records: the service type is stun (stuns for TLS-over-TCP)
Default port for UDP and TCP: 3478
Default port for TLS: 5349
No SRV record: perform A or AAAA lookup.
18
ALTERNATE-SERVER mechanism
Used to redirect STUN clients to another STUN server.
ERROR-CODE is 300
ALTERNATE-SERVER Attribute present in response
19
STUN Attributes
A STUN message can have 0 or more Attributes, after the header. Attributes can
appear more than once inside a message
Each Attribute is a Type-Length-Value structure.
Type: 16 bits - 0x0000 to 0x7FFF are comprehension-required, 0x8000 to 0xFFFF
are comprehension-optional
Length: 16 bits
Value: variable, padded to multiple of 32 bits. 20
MAPPED-ADDRESS
A reflexive transport address of the client.
First 8 bits set to 0
Address family: 8 bits (0x01: IPv4, 0x02: IPv6)
Port: 16 bits
IP address: 32 bits if IPv4, 128 bits if IPv6
Network byte order
21
XOR-MAPPED-ADDRESS
Same as MAPPED-ADDRESS, but the reflexive transport address is obfuscated
through the XOR function (with the Magic Cookie).
X-Port is the Port XOR’d with the 16 most significant bits of the Magic Cookie.
X-Address:
- IPv4: XOR’d Address with Magic Cookie (32 bits)
- IPv6: XOR-d Address with Magic Cookie (32 bits) + Transaction ID (96 bits)
22
MESSAGE-INTEGRITY
HMAC-SHA1 of the STUN message
20 Bytes
For long-term credentials: key = MD5(username ":" realm ":" SASLprep(password))
For short-term credentials: key = SASLprep(password)
23
FINGERPRINT
CRC-32 of the STUN message (excluding the FINGERPRINT Attribute itself),
XOR’d with 0x5354554E.
When present must be the last Attribute, so also after MESSAGE-INTEGRITY.
This means FINGERPRINT depends on MESSAGE-INTEGRITY value.
24
Other Attributes
- USERNAME
- ERROR-CODE
- REALM
- NONCE
- UNKNOWN-ATTRIBUTES (in 420 error responses)
- SOFTWARE
- ALTERNATE-SERVER
25
Security
Considerations
1. Attacks against the protocol
- Outside attacks
- Inside attacks
2. Attacks affecting the usage
- DDoS against a Target
- Silencing a Client
- Assuming the identity of a
Client
- Eavesdropping
3. Hash agility plan
- In case HMAC-SHA1
becomes compromised
26
Attacks against the protocol
Outside attacks: an attacker modifies a message in transit. These are detected
through the message-integrity mechanism. Such packets must be dropped.
Subject to offline dictionary attacks: use TLS or strong passwords.
Inside attacks: DDoS attack from a malicious client to a STUN server. False
source address to generate traffic (responses) to a victim: apply ingress source
filtering.
Revealing software versions in SOFTWARE attribute: make it optional.
27
Attacks affecting the usage
DDoS against a Target: The attacker provides one or more clients with a faked reflexive address that
points to the target. Only possible if the packets from the server pass through the attacker.
Silencing a Client: The attacker provides a client with a faked reflexive address that points nowhere, so
the target can’t receive.
Assuming the identity of a Client: As in “Silencing a Client”, but the faked reflexive address points to the
attacker.
Eavesdropping: The attacker forces the client to use a reflexive address that routes to the attacker itself,
then the attacker forwards any client it receives to the client. The attacker sees all the packets received
by the target.
28
References
https://tools.ietf.org/html/rfc5389, “Session Traversal Utilities for NAT”
29
Thanks!
Giacomo Vacca
@giavac
30

More Related Content

What's hot

Cisco Live! :: Introduction to Segment Routing :: BRKRST-2124 | Las Vegas 2017
Cisco Live! :: Introduction to Segment Routing :: BRKRST-2124  | Las Vegas 2017Cisco Live! :: Introduction to Segment Routing :: BRKRST-2124  | Las Vegas 2017
Cisco Live! :: Introduction to Segment Routing :: BRKRST-2124 | Las Vegas 2017Bruno Teixeira
 
14 palo alto quality of service(qos) concept
14 palo alto quality of service(qos) concept14 palo alto quality of service(qos) concept
14 palo alto quality of service(qos) conceptMostafa El Lathy
 
Introduction to OpenFlow
Introduction to OpenFlowIntroduction to OpenFlow
Introduction to OpenFlowJoel W. King
 
10 palo alto nat policy concepts
10 palo alto nat policy concepts10 palo alto nat policy concepts
10 palo alto nat policy conceptsMostafa El Lathy
 
Advanced Topics and Future Directions in MPLS
Advanced Topics and Future Directions in MPLS Advanced Topics and Future Directions in MPLS
Advanced Topics and Future Directions in MPLS Cisco Canada
 
Real time transport protocol
Real time transport protocolReal time transport protocol
Real time transport protocolSwaroopSorte
 
MPLS L3 VPN Tutorial, by Nurul Islam Roman [APNIC 38]
MPLS L3 VPN Tutorial, by Nurul Islam Roman [APNIC 38]MPLS L3 VPN Tutorial, by Nurul Islam Roman [APNIC 38]
MPLS L3 VPN Tutorial, by Nurul Islam Roman [APNIC 38]APNIC
 
Session Initiation Protocol
Session Initiation ProtocolSession Initiation Protocol
Session Initiation ProtocolMatt Bynum
 
DDoS Mitigation using BGP Flowspec
DDoS Mitigation using BGP Flowspec DDoS Mitigation using BGP Flowspec
DDoS Mitigation using BGP Flowspec APNIC
 

What's hot (20)

IGMP
IGMPIGMP
IGMP
 
Cisco Live! :: Introduction to Segment Routing :: BRKRST-2124 | Las Vegas 2017
Cisco Live! :: Introduction to Segment Routing :: BRKRST-2124  | Las Vegas 2017Cisco Live! :: Introduction to Segment Routing :: BRKRST-2124  | Las Vegas 2017
Cisco Live! :: Introduction to Segment Routing :: BRKRST-2124 | Las Vegas 2017
 
Radius1
Radius1Radius1
Radius1
 
Cisco ASA Firewalls
Cisco ASA FirewallsCisco ASA Firewalls
Cisco ASA Firewalls
 
IPSec and VPN
IPSec and VPNIPSec and VPN
IPSec and VPN
 
IPv6
IPv6IPv6
IPv6
 
14 palo alto quality of service(qos) concept
14 palo alto quality of service(qos) concept14 palo alto quality of service(qos) concept
14 palo alto quality of service(qos) concept
 
Introduction to OpenFlow
Introduction to OpenFlowIntroduction to OpenFlow
Introduction to OpenFlow
 
ccna
ccnaccna
ccna
 
10 palo alto nat policy concepts
10 palo alto nat policy concepts10 palo alto nat policy concepts
10 palo alto nat policy concepts
 
Asa packet-flow-00
Asa packet-flow-00Asa packet-flow-00
Asa packet-flow-00
 
Advanced Topics and Future Directions in MPLS
Advanced Topics and Future Directions in MPLS Advanced Topics and Future Directions in MPLS
Advanced Topics and Future Directions in MPLS
 
Real time transport protocol
Real time transport protocolReal time transport protocol
Real time transport protocol
 
MPLS L3 VPN Tutorial, by Nurul Islam Roman [APNIC 38]
MPLS L3 VPN Tutorial, by Nurul Islam Roman [APNIC 38]MPLS L3 VPN Tutorial, by Nurul Islam Roman [APNIC 38]
MPLS L3 VPN Tutorial, by Nurul Islam Roman [APNIC 38]
 
Chapter 2 point-to-point protocol (ppp)
Chapter 2   point-to-point protocol (ppp)Chapter 2   point-to-point protocol (ppp)
Chapter 2 point-to-point protocol (ppp)
 
VPLS Fundamental
VPLS FundamentalVPLS Fundamental
VPLS Fundamental
 
Session Initiation Protocol
Session Initiation ProtocolSession Initiation Protocol
Session Initiation Protocol
 
NAT Traversal
NAT TraversalNAT Traversal
NAT Traversal
 
MENOG-Segment Routing Introduction
MENOG-Segment Routing IntroductionMENOG-Segment Routing Introduction
MENOG-Segment Routing Introduction
 
DDoS Mitigation using BGP Flowspec
DDoS Mitigation using BGP Flowspec DDoS Mitigation using BGP Flowspec
DDoS Mitigation using BGP Flowspec
 

Similar to STUN How to Determine Your Public IP and Port Using the STUN Protocol

Introduction to DIAMETER
Introduction to DIAMETERIntroduction to DIAMETER
Introduction to DIAMETERHossein Yavari
 
Ssl (Secure Socket Layer)
Ssl (Secure Socket Layer)Ssl (Secure Socket Layer)
Ssl (Secure Socket Layer)Sandeep Gupta
 
Computer network (4)
Computer network (4)Computer network (4)
Computer network (4)NYversity
 
Radius Protocol
Radius ProtocolRadius Protocol
Radius ProtocolNetwax Lab
 
CCNA Interview.pdf
CCNA Interview.pdfCCNA Interview.pdf
CCNA Interview.pdfhoang971
 
Bt0072 computer networks 2
Bt0072 computer networks  2Bt0072 computer networks  2
Bt0072 computer networks 2Techglyphs
 
Training Day Slides
Training Day SlidesTraining Day Slides
Training Day Slidesadam_merritt
 
Transport Layer Services : Multiplexing And Demultiplexing
Transport Layer Services : Multiplexing And DemultiplexingTransport Layer Services : Multiplexing And Demultiplexing
Transport Layer Services : Multiplexing And DemultiplexingKeyur Vadodariya
 
Chapter Five - Transport Layer.pptx
Chapter Five - Transport Layer.pptxChapter Five - Transport Layer.pptx
Chapter Five - Transport Layer.pptxGirT2
 
Network protocols
Network protocolsNetwork protocols
Network protocolsAbiud Orina
 
Remote access service
Remote access serviceRemote access service
Remote access serviceApoorw Pandey
 
Tcp header/IP Header/Authentication header
Tcp header/IP Header/Authentication headerTcp header/IP Header/Authentication header
Tcp header/IP Header/Authentication headerFaizan Shaikh
 
tcpheader-151221111244.pdf
tcpheader-151221111244.pdftcpheader-151221111244.pdf
tcpheader-151221111244.pdfEnumulaBhargava1
 

Similar to STUN How to Determine Your Public IP and Port Using the STUN Protocol (20)

Introduction to DIAMETER
Introduction to DIAMETERIntroduction to DIAMETER
Introduction to DIAMETER
 
Ssl (Secure Socket Layer)
Ssl (Secure Socket Layer)Ssl (Secure Socket Layer)
Ssl (Secure Socket Layer)
 
Computer network (4)
Computer network (4)Computer network (4)
Computer network (4)
 
Ipv6up
Ipv6upIpv6up
Ipv6up
 
Radius Protocol
Radius ProtocolRadius Protocol
Radius Protocol
 
CCNA Interview.pdf
CCNA Interview.pdfCCNA Interview.pdf
CCNA Interview.pdf
 
Bt0072 computer networks 2
Bt0072 computer networks  2Bt0072 computer networks  2
Bt0072 computer networks 2
 
Firewall
FirewallFirewall
Firewall
 
Training Day Slides
Training Day SlidesTraining Day Slides
Training Day Slides
 
Transport Layer Services : Multiplexing And Demultiplexing
Transport Layer Services : Multiplexing And DemultiplexingTransport Layer Services : Multiplexing And Demultiplexing
Transport Layer Services : Multiplexing And Demultiplexing
 
Lecture set 7
Lecture set 7Lecture set 7
Lecture set 7
 
Firewalls
FirewallsFirewalls
Firewalls
 
Chapter Five - Transport Layer.pptx
Chapter Five - Transport Layer.pptxChapter Five - Transport Layer.pptx
Chapter Five - Transport Layer.pptx
 
Transportsec
TransportsecTransportsec
Transportsec
 
Network protocols
Network protocolsNetwork protocols
Network protocols
 
4 vpn s
4 vpn s4 vpn s
4 vpn s
 
Lecture9
Lecture9Lecture9
Lecture9
 
Remote access service
Remote access serviceRemote access service
Remote access service
 
Tcp header/IP Header/Authentication header
Tcp header/IP Header/Authentication headerTcp header/IP Header/Authentication header
Tcp header/IP Header/Authentication header
 
tcpheader-151221111244.pdf
tcpheader-151221111244.pdftcpheader-151221111244.pdf
tcpheader-151221111244.pdf
 

More from Giacomo Vacca

Modern VoIP in modern infrastructures
Modern VoIP in modern infrastructuresModern VoIP in modern infrastructures
Modern VoIP in modern infrastructuresGiacomo Vacca
 
Modern VoIP in Modern Infrastructures
Modern VoIP in Modern InfrastructuresModern VoIP in Modern Infrastructures
Modern VoIP in Modern InfrastructuresGiacomo Vacca
 
An SFU/MCU integration for heterogeneous environments
An SFU/MCU integration for heterogeneous environmentsAn SFU/MCU integration for heterogeneous environments
An SFU/MCU integration for heterogeneous environmentsGiacomo Vacca
 
Kamailio World 2018 - Workshop: kamailio-tests
Kamailio World 2018 - Workshop: kamailio-testsKamailio World 2018 - Workshop: kamailio-tests
Kamailio World 2018 - Workshop: kamailio-testsGiacomo Vacca
 
Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017Giacomo Vacca
 
[workshop] The Revolutionary WebRTC
[workshop] The Revolutionary WebRTC[workshop] The Revolutionary WebRTC
[workshop] The Revolutionary WebRTCGiacomo Vacca
 
Continuous Integration and Kamailio
Continuous Integration and KamailioContinuous Integration and Kamailio
Continuous Integration and KamailioGiacomo Vacca
 
Docker - From Walking To Running
Docker - From Walking To RunningDocker - From Walking To Running
Docker - From Walking To RunningGiacomo Vacca
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationGiacomo Vacca
 
Top 5 Challenges To Add Web Calls to Truphone VoIP Platform
Top 5 Challenges To Add Web Calls to Truphone VoIP PlatformTop 5 Challenges To Add Web Calls to Truphone VoIP Platform
Top 5 Challenges To Add Web Calls to Truphone VoIP PlatformGiacomo Vacca
 
Automatic Kamailio Deployments With Puppet
Automatic Kamailio Deployments With PuppetAutomatic Kamailio Deployments With Puppet
Automatic Kamailio Deployments With PuppetGiacomo Vacca
 

More from Giacomo Vacca (13)

Modern VoIP in modern infrastructures
Modern VoIP in modern infrastructuresModern VoIP in modern infrastructures
Modern VoIP in modern infrastructures
 
RIPP Notes
RIPP NotesRIPP Notes
RIPP Notes
 
Modern VoIP in Modern Infrastructures
Modern VoIP in Modern InfrastructuresModern VoIP in Modern Infrastructures
Modern VoIP in Modern Infrastructures
 
An SFU/MCU integration for heterogeneous environments
An SFU/MCU integration for heterogeneous environmentsAn SFU/MCU integration for heterogeneous environments
An SFU/MCU integration for heterogeneous environments
 
Kamailio World 2018 - Workshop: kamailio-tests
Kamailio World 2018 - Workshop: kamailio-testsKamailio World 2018 - Workshop: kamailio-tests
Kamailio World 2018 - Workshop: kamailio-tests
 
Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017
 
[workshop] The Revolutionary WebRTC
[workshop] The Revolutionary WebRTC[workshop] The Revolutionary WebRTC
[workshop] The Revolutionary WebRTC
 
Continuous Integration and Kamailio
Continuous Integration and KamailioContinuous Integration and Kamailio
Continuous Integration and Kamailio
 
Docker - From Walking To Running
Docker - From Walking To RunningDocker - From Walking To Running
Docker - From Walking To Running
 
Docker From Scratch
Docker From ScratchDocker From Scratch
Docker From Scratch
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker and Puppet for Continuous Integration
Docker and Puppet for Continuous Integration
 
Top 5 Challenges To Add Web Calls to Truphone VoIP Platform
Top 5 Challenges To Add Web Calls to Truphone VoIP PlatformTop 5 Challenges To Add Web Calls to Truphone VoIP Platform
Top 5 Challenges To Add Web Calls to Truphone VoIP Platform
 
Automatic Kamailio Deployments With Puppet
Automatic Kamailio Deployments With PuppetAutomatic Kamailio Deployments With Puppet
Automatic Kamailio Deployments With Puppet
 

Recently uploaded

VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsThierry TROUIN ☁
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Gram Darshan PPT cyber rural in villages of india
Gram Darshan PPT cyber rural  in villages of indiaGram Darshan PPT cyber rural  in villages of india
Gram Darshan PPT cyber rural in villages of indiaimessage0108
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607dollysharma2066
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Sheetaleventcompany
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
Radiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsRadiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsstephieert
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Roomdivyansh0kumar0
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝soniya singh
 

Recently uploaded (20)

VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with Flows
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Gram Darshan PPT cyber rural in villages of india
Gram Darshan PPT cyber rural  in villages of indiaGram Darshan PPT cyber rural  in villages of india
Gram Darshan PPT cyber rural in villages of india
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Radiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsRadiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girls
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
 
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 

STUN How to Determine Your Public IP and Port Using the STUN Protocol

  • 1. STUN Studying the STUN protocol Giacomo Vacca, @giavac
  • 2. STUN: Session Traversal Utilities for NAT RFC 5389 (8489) "[STUN] can be used by an endpoint to determine the IP address and port allocated to it by a NAT. It can also be used to check connectivity between two endpoints, and as a keep-alive protocol to maintain NAT bindings." Combination with other protocols: - Connectivity checks: ICE (RFC 8845) - Relay: TURN (RFC 5766, 8656) 2
  • 3. Main characteristics - Extensible packet format - Several transport protocols - Two forms of authentication 3
  • 4. STUN “usages” A “usage” defines: - When STUN messages get sent - Optional Attributes to include - What server is used - The authentication mechanism ICE (RFC 8445), SIP OUTBOUND (RFC 5626) and NAT Behaviour Discovery (RFC 5780) are all “STUN usages” and are “complete NAT traversal solutions”. A STUN extension may define new methods, attributes or response codes. 4
  • 5. STUN operations STUN is a client-server protocol. STUN defines 2 types of transactions: 1. Request/Response 2. Indication Request/Response: client sends a request, server sends a response. Indication: either client or server sends an indication, without the need for a response. A 96-bit transaction ID is required. 5
  • 6. STUN messages All STUN messages start with a fixed header with: - Method (e.g. Binding) - Class (Request, Success Response, Error Response or Indication) - Transaction ID (96-bit number) After the header there are zero or more Attributes (in the form of Type-Length-Value). Attributes can be required (“comprehension-required”) or optional (“comprehension-optional”). Attributes are always padded to a multiple of 4 Bytes. Optional: FINGERPRINT 6
  • 7. STUN header Binary, network order, big endian. 20 Bytes header + 0 or more Attributes. The header contains: - Message Type (16 bits) - Message Length (16 bits) - Magic Cookie (32 bits) - Transaction ID (96 bits) Message Type: First 2 most significant bits: 00, Class (Request, Success Response, Error Response, Indication), Method. 7
  • 8. The Magic Cookie 0x2112A442 0010 0001 0001 0010 1010 0100 0100 0010 It’s used to further distinguish a STUN packet from other types, and to XOR the transport addresses. 8
  • 9. Transport Addresses A Transport Address is the combination of an IP address and port, e.g. 172.17.0.3:44567 Reflexive Transport Address: A Transport Address learned by a STUN client, identifying that client as seen by another host or network, typically a STUN server. e.g. “What’s my public IP and port?” Provided in MAPPED-ADDRESS or XOR-MAPPED-ADDRESS attributes in STUN responses. ç 9
  • 10. STUN Binding method 1/2 Used in Request/Response transactions: to determine what binding a STUN server has allocated for the client, and keep the binding alive. Used in Indication transactions: to keep the binding alive. In Request/Response transactions, a STUN client sends a “Binding Request” to the STUN server. The STUN server replies with a “Binding Success Response”, containing an attribute called XOR-MAPPED-ADDRESS, which value is the XOR’d source transport address, as seen by the STUN server. In this way the STUN client learns its Reflexive Transport Address allocated by the outermost NAT. 10
  • 12. STUN mechanisms (optional procedures) - DNS discovery - Redirection to an alternate server - A fingerprint attribute for demultiplexing - 2 authentication and message integrity exchanges (username, password, message-integrity) - long-term credentials (pre-provisioned credentials) - short-term credentials (out-of-band method before STUN exchange, credentials expire quickly; e.g. ICE) 12
  • 13. Authentication and message integrity - long-term credentials (pre-provisioned credentials with digest authentication) - Server replies with ERROR-CODE 401, REALM and NONCE (for replay protection) - Client sends request again, with USERNAME, REALM, NONCE and the computed MESSAGE-INTEGRITY - Indications cannot be challenged so cannot use this method - short-term credentials (out-of-band method before STUN, credentials expire; e.g. ICE) - Authentication requires USERNAME and MESSAGE-INTEGRITY Attributes. - Responses contain the MESSAGE-INTEGRITY Attribute. Errors: 401 (unauthorized, failed authentication), 400 (bad request, missing attributes), 438 (stale nonce) 13
  • 14. Multiplexing STUN Messages can be multiplexed with other protocols, e.g. with RTP. 14
  • 15. Sending Requests or Indications over UDP Requests can be retransmitted until a Response is received. Exponential backoff with RTO (Retransmission TimeOut) Indications are not retransmitted and so are not reliable. 15
  • 16. Sending Requests or Indications over TCP or TLS-over-TCP The STUN client opens a TCP connection to the STUN server. TLS: - Minimum TLS_RSA_WITH_AES_128_CBC_SHA ciphersuite - The client SHOULD verify the server certificate - The client MUST verify the server identity The STUN server should not close TCP connections (nor open connections towards the client). 16
  • 17. Sending Responses (Success or Error) The Method is the same as the Request. Class is either “Success Response” or “Error Response”. For Success Response to Binding method: - The server adds a XOR-MAPPED-ADDRESS Attribute with source Transport Address. For Error Response: - The server adds an ERROR-CODE Attribute. - Add the authentication Attributes if applicable (e.g. error 401) - Add other applicable Attributes (e.g. UNKNOWN-ATTRIBUTES for error 420) 17
  • 18. DNS discovery SRV records: the service type is stun (stuns for TLS-over-TCP) Default port for UDP and TCP: 3478 Default port for TLS: 5349 No SRV record: perform A or AAAA lookup. 18
  • 19. ALTERNATE-SERVER mechanism Used to redirect STUN clients to another STUN server. ERROR-CODE is 300 ALTERNATE-SERVER Attribute present in response 19
  • 20. STUN Attributes A STUN message can have 0 or more Attributes, after the header. Attributes can appear more than once inside a message Each Attribute is a Type-Length-Value structure. Type: 16 bits - 0x0000 to 0x7FFF are comprehension-required, 0x8000 to 0xFFFF are comprehension-optional Length: 16 bits Value: variable, padded to multiple of 32 bits. 20
  • 21. MAPPED-ADDRESS A reflexive transport address of the client. First 8 bits set to 0 Address family: 8 bits (0x01: IPv4, 0x02: IPv6) Port: 16 bits IP address: 32 bits if IPv4, 128 bits if IPv6 Network byte order 21
  • 22. XOR-MAPPED-ADDRESS Same as MAPPED-ADDRESS, but the reflexive transport address is obfuscated through the XOR function (with the Magic Cookie). X-Port is the Port XOR’d with the 16 most significant bits of the Magic Cookie. X-Address: - IPv4: XOR’d Address with Magic Cookie (32 bits) - IPv6: XOR-d Address with Magic Cookie (32 bits) + Transaction ID (96 bits) 22
  • 23. MESSAGE-INTEGRITY HMAC-SHA1 of the STUN message 20 Bytes For long-term credentials: key = MD5(username ":" realm ":" SASLprep(password)) For short-term credentials: key = SASLprep(password) 23
  • 24. FINGERPRINT CRC-32 of the STUN message (excluding the FINGERPRINT Attribute itself), XOR’d with 0x5354554E. When present must be the last Attribute, so also after MESSAGE-INTEGRITY. This means FINGERPRINT depends on MESSAGE-INTEGRITY value. 24
  • 25. Other Attributes - USERNAME - ERROR-CODE - REALM - NONCE - UNKNOWN-ATTRIBUTES (in 420 error responses) - SOFTWARE - ALTERNATE-SERVER 25
  • 26. Security Considerations 1. Attacks against the protocol - Outside attacks - Inside attacks 2. Attacks affecting the usage - DDoS against a Target - Silencing a Client - Assuming the identity of a Client - Eavesdropping 3. Hash agility plan - In case HMAC-SHA1 becomes compromised 26
  • 27. Attacks against the protocol Outside attacks: an attacker modifies a message in transit. These are detected through the message-integrity mechanism. Such packets must be dropped. Subject to offline dictionary attacks: use TLS or strong passwords. Inside attacks: DDoS attack from a malicious client to a STUN server. False source address to generate traffic (responses) to a victim: apply ingress source filtering. Revealing software versions in SOFTWARE attribute: make it optional. 27
  • 28. Attacks affecting the usage DDoS against a Target: The attacker provides one or more clients with a faked reflexive address that points to the target. Only possible if the packets from the server pass through the attacker. Silencing a Client: The attacker provides a client with a faked reflexive address that points nowhere, so the target can’t receive. Assuming the identity of a Client: As in “Silencing a Client”, but the faked reflexive address points to the attacker. Eavesdropping: The attacker forces the client to use a reflexive address that routes to the attacker itself, then the attacker forwards any client it receives to the client. The attacker sees all the packets received by the target. 28