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

Support decimal-IP notation for destination in Ncat #375

Closed
dmiller-nmap opened this issue May 11, 2016 · 4 comments · May be fixed by #2807
Closed

Support decimal-IP notation for destination in Ncat #375

dmiller-nmap opened this issue May 11, 2016 · 4 comments · May be fixed by #2807

Comments

@dmiller-nmap
Copy link

Both traditional (Hobbit) and OpenBSD netcat support using IPv4 address in decimal notation as a destination address. Example:

$ host nmap.org
nmap.org has address 45.33.49.119
$ nc.openbsd $((45 * 256**3 + 33 * 256**2 + 49 * 256 + 119)) 22
SSH-2.0-OpenSSH_6.6.1

At least one user has complained of this on IRC. Ncat gives this error instead:

Ncat: You must specify a host to connect to. QUITTING.
@bensherman
Copy link

The specific use case for me is using 0 in place of 0.0.0.0.

@fyodor
Copy link
Member

fyodor commented May 27, 2016

I'm not totally against this, but I'm also not sure we really need to support an obsolete syntax just because some other ancient tools do. Then again, I just tested the Chrome web browser and it allowed me to reach nmap.org at https://757150071/. If "0" is the only specific use case anyone has, maybe we could just special case that? Is there anyone who might use this in other situations than "0"?

@dmiller-nmap
Copy link
Author

Further testing reveals only decimal numbers are failing to work: converting to hex works just fine:

$ ./ncat/ncat 0x2d213177 22
SSH-2.0-OpenSSH_6.6.1

We're actually specifically checking for a non-digit character to distinguish hostname from port number in ncat_main.c:

        /* Resolve hostname if we're given one */
        if (strspn(argv[optind], "0123456789") != strlen(argv[optind])) {
/*<snip>*/
        } else {
            if (!o.listen)
                bye("You must specify a host to connect to.");
        }

This is to avoid ambiguity: ncat -l 22; does this mean "listen on all addresses on port 22" or "listen on 0.0.0.22 on port DEFAULT_NCAT_PORT"? If the former, then there is no way to use decimal address for listen address. If the latter, then we break compatibility with other netcats. A better solution would be to always treat a digits-only last argument as a port number.

@Varunram
Copy link

Varunram commented Feb 9, 2017

But that might break the command's flexibility for some right?

stefano-garzarella added a commit to stefano-garzarella/nmap that referenced this issue Mar 20, 2024
Commit 04c4c70 ("Support decimal integer representation of target
addresses. Fixes nmap#375") introduced a regression when the user specify
only the port using AF_VSOCK in listening (e.g. `ncat --vsock -l 1234`).

Before that commit we supported this invocation, but currently we
interpret the parameter as CID. Alternatively, the version with -p is
still working (e.g. `ncat --vsock -l -p 1234`).

Having documented this usage in the manpage as well, it's better to fix
it and support it again.

Tested locally (without VMs involved), using CID = 1 (loopback) in this
way:

    shell1$ ncat --vsock -l 1234

    shell2$ ncat --vsock 1 1234

    # Note: If CID 1 is not supported and the previous command fails,
    # it means that you have to manually load `vsock_loopback` kernel
    # module (usually it is autoamtically loaded when AF_VSOCK is used
    # if the `vsock` kernel module is not already loaded in the system)

Signed-off-by: Stefano Garzarella <[email protected]>
stefano-garzarella added a commit to stefano-garzarella/nmap that referenced this issue Mar 20, 2024
Commit 04c4c70 ("Support decimal integer representation of target
addresses. Fixes nmap#375") introduced a regression when the user specify
only the port using AF_VSOCK in listening (e.g. `ncat --vsock -l 1234`).

Before that commit we supported this invocation, but currently we
interpret the parameter as CID. Alternatively, the version with -p is
still working (e.g. `ncat --vsock -l -p 1234`).

Having documented this usage in the manpage as well, it's better to fix
it and support it again.

Tested locally (without VMs involved), using CID = 1 (loopback) in this
way:

    shell1$ ncat --vsock -l 1234

    shell2$ ncat --vsock 1 1234

    # Note: If CID 1 is not supported and the previous command fails,
    # it means that you have to manually load `vsock_loopback` kernel
    # module (usually it is autoamtically loaded when AF_VSOCK is used
    # if the `vsock` kernel module is not already loaded in the system)

Reported-by: Luigi Leonardi <[email protected]>
Signed-off-by: Stefano Garzarella <[email protected]>
stefano-garzarella added a commit to stefano-garzarella/nmap that referenced this issue Mar 21, 2024
Commit 04c4c70 ("Support decimal integer representation of target
addresses. Fixes nmap#375") introduced a regression when the user specifies
only the port using AF_VSOCK in listening (e.g. `ncat --vsock -l 1234`).

Before that commit, we supported this invocation, but currently we
interpret the parameter as CID. Alternatively, the version with -p is
still working (e.g. `ncat --vsock -l -p 1234`).

Having documented this usage in the manpage as well, it's better to fix
it and support it again.

Tested locally (without VMs involved), using CID = 1 (loopback) in this
way:

    shell1$ ncat --vsock -l 1234

    shell2$ ncat --vsock 1 1234

    # Note: If CID 1 is not supported and the previous command fails,
    # it means that you have to manually load `vsock_loopback` kernel
    # module (usually it is autoamtically loaded when AF_VSOCK is used
    # if the `vsock` kernel module is not already loaded in the system)

Reported-by: Luigi Leonardi <[email protected]>
Signed-off-by: Stefano Garzarella <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants