Peer to peer connection without port forwarding

I’m sorry but that’s just plain wrong.

If uPnP is enabled then technically any malicious program installed on a users computer on their network can open a port out to the internet, to which anyone can then use to gain control of said computer.

Most routers only have the usual required ports open by default (i.e. 80, 443 etc.). You have to manually open the rest to an internal IP in order for it to be open. It’s literally the opposite of uPnP and far safer.

You are right that any malicious program could open a port via uPnP to abuse it. However if you were to forward a port for a game, you would likely leave it open (most people do that). This means that if you have a malicious program that knows you’ve opened that specific port (let say it is a malicious piece of code loaded into a mod for a game that requires XXXX port for online play), then it could also abuse said port at all times.

The proper way to use uPnP is via a proper firewall configuration. Manually allow the programs you want to use uPnP to prevent any random malicious program to open ports freely using it.

The whole point of uPnP is so you don’t need to open firewall ports, hence why it will always be more of a security risk than manually opening ports. That’s what makes it far more dangerous if there is malicious code running somewhere. By your logic port 80 and 443 are also therefore a risk and they could also be used to access a computer in some way.

However its still far safer to have only the ports you need open (going to a particular internal IP address) rather than an application asking uPnP to open ports without a users knowledge.

For example on my router I have all the ports open for Xbox Live, but they are only going to my Xbox as a destination IP. So if the Xbox is turned off, nothing else on my network is going to respond to those port, because nothing else on my network has that IP.

uPnP as a piece of technology isn’t inherently unsafe, but when combined with a virus or malicious code it certainly is. Far more than opening a manual port to a static IP on your network.

The whole point of uPnP is so you don’t need to open firewall ports, hence why it will always be more of a security risk than manually opening ports.

The point of uPnP is to be able to open and close ports automatically as they are needed without leaving a port open that is not being used. Any port that is opened and not being used is a potential security vulnerability.

As I mentioned in the last post, if you were to open a port for some game on your computer, and I know you’ve done that I can use that in a malicious program if you are not currently using said port. I’ve seen many people open ports on their computers for a game and just leave them open forever. All of those ports are vulnerabilities except if are running a server 24/7 on that port.

The point with uPnP is that a program that is authorised will open a port for said game, and once you stop using it it would close the port, meaning that I have no window to abuse said port with my malicious program.

uPnP as a piece of technology isn’t inherently unsafe, but when combined with a virus or malicious code it certainly is. Far more than opening a manual port to a static IP on your network.

uPnP with improper firewall configuration is the thing that is unsafe. A malicious code would not be able to abuse uPnP unless you manually allow it if you properly set up your firewall. A uPnP with properly setup firewall is far safer than opening a manual port and just leaving it there 24/7.

As it didn’t work to connect to myself (using the public IP) it is probably safe to assume that it wasn’t set up properly.

An important mention is that STUN didn’t even work for me to connect to my own server.

From what I have read a few years ago when it comes to UPNP generally people criticize the fact that it comes enabled on new routers/devices.

What is generally recommended is to disable it unless you need it.

When it comes to malicious programs I doubt it makes that big of a difference.
Regarding firewall configuration, I’m not entirely sure what qualifies as proper or improper setup. Typically, you’ll just get a permission prompt (at least on Windows). If you play any multiplayer games you probably have more then one game that has these permissions. You could still add a mod to a game that already has these permissions and end up with problems…

I can see UPNP being useful if you have to open multiple ports for god knows what reason. In such situations it could be quite helpful to enable it(if you follow the general recommendation you would probably have disabled it previously).

You only need 1 port to host a game. Having a “service” that opens/“closes” any port automatically seems like overkill.

For this necessity to open 1 port if you follow the general recommendation then you would enable UPNP and then disable it when you are done. It is probably safer than port forwarding but just as tedious (if you do it like this).

It’s also not ideal that UPNP is managed in the same place as port forwarding. While it makes sense to be there, it defeats the purpose for users who can’t access router settings (I get that this isn’t a case it is supposed to cover). If you were avoiding port forwarding due to lack of access, UPNP likely won’t help you ( unless you already have it enabled =) which is not recommended )

You can’t rely on it as a single solution (for hosting multiplayer games) since there are a lot of people that do not have it.

Probably it can be used for hosting multiplayer games if so many people recommend it. But my experience hasn’t been great since I could not use it. So I like to call it a useless option.

What is generally recommended is to disable it unless you need it.

If you are not using it at all sure disable it, but if you will use it, then you need to configure your firewall properly to prevent abuse.

When it comes to malicious programs I doubt it makes that big of a difference.
Regarding firewall configuration, I’m not entirely sure what qualifies as proper or improper setup. Typically, you’ll just get a permission prompt (at least on Windows). If you play any multiplayer games you probably have more then one game that has these permissions. You could still add a mod to a game that already has these permissions and end up with problems…

Yeah you could get a malicious program that is connected to a game you play, but in that case you have a problem with both UPNP and port forwarding (that you did for the game) all the same.

You only need 1 port to host a game. Having a “service” that opens/“closes” any port automatically seems like overkill.

You could manage which ports UPNP can open and for which program via the firewall.

You can’t rely on it as a single solution (for hosting multiplayer games) since there are a lot of people that do not have it.

I’m not suggesting to use only UPNP. You need to use the swissknife of tools you have that would increase the chances of connecting 2 random people the most. UPNP is part of that swissknife and avoiding UPNP support would only lead to more unreliable connection in your game, as you would lose out on potential people you can connect via UPNP instead of a TURN server.

If the user has decided that they are willing to use UPNP let them use it. They could have proper configuration. Or maybe they have a dedicated machine for gaming that they don’t care if it gets infected and hacked.

Sure there will be people who are unaware of the risks regarding UPNP and are going to mishandle its configuration. But we can’t just punish people who have access to a technology, understand it and want to use it! It is not our job to act as a judge here, we can only inform people of the risks regarding the technologies we would use to allow them to play a p2p game over the web, and advice them to research and configure their security.

And thats exactly the reason why its more unsafe than manual port forwarding. When manually opening ports to a specific IP you are setting that yourself and are in control of it. With uPnP you are not. A malicious piece of code can open any port to uPnP WITHOUT user knowledge. That malicious app is going to leave the port open as long as its needed, so whats the difference? None.

But the hacker would HAVE to know that in advance, and know what internal IP it was forwarding to. The only way they would know that is if they had already infiltrated the network / computer. In which case it doesn’t matter anyway as by then its too late.

With uPnP they don’t need to know what the network setup is, all they need to do is get a virus / malware on a computer and thats it. Thats an absolute massive difference.

We are going to have to agree to disagree on this one I’m afraid.

A malicious piece of code can open any port to uPnP WITHOUT user knowledge.

Not any, it can open any port only with improperly setup firewall.

With uPnP they don’t need to know what the network setup is, all they need to do is get a virus / malware on a computer and thats it. Thats an absolute massive difference.

It needs to know how the firewall of the machine is setup. Theoretically you can say that it could just try to open all the ports (unrealstic) until it finds the one that it is allowed to do. However technically you can say the same about a port forwarding, it could try all the port until it finds which one is open for use. So here the question you asked “so whats the difference?”.

The difference is that with uPnP enabled and firewall properly setup a malicious program could potentially ONLY use an open port if it inflitrated the program that HAS uPnP access. On the other side with port forwarding ANY program could access the port that you port forwarded.

So to put it in other words. If the virus doesn’t know which port is forwarded or is allowed to be forwarded by upnp in the specific program it inflitrated then there is no difference.
HOWEVER if the virus KNOWS the specific port that has been forwarded, then it could abuse it no matter which program it is. For example if you mod the game itself, then yeah the game would need firewall access for the port so nothing you can do here. But what if the player downloads some 3rd party program related to the game itself, but not something that actually modifies it.
In the upnp with firewall case the 3rd party program would not have access to upnp. In the case that you don’t have upnp with firewall and instead you just opened up a port, now that 3rd party program could use said port.

I’m not suggesting to use only UPNP. You need to use the swissknife of tools you have that would increase the chances of connecting 2 random people the most.

I wasn’t trying to say that you suggested that.

I was just saying that if you want a general solution is better to not look into UPNP first (i was just insisting on what I said previously ).

If you want lets say try to find a solution for some kind of connection without port forwarding and you google it (mby with the AI now this is no longer a problem) you find a lot of comments to such posts with people strait up recommending UPNP as THE solution.

If you never heard of UPNP you may just end up wasting a lot of time looking into it just to find out its not what you requested in the first place.

Its fair to say that its not a solution that should completely be discarded.
If you have people playing your game request it, I do not see why you would not use it.
Unfortunately UPNP and even IPv6 are not that popular to the users that try to host their first multiplayer game. So unless they search about it or you provide some information about in your game even if they have it they may not use it.

I am curious what you guys think about things like hamachi, tungle (no longer available), zerotier?
I have used them in the past to play games, so did a lot of other people.

My idea was to have a similar service that could be controlled from godot.
It could serve as another solution somewhat similar to Steam/Epic (since if you use it you probably release your game on desktop)

1 Like

PS.:
uPnP security risk is also somewhat redundant. Technically you could do the same things just via STUN and TURN servers ironically. So someone writing malicious code is likely to implement that kind of functionality to increase the infection rate of their virus. The only question here is that it is technnically easier to write something that exploits IMPROPERLY configured uPnP than it is to setup a STUN+TURN for your virus.

If you want lets say try to find a solution for some kind of connection without port forwarding and you google it (mby with the AI now this is no longer a problem) you find a lot of comments to such posts with people strait up recommending UPNP as THE solution.

Yeah I agree this could be frustrating for someone looking into how to setup online play for their game!

Unfortunately UPNP and even IPv6 are not that popular to the users that try to host their first multiplayer game. So unless they search about it or you provide some information about in your game even if they have it they may not use it.

You could automate it for p2p games. Since in there connection is automatic, so if someone has IPv6 or UPNP enabled you can test if they do and use it.

I am curious what you guys think about things like hamachi, tungle (no longer available), zerotier?
I have used them in the past to play games, so did a lot of other people.

They are essentially relay (TURN) service. This is why you have a lot of added lag. The main benefit of those things is that they emulate LAN play so you can trick games with only LAN play into letting you play online through a relay service. Honestly it is a good solution for that! You could also host your own server to emulate LAN play that way to get less lag.

My idea was to have a similar service that could be controlled from godot.
It could serve as another solution somewhat similar to Steam/Epic (since if you use it you probably release your game on desktop)

It is just relay server, you don’t need to emulate LAN play, you can just host your own dedicated servers.

If you believe it was improperly setup I think you might be suprised at how effective it actually is and how cheap it can be. So if you have the project time to work on a network solution I would definitely recomend it, as you will have a really relyable way to let your players connect with each other.

They are essentially relay (TURN) service.

That was my feel for it as well but I haven’t research enough to be certain.
Some people say that some also use STUN (tho I have no idea how valid this is)

It is just relay server, you don’t need to emulate LAN play, you can just host your own dedicated servers.

It does require quite a big time investment =/.
After testing yggdrasil I am hesitant to consider other options.

Even if hosting your own dedicated server may be better in terms of connectivity and security and so on, reusing some of these solution as a way of getting them to do the heavy lifting is tempting to say the least (the only problem is that there is no such solutions in godot yet =)) ).

You could automate it for p2p games. Since in there connection is automatic, so if someone has IPv6 or UPNP enabled you can test if they do and use it.

I am not sure how you would do it for IPv6, I guess you could run something like ipconfig or some service to get the IPv6 address to then display in the game?

That was my feel for it as well but I haven’t research enough to be certain.
Some people say that some also use STUN (tho I have no idea how valid this is)

Yeah they could potentially use STUN as well.

Even if hosting your own dedicated server may be better in terms of connectivity and security and so on, reusing some of these solution as a way of getting them to do the heavy lifting is tempting to say the least (the only problem is that there is no such solutions in godot yet =)) ).

The guide I wrote in the first message in this post should work for any engine or pragramming languange that supports UDP packets. It is focused on peer to peer connection and has example Godot code.

I am not sure how you would do it for IPv6, I guess you could run something like ipconfig or some service to get the IPv6 address to then display in the game?

For most reliability use a signaling server (your stun server). You send a UDP packets to the IPv6 of the signaling server, the server can then check the packet and see if it was send via IPv4 or IPv6, they appear as different addresses.

For most reliability use a signaling server (your stun server). You send a UDP packets to the IPv6 of the signaling server, the server can then check the packet and see if it was send via IPv4 or IPv6, they appear as different addresses.

I mean you could argue that a good signaling server should have this already. =)

The guide I wrote in the first message in this post should work for any engine or pragramming languange that supports UDP packets. It is focused on peer to peer connection and has example Godot code.|

One downside to that solution and mby is just me configuring things wrong, is that using such solutions with godot will prevent you from using the High-level multiplayer API (and I kinda like it).

By just reusing something like yggdrasil, zero tier or whatever not only you get rid of configuring your own server (which is often a terrible experience) but also you get to keep all your godot options ( + it could be used completely for “free” - nothing really is…).

One downside to that solution and mby is just me configuring things wrong, is that using such solutions with godot will prevent you from using the High-level multiplayer API (and I kinda like it).

Nope. You use the low-level API ONLY to send the initial UDP packets to establish the connection. Onec you’ve established the connection you can use high-level multiplayer API.

The trick is you can actually establish connection using a 3rd party program as well, it doesn’t need to be your game. Doing it in your game just automates it.

How would you do that (I looked at this in godot 3 and it didn’t seem to be possible)?
Tho now a lot of features have been added so mby it is possible.