How To Create UDP Peer-To-Peer Connections With Netcat

Поділитися
Вставка
  • Опубліковано 2 січ 2025

КОМЕНТАРІ • 136

  • @EngineerMan
    @EngineerMan  3 роки тому +220

    I would tell everyone a UDP joke, but I'm not sure anyone would get it.

    • @devnull365
      @devnull365 3 роки тому +3

      I didn't get that what was it about?

    • @ray_gannon
      @ray_gannon 3 роки тому +3

      Groannnnnnnnnnnn

    • @MartinPHellwig
      @MartinPHellwig 3 роки тому

      Well what is it then, broadcast or multicast?

    • @notyoursurya
      @notyoursurya 3 роки тому +2

      "Use UDP over TCP to avoid handshakes" ? 🤔

    • @ibnbroly
      @ibnbroly 3 роки тому

      Nice one haha

  • @rickmellor
    @rickmellor 3 роки тому +53

    I'm STUNned that you're talking about this stuff! 😀

    • @EngineerMan
      @EngineerMan  3 роки тому +6

      Relevant pun. I dig it.

    • @cloudtraining3816
      @cloudtraining3816 3 роки тому +2

      sorry i don't get it, but i'm curious, please explain

    • @rickmellor
      @rickmellor 3 роки тому

      @@cloudtraining3816 here you go. en.m.wikipedia.org/wiki/STUN

    • @Nafrayu
      @Nafrayu 2 роки тому +2

      @@cloudtraining3816 "STUN" is a technology that helps with NAT traversal, hence the "STUNned" pun :D

  • @emmanuelpetit9064
    @emmanuelpetit9064 3 роки тому +32

    Informative and Straight to the point as always thanks :). I've learned so much from you!

  • @justbendev2324
    @justbendev2324 3 місяці тому +1

    Great job , this is the easiest way to explain hole punching to someone.

  • @ddjazz
    @ddjazz 3 роки тому +7

    great stuff , title should contain "udp hole punching"

  • @aniket00796
    @aniket00796 3 роки тому +12

    WebRTC would be a cool example for demonstration purposes.

  • @u0000-u2x
    @u0000-u2x Рік тому +3

    I may be wrong here so please correct me, but this doesn't work as explained without a 3rd server. It is not punching a hole in the NAT because his machines are not using a NAT. If they were the NAT would change the source port. To do a hole punch behind NAT you need a 3rd party server that has visibility on the ports used by each of the two NATs.

    • @gerooq
      @gerooq Рік тому

      Exactly. The source port changes on an outgoing packet after it leaves your network

  • @idk____idk6530
    @idk____idk6530 3 роки тому +3

    To the world, you may be just a teacher but to me, you are a hero! Wishing you a Happy Guru Purnima! I bow to the one who has inspired me and taught the right way of life! You are the inspiration who made me overcome every hurdle in python ❤️

  • @amrhegazy7221
    @amrhegazy7221 Рік тому +2

    i've got nc: bind failed: Address already in use

  • @reyuki-i
    @reyuki-i 5 місяців тому

    6:39 wondering why you can reuse the port on p2p-01 machine?

  • @SirKenchalot
    @SirKenchalot 3 роки тому +7

    I think you could have explain more about the hole punching mechanism itself; how doe sit work without opening ports on the firewall?

    • @cl60cruzer
      @cl60cruzer 3 роки тому +4

      Watch between 1:40 and 3:00 again. All "inbound" traffic is firewalled. So he can still dial out. Because hes making requests on both sides the traffic gets through. If outbound traffic was blocked too, then youd be stuck.

    • @AureliusAurelius
      @AureliusAurelius 3 роки тому

      @@cl60cruzer I still don’t get it. Inbound traffic is still blocked, no?

    • @funkypocorn
      @funkypocorn 2 роки тому +6

      @@AureliusAurelius
      It's because nowadays you are almost in any case dealing with so called stateful firewalls. Since its a linux machine it's probably iptables, firewalld or sth. similar.
      So when he sends out the package with src-port 50001 and dst-port: 50002 to ip ... the stateful firewall marks/flags this packet so every return packet for it arriving with dst-port 50001 within a certain threshold time is considered as the answer packet by the firewall and therefore let through. This is often also called UDP pseudo state in firewall systems.
      For the timeout I think the default is 30 seconds but could be changed in /proc/sys/net/netfilter/nf_conntrack_udp_timeout

    • @AureliusAurelius
      @AureliusAurelius 2 роки тому

      @@funkypocorn wow, so interesting. Thank you

    • @funkypocorn
      @funkypocorn 2 роки тому

      @@AureliusAurelius
      Just a few info to add: if you are on a linux system with iptables, most likely a rule like this is in place on your INPUT chain:
      " -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT"
      This lets this so called established udp connection/flow pass, which was created from your outgoing packet with src-port:50001 dst-port:50002 you send earlier. Because this pseudo state or in firewall slang called flow got created your input chain let's it go through.
      If you want to dig in deeper I recommend reading about connecting tracking via the conntrack module within the linux kernel.

  • @xspeed7434
    @xspeed7434 Рік тому

    So at 6:20 you are typing the command to send from p2 to p1. I see you specified a source port. If I wanted to only do a one way connection where I only send from p2 to p1 would this work if I didn’t specify source port like u did at 6:20?

  • @Andrew90046zero
    @Andrew90046zero 2 роки тому

    I know somone may have mentioned somthing about this, but at 6:37 when you send a message from p2p1 to p2p2, and there is still no message recieved on p2p2 listener, and that's because on p2p2 you only punched a hole for port 50002, but p2p1 was trying to send a message to p2p1. So nothing came through. A p2p1's hole punch was on port 50001, and p2p2 was sending packets to 50001.
    This kinda confusing me when I was trying to write my code in C#, but I eventually figured out what was going on.
    So when you hole punch, you want both routers (for simplicity sake) to punch a hole for the same port (in your case 50001), it seems like the destination port (50002) doesn't matter as much. But I could be wrong on that.

  • @UnixDaemonKiller
    @UnixDaemonKiller 7 місяців тому

    When Anycast starts interfering with this shit really hits the fan.

  • @thefather8362
    @thefather8362 3 роки тому +1

    Great video. This is exactly why most corporate networks disable up, at least my company does.

  • @Smiff3447
    @Smiff3447 3 роки тому +6

    Did not think this was possible without port forwarding or a third server. From what I understand, this only works with UDP since it's "connection-less", or is this also possible with TCP?

    • @Belioyt
      @Belioyt 3 роки тому

      It's in the title, did you watch the video?

    • @MartinPHellwig
      @MartinPHellwig 3 роки тому +2

      You could always encapsulate TCP over UDP, though unless you know what you are doing you are going to have a world of pain with determining appropriate MTU and TTL values.

    • @gerooq
      @gerooq Рік тому

      @@Belioythe had a valid question you just didn’t understand his question

    • @unique-username
      @unique-username Місяць тому

      Yes, I don't understand how he knew port 50002 was going to be the translated port. Maybe he made it open for the demo?

  • @haroldpepete
    @haroldpepete 3 роки тому +2

    something that you miss, Isp currently makes Carrier Grade-nat, that means you have multiple state nat inside Carrier network, too many customers navigate with one public ip

    • @grp635
      @grp635 3 роки тому

      In this case, the technique won't works?

    • @haroldpepete
      @haroldpepete 3 роки тому +1

      @@grp635 it doesn't work, isp uses Carrier Grade-nat and.your router have to make multiples jump inside carrier.network to navigate to internet, you can use traceroute to see how many jump makes your pc to navigate

  • @reyuki-i
    @reyuki-i 5 місяців тому

    what is network condition that prevent UDP hole punch technique? or this technique will work all the time and only need both peer to be connected to the internet?

  • @unique-username
    @unique-username Місяць тому

    How do you know the routers will use 50002 as the translated port?

  • @tomwimmenhove4652
    @tomwimmenhove4652 Рік тому +1

    I'm surprised netcat lets you pick a source port that's already in use by the other process listening on it. I'm simply getting an 'address already in use' error when running the hole punch command.

    • @JonathanJardine
      @JonathanJardine Рік тому +1

      Me too not sure how he got around this.

    • @AareffSystems
      @AareffSystems Рік тому

      YES, me too, tried everything, but always an error saying port is already being used
      @@JonathanJardine

  • @himanshushukla787
    @himanshushukla787 3 роки тому +7

    No BS straight Info. That's Engineer man for you. :)

  • @socksincrocks4421
    @socksincrocks4421 3 роки тому +1

    what about traffic security? Is the transfer of data encrypted / secured by netcat?

  • @tatterdemalion898
    @tatterdemalion898 3 роки тому +1

    Hello, i would like to make a server client app, where i would chat, and i was thinking to use a server somewhere over the internet, as php could handle the handshaking process and the clients i would write in C. C is not a problem for me, but networking is. Could you point me in the right direction to read up on this, or if there is an example somewhere for me to take a look at.

  • @jonasavory8339
    @jonasavory8339 2 роки тому +1

    I dont really get how you can listen to port 50001 on both machines and then send data from the same port without stopping the listener... why is there no port already used-error?

    • @noweare1
      @noweare1 2 роки тому

      I get a "bind failed: Address already in use' error

  • @melvinhicklin5752
    @melvinhicklin5752 3 роки тому +1

    Nice information! Looking forward to the next part!

  • @tw-721
    @tw-721 Рік тому

    this doesn't seem to work on my network, it's stuck in the 'punch hole' command on both the machines. Are there any limitations to this?

  • @soupnoodles
    @soupnoodles 7 місяців тому

    This is perfect, Love your videos 👍

  • @AlfonsoRoque257
    @AlfonsoRoque257 2 роки тому

    First al all it is a good explanation, solve part of some daub that I had. But, I have a question, what you show in this video only work because those ip are public? In case I wan to do that between two privates pc (behind a NAT)? Thanks!

  • @Fereri07
    @Fereri07 Рік тому

    Hey. I wonder how do you know that the port chosen on the computer will be the same as the port chosen on the firewall? Especially if the firewall is on an external machine like a router.

    • @justbendev2324
      @justbendev2324 3 місяці тому

      Since this a VPS with a public ip he is the firewall so anything he can bind to is free so he knows if he request source port 50001 it will go out with 50001. He's using a oversimplified setup to explain the concept, unfortunately in the real world its a bit more complicated than this because each nat type will handle the outgoing port differently so you can't predict the output port without some help. That why stun servers exist You both ask the stun server which port you have used viewed from the internet and then forward this information to your peer / other client.

  • @melsonmascarenhas
    @melsonmascarenhas Рік тому +1

    This code will only work on machine with direct public IPs , not device behind NAT

    • @dominykas5195
      @dominykas5195 Рік тому

      Is it possible for two devices behind NAT to establish a peer to peer connection?

  • @electr0nux
    @electr0nux 3 роки тому +2

    Netcat is giving me bing failed: address already in use for the second command

    • @EngineerMan
      @EngineerMan  3 роки тому +1

      If you get that error, run the second command first and then start the listener.

    • @amir3515
      @amir3515 2 роки тому +2

      I did this and I still get the error. The issue with me is that when issuing the hole punch command, it just hangs and doesn't return control back to the shell. What could that mean? I am using 2 raspberry pis, one is connected to my home network and the other is using my mobile phone's hotspot. The error and hanging occurs on both pis

    • @amir3515
      @amir3515 2 роки тому

      I found the reason for me. It's because i am on symmetric nat for both networks

    • @martinseminsky8580
      @martinseminsky8580 2 роки тому

      @@amir3515 how did you find out?

    • @amir3515
      @amir3515 2 роки тому

      @@martinseminsky8580 by querying a stun server as a stun client

  • @LucasDoNascimento1989
    @LucasDoNascimento1989 Рік тому

    Not working. nc -u -l 50001 outputs UDP listen needs -p arg error

  • @billprice3899
    @billprice3899 3 роки тому +1

    Curious if this leaves either machine vulnerable for anyone to take advantage of with no passwords, encryption...
    port scanners?

    • @benargee
      @benargee 3 роки тому +1

      I would imagine it's up to the service bound to that port to properly implement security. A secure protocol can be implemented on top of an insecure one as can be done with plain text on a sheet of paper. The firewall should also have outbound traffic timeouts so that it will not accept inbound traffic indefinitely.

  • @jayadevashok2070
    @jayadevashok2070 2 роки тому +1

    Are the port numbers the router's port numbers or the vm's?

    • @jayadevashok2070
      @jayadevashok2070 2 роки тому

      Also does the first command not result in a NAT entry on either router?

  • @jazzthedog1
    @jazzthedog1 2 роки тому +1

    Interesting stuff, great demo, but how can this be used in a practical manner? This is not a technique that can be leveraged safely in an app? How are companies using this technique currently?

  • @qock1106
    @qock1106 3 роки тому

    Looking forward to part 2!

  • @kevinkkirimii
    @kevinkkirimii Рік тому

    tres bien, thank you, mungu akubariki

  • @robertperaltab
    @robertperaltab 2 роки тому +1

    Great video!
    I didn't quite get why you chose port 5002 when punching the hole. Is that arbitrary?

    • @supernovaw39
      @supernovaw39 Рік тому

      Yes, as long as they are used consistently. What is source port for one machine is the destination port from the standpoint of another machine.

  • @venomxl1655
    @venomxl1655 2 роки тому

    Is there a way I could send a VPN over it ???

  • @imlucluc
    @imlucluc Рік тому

    really appreciate the demo

  • @deathdefier45
    @deathdefier45 15 днів тому

    This is awesome content ❤

  • @mathewcohen3826
    @mathewcohen3826 3 роки тому +1

    Good job. Thanks for taking the time to explain that. These things (NAT) we use every day and often don't really know whats going on in there. :-)

  • @frankfrank8799
    @frankfrank8799 3 роки тому +1

    Nice one... learned something... quickly... THX

  • @stephenkamenar
    @stephenkamenar 3 роки тому

    this video was so sick dude

  • @danlee1027
    @danlee1027 3 роки тому

    Great video. Love the how-tos!

  • @richo13
    @richo13 3 роки тому

    Looking forward to the next vid

  • @diaahanna8882
    @diaahanna8882 Рік тому

    Why can't this concept work with tcp?

  • @n3r0z3r0
    @n3r0z3r0 3 роки тому

    why not terminator/tmux ?

  • @Melsss3305
    @Melsss3305 Рік тому

    you earned a subscribe thanks

  • @elegantchrisarts001
    @elegantchrisarts001 3 роки тому +2

    Nicely explained. By the way, do you do hacking ? You're so smart in how you explain your videos!

  • @garyprice3757
    @garyprice3757 3 роки тому

    Hi. great vid.
    Not used DO for a while but I remember that they issue the public IP to the interface directly. So in this case, surely it will be upnp that is dynamically opening the port mapping through the fw and not natting?

  • @Reyelll
    @Reyelll 3 роки тому

    Excelente video

  • @michaelmounts1269
    @michaelmounts1269 3 роки тому

    great video…Ive used version in past to scan ports, etc in “zero mode” …not really new..but cloud environments make it mire useful

  • @ianbdb7686
    @ianbdb7686 3 роки тому

    Next do how to use remote device to steal transaction data

  • @AkshayGupta-dd4ht
    @AkshayGupta-dd4ht 2 роки тому

    I successfully created hole punching...
    Just a suggestion... If you made.. just use Single socket for all.. with different IPEndPoints

    • @gerooq
      @gerooq Рік тому

      That’s what I did

  • @d1ddle
    @d1ddle 3 роки тому

    Cool 👍 I'm making a multiplayer python game so I'm interested in the next vid

    • @ibnbroly
      @ibnbroly 3 роки тому +1

      Honestly you can get some useful info from this video but you will, in most cases, not use p2p for video games. It can still be a cool project tho

    • @kooltyme
      @kooltyme 3 роки тому

      @@ibnbroly if its a game where the connection between two playesr really matters, liek a fighting game for example, then p2p would really help

  • @FreeDomSy-nk9ue
    @FreeDomSy-nk9ue 3 роки тому

    Awesome thanks

  • @martinseminsky8580
    @martinseminsky8580 3 роки тому

    COOOOOOOOOOOOOOL ! THANKS

  • @aristotlesimone4773
    @aristotlesimone4773 3 роки тому

    Just wanted to share with everyone that I shit my pants again.

  • @aminghafoori6496
    @aminghafoori6496 3 роки тому

    information injection

  • @Laflamablanca969
    @Laflamablanca969 3 роки тому +1

    Anyone else love the UDP vs TCP meme? 😂😂

  • @Pervy
    @Pervy 3 роки тому

    Please use proper social distancing and UDP signaling to reduce the spread.

  • @BunkMayne
    @BunkMayne 3 роки тому +2

    UDP segmentation 🤮

  • @m4l490n
    @m4l490n 3 роки тому +2

    This video is awesome!!
    But then my heart was broken and everything went down the drain when you said you were going to use python for the second part. You should do it with bash scripting.

  • @furkansherifi5731
    @furkansherifi5731 3 роки тому

    why u dont make some hacking videos !!

  • @MangJar-j8q
    @MangJar-j8q 2 дні тому

    crap