1 /*************************************************************************** 2 * NewTargets.h -- The "NewTargets" class allows NSE scripts to add new * 3 * targets to the scan queue. * 4 ***********************IMPORTANT NMAP LICENSE TERMS************************ 5 * * 6 * The Nmap Security Scanner is (C) 1996-2020 Insecure.Com LLC ("The Nmap * 7 * Project"). Nmap is also a registered trademark of the Nmap Project. * 8 * * 9 * This program is distributed under the terms of the Nmap Public Source * 10 * License (NPSL). The exact license text applying to a particular Nmap * 11 * release or source code control revision is contained in the LICENSE * 12 * file distributed with that version of Nmap or source code control * 13 * revision. More Nmap copyright/legal information is available from * 14 * https://nmap.org/book/man-legal.html, and further information on the * 15 * NPSL license itself can be found at https://nmap.org/npsl. This header * 16 * summarizes some key points from the Nmap license, but is no substitute * 17 * for the actual license text. * 18 * * 19 * Nmap is generally free for end users to download and use themselves, * 20 * including commercial use. It is available from https://nmap.org. * 21 * * 22 * The Nmap license generally prohibits companies from using and * 23 * redistributing Nmap in commercial products, but we sell a special Nmap * 24 * OEM Edition with a more permissive license and special features for * 25 * this purpose. See https://nmap.org/oem * 26 * * 27 * If you have received a written Nmap license agreement or contract * 28 * stating terms other than these (such as an Nmap OEM license), you may * 29 * choose to use and redistribute Nmap under those terms instead. * 30 * * 31 * The official Nmap Windows builds include the Npcap software * 32 * (https://npcap.org) for packet capture and transmission. It is under * 33 * separate license terms which forbid redistribution without special * 34 * permission. So the official Nmap Windows builds may not be * 35 * redistributed without special permission (such as an Nmap OEM * 36 * license). * 37 * * 38 * Source is provided to this software because we believe users have a * 39 * right to know exactly what a program is going to do before they run it. * 40 * This also allows you to audit the software for security holes. * 41 * * 42 * Source code also allows you to port Nmap to new platforms, fix bugs, * 43 * and add new features. You are highly encouraged to submit your * 44 * changes as a Github PR or by email to the dev@nmap.org mailing list * 45 * for possible incorporation into the main distribution. Unless you * 46 * specify otherwise, it is understood that you are offering us very * 47 * broad rights to use your submissions as described in the Nmap Public * 48 * Source License Contributor Agreement. This is important because we * 49 * fund the project by selling licenses with various terms, and also * 50 * because the inability to relicense code has caused devastating * 51 * problems for other Free Software projects (such as KDE and NASM). * 52 * * 53 * The free version of Nmap is distributed in the hope that it will be * 54 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * 55 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Warranties, * 56 * indemnification and commercial support are all available through the * 57 * Npcap OEM program--see https://nmap.org/oem. * 58 * * 59 ***************************************************************************/ 60 61 /* $Id: NewTargets.h 38078 2020-10-02 16:12:22Z dmiller $ */ 62 63 #ifndef NEWTARGETS_H 64 #define NEWTARGETS_H 65 66 #include <queue> 67 #include <set> 68 #include <string> 69 70 71 /* Adding new targets is for NSE scripts */ 72 class NewTargets { 73 public: 74 NewTargets(); 75 76 /* return a previous inserted target */ 77 static std::string read (void); 78 79 /* clear the scanned_targets_cache */ 80 static void clear (void); 81 82 /* get the number of all new added targets */ 83 static unsigned long get_number (void); 84 85 /* get the number that have been scanned */ 86 static unsigned long get_scanned (void); 87 88 /* get the number of queued targets left to scan */ 89 static unsigned long get_queued (void); 90 91 /* get the new_targets object */ 92 static NewTargets *get (void); 93 94 /* insert targets to the new_targets_queue */ 95 static unsigned long insert (const char *target); 96 private: 97 /* unsigned long mex_new_targets; */ 98 99 /* A queue to push new targets that were discovered by NSE scripts. 100 * Nmap will pop future targets from this queue. */ 101 std::queue<std::string> queue; 102 103 /* A cache to save scanned targets specifications. 104 * (These are targets that were pushed to Nmap scan queue) */ 105 std::set<std::string> history; 106 107 void Initialize(); 108 109 /* Save new targets onto the queue */ 110 unsigned long push (const char *target); 111 protected: 112 static NewTargets *new_targets; 113 }; 114 115 #endif /* NEWTARGETS_H */ 116