Foro de elhacker.net

Comunicaciones => Redes => Mensaje iniciado por: xustyx en 8 Diciembre 2016, 07:32 am



Título: UDP Hole Punching
Publicado por: xustyx en 8 Diciembre 2016, 07:32 am
Buenas,

En esta larga noche sin dormir, dando vueltas por Internet y leyendo cosas interesantes me topado con esto:

https://en.wikipedia.org/wiki/UDP_hole_punching


¿Sabéis de alguna implementación sencilla para echarle un ojo?


Título: Re: UDP Hole Punching
Publicado por: [Arg] $triker; en 8 Diciembre 2016, 15:55 pm
En esta larga noche sin dormir, [...]

Dormir es bueno.



Con respecto a lo otro, parece ser algo muy utilizado a juzgar por lo que veo en el artículo - según lo que dice es un protocolo para enrutar paquetes a Internet entre NATs. Dice que sirve para facilitar la comunicación por proto UDP cuando los paquetes de éste tienen que ser enrutados hacia múltiples NATs, y que no funciona en NATs simétricos.
De hecho, hay un ejemplo.

Citar
Let A and B be the two hosts, each in its own private network; NA and NB are the two NAT devices with globally reachable IP addresses EIPA and EIPB respectively; S is a public server with a well-known globally reachable IP address.

A and B each begin a UDP conversation with S; the NAT devices NA and NB create UDP translation states and assign temporary external port numbers EPA and EPB
S examines the UDP packets to get the source port used by NA and NB (the external NAT ports EPA and EPB)
S passes EIPA:EPA to B and EIPB:EPB to A
A sends a packet to EIPB:EPB.
NA examines A's packet and creates the following tuple in its translation table: {Source-IP-A, EPA, EIPB, EPB}
B sends a packet to EIPA:EPA
NB examines B's packet and creates the following tuple in its translation table: {Source-IP-B, EPB, EIPA, EPA}
Depending on the state of NA's translation table when B's first packet arrives (i.e. whether the tuple {Source-IP-A, EPA, EIPB, EPB} has been created by the time of arrival of B's first packet), B's first packet is dropped (no entry in translation table) or passed (entry in translation table has been made).
Depending on the state of NB's translation table when A's first packet arrives (i.e. whether the tuple {Source-IP-B, EPB, EIPA, EPA} has been created by the time of arrival of A's first packet), A's first packet is dropped (no entry in translation table) or passed (entry in translation table has been made).
At worst, the second packet from A reaches B; at worst the second packet from B reaches A. Holes have been "punched" in the NAT and both hosts can communicate.
If both hosts have Restricted cone NATs or Symmetric NATs, the external NAT ports will differ from those used with S. On some routers, the external ports are picked sequentially making it possible to establish a conversation through guessing nearby ports.

[Fe de erratas] Capaz que podrías hostear dos NATs en tu LAN desde tu PC (calculo que si se puede hostear un proxy y un AP en una PC, esto también se puede hacer), y practicar esto en esa circunstancia.


Título: Re: UDP Hole Punching
Publicado por: engel lex en 8 Diciembre 2016, 16:25 pm
es más o menos lo que hace el protocolo torrent... para los peer comunicarse directamente no podrán porque no hay un port forwarding por los puertos para acceder... así que el nodo le indica a 2 peer que se conectarán y usan esta tecnica

suponga que esta peer 1 y peer 2, los llamaremos p1 y p2

ambos se quieren comunicar pero no hay un port forwarding y el nat no sabrá que hacer con los paquetes entrantes, así que el nodo le comunica a p1 que p2 quiere comunicarse por el puerto de entrada XX y el puerto de salida YY

p1 abre la comunicación llamando a p2:XX desde el puerto YY
p2 abre la comunicación llamando a p1:YY desde el puerto XX

esto creará en el nat de ambos las relación tal que los paquetes pasen sin problema... este comportamiento siempre es con consentimiento de ambas partes...


Título: Re: UDP Hole Punching
Publicado por: xustyx en 8 Diciembre 2016, 22:14 pm
Gracias por la respuestas, ya estuve leyendo un poco ayer y me pareció una manera muy curiosa de saltarse la configuración del router :D

Aún así requiere de un servidor relay y eso es lo que no me gusta por que no deja de ser centralizado... pero bueno.

¿Habéis trabajado con alguna librería para GO o Java?

Me gustaría hacer una POC y programar un poquito haber que sale.