Forum Thread: Failed to Bind to Port/IP

So in my mission to get admin rights on my schools network (i have premission)

I've thought of using metasploit to make a reversetcp connect back to me.
how ever when i set up the payload it errors saying it cannot bind it IP handler.

Very annoyed i wrote a python web server script (a very simple one) and long behold same error howerver ! if i ran the python server on my LAN ip adress (10.0.0.X) it works fine and even then website "Can you see me?" Finds the port and is happy with it. But i don't understand how? if i close the webserver the port closers with it. Perhaps it's some kind of port trigger? even so how does "Can you see me ?" only find my port once the python web server is running on LAN IP ? everystrange.

Any help would be amazing thanks !

14 Responses

You need to understand how network ports operate.

When you start a networking service on a machine, be it a server or something else, the application that initiates this service will ask the system for a port to be opened to make the service accessible to outsiders.

Most of the time, with sufficient privileges, the system will grant access to said port and now any outsider is able to connect to your specific machine. However, some mediums may stand in the way and obstruct connections to the port. These mediums include:

• Local firewall
• Antivirus firewall
• Router firewall
• Router forwarding rules
• ISP

If any of these stand in the way of the connection being made to that port, the connection will show as "timed out" on the canyouseeme.org website.

If, however, the connection is let through, then your computer is the final node that needs to accept that connection. If that connection is not accepted by your computer, it will show on canyouseeme.org as "refused". This is because, to maintain an open port, your computer must have a service running and using that port.

So, for example, when an http server is running, port 80 is open. Once you quit the http service, port 80 immediately closes and your machine is no longer accessible to outsiders through that port.

TRT

Yea i understand that.
Firewall is off
windows defender off (running windows 10)
router firewall (i've opened the port and pointed it to my LAN IP)

I am also running AVG i've tested it with it disable same thing.

And interseting this about the canyouseeme.org is that it says it can see my service on 105.XXX.XXX (IP) and the port 4444 only when the pyton server is running on the LAN adress.

In other words if i where to type my public ip followed by the port number into a brower it would error. But if i type my LAN ip (when on the same network ofcourse) it shows me the website.

So the question is how would i get it to bind to my public address so anyone can acces the website.

Thanks !

The reason for the site being displayed when accessed by another host on the same network is because it didn't have to leave the network to access it, it's right there.

Secondly, binding to your local IP is fine, it's all about the forwarding configuration on the router and the payload you generate.

This recently published article explains it all very well.

-Defalt

Thanks for the reply mate but i've read throught that article and i've done exactly what his been doing. The only problem is it fails to bind to Port/IP when i put my public IP address. It's rather annoying i've tried making it a static IP same result i'll copy the python webserver erorr:

Traceback (most recent call last):
File "I:\Python Def\web.py", line 7, in <module>
listensocket.bind((HOST, PORT))
File "C:\Python27\lib\socket.py", line 224, in meth
return getattr(self.
sock,name)(args)
error: Errno 10049 The requested address is not valid in its context

Using socket.bind(...) requires the host to be a local address. You do not bind to a public IP address, you connect to it.

TRT

Will that makes way more sense. Feeling abit dumb right now haha.

Right so i've bound the webserver to local IP on the port 4444 i've then opened port 4444 to a tcp/udp and CanYouSeeMe.org says the port is open and it can reach my service! But when i type PublicIP:4444 into webbrower it is unable to connect any ideas?

You are beginning to confuse me. Share your code on Pastebin so that I can more easily understand what you are trying to accomplish.

Edit: to answer your question, it depends on the service running; you can't just type any port into a browser, the choice is 80 or 443 usually.

TRT

alright! So i've tried 443 port same error. If i use the 80 port it wants to login me into the Router? I am guessing the port to my PC is not working 100% but here is the python code.

http://pastebin.com/PDgZPVRm

EDIT: Oh my goal is to access the webserver from outside of the network

Change the binding address to listen on any connections, like this:
HOST, PORT = '',4444 or HOST, PORT = '0.0.0.0',4444

TRT

i've changed it to
HOST, PORT = '0.0.0.0',4444
Aswell as opened the port in the router.
Same problem ?

Make sure:
• your local IP address is static
• port forwarding is set up correctly
• all firewall rules are adjusted
• your ISP isn't filtering the port

TRT

The port is open according to Canyouseeme.org
The firewall on my windows is completely turned off along with all anti-virus.

Not to sure about the ISP flitering but i've gotten the python server to work before... It's the stangest thing. It kinda just stopped working.

Been thinking of factor defaulting my router and starting from 0 again.

When attempting to connect from outside the network, you need to enter your public IP with the forwarded port, not the bound port.

Ex: [Public IP]:[Forwarded Port]

You should be fine binding to port 4444 as long as that's the port your router is set to forward to.

-Defalt

Ye I've been doing that will the bound port and the forwarded port are both 4444 at the moment. It honesty is so strange anything I try to bind to my public ip fails.

Thanks for all the feedback been very helpful

Share Your Thoughts

  • Hot
  • Active