1 
2 /***************************************************************************
3  * FingerPrintResults.h -- The FingerPrintResults class the results of OS  *
4  * fingerprint matching against a certain host.                            *
5  *                                                                         *
6  ***********************IMPORTANT NMAP LICENSE TERMS************************
7  *                                                                         *
8  * The Nmap Security Scanner is (C) 1996-2020 Insecure.Com LLC ("The Nmap  *
9  * Project"). Nmap is also a registered trademark of the Nmap Project.     *
10  *                                                                         *
11  * This program is distributed under the terms of the Nmap Public Source   *
12  * License (NPSL). The exact license text applying to a particular Nmap    *
13  * release or source code control revision is contained in the LICENSE     *
14  * file distributed with that version of Nmap or source code control       *
15  * revision. More Nmap copyright/legal information is available from       *
16  * https://nmap.org/book/man-legal.html, and further information on the    *
17  * NPSL license itself can be found at https://nmap.org/npsl. This header  *
18  * summarizes some key points from the Nmap license, but is no substitute  *
19  * for the actual license text.                                            *
20  *                                                                         *
21  * Nmap is generally free for end users to download and use themselves,    *
22  * including commercial use. It is available from https://nmap.org.        *
23  *                                                                         *
24  * The Nmap license generally prohibits companies from using and           *
25  * redistributing Nmap in commercial products, but we sell a special Nmap  *
26  * OEM Edition with a more permissive license and special features for     *
27  * this purpose. See https://nmap.org/oem                                  *
28  *                                                                         *
29  * If you have received a written Nmap license agreement or contract       *
30  * stating terms other than these (such as an Nmap OEM license), you may   *
31  * choose to use and redistribute Nmap under those terms instead.          *
32  *                                                                         *
33  * The official Nmap Windows builds include the Npcap software             *
34  * (https://npcap.org) for packet capture and transmission. It is under    *
35  * separate license terms which forbid redistribution without special      *
36  * permission. So the official Nmap Windows builds may not be              *
37  * redistributed without special permission (such as an Nmap OEM           *
38  * license).                                                               *
39  *                                                                         *
40  * Source is provided to this software because we believe users have a     *
41  * right to know exactly what a program is going to do before they run it. *
42  * This also allows you to audit the software for security holes.          *
43  *                                                                         *
44  * Source code also allows you to port Nmap to new platforms, fix bugs,    *
45  * and add new features.  You are highly encouraged to submit your         *
46  * changes as a Github PR or by email to the dev@nmap.org mailing list     *
47  * for possible incorporation into the main distribution. Unless you       *
48  * specify otherwise, it is understood that you are offering us very       *
49  * broad rights to use your submissions as described in the Nmap Public    *
50  * Source License Contributor Agreement. This is important because we      *
51  * fund the project by selling licenses with various terms, and also       *
52  * because the inability to relicense code has caused devastating          *
53  * problems for other Free Software projects (such as KDE and NASM).       *
54  *                                                                         *
55  * The free version of Nmap is distributed in the hope that it will be     *
56  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of  *
57  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Warranties,        *
58  * indemnification and commercial support are all available through the    *
59  * Npcap OEM program--see https://nmap.org/oem.                            *
60  *                                                                         *
61  ***************************************************************************/
62 
63 /* $Id: FingerPrintResults.h 38078 2020-10-02 16:12:22Z dmiller $ */
64 
65 #ifndef FINGERPRINTRESULTS_H
66 #define FINGERPRINTRESULTS_H
67 
68 class FingerPrintResults;
69 
70 #include "FPEngine.h"
71 #include "osscan.h"
72 
73 /* Maximum number of results allowed in one of these things ... */
74 #define MAX_FP_RESULTS 36
75 
76 struct OS_Classification_Results {
77   struct OS_Classification *OSC[MAX_FP_RESULTS];
78   double OSC_Accuracy[MAX_FP_RESULTS];
79   int OSC_num_perfect_matches; // Number of perfect matches in OSC[\]
80   int OSC_num_matches; // Number of matches total in OSC[] (and, of course, _accuracy[])
81   int overall_results; /* OSSCAN_TOOMANYMATCHES, OSSCAN_NOMATCHES, OSSCAN_SUCCESS, etc */
82 };
83 
84 class FingerPrintResults {
85  public: /* For now ... a lot of the data members should be made private */
86   FingerPrintResults();
87   virtual ~FingerPrintResults();
88 
89   double accuracy[MAX_FP_RESULTS]; /* Percentage of match (1.0 == perfect
90                                       match) in same order as matches[] below */
91   FingerMatch *matches[MAX_FP_RESULTS]; /* ptrs to matching references --
92                                               highest accuracy matches first */
93   int num_perfect_matches; /* Number of 1.0 accuracy matches in matches[] */
94   int num_matches; /* Total number of matches in matches[] */
95   int overall_results; /* OSSCAN_TOOMANYMATCHES, OSSCAN_NOMATCHES,
96                           OSSCAN_SUCCESS, etc */
97 
98   /* Ensures that the results are available and then returns them.
99    You should only call this AFTER all matching has been completed
100    (because results are cached and won't change if new matches[] are
101    added.)  All OS Classes in the results will be unique, and if there
102    are any perfect (accuracy 1.0) matches, only those will be
103    returned */
104   const struct OS_Classification_Results *getOSClassification();
105 
106   int osscan_opentcpport; /* Open TCP port used for scanning (if one found --
107                           otherwise -1) */
108   int osscan_closedtcpport; /* Closed TCP port used for scanning (if one found --
109                             otherwise -1) */
110   int osscan_closedudpport;  /* Closed UDP port used for scanning (if one found --
111                             otherwise -1) */
112   int distance; /* How "far" is this FP gotten from? */
113   int distance_guess; /* How "far" is this FP gotten from? by guessing based on ttl. */
114   enum dist_calc_method distance_calculation_method;
115 
116   /* The largest ratio we have seen of time taken vs. target time
117      between sending 1st tseq probe and sending first ICMP echo probe.
118      Zero means we didn't see any ratios (the tseq probes weren't
119      sent), 1 is ideal, and larger values are undesirable from a
120      consistency standpoint. */
121   double maxTimingRatio;
122 
123   bool incomplete; /* Were we unable to send all necessary probes? */
124 
125 /* If the fingerprint is of potentially poor quality, we don't want to
126    print it and ask the user to submit it.  In that case, the reason
127    for skipping the FP is returned as a static string.  If the FP is
128    great and should be printed, NULL is returned. */
129   virtual const char *OmitSubmissionFP();
130 
131   virtual const char *merge_fpr(const Target *currenths, bool isGoodFP, bool wrapit) const = 0;
132 
133  private:
134   bool isClassified; // Whether populateClassification() has been called
135   /* Goes through fingerprinting results to populate OSR */
136 
137   void populateClassification();
138   bool classAlreadyExistsInResults(struct OS_Classification *OSC);
139   struct OS_Classification_Results OSR;
140 };
141 
142 class FingerPrintResultsIPv4 : public FingerPrintResults {
143 public:
144   FingerPrint **FPs; /* Fingerprint data obtained from host */
145   int numFPs;
146 
147   FingerPrintResultsIPv4();
148   virtual ~FingerPrintResultsIPv4();
149   const char *merge_fpr(const Target *currenths, bool isGoodFP, bool wrapit) const;
150 };
151 
152 class FingerPrintResultsIPv6 : public FingerPrintResults {
153 public:
154   FPResponse *fp_responses[NUM_FP_PROBES_IPv6];
155   struct timeval begin_time;
156   /* The flow label we set in our sent packets, for calculating offsets later. */
157   unsigned int flow_label;
158 
159   FingerPrintResultsIPv6();
160   virtual ~FingerPrintResultsIPv6();
161   const char *OmitSubmissionFP();
162   const char *merge_fpr(const Target *currenths, bool isGoodFP, bool wrapit) const;
163 };
164 
165 #endif /* FINGERPRINTRESULTS_H */
166 
167