Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPv6 link-local address causes "Invalid argument" / "Bind Error" #89

Open
3 tasks done
oza6ut0ne opened this issue Aug 16, 2020 · 3 comments
Open
3 tasks done

IPv6 link-local address causes "Invalid argument" / "Bind Error" #89

oza6ut0ne opened this issue Aug 16, 2020 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@oza6ut0ne
Copy link

ISSUE TYPE

  • Bug Report

OS / ENVIRONMENT

  1. Operating system: Ubuntu 20.04
  2. Python version: 3.8.2
  3. Command with highest logging output level is attached.

Here is the terminal output (address is masked for privacy).

$ pwncat -V
pwncat: Version 0.1.0 (https://github.com/cytopia/pwncat) by cytopia

$ pwncat -vvvv fe80::xxxx:xxxx:xxxx:xxxx%eth0 7777
2020-08-16 13:52:30,945 DEBUG [MainThread] 3391:__init__(): STDOUT isatty: True
2020-08-16 13:52:30,945 DEBUG [MainThread] 3392:__init__(): STDIN  isatty: True
2020-08-16 13:52:30,945 DEBUG [MainThread] 3393:__init__(): STDIN  posix:  False (posix)
2020-08-16 13:52:30,945 DEBUG [MainThread] 1465:create_socket(): Creating (family 10/IPv6, TCP) socket
2020-08-16 13:52:30,945 DEBUG [MainThread] 1485:create_socket(): Disabling IPv4 support on IPv6 socket
2020-08-16 13:52:30,945 DEBUG [MainThread] 1465:create_socket(): Creating (family 2/IPv4, TCP) socket
2020-08-16 13:52:30,946 DEBUG [MainThread] 1429:gethostbyname(): Resolved IPv6 host: fe80::xxxx:xxxx:xxxx:xxxx
2020-08-16 13:52:30,946 DEBUG [MainThread] 1435:gethostbyname(): Resolving IPv4 host: fe80::xxxx:xxxx:xxxx:xxxx%eth0 failed: [Errno -9] Address family for hostname not supported
2020-08-16 13:52:30,946 DEBUG [MainThread] 1641:connect(): Connecting to fe80::xxxx:xxxx:xxxx:xxxx:7777 (family 10/IPv6, TCP)
2020-08-16 13:52:30,946 ERROR [MainThread] 2122:run_client(): Connecting to fe80::xxxx:xxxx:xxxx:xxxx:7777 (family 10/IPv6, TCP) failed: [Errno 22] Invalid argument
2020-08-16 13:52:30,946 INFO [MainThread] 2976:__client_reconnect_to_server(): Reconnect count is used up. Shutting down.

$ pwncat -vvvv -l fe80::xxxx:xxxx:xxxx:xxxx%eth0 7777
2020-08-16 13:52:35,838 DEBUG [MainThread] 3391:__init__(): STDOUT isatty: True
2020-08-16 13:52:35,838 DEBUG [MainThread] 3392:__init__(): STDIN  isatty: True
2020-08-16 13:52:35,838 DEBUG [MainThread] 3393:__init__(): STDIN  posix:  False (posix)
2020-08-16 13:52:35,838 DEBUG [MainThread] 1465:create_socket(): Creating (family 10/IPv6, TCP) socket
2020-08-16 13:52:35,838 DEBUG [MainThread] 1485:create_socket(): Disabling IPv4 support on IPv6 socket
2020-08-16 13:52:35,838 DEBUG [MainThread] 1465:create_socket(): Creating (family 2/IPv4, TCP) socket
2020-08-16 13:52:35,839 DEBUG [MainThread] 1429:gethostbyname(): Resolved IPv6 host: fe80::xxxx:xxxx:xxxx:xxxx
2020-08-16 13:52:35,839 DEBUG [MainThread] 1435:gethostbyname(): Resolving IPv4 host: fe80::xxxx:xxxx:xxxx:xxxx%eth0 failed: [Errno -9] Address family for hostname not supported
2020-08-16 13:52:35,839 DEBUG [MainThread] 2187:run_server(): Removing (family 2/IPv4) due to: Resolving IPv4 host: fe80::xxxx:xxxx:xxxx:xxxx%eth0 failed: [Errno -9] Address family for hostname not supported
2020-08-16 13:52:35,839 DEBUG [MainThread] 1517:bind(): Binding (family 10/IPv6, TCP) socket to fe80::xxxx:xxxx:xxxx:xxxx:7777
2020-08-16 13:52:35,839 DEBUG [MainThread] 2207:run_server(): Removing (family 10/IPv6) due to: Binding (family 10/IPv6, TCP) socket to fe80::xxxx:xxxx:xxxx:xxxx:7777 failed: [Errno 22] Invalid argument
2020-08-16 13:52:35,839 ERROR [MainThread] 2216:run_server(): Bind Error: Could not bind any socket
2020-08-16 13:52:35,839 INFO [MainThread] 3034:__server_rebind(): Rebind count is used up. Shutting down.

STEPS TO REPRODUCE

Same as above log.

EXPECTED BEHAVIOUR

Works same as IPv6 global unicast address.

ACTUAL BEHAVIOUR

Invalid argument / Bind Error

@oza6ut0ne oza6ut0ne added the bug Something isn't working label Aug 16, 2020
@oza6ut0ne
Copy link
Author

This may not be a very important feature, but netcat can do it.
I found scope id is dropped here.
This may be the main cause of these errors.

For reference:

@cytopia cytopia self-assigned this Aug 17, 2020
@cytopia
Copy link
Owner

cytopia commented Aug 17, 2020

Thanks @oza6ut0ne for the provided links 👍 . Will be looking into this.

@cytopia
Copy link
Owner

cytopia commented Aug 22, 2020

I found scope id is dropped here.
This may be the main cause of these errors.

At least for the server part, it doesn't seem to be it, as the function already terminates here:

        # [2/4] Already an IP address
        if family == int(socket.AF_INET6):
            if Sock.is_ipv6_address(host):
                self.__log.debug("Resolving IPv6 name not required, already an IP: %s", host)
                return host

and it never gets to this part:

        # [4/4] Resolve
        try:
            infos = socket.getaddrinfo(host, port, family, socktype, proto, flags)
            addr = str(infos[0][4][0])
            self.__log.debug("Resolved %s host: %s", self.get_family_name(family), addr)
            return addr

What is failing is this one:

        try:
            sock.bind((addr, port))
        except (OverflowError, OSError, socket.gaierror, socket.error) as error:
            msg = "Binding (family {}/{}, {}) socket to {}:{} failed: {}".format(
                sock.family, sock_family_name, sock_type_name, addr, port, error
            )
            raise socket.error(msg)

This is how I started it.

$ ./pwncat -l -vvvvvvvvvvvvv fe80::93e4:8997:60c4:f3f5 7777
2020-08-22 10:31:53,037 DEBUG [MainThread] 3392:__init__(): STDOUT isatty: True
2020-08-22 10:31:53,037 DEBUG [MainThread] 3393:__init__(): STDIN  isatty: True
2020-08-22 10:31:53,037 DEBUG [MainThread] 3394:__init__(): STDIN  posix:  False (posix)
2020-08-22 10:31:53,037 DEBUG [MainThread] 1467:create_socket(): Creating (family 10/IPv6, TCP) socket
2020-08-22 10:31:53,037 DEBUG [MainThread] 1487:create_socket(): Disabling IPv4 support on IPv6 socket
2020-08-22 10:31:53,038 DEBUG [MainThread] 1467:create_socket(): Creating (family 2/IPv4, TCP) socket
2020-08-22 10:31:53,038 DEBUG [MainThread] 1430:gethostbyname(): Resolved IPv6 host: fe80::93e4:8997:60c4:f3f5
2020-08-22 10:31:53,038 DEBUG [MainThread] 1436:gethostbyname(): Resolving IPv4 host: fe80::93e4:8997:60c4:f3f5 failed: [Errno -9] Address family for hostname not supported
2020-08-22 10:31:53,038 DEBUG [MainThread] 2192:run_server(): Removing (family 2/IPv4) due to: Resolving IPv4 host: fe80::93e4:8997:60c4:f3f5 failed: [Errno -9] Address family for hostname not supported
2020-08-22 10:31:53,038 DEBUG [MainThread] 1524:bind(): Binding (family 10/IPv6, TCP) socket to fe80::93e4:8997:60c4:f3f5:7777
2020-08-22 10:31:53,038 DEBUG [MainThread] 2212:run_server(): Removing (family 10/IPv6) due to: Binding (family 10/IPv6, TCP) socket to fe80::93e4:8997:60c4:f3f5:7777 failed: [Errno 22] Invalid argument
2020-08-22 10:31:53,038 ERROR [MainThread] 2217:run_server(): Bind Error: Could not bind any socket
2020-08-22 10:31:53,038 INFO [MainThread] 3035:__server_rebind(): Rebind count is used up. Shutting down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants