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โ€ de๏ฌnes:
- 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 de๏ฌne new methods, attributes or response codes. 4
STUN operations
STUN is a client-server protocol.
STUN de๏ฌnes 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 ๏ฌxed 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 signi๏ฌcant
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
Re๏ฌ‚exive 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 Re๏ฌ‚exive 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 ๏ฌngerprint 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 certi๏ฌcate
- 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 re๏ฌ‚exive 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 re๏ฌ‚exive transport address is obfuscated
through the XOR function (with the Magic Cookie).
X-Port is the Port XORโ€™d with the 16 most signi๏ฌcant 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 modi๏ฌes a message in transit. These are detected
through the message-integrity mechanism. Such packets must be dropped.
Subject to o๏ฌ„ine dictionary attacks: use TLS or strong passwords.
Inside attacks: DDoS attack from a malicious client to a STUN server. False
source address to generate tra๏ฌƒc (responses) to a victim: apply ingress source
๏ฌltering.
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 re๏ฌ‚exive 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 re๏ฌ‚exive address that points nowhere, so
the target canโ€™t receive.
Assuming the identity of a Client: As in โ€œSilencing a Clientโ€, but the faked re๏ฌ‚exive address points to the
attacker.
Eavesdropping: The attacker forces the client to use a re๏ฌ‚exive 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 IPv6 Tutorial
Cisco IPv6 TutorialCisco IPv6 Tutorial
Cisco IPv6 Tutorial
kriz5
ย 

What's hot (20)

MPLS Traffic Engineering
MPLS Traffic EngineeringMPLS Traffic Engineering
MPLS Traffic Engineering
ย 
IPv6 - Neighbour Discovery
IPv6 - Neighbour DiscoveryIPv6 - Neighbour Discovery
IPv6 - Neighbour Discovery
ย 
VXLAN BGP EVPN: Technology Building Blocks
VXLAN BGP EVPN: Technology Building BlocksVXLAN BGP EVPN: Technology Building Blocks
VXLAN BGP EVPN: Technology Building Blocks
ย 
How BGP Works
How BGP WorksHow BGP Works
How BGP Works
ย 
Cisco IPv6 Tutorial
Cisco IPv6 TutorialCisco IPv6 Tutorial
Cisco IPv6 Tutorial
ย 
Mpls L3_vpn
Mpls L3_vpnMpls L3_vpn
Mpls L3_vpn
ย 
Routage ospf
Routage ospfRoutage ospf
Routage ospf
ย 
Segment Routing
Segment RoutingSegment Routing
Segment Routing
ย 
EVPN Introduction
EVPN IntroductionEVPN Introduction
EVPN Introduction
ย 
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]
ย 
EMEA Airheads- Aruba Instant AP- VPN Troubleshooting
EMEA Airheads- Aruba Instant AP-  VPN TroubleshootingEMEA Airheads- Aruba Instant AP-  VPN Troubleshooting
EMEA Airheads- Aruba Instant AP- VPN Troubleshooting
ย 
Vxlan deep dive session rev0.5 final
Vxlan deep dive session rev0.5   finalVxlan deep dive session rev0.5   final
Vxlan deep dive session rev0.5 final
ย 
Building DataCenter networks with VXLAN BGP-EVPN
Building DataCenter networks with VXLAN BGP-EVPNBuilding DataCenter networks with VXLAN BGP-EVPN
Building DataCenter networks with VXLAN BGP-EVPN
ย 
Real time stock processing with apache nifi, apache flink and apache kafka
Real time stock processing with apache nifi, apache flink and apache kafkaReal time stock processing with apache nifi, apache flink and apache kafka
Real time stock processing with apache nifi, apache flink and apache kafka
ย 
Atelier Technique WALLIX ACSS 2018
Atelier Technique WALLIX ACSS 2018Atelier Technique WALLIX ACSS 2018
Atelier Technique WALLIX ACSS 2018
ย 
Next Generation IP Transport
Next Generation IP TransportNext Generation IP Transport
Next Generation IP Transport
ย 
Cisco Live! :: Carrier Ethernet 2.0 :: BRKSPG-2720 | Las Vegas July/2016
Cisco Live! :: Carrier Ethernet 2.0 :: BRKSPG-2720 | Las Vegas July/2016Cisco Live! :: Carrier Ethernet 2.0 :: BRKSPG-2720 | Las Vegas July/2016
Cisco Live! :: Carrier Ethernet 2.0 :: BRKSPG-2720 | Las Vegas July/2016
ย 
MPLS Layer 3 VPN
MPLS Layer 3 VPN MPLS Layer 3 VPN
MPLS Layer 3 VPN
ย 
Ssl Vpn presentation at CoolTech club
Ssl Vpn presentation at CoolTech clubSsl Vpn presentation at CoolTech club
Ssl Vpn presentation at CoolTech club
ย 
3 Kafka patterns to deliver Streaming Machine Learning models with Andrea Spi...
3 Kafka patterns to deliver Streaming Machine Learning models with Andrea Spi...3 Kafka patterns to deliver Streaming Machine Learning models with Andrea Spi...
3 Kafka patterns to deliver Streaming Machine Learning models with Andrea Spi...
ย 

Similar to STUN protocol

Computer network (4)
Computer network (4)Computer network (4)
Computer network (4)
NYversity
ย 
Lecture set 7
Lecture set 7Lecture set 7
Lecture set 7
Gopi Saiteja
ย 
Chapter Five - Transport Layer.pptx
Chapter Five - Transport Layer.pptxChapter Five - Transport Layer.pptx
Chapter Five - Transport Layer.pptx
GirT2
ย 
Remote access service
Remote access serviceRemote access service
Remote access service
Apoorw Pandey
ย 

Similar to 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

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

๐Ÿ’š๐Ÿ˜‹ Salem Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹
๐Ÿ’š๐Ÿ˜‹ Salem Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹๐Ÿ’š๐Ÿ˜‹ Salem Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹
๐Ÿ’š๐Ÿ˜‹ Salem Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹
nirzagarg
ย 
( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...
nilamkumrai
ย 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
SUHANI PANDEY
ย 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
SUHANI PANDEY
ย 
๐Ÿ’š๐Ÿ˜‹ Bilaspur Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹
๐Ÿ’š๐Ÿ˜‹ Bilaspur Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹๐Ÿ’š๐Ÿ˜‹ Bilaspur Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹
๐Ÿ’š๐Ÿ˜‹ Bilaspur Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹
nirzagarg
ย 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
SUHANI PANDEY
ย 
๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ
๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ
๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ
@Chandigarh #call #Girls 9053900678 @Call #Girls in @Punjab 9053900678
ย 
valsad Escorts Service โ˜Ž๏ธ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service โ˜Ž๏ธ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service โ˜Ž๏ธ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service โ˜Ž๏ธ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
ย 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
singhpriety023
ย 

Recently uploaded (20)

๐Ÿ’š๐Ÿ˜‹ Salem Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹
๐Ÿ’š๐Ÿ˜‹ Salem Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹๐Ÿ’š๐Ÿ˜‹ Salem Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹
๐Ÿ’š๐Ÿ˜‹ Salem Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹
ย 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
ย 
( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...
ย 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
ย 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
ย 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
ย 
All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445
All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445
All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445
ย 
๐Ÿ’š๐Ÿ˜‹ Bilaspur Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹
๐Ÿ’š๐Ÿ˜‹ Bilaspur Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹๐Ÿ’š๐Ÿ˜‹ Bilaspur Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹
๐Ÿ’š๐Ÿ˜‹ Bilaspur Escort Service Call Girls, 9352852248 โ‚น5000 To 25K With AC๐Ÿ’š๐Ÿ˜‹
ย 
best call girls in Hyderabad Finest Escorts Service ๐Ÿ“ž 9352988975 ๐Ÿ“ž Available ...
best call girls in Hyderabad Finest Escorts Service ๐Ÿ“ž 9352988975 ๐Ÿ“ž Available ...best call girls in Hyderabad Finest Escorts Service ๐Ÿ“ž 9352988975 ๐Ÿ“ž Available ...
best call girls in Hyderabad Finest Escorts Service ๐Ÿ“ž 9352988975 ๐Ÿ“ž Available ...
ย 
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
ย 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
ย 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
ย 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
ย 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
ย 
๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ
๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ
๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ
ย 
valsad Escorts Service โ˜Ž๏ธ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service โ˜Ž๏ธ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service โ˜Ž๏ธ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service โ˜Ž๏ธ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
ย 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
ย 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
ย 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
ย 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
ย 

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โ€ de๏ฌnes: - 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 de๏ฌne new methods, attributes or response codes. 4
  • 5. STUN operations STUN is a client-server protocol. STUN de๏ฌnes 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 ๏ฌxed 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 signi๏ฌcant 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 Re๏ฌ‚exive 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 Re๏ฌ‚exive Transport Address allocated by the outermost NAT. 10
  • 12. STUN mechanisms (optional procedures) - DNS discovery - Redirection to an alternate server - A ๏ฌngerprint 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 certi๏ฌcate - 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 re๏ฌ‚exive 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 re๏ฌ‚exive transport address is obfuscated through the XOR function (with the Magic Cookie). X-Port is the Port XORโ€™d with the 16 most signi๏ฌcant 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 modi๏ฌes a message in transit. These are detected through the message-integrity mechanism. Such packets must be dropped. Subject to o๏ฌ„ine dictionary attacks: use TLS or strong passwords. Inside attacks: DDoS attack from a malicious client to a STUN server. False source address to generate tra๏ฌƒc (responses) to a victim: apply ingress source ๏ฌltering. 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 re๏ฌ‚exive 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 re๏ฌ‚exive address that points nowhere, so the target canโ€™t receive. Assuming the identity of a Client: As in โ€œSilencing a Clientโ€, but the faked re๏ฌ‚exive address points to the attacker. Eavesdropping: The attacker forces the client to use a re๏ฌ‚exive 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