1 
2 /***************************************************************************
3  * NcrackOps.h -- The NcrackOps class contains global options, mostly      *
4  * based on user-provided command-line settings.                           *
5  *                                                                         *
6  ***********************IMPORTANT NMAP LICENSE TERMS************************
7  *                                                                         *
8  * The Nmap Security Scanner is (C) 1996-2019 Insecure.Com LLC ("The Nmap  *
9  * Project"). Nmap is also a registered trademark of the Nmap Project.     *
10  * This program is free software; you may redistribute and/or modify it    *
11  * under the terms of the GNU General Public License as published by the   *
12  * Free Software Foundation; Version 2 ("GPL"), BUT ONLY WITH ALL OF THE   *
13  * CLARIFICATIONS AND EXCEPTIONS DESCRIBED HEREIN.  This guarantees your   *
14  * right to use, modify, and redistribute this software under certain      *
15  * conditions.  If you wish to embed Nmap technology into proprietary      *
16  * software, we sell alternative licenses (contact sales@nmap.com).        *
17  * Dozens of software vendors already license Nmap technology such as      *
18  * host discovery, port scanning, OS detection, version detection, and     *
19  * the Nmap Scripting Engine.                                              *
20  *                                                                         *
21  * Note that the GPL places important restrictions on "derivative works",  *
22  * yet it does not provide a detailed definition of that term.  To avoid   *
23  * misunderstandings, we interpret that term as broadly as copyright law   *
24  * allows.  For example, we consider an application to constitute a        *
25  * derivative work for the purpose of this license if it does any of the   *
26  * following with any software or content covered by this license          *
27  * ("Covered Software"):                                                   *
28  *                                                                         *
29  * o Integrates source code from Covered Software.                         *
30  *                                                                         *
31  * o Reads or includes copyrighted data files, such as Nmap's nmap-os-db   *
32  * or nmap-service-probes.                                                 *
33  *                                                                         *
34  * o Is designed specifically to execute Covered Software and parse the    *
35  * results (as opposed to typical shell or execution-menu apps, which will *
36  * execute anything you tell them to).                                     *
37  *                                                                         *
38  * o Includes Covered Software in a proprietary executable installer.  The *
39  * installers produced by InstallShield are an example of this.  Including *
40  * Nmap with other software in compressed or archival form does not        *
41  * trigger this provision, provided appropriate open source decompression  *
42  * or de-archiving software is widely available for no charge.  For the    *
43  * purposes of this license, an installer is considered to include Covered *
44  * Software even if it actually retrieves a copy of Covered Software from  *
45  * another source during runtime (such as by downloading it from the       *
46  * Internet).                                                              *
47  *                                                                         *
48  * o Links (statically or dynamically) to a library which does any of the  *
49  * above.                                                                  *
50  *                                                                         *
51  * o Executes a helper program, module, or script to do any of the above.  *
52  *                                                                         *
53  * This list is not exclusive, but is meant to clarify our interpretation  *
54  * of derived works with some common examples.  Other people may interpret *
55  * the plain GPL differently, so we consider this a special exception to   *
56  * the GPL that we apply to Covered Software.  Works which meet any of     *
57  * these conditions must conform to all of the terms of this license,      *
58  * particularly including the GPL Section 3 requirements of providing      *
59  * source code and allowing free redistribution of the work as a whole.    *
60  *                                                                         *
61  * As another special exception to the GPL terms, the Nmap Project grants  *
62  * permission to link the code of this program with any version of the     *
63  * OpenSSL library which is distributed under a license identical to that  *
64  * listed in the included docs/licenses/OpenSSL.txt file, and distribute   *
65  * linked combinations including the two.                                  *
66  *                                                                         *
67  * The Nmap Project has permission to redistribute Npcap, a packet         *
68  * capturing driver and library for the Microsoft Windows platform.        *
69  * Npcap is a separate work with it's own license rather than this Nmap    *
70  * license.  Since the Npcap license does not permit redistribution        *
71  * without special permission, our Nmap Windows binary packages which      *
72  * contain Npcap may not be redistributed without special permission.      *
73  *                                                                         *
74  * Any redistribution of Covered Software, including any derived works,    *
75  * must obey and carry forward all of the terms of this license, including *
76  * obeying all GPL rules and restrictions.  For example, source code of    *
77  * the whole work must be provided and free redistribution must be         *
78  * allowed.  All GPL references to "this License", are to be treated as    *
79  * including the terms and conditions of this license text as well.        *
80  *                                                                         *
81  * Because this license imposes special exceptions to the GPL, Covered     *
82  * Work may not be combined (even as part of a larger work) with plain GPL *
83  * software.  The terms, conditions, and exceptions of this license must   *
84  * be included as well.  This license is incompatible with some other open *
85  * source licenses as well.  In some cases we can relicense portions of    *
86  * Nmap or grant special permissions to use it in other open source        *
87  * software.  Please contact fyodor@nmap.org with any such requests.       *
88  * Similarly, we don't incorporate incompatible open source software into  *
89  * Covered Software without special permission from the copyright holders. *
90  *                                                                         *
91  * If you have any questions about the licensing restrictions on using     *
92  * Nmap in other works, we are happy to help.  As mentioned above, we also *
93  * offer an alternative license to integrate Nmap into proprietary         *
94  * applications and appliances.  These contracts have been sold to dozens  *
95  * of software vendors, and generally include a perpetual license as well  *
96  * as providing support and updates.  They also fund the continued         *
97  * development of Nmap.  Please email sales@nmap.com for further           *
98  * information.                                                            *
99  *                                                                         *
100  * If you have received a written license agreement or contract for        *
101  * Covered Software stating terms other than these, you may choose to use  *
102  * and redistribute Covered Software under those terms instead of these.   *
103  *                                                                         *
104  * Source is provided to this software because we believe users have a     *
105  * right to know exactly what a program is going to do before they run it. *
106  * This also allows you to audit the software for security holes.          *
107  *                                                                         *
108  * Source code also allows you to port Nmap to new platforms, fix bugs,    *
109  * and add new features.  You are highly encouraged to send your changes   *
110  * to the dev@nmap.org mailing list for possible incorporation into the    *
111  * main distribution.  By sending these changes to Fyodor or one of the    *
112  * Insecure.Org development mailing lists, or checking them into the Nmap  *
113  * source code repository, it is understood (unless you specify            *
114  * otherwise) that you are offering the Nmap Project the unlimited,        *
115  * non-exclusive right to reuse, modify, and relicense the code.  Nmap     *
116  * will always be available Open Source, but this is important because     *
117  * the inability to relicense code has caused devastating problems for     *
118  * other Free Software projects (such as KDE and NASM).  We also           *
119  * occasionally relicense the code to third parties as discussed above.    *
120  * If you wish to specify special license conditions of your               *
121  * contributions, just say so when you send them.                          *
122  *                                                                         *
123  * This program is distributed in the hope that it will be useful, but     *
124  * WITHOUT ANY WARRANTY; without even the implied warranty of              *
125  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the Nmap      *
126  * license file for more details (it's in a COPYING file included with     *
127  * Nmap, and also available from https://svn.nmap.org/nmap/COPYING)        *
128  *                                                                         *
129  ***************************************************************************/
130 
131 
132 #ifndef NCRACK_OPS_H
133 #define NCRACK_OPS_H 1
134 
135 #include "ncrack.h"
136 #include "output.h"
137 #include <map>
138 using namespace std;
139 
140 /* Each service has an associated saved_info struct that holds everything
141  * needed to continue the session.
142  */
143 struct saved_info {
144   uint32_t user_index;
145   uint32_t pass_index;
146   vector <loginpair> credentials_found;
147 
saved_infosaved_info148   saved_info() {
149     user_index = 0;
150     pass_index = 0;
151   }
152 };
153 
154 class NcrackOps {
155   public:
156     NcrackOps();
157     ~NcrackOps();
158 
setaf(int af)159     void setaf(int af) { addressfamily = af; }
af()160     int af() { return addressfamily; }
161 
162     /* The time this obj. was instantiated */
getStartTime()163     const struct timeval *getStartTime() { return &start_time; }
164 
165     /* Number of milliseconds since getStartTime().  The current time is an
166      * optional argument to avoid an extra gettimeofday() call. */
167     long long TimeSinceStartMS(struct timeval *now=NULL);
168 
169     /* The requested auto stats printing interval, or 0.0 if unset. */
170     float stats_interval;
171     bool log_errors;      /* write errors to log files */
172     bool append_output;   /* append output to log files */
173 
174     int userlist_src;/* 0 -> unassigned (default),
175                         1 -> username list from command line (--user option)
176                         2 -> username list from file (-U option)
177                       */
178     int passlist_src;/* 0 -> unassigned (default),
179                         1 -> password list from command line (--pass option)
180                         2 -> username list from file (-P option)
181                       */
182     bool nmap_input_normal; /* true if host input from Nmap's -oN output */
183     bool nmap_input_xml;    /* true if host input from Nmap's -oX output */
184     /* iterate password list for each username instead of opposite */
185     bool passwords_first;
186     /* choose a username and a password from the username and password lists
187      * correspondingly in pairs */
188     bool pairwise;
189     bool global_options;  /* true if -g has been specified */
190     bool list_only;       /* only list hosts and exit */
191     int timing_level;     /* timing template number: T(0-5) */
192     int debugging;        /* valid for range 0-10 */
193     int finish;           /* 0 -> disabled
194                            * 1 -> quit each service after one credential is found
195                            * 2 -> quit after any credential is found on any
196                            * service
197                            */
198     nsock_loglevel_t nsock_loglevel;
199     int verbose;
200     int numhosts_scanned;
201     long connection_limit;/* global maximum total connections */
202     FILE *logfd[LOG_NUM_FILES];
203     FILE *ncrack_stdout; /* Ncrack standard output */
204     char *datadir;
205 
206     nsock_proxychain proxychain; /* only assigned when --proxy is valid */
207     bool socks4a; /* only true when first proxy is socks4a */
208     int saved_signal;    /* save caught signal here, -1 for no signal */
209     char **saved_argv;    /* pointer to current argv array */
210     int saved_argc;      /* saved argument count */
211     /* This associative container holds the unique id of each service and the
212      * corresponding saved_info struct which holds all the necessary
213      * data to continue the session from where it had been previously stopped.
214      */
215     bool resume;
216     map<uint32_t, struct saved_info> resume_map;
217 
218     char *save_file;
219 
220     bool stealthy_linear; /* true if stealty linear mode is enabled */
221 
222   private:
223     struct timeval start_time;
224     int addressfamily; /* Address family:  AF_INET or AF_INET6 */
225 };
226 
227 #endif
228