diff options
Diffstat (limited to 'src/usr.bin/nc/netcat.c')
| -rw-r--r-- | src/usr.bin/nc/netcat.c | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index 7bd88ad681..f2b7c19c4a 100644 --- a/src/usr.bin/nc/netcat.c +++ b/src/usr.bin/nc/netcat.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: netcat.c,v 1.33 2001/08/25 21:50:13 ericj Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.34 2001/09/02 18:45:41 jakob Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
| 4 | * | 4 | * |
| @@ -61,6 +61,7 @@ char *sflag; /* Source Address */ | |||
| 61 | int tflag; /* Telnet Emulation */ | 61 | int tflag; /* Telnet Emulation */ |
| 62 | int uflag; /* UDP - Default to TCP */ | 62 | int uflag; /* UDP - Default to TCP */ |
| 63 | int vflag; /* Verbosity */ | 63 | int vflag; /* Verbosity */ |
| 64 | int xflag; /* Socks proxy */ | ||
| 64 | int zflag; /* Port Scan Flag */ | 65 | int zflag; /* Port Scan Flag */ |
| 65 | 66 | ||
| 66 | int timeout; | 67 | int timeout; |
| @@ -88,6 +89,9 @@ main(argc, argv) | |||
| 88 | struct servent *sv; | 89 | struct servent *sv; |
| 89 | socklen_t len; | 90 | socklen_t len; |
| 90 | struct sockaddr *cliaddr; | 91 | struct sockaddr *cliaddr; |
| 92 | char *proxy; | ||
| 93 | char *proxyhost, *proxyport; | ||
| 94 | struct addrinfo proxyhints; | ||
| 91 | 95 | ||
| 92 | ret = 1; | 96 | ret = 1; |
| 93 | s = 0; | 97 | s = 0; |
| @@ -96,7 +100,7 @@ main(argc, argv) | |||
| 96 | endp = NULL; | 100 | endp = NULL; |
| 97 | sv = NULL; | 101 | sv = NULL; |
| 98 | 102 | ||
| 99 | while ((ch = getopt(argc, argv, "46hi:klnp:rs:tuvw:z")) != -1) { | 103 | while ((ch = getopt(argc, argv, "46hi:klnp:rs:tuvw:x:z")) != -1) { |
| 100 | switch (ch) { | 104 | switch (ch) { |
| 101 | case '4': | 105 | case '4': |
| 102 | family = AF_INET; | 106 | family = AF_INET; |
| @@ -144,6 +148,10 @@ main(argc, argv) | |||
| 144 | if (timeout < 0 || *endp != '\0') | 148 | if (timeout < 0 || *endp != '\0') |
| 145 | errx(1, "timeout cannot be negative"); | 149 | errx(1, "timeout cannot be negative"); |
| 146 | break; | 150 | break; |
| 151 | case 'x': | ||
| 152 | xflag = 1; | ||
| 153 | proxy = strdup(optarg); | ||
| 154 | break; | ||
| 147 | case 'z': | 155 | case 'z': |
| 148 | zflag = 1; | 156 | zflag = 1; |
| 149 | break; | 157 | break; |
| @@ -183,6 +191,33 @@ main(argc, argv) | |||
| 183 | if (nflag) | 191 | if (nflag) |
| 184 | hints.ai_flags |= AI_NUMERICHOST; | 192 | hints.ai_flags |= AI_NUMERICHOST; |
| 185 | 193 | ||
| 194 | if (xflag) { | ||
| 195 | char *tmp; | ||
| 196 | |||
| 197 | if (uflag) | ||
| 198 | errx(1, "no proxy support for UDP mode"); | ||
| 199 | |||
| 200 | if (lflag) | ||
| 201 | errx(1, "no proxy support for listen"); | ||
| 202 | |||
| 203 | /* XXX IPv6 transport to proxy would probably work */ | ||
| 204 | if (family == AF_INET6) | ||
| 205 | errx(1, "no proxy support for IPv6"); | ||
| 206 | |||
| 207 | if (sflag) | ||
| 208 | errx(1, "no proxy support for local source address"); | ||
| 209 | |||
| 210 | proxyhost = strsep(&proxy, ":"); | ||
| 211 | proxyport = proxy; | ||
| 212 | |||
| 213 | memset(&proxyhints, 0, sizeof(struct addrinfo)); | ||
| 214 | proxyhints.ai_family = family; | ||
| 215 | proxyhints.ai_socktype = SOCK_STREAM; | ||
| 216 | proxyhints.ai_protocol = IPPROTO_TCP; | ||
| 217 | if (nflag) | ||
| 218 | proxyhints.ai_flags |= AI_NUMERICHOST; | ||
| 219 | } | ||
| 220 | |||
| 186 | if (lflag) { | 221 | if (lflag) { |
| 187 | int connfd; | 222 | int connfd; |
| 188 | ret = 0; | 223 | ret = 0; |
| @@ -236,8 +271,14 @@ main(argc, argv) | |||
| 236 | 271 | ||
| 237 | if (s) | 272 | if (s) |
| 238 | close(s); | 273 | close(s); |
| 239 | 274 | ||
| 240 | if ((s = remote_connect(host, portlist[i], hints)) < 0) | 275 | if (xflag) |
| 276 | s = socks_connect(host, portlist[i], hints, | ||
| 277 | proxyhost, proxyport, proxyhints); | ||
| 278 | else | ||
| 279 | s = remote_connect(host, portlist[i], hints); | ||
| 280 | |||
| 281 | if (s < 0) | ||
| 241 | continue; | 282 | continue; |
| 242 | 283 | ||
| 243 | ret = 0; | 284 | ret = 0; |
| @@ -326,6 +367,9 @@ remote_connect(host, port, hints) | |||
| 326 | 367 | ||
| 327 | if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0) | 368 | if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0) |
| 328 | break; | 369 | break; |
| 370 | |||
| 371 | if (error == 0) | ||
| 372 | break; | ||
| 329 | 373 | ||
| 330 | close(s); | 374 | close(s); |
| 331 | s = -1; | 375 | s = -1; |
| @@ -584,6 +628,7 @@ help() | |||
| 584 | \t-u UDP mode\n\ | 628 | \t-u UDP mode\n\ |
| 585 | \t-v Verbose\n\ | 629 | \t-v Verbose\n\ |
| 586 | \t-w secs\t Timeout for connects and final net reads\n\ | 630 | \t-w secs\t Timeout for connects and final net reads\n\ |
| 631 | \t-x addr[:port]\tSpecify socks5 proxy address and port\n\ | ||
| 587 | \t-z Zero-I/O mode [used for scanning]\n\ | 632 | \t-z Zero-I/O mode [used for scanning]\n\ |
| 588 | Port numbers can be individual or ranges: lo-hi [inclusive]\n"); | 633 | Port numbers can be individual or ranges: lo-hi [inclusive]\n"); |
| 589 | exit(1); | 634 | exit(1); |
