1
0
mirror of https://github.com/calebstewart/pwncat.git synced 2024-11-24 09:35:39 +01:00

Added 'OSError' handling to bind protocol

This commit is contained in:
Mitul16 2021-07-26 11:21:26 +05:30
parent dfb2f28f90
commit a859007ca4

View File

@ -8,6 +8,7 @@ The only required argument for a bind channel is the port number. By default,
the channel will listen on all interfaces (bound to ``0.0.0.0``). the channel will listen on all interfaces (bound to ``0.0.0.0``).
""" """
import socket import socket
import errno
from rich.progress import Progress, BarColumn from rich.progress import Progress, BarColumn
@ -34,7 +35,23 @@ class Bind(Socket):
super().__init__(client=None, host=host, port=port, **kwargs) super().__init__(client=None, host=host, port=port, **kwargs)
self.address = (host, port) self.address = (host, port)
try:
self.server = socket.create_server((host, port), reuse_port=True) self.server = socket.create_server((host, port), reuse_port=True)
except OSError as exc:
error_message = str(exc)
if exc.args[0] == errno.EACCES:
# See `/proc/sys/net/ipv4/ip_unprivileged_port_start`
error_message = "unable to listen on a privileged port" +\
"\nusually ports in the range 0-1023 are restricted" +\
"\n[green][TRY][/green]: try to run `pwncat` as `[red]root[/red]`"
elif exc.args[0] == errno.EADDRINUSE:
error_message = "port is already in use"
elif exc.args[0] == errno.EADDRNOTAVAIL:
error_message = "unable to bind on given address"
raise ChannelError(self, error_message)
def connect(self): def connect(self):