"Fossies" - the Fresh Open Source Software Archive

Member "nmap-7.91/ncat/ncat.h" (9 Oct 2020, 8360 Bytes) of package /linux/misc/nmap-7.91.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ncat.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 7.90_vs_7.91.

    1 /***************************************************************************
    2  * ncat.h                                                                  *
    3  ***********************IMPORTANT NMAP LICENSE TERMS************************
    4  *                                                                         *
    5  * The Nmap Security Scanner is (C) 1996-2020 Insecure.Com LLC ("The Nmap  *
    6  * Project"). Nmap is also a registered trademark of the Nmap Project.     *
    7  *                                                                         *
    8  * This program is distributed under the terms of the Nmap Public Source   *
    9  * License (NPSL). The exact license text applying to a particular Nmap    *
   10  * release or source code control revision is contained in the LICENSE     *
   11  * file distributed with that version of Nmap or source code control       *
   12  * revision. More Nmap copyright/legal information is available from       *
   13  * https://nmap.org/book/man-legal.html, and further information on the    *
   14  * NPSL license itself can be found at https://nmap.org/npsl. This header  *
   15  * summarizes some key points from the Nmap license, but is no substitute  *
   16  * for the actual license text.                                            *
   17  *                                                                         *
   18  * Nmap is generally free for end users to download and use themselves,    *
   19  * including commercial use. It is available from https://nmap.org.        *
   20  *                                                                         *
   21  * The Nmap license generally prohibits companies from using and           *
   22  * redistributing Nmap in commercial products, but we sell a special Nmap  *
   23  * OEM Edition with a more permissive license and special features for     *
   24  * this purpose. See https://nmap.org/oem                                  *
   25  *                                                                         *
   26  * If you have received a written Nmap license agreement or contract       *
   27  * stating terms other than these (such as an Nmap OEM license), you may   *
   28  * choose to use and redistribute Nmap under those terms instead.          *
   29  *                                                                         *
   30  * The official Nmap Windows builds include the Npcap software             *
   31  * (https://npcap.org) for packet capture and transmission. It is under    *
   32  * separate license terms which forbid redistribution without special      *
   33  * permission. So the official Nmap Windows builds may not be              *
   34  * redistributed without special permission (such as an Nmap OEM           *
   35  * license).                                                               *
   36  *                                                                         *
   37  * Source is provided to this software because we believe users have a     *
   38  * right to know exactly what a program is going to do before they run it. *
   39  * This also allows you to audit the software for security holes.          *
   40  *                                                                         *
   41  * Source code also allows you to port Nmap to new platforms, fix bugs,    *
   42  * and add new features.  You are highly encouraged to submit your         *
   43  * changes as a Github PR or by email to the dev@nmap.org mailing list     *
   44  * for possible incorporation into the main distribution. Unless you       *
   45  * specify otherwise, it is understood that you are offering us very       *
   46  * broad rights to use your submissions as described in the Nmap Public    *
   47  * Source License Contributor Agreement. This is important because we      *
   48  * fund the project by selling licenses with various terms, and also       *
   49  * because the inability to relicense code has caused devastating          *
   50  * problems for other Free Software projects (such as KDE and NASM).       *
   51  *                                                                         *
   52  * The free version of Nmap is distributed in the hope that it will be     *
   53  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of  *
   54  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Warranties,        *
   55  * indemnification and commercial support are all available through the    *
   56  * Npcap OEM program--see https://nmap.org/oem.                            *
   57  *                                                                         *
   58  ***************************************************************************/
   59 
   60 /* $Id: ncat.h 38100 2020-10-09 22:33:04Z dmiller $ */
   61 
   62 #ifndef NCAT_H_
   63 #define NCAT_H_
   64 
   65 #include "ncat_config.h"
   66 
   67 #include <nbase.h>
   68 
   69 #ifdef HAVE_OPENSSL
   70 #include <openssl/ssl.h>
   71 #endif
   72 
   73 #include "nsock.h"
   74 #include "util.h"
   75 #include "sys_wrap.h"
   76 
   77 #include "ncat_connect.h"
   78 #include "ncat_core.h"
   79 #include "ncat_exec.h"
   80 #include "ncat_listen.h"
   81 #include "ncat_proxy.h"
   82 #include "ncat_ssl.h"
   83 
   84 /* Ncat information for output, etc. */
   85 #define NCAT_NAME "Ncat"
   86 #define NCAT_URL "https://nmap.org/ncat"
   87 #define NCAT_VERSION "7.91"
   88 
   89 #ifndef __GNUC__
   90 #ifndef __attribute__
   91 #define __attribute__(x)
   92 #endif
   93 #endif
   94 
   95 #define SOCKS_BUFF_SIZE 512
   96 
   97 /* structs */
   98 
   99 #ifdef WIN32
  100 #pragma pack(1)
  101 #endif
  102 struct socks4_data {
  103     char version;
  104     char type;
  105     unsigned short port;
  106     uint32_t address;
  107     char data[SOCKS_BUFF_SIZE]; // this has to be able to hold FQDN and username
  108 } __attribute__((packed));
  109 
  110 struct socks5_connect {
  111     char ver;
  112     unsigned char nmethods;
  113     char methods[3];
  114 } __attribute__((packed));
  115 
  116 struct socks5_auth {
  117     char ver; // must be always 1
  118     unsigned char data[SOCKS_BUFF_SIZE];
  119 } __attribute__((packed));
  120 
  121 struct socks5_request {
  122     char ver;
  123     char cmd;
  124     char rsv;
  125     char atyp;
  126     unsigned char dst[SOCKS_BUFF_SIZE]; // addr/name and port info
  127 } __attribute__((packed));
  128 #ifdef WIN32
  129 #pragma pack()
  130 #endif
  131 
  132 /* defines */
  133 
  134 /* Client-mode timeout for reads, infinite */
  135 #define DEFAULT_READ_TIMEOUT -1
  136 
  137 /* Client-mode timeout for writes, in msecs */
  138 #define DEFAULT_WRITE_TIMEOUT 2000
  139 
  140 /* Client-mode timeout for connection establishment, in msecs */
  141 #define DEFAULT_CONNECT_TIMEOUT 10000
  142 
  143 /* The default length of Ncat buffers */
  144 #define DEFAULT_BUF_LEN      (1024)
  145 #define DEFAULT_TCP_BUF_LEN  (1024 * 8)
  146 #define DEFAULT_UDP_BUF_LEN  (1024 * 128)
  147 
  148 /* Default Ncat port */
  149 #define DEFAULT_NCAT_PORT 31337
  150 
  151 /* Default port for SOCKS4 */
  152 #define DEFAULT_SOCKS4_PORT 1080
  153 
  154 /* Default port for SOCKS5 */
  155 #define DEFAULT_SOCKS5_PORT 1080
  156 
  157 
  158 /* The default port Ncat will connect to when trying to connect to an HTTP
  159  * proxy server.  The current setting is the default for squid and probably
  160  * other HTTP proxies. But it may also be 8080, 8888, etc.
  161  */
  162 #define DEFAULT_PROXY_PORT 3128
  163 
  164 /* Listen() backlog */
  165 #define BACKLOG 10
  166 
  167 /* The default maximum number of simultaneous connections Ncat will accept to
  168  * a listening port. You may want to increase or decrease this value depending
  169  * on your specific needs.
  170  */
  171 #ifdef WIN32
  172 /* Windows is commonly limited to 64 sockets, so keep the default somewhat below
  173    that. http://www.tangentsoft.net/wskfaq/advanced.html#64sockets */
  174 #define DEFAULT_MAX_CONNS 60
  175 #else
  176 #define DEFAULT_MAX_CONNS 100
  177 #endif
  178 
  179 /* SOCKS4 protocol responses */
  180 #define SOCKS4_VERSION          4
  181 #define SOCKS_CONNECT           1
  182 #define SOCKS_BIND              2
  183 #define SOCKS4_CONN_ACC         90 /* woot */
  184 #define SOCKS4_CONN_REF         91
  185 #define SOCKS4_CONN_IDENT       92
  186 #define SOCKS4_CONN_IDENTDIFF   93
  187 
  188 /* SOCKS5 protocol */
  189 #define SOCKS5_VERSION          5
  190 #define SOCKS5_AUTH_NONE        0
  191 #define SOCKS5_AUTH_GSSAPI      1
  192 #define SOCKS5_AUTH_USERPASS    2
  193 #define SOCKS5_AUTH_FAILED      255
  194 #define SOCKS5_ATYP_IPv4        1
  195 #define SOCKS5_ATYP_NAME        3
  196 #define SOCKS5_ATYP_IPv6        4
  197 
  198 #define SOCKS5_USR_MAXLEN       255
  199 #define SOCKS5_PWD_MAXLEN       255
  200 #define SOCKS5_DST_MAXLEN       255
  201 
  202 #if SOCKS_BUFF_SIZE < (1 + SOCKS5_USR_MAXLEN) + (1 + SOCKS5_PWD_MAXLEN)
  203 #error SOCKS_BUFF_SIZE is defined too small to handle SOCKS5 authentication
  204 #endif
  205 
  206 #if SOCKS_BUFF_SIZE < (1 + SOCKS5_DST_MAXLEN) + 2
  207 #error SOCKS_BUFF_SIZE is defined too small to handle SOCKS5 destination
  208 #endif
  209 
  210 /* Length of IPv6 address */
  211 #ifndef INET6_ADDRSTRLEN
  212 #define INET6_ADDRSTRLEN 46
  213 #endif
  214 
  215 #ifndef IPPROTO_SCTP
  216 #define IPPROTO_SCTP 132
  217 #endif
  218 
  219 /* Dummy WNOHANG for Windows */
  220 #ifndef WNOHANG
  221 #define WNOHANG 0
  222 #endif
  223 
  224 #endif