forked from tux-mind/platform_external_nmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nmap.cc
3097 lines (2820 loc) · 118 KB
/
nmap.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
* nmap.cc -- Currently handles some of Nmap's port scanning features as *
* well as the command line user interface. Note that the actual main() *
* function is in main.cc *
* *
***********************IMPORTANT NMAP LICENSE TERMS************************
* *
* The Nmap Security Scanner is (C) 1996-2013 Insecure.Com LLC. Nmap is *
* also a registered trademark of Insecure.Com LLC. This program is free *
* software; you may redistribute and/or modify it under the terms of the *
* GNU General Public License as published by the Free Software *
* Foundation; Version 2 ("GPL"), BUT ONLY WITH ALL OF THE CLARIFICATIONS *
* AND EXCEPTIONS DESCRIBED HEREIN. This guarantees your right to use, *
* modify, and redistribute this software under certain conditions. If *
* you wish to embeed Nmap technology into proprietary software, we sell *
* alternative licenses (contact [email protected]). Dozens of software *
* vendors already license Nmap technology such as host discovery, port *
* scanning, OS detection, version detection, and the Nmap Scripting *
* Engine. *
* *
* Note that the GPL places important restrictions on "derivative works", *
* yet it does not provide a detailed definition of that term. To avoid *
* misunderstandings, we interpret that term as broadly as copyright law *
* allows. For example, we consider an application to constitute a *
* derivative work for the purpose of this license if it does any of the *
* following with any software or content covered by this license *
* ("Covered Software"): *
* *
* o Integrates source code from Covered Software. *
* *
* o Reads or includes copyrighted data files, such as Nmap's nmap-os-db *
* or nmap-service-probes. *
* *
* o Is designed specifically to execute Covered Software and parse the *
* results (as opposed to typical shell or execution-menu apps, which will *
* execute anything you tell them to). *
* *
* o Includes Covered Software in a proprietary executable installer. The *
* installers produced by InstallShield are an example of this. Including *
* Nmap with other software in compressed or archival form does not *
* trigger this provision, provided appropriate open source decompression *
* or de-archiving software is widely available for no charge. For the *
* purposes of this license, an installer is considered to include Covered *
* Software even if it actually retrieves a copy of Covered Software from *
* another source during runtime (such as by downloading it from the *
* Internet). *
* *
* o Links (statically or dynamically) to a library which does any of the *
* above. *
* *
* o Executes a helper program, module, or script to do any of the above. *
* *
* This list is not exclusive, but is meant to clarify our interpretation *
* of derived works with some common examples. Other people may interpret *
* the plain GPL differently, so we consider this a special exception to *
* the GPL that we apply to Covered Software. Works which meet any of *
* these conditions must conform to all of the terms of this license, *
* particularly including the GPL Section 3 requirements of providing *
* source code and allowing free redistribution of the work as a whole. *
* *
* As another special exception to the GPL terms, Insecure.Com LLC grants *
* permission to link the code of this program with any version of the *
* OpenSSL library which is distributed under a license identical to that *
* listed in the included docs/licenses/OpenSSL.txt file, and distribute *
* linked combinations including the two. *
* *
* Any redistribution of Covered Software, including any derived works, *
* must obey and carry forward all of the terms of this license, including *
* obeying all GPL rules and restrictions. For example, source code of *
* the whole work must be provided and free redistribution must be *
* allowed. All GPL references to "this License", are to be treated as *
* including the terms and conditions of this license text as well. *
* *
* Because this license imposes special exceptions to the GPL, Covered *
* Work may not be combined (even as part of a larger work) with plain GPL *
* software. The terms, conditions, and exceptions of this license must *
* be included as well. This license is incompatible with some other open *
* source licenses as well. In some cases we can relicense portions of *
* Nmap or grant special permissions to use it in other open source *
* software. Please contact [email protected] with any such requests. *
* Similarly, we don't incorporate incompatible open source software into *
* Covered Software without special permission from the copyright holders. *
* *
* If you have any questions about the licensing restrictions on using *
* Nmap in other works, are happy to help. As mentioned above, we also *
* offer alternative license to integrate Nmap into proprietary *
* applications and appliances. These contracts have been sold to dozens *
* of software vendors, and generally include a perpetual license as well *
* as providing for priority support and updates. They also fund the *
* continued development of Nmap. Please email [email protected] for further *
* information. *
* *
* If you have received a written license agreement or contract for *
* Covered Software stating terms other than these, you may choose to use *
* and redistribute Covered Software under those terms instead of these. *
* *
* Source is provided to this software because we believe users have a *
* right to know exactly what a program is going to do before they run it. *
* This also allows you to audit the software for security holes (none *
* have been found so far). *
* *
* Source code also allows you to port Nmap to new platforms, fix bugs, *
* and add new features. You are highly encouraged to send your changes *
* to the [email protected] mailing list for possible incorporation into the *
* main distribution. By sending these changes to Fyodor or one of the *
* Insecure.Org development mailing lists, or checking them into the Nmap *
* source code repository, it is understood (unless you specify otherwise) *
* that you are offering the Nmap Project (Insecure.Com LLC) the *
* unlimited, non-exclusive right to reuse, modify, and relicense the *
* code. Nmap will always be available Open Source, but this is important *
* because the inability to relicense code has caused devastating problems *
* for other Free Software projects (such as KDE and NASM). We also *
* occasionally relicense the code to third parties as discussed above. *
* If you wish to specify special license conditions of your *
* contributions, just say so when you send them. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Nmap *
* license file for more details (it's in a COPYING file included with *
* Nmap, and also available from https://svn.nmap.org/nmap/COPYING *
* *
***************************************************************************/
/* $Id: nmap.cc 32748 2014-02-21 21:10:51Z dmiller $ */
#include "nmap.h"
#include "osscan.h"
#include "osscan2.h"
#include "scan_engine.h"
#include "idle_scan.h"
#include "timing.h"
#include "NmapOps.h"
#include "MACLookup.h"
#include "traceroute.h"
#include "nmap_tty.h"
#include "nmap_dns.h"
#include "nmap_ftp.h"
#include "services.h"
#include "protocols.h"
#include "targets.h"
#include "TargetGroup.h"
#include "service_scan.h"
#include "charpool.h"
#include "nmap_error.h"
#include "utils.h"
#include "xml.h"
#ifndef NOLUA
#include "nse_main.h"
#endif
#ifdef WIN32
#include "winfix.h"
#include <shlobj.h>
#endif
#if HAVE_OPENSSL
#include <openssl/opensslv.h>
#endif
/* To get the version number only. */
#ifdef WIN32
#include "libdnet-stripped/include/dnet_winconfig.h"
#else
#include "libdnet-stripped/include/config.h"
#endif
#define DNET_VERSION VERSION
/* global options */
extern char *optarg;
extern int optind;
extern NmapOps o; /* option structure */
static bool target_needs_new_hostgroup(std::vector<Target *> &targets,
const Target *target);
static void display_nmap_version();
/* A mechanism to save argv[0] for code that requires that. */
static const char *program_name = NULL;
void set_program_name(const char *name) {
program_name = name;
}
static const char *get_program_name(void) {
return program_name;
}
/* parse the --scanflags argument. It can be a number >=0 or a string consisting of TCP flag names like "URGPSHFIN". Returns -1 if the argument is invalid. */
static int parse_scanflags(char *arg) {
int flagval = 0;
char *end = NULL;
if (isdigit((int) (unsigned char) arg[0])) {
flagval = strtol(arg, &end, 0);
if (*end || flagval < 0 || flagval > 255)
return -1;
} else {
if (strcasestr(arg, "FIN"))
flagval |= TH_FIN;
if (strcasestr(arg, "SYN"))
flagval |= TH_SYN;
if (strcasestr(arg, "RST") || strcasestr(arg, "RESET"))
flagval |= TH_RST;
if (strcasestr(arg, "PSH") || strcasestr(arg, "PUSH"))
flagval |= TH_PUSH;
if (strcasestr(arg, "ACK"))
flagval |= TH_ACK;
if (strcasestr(arg, "URG"))
flagval |= TH_URG;
if (strcasestr(arg, "ECE"))
flagval |= TH_ECE;
if (strcasestr(arg, "CWR"))
flagval |= TH_CWR;
if (strcasestr(arg, "ALL"))
flagval = 255;
if (strcasestr(arg, "NONE"))
flagval = 0;
}
return flagval;
}
static void printusage(int rc) {
printf("%s %s ( %s )\n"
"Usage: nmap [Scan Type(s)] [Options] {target specification}\n"
"TARGET SPECIFICATION:\n"
" Can pass hostnames, IP addresses, networks, etc.\n"
" Ex: scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254\n"
" -iL <inputfilename>: Input from list of hosts/networks\n"
" -iR <num hosts>: Choose random targets\n"
" --exclude <host1[,host2][,host3],...>: Exclude hosts/networks\n"
" --excludefile <exclude_file>: Exclude list from file\n"
"HOST DISCOVERY:\n"
" -sL: List Scan - simply list targets to scan\n"
" -sn: Ping Scan - disable port scan\n"
" -Pn: Treat all hosts as online -- skip host discovery\n"
" -PS/PA/PU/PY[portlist]: TCP SYN/ACK, UDP or SCTP discovery to given ports\n"
" -PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes\n"
" -PO[protocol list]: IP Protocol Ping\n"
" -n/-R: Never do DNS resolution/Always resolve [default: sometimes]\n"
" --dns-servers <serv1[,serv2],...>: Specify custom DNS servers\n"
" --system-dns: Use OS's DNS resolver\n"
" --traceroute: Trace hop path to each host\n"
"SCAN TECHNIQUES:\n"
" -sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans\n"
" -sU: UDP Scan\n"
" -sN/sF/sX: TCP Null, FIN, and Xmas scans\n"
" --scanflags <flags>: Customize TCP scan flags\n"
" -sI <zombie host[:probeport]>: Idle scan\n"
" -sY/sZ: SCTP INIT/COOKIE-ECHO scans\n"
" -sO: IP protocol scan\n"
" -b <FTP relay host>: FTP bounce scan\n"
"PORT SPECIFICATION AND SCAN ORDER:\n"
" -p <port ranges>: Only scan specified ports\n"
" Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9\n"
" -F: Fast mode - Scan fewer ports than the default scan\n"
" -r: Scan ports consecutively - don't randomize\n"
" --top-ports <number>: Scan <number> most common ports\n"
" --port-ratio <ratio>: Scan ports more common than <ratio>\n"
"SERVICE/VERSION DETECTION:\n"
" -sV: Probe open ports to determine service/version info\n"
" --version-intensity <level>: Set from 0 (light) to 9 (try all probes)\n"
" --version-light: Limit to most likely probes (intensity 2)\n"
" --version-all: Try every single probe (intensity 9)\n"
" --version-trace: Show detailed version scan activity (for debugging)\n"
#ifndef NOLUA
"SCRIPT SCAN:\n"
" -sC: equivalent to --script=default\n"
" --script=<Lua scripts>: <Lua scripts> is a comma separated list of \n"
" directories, script-files or script-categories\n"
" --script-args=<n1=v1,[n2=v2,...]>: provide arguments to scripts\n"
" --script-args-file=filename: provide NSE script args in a file\n"
" --script-trace: Show all data sent and received\n"
" --script-updatedb: Update the script database.\n"
" --script-help=<Lua scripts>: Show help about scripts.\n"
" <Lua scripts> is a comma-separated list of script-files or\n"
" script-categories.\n"
#endif
"OS DETECTION:\n"
" -O: Enable OS detection\n"
" --osscan-limit: Limit OS detection to promising targets\n"
" --osscan-guess: Guess OS more aggressively\n"
"TIMING AND PERFORMANCE:\n"
" Options which take <time> are in seconds, or append 'ms' (milliseconds),\n"
" 's' (seconds), 'm' (minutes), or 'h' (hours) to the value (e.g. 30m).\n"
" -T<0-5>: Set timing template (higher is faster)\n"
" --min-hostgroup/max-hostgroup <size>: Parallel host scan group sizes\n"
" --min-parallelism/max-parallelism <numprobes>: Probe parallelization\n"
" --min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <time>: Specifies\n"
" probe round trip time.\n"
" --max-retries <tries>: Caps number of port scan probe retransmissions.\n"
" --host-timeout <time>: Give up on target after this long\n"
" --scan-delay/--max-scan-delay <time>: Adjust delay between probes\n"
" --min-rate <number>: Send packets no slower than <number> per second\n"
" --max-rate <number>: Send packets no faster than <number> per second\n"
"FIREWALL/IDS EVASION AND SPOOFING:\n"
" -f; --mtu <val>: fragment packets (optionally w/given MTU)\n"
" -D <decoy1,decoy2[,ME],...>: Cloak a scan with decoys\n"
" -S <IP_Address>: Spoof source address\n"
" -e <iface>: Use specified interface\n"
" -g/--source-port <portnum>: Use given port number\n"
" --proxies <url1,[url2],...>: Relay connections through HTTP/SOCKS4 proxies\n"
" --data-length <num>: Append random data to sent packets\n"
" --ip-options <options>: Send packets with specified ip options\n"
" --ttl <val>: Set IP time-to-live field\n"
" --spoof-mac <mac address/prefix/vendor name>: Spoof your MAC address\n"
" --badsum: Send packets with a bogus TCP/UDP/SCTP checksum\n"
"OUTPUT:\n"
" -oN/-oX/-oS/-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3,\n"
" and Grepable format, respectively, to the given filename.\n"
" -oA <basename>: Output in the three major formats at once\n"
" -v: Increase verbosity level (use -vv or more for greater effect)\n"
" -d: Increase debugging level (use -dd or more for greater effect)\n"
" --reason: Display the reason a port is in a particular state\n"
" --open: Only show open (or possibly open) ports\n"
" --packet-trace: Show all packets sent and received\n"
" --iflist: Print host interfaces and routes (for debugging)\n"
" --log-errors: Log errors/warnings to the normal-format output file\n"
" --append-output: Append to rather than clobber specified output files\n"
" --resume <filename>: Resume an aborted scan\n"
" --stylesheet <path/URL>: XSL stylesheet to transform XML output to HTML\n"
" --webxml: Reference stylesheet from Nmap.Org for more portable XML\n"
" --no-stylesheet: Prevent associating of XSL stylesheet w/XML output\n"
"MISC:\n"
" -6: Enable IPv6 scanning\n"
" -A: Enable OS detection, version detection, script scanning, and traceroute\n"
" --datadir <dirname>: Specify custom Nmap data file location\n"
" --send-eth/--send-ip: Send using raw ethernet frames or IP packets\n"
" --privileged: Assume that the user is fully privileged\n"
" --unprivileged: Assume the user lacks raw socket privileges\n"
" -V: Print version number\n"
" -h: Print this help summary page.\n"
"EXAMPLES:\n"
" nmap -v -A scanme.nmap.org\n"
" nmap -v -sn 192.168.0.0/16 10.0.0.0/8\n"
" nmap -v -iR 10000 -Pn -p 80\n"
"SEE THE MAN PAGE (http://nmap.org/book/man.html) FOR MORE OPTIONS AND EXAMPLES\n", NMAP_NAME, NMAP_VERSION, NMAP_URL);
exit(rc);
}
#ifdef WIN32
static void check_setugid(void) {
}
#else
/* Show a warning when running setuid or setgid, as this allows code execution
(for example NSE scripts) as the owner/group. */
static void check_setugid(void) {
if (getuid() != geteuid())
error("WARNING: Running Nmap setuid, as you are doing, is a major security risk.\n");
if (getgid() != getegid())
error("WARNING: Running Nmap setgid, as you are doing, is a major security risk.\n");
}
#endif
static void insert_port_into_merge_list(unsigned short *mlist,
int *merged_port_count,
unsigned short p) {
int i;
// make sure the port isn't already in the list
for (i = 0; i < *merged_port_count; i++) {
if (mlist[i] == p) {
return;
}
}
mlist[*merged_port_count] = p;
(*merged_port_count)++;
}
static unsigned short *merge_port_lists(unsigned short *port_list1, int count1,
unsigned short *port_list2, int count2,
int *merged_port_count) {
int i;
unsigned short *merged_port_list = NULL;
*merged_port_count = 0;
merged_port_list =
(unsigned short *) safe_zalloc((count1 + count2) * sizeof(unsigned short));
for (i = 0; i < count1; i++) {
insert_port_into_merge_list(merged_port_list,
merged_port_count,
port_list1[i]);
}
for (i = 0; i < count2; i++) {
insert_port_into_merge_list(merged_port_list,
merged_port_count,
port_list2[i]);
}
// if there were duplicate ports then we can save some memory
if (*merged_port_count < (count1 + count2)) {
merged_port_list = (unsigned short*)
safe_realloc(merged_port_list,
(*merged_port_count) * sizeof(unsigned short));
}
return merged_port_list;
}
void validate_scan_lists(scan_lists &ports, NmapOps &o) {
if (o.pingtype == PINGTYPE_UNKNOWN) {
if (o.isr00t) {
if (o.pf() == PF_INET) {
o.pingtype = DEFAULT_IPV4_PING_TYPES;
} else {
o.pingtype = DEFAULT_IPV6_PING_TYPES;
}
getpts_simple(DEFAULT_PING_ACK_PORT_SPEC, SCAN_TCP_PORT,
&ports.ack_ping_ports, &ports.ack_ping_count);
getpts_simple(DEFAULT_PING_SYN_PORT_SPEC, SCAN_TCP_PORT,
&ports.syn_ping_ports, &ports.syn_ping_count);
} else {
o.pingtype = PINGTYPE_TCP; // if nonr00t
getpts_simple(DEFAULT_PING_CONNECT_PORT_SPEC, SCAN_TCP_PORT,
&ports.syn_ping_ports, &ports.syn_ping_count);
}
}
if ((o.pingtype & PINGTYPE_TCP) && (!o.isr00t)) {
// We will have to do a connect() style ping
// Pretend we wanted SYN probes all along.
if (ports.ack_ping_count > 0) {
// Combine the ACK and SYN ping port lists since they both reduce to
// SYN probes in this case
unsigned short *merged_port_list;
int merged_port_count;
merged_port_list = merge_port_lists(
ports.syn_ping_ports, ports.syn_ping_count,
ports.ack_ping_ports, ports.ack_ping_count,
&merged_port_count);
// clean up a bit
free(ports.syn_ping_ports);
free(ports.ack_ping_ports);
ports.syn_ping_count = merged_port_count;
ports.syn_ping_ports = merged_port_list;
ports.ack_ping_count = 0;
ports.ack_ping_ports = NULL;
}
o.pingtype &= ~PINGTYPE_TCP_USE_ACK;
o.pingtype |= PINGTYPE_TCP_USE_SYN;
}
#ifndef WIN32 /* Win32 has perfectly fine ICMP socket support */
if (!o.isr00t) {
if (o.pingtype & (PINGTYPE_ICMP_PING | PINGTYPE_ICMP_MASK | PINGTYPE_ICMP_TS)) {
error("Warning: You are not root -- using TCP pingscan rather than ICMP");
o.pingtype = PINGTYPE_TCP;
if (ports.syn_ping_count == 0) {
getpts_simple(DEFAULT_TCP_PROBE_PORT_SPEC, SCAN_TCP_PORT, &ports.syn_ping_ports, &ports.syn_ping_count);
assert(ports.syn_ping_count > 0);
}
}
}
#endif
}
struct ftpinfo ftp = get_default_ftpinfo();
/* A list of targets to be displayed by the --route-dst debugging option. */
static std::vector<std::string> route_dst_hosts;
struct scan_lists ports = { 0 };
/* This struct is used is a temporary storage place that holds options that
can't be correctly parsed and interpreted before the entire command line has
been read. Examples are -6 and -S. Trying to set the source address without
knowing the address family first could result in a failure if you pass an
IPv6 address and the address family is still IPv4. */
static struct delayed_options {
public:
delayed_options() {
this->pre_max_parallelism = -1;
this->pre_scan_delay = -1;
this->pre_max_scan_delay = -1;
this->pre_init_rtt_timeout = -1;
this->pre_min_rtt_timeout = -1;
this->pre_max_rtt_timeout = -1;
this->pre_max_retries = -1;
this->pre_host_timeout = -1;
this->iflist = false;
}
// Pre-specified timing parameters.
// These are stored here during the parsing of the arguments so that we can
// set the defaults specified by any timing template options (-T2, etc) BEFORE
// any of these. In other words, these always take precedence over the templates.
int pre_max_parallelism, pre_scan_delay, pre_max_scan_delay;
int pre_init_rtt_timeout, pre_min_rtt_timeout, pre_max_rtt_timeout;
int pre_max_retries;
long pre_host_timeout;
char *machinefilename, *kiddiefilename, *normalfilename, *xmlfilename;
bool iflist;
char *exclude_spec, *exclude_file;
char *spoofSource;
const char *spoofmac;
} delayed_options;
struct tm *local_time;
void parse_options(int argc, char **argv) {
char *p, *q;
int arg;
long l;
double d;
char *endptr = NULL;
char errstr[256];
int option_index;
struct option long_options[] = {
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'},
{"datadir", required_argument, 0, 0},
{"servicedb", required_argument, 0, 0},
{"versiondb", required_argument, 0, 0},
{"debug", optional_argument, 0, 'd'},
{"help", no_argument, 0, 'h'},
{"iflist", no_argument, 0, 0},
{"release_memory", no_argument, 0, 0},
{"release-memory", no_argument, 0, 0},
{"nogcc", no_argument, 0, 0},
{"max_os_tries", required_argument, 0, 0},
{"max-os-tries", required_argument, 0, 0},
{"max_parallelism", required_argument, 0, 'M'},
{"max-parallelism", required_argument, 0, 'M'},
{"min_parallelism", required_argument, 0, 0},
{"min-parallelism", required_argument, 0, 0},
{"timing", required_argument, 0, 'T'},
{"max_rtt_timeout", required_argument, 0, 0},
{"max-rtt-timeout", required_argument, 0, 0},
{"min_rtt_timeout", required_argument, 0, 0},
{"min-rtt-timeout", required_argument, 0, 0},
{"initial_rtt_timeout", required_argument, 0, 0},
{"initial-rtt-timeout", required_argument, 0, 0},
{"excludefile", required_argument, 0, 0},
{"exclude", required_argument, 0, 0},
{"max_hostgroup", required_argument, 0, 0},
{"max-hostgroup", required_argument, 0, 0},
{"min_hostgroup", required_argument, 0, 0},
{"min-hostgroup", required_argument, 0, 0},
{"open", no_argument, 0, 0},
{"scanflags", required_argument, 0, 0},
{"defeat_rst_ratelimit", no_argument, 0, 0},
{"defeat-rst-ratelimit", no_argument, 0, 0},
{"host_timeout", required_argument, 0, 0},
{"host-timeout", required_argument, 0, 0},
{"scan_delay", required_argument, 0, 0},
{"scan-delay", required_argument, 0, 0},
{"max_scan_delay", required_argument, 0, 0},
{"max-scan-delay", required_argument, 0, 0},
{"max_retries", required_argument, 0, 0},
{"max-retries", required_argument, 0, 0},
{"oA", required_argument, 0, 0},
{"oN", required_argument, 0, 0},
{"oM", required_argument, 0, 0},
{"oG", required_argument, 0, 0},
{"oS", required_argument, 0, 0},
{"oH", required_argument, 0, 0},
{"oX", required_argument, 0, 0},
{"iL", required_argument, 0, 'i'},
{"iR", required_argument, 0, 0},
{"sI", required_argument, 0, 0},
{"source_port", required_argument, 0, 'g'},
{"source-port", required_argument, 0, 'g'},
{"randomize_hosts", no_argument, 0, 0},
{"randomize-hosts", no_argument, 0, 0},
{"nsock_engine", required_argument, 0, 0},
{"nsock-engine", required_argument, 0, 0},
{"proxies", required_argument, 0, 0},
{"proxy", required_argument, 0, 0},
{"osscan_limit", no_argument, 0, 0}, /* skip OSScan if no open ports */
{"osscan-limit", no_argument, 0, 0}, /* skip OSScan if no open ports */
{"osscan_guess", no_argument, 0, 0}, /* More guessing flexibility */
{"osscan-guess", no_argument, 0, 0}, /* More guessing flexibility */
{"fuzzy", no_argument, 0, 0}, /* Alias for osscan_guess */
{"packet_trace", no_argument, 0, 0}, /* Display all packets sent/rcv */
{"packet-trace", no_argument, 0, 0}, /* Display all packets sent/rcv */
{"version_trace", no_argument, 0, 0}, /* Display -sV related activity */
{"version-trace", no_argument, 0, 0}, /* Display -sV related activity */
{"data_length", required_argument, 0, 0},
{"data-length", required_argument, 0, 0},
{"send_eth", no_argument, 0, 0},
{"send-eth", no_argument, 0, 0},
{"send_ip", no_argument, 0, 0},
{"send-ip", no_argument, 0, 0},
{"stylesheet", required_argument, 0, 0},
{"no_stylesheet", no_argument, 0, 0},
{"no-stylesheet", no_argument, 0, 0},
{"webxml", no_argument, 0, 0},
{"rH", no_argument, 0, 0},
{"vv", no_argument, 0, 0},
{"ff", no_argument, 0, 0},
{"privileged", no_argument, 0, 0},
{"unprivileged", no_argument, 0, 0},
{"mtu", required_argument, 0, 0},
{"append_output", no_argument, 0, 0},
{"append-output", no_argument, 0, 0},
{"noninteractive", no_argument, 0, 0},
{"spoof_mac", required_argument, 0, 0},
{"spoof-mac", required_argument, 0, 0},
{"thc", no_argument, 0, 0},
{"badsum", no_argument, 0, 0},
{"ttl", required_argument, 0, 0}, /* Time to live */
{"traceroute", no_argument, 0, 0},
{"reason", no_argument, 0, 0},
{"allports", no_argument, 0, 0},
{"version_intensity", required_argument, 0, 0},
{"version-intensity", required_argument, 0, 0},
{"version_light", no_argument, 0, 0},
{"version-light", no_argument, 0, 0},
{"version_all", no_argument, 0, 0},
{"version-all", no_argument, 0, 0},
{"system_dns", no_argument, 0, 0},
{"system-dns", no_argument, 0, 0},
{"log_errors", no_argument, 0, 0},
{"log-errors", no_argument, 0, 0},
{"deprecated_xml_osclass", no_argument, 0, 0},
{"deprecated-xml-osclass", no_argument, 0, 0},
{"dns_servers", required_argument, 0, 0},
{"dns-servers", required_argument, 0, 0},
{"port-ratio", required_argument, 0, 0},
{"port_ratio", required_argument, 0, 0},
{"top-ports", required_argument, 0, 0},
{"top_ports", required_argument, 0, 0},
#ifndef NOLUA
{"script", required_argument, 0, 0},
{"script-trace", no_argument, 0, 0},
{"script_trace", no_argument, 0, 0},
{"script-updatedb", no_argument, 0, 0},
{"script_updatedb", no_argument, 0, 0},
{"script-args", required_argument, 0, 0},
{"script_args", required_argument, 0, 0},
{"script-args-file", required_argument, 0, 0},
{"script_args_file", required_argument, 0, 0},
{"script-help", required_argument, 0, 0},
{"script_help", required_argument, 0, 0},
#endif
{"ip_options", required_argument, 0, 0},
{"ip-options", required_argument, 0, 0},
{"min_rate", required_argument, 0, 0},
{"min-rate", required_argument, 0, 0},
{"max_rate", required_argument, 0, 0},
{"max-rate", required_argument, 0, 0},
{"adler32", no_argument, 0, 0},
{"stats_every", required_argument, 0, 0},
{"stats-every", required_argument, 0, 0},
{"disable_arp_ping", no_argument, 0, 0},
{"disable-arp-ping", no_argument, 0, 0},
{"route_dst", required_argument, 0, 0},
{"route-dst", required_argument, 0, 0},
{0, 0, 0, 0}
};
/* OK, lets parse these args! */
optind = 1; /* so it can be called multiple times */
while ((arg = getopt_long_only(argc, argv, "6Ab:D:d::e:Ffg:hIi:M:m:nO::o:P:p:qRrS:s:T:Vv::", long_options, &option_index)) != EOF) {
switch (arg) {
case 0:
#ifndef NOLUA
if (strcmp(long_options[option_index].name, "script") == 0) {
o.script = 1;
o.chooseScripts(optarg);
} else if (optcmp(long_options[option_index].name, "script-args") == 0) {
o.scriptargs = strdup(optarg);
} else if (optcmp(long_options[option_index].name, "script-args-file") == 0) {
o.scriptargsfile = strdup(optarg);
} else if (optcmp(long_options[option_index].name, "script-trace") == 0) {
o.scripttrace = 1;
} else if (optcmp(long_options[option_index].name, "script-updatedb") == 0) {
o.scriptupdatedb = 1;
} else if (optcmp(long_options[option_index].name, "script-help") == 0) {
o.scripthelp = true;
o.chooseScripts(optarg);
} else
#endif
if (optcmp(long_options[option_index].name, "max-os-tries") == 0) {
l = atoi(optarg);
if (l < 1 || l > 50)
fatal("Bogus --max-os-tries argument specified, must be between 1 and 50 (inclusive)");
o.setMaxOSTries(l);
} else if (optcmp(long_options[option_index].name, "max-rtt-timeout") == 0) {
l = tval2msecs(optarg);
if (l < 5)
fatal("Bogus --max-rtt-timeout argument specified, must be at least 5ms");
if (l >= 50 * 1000 && tval_unit(optarg) == NULL)
fatal("Since April 2010, the default unit for --max-rtt-timeout is seconds, so your time of \"%s\" is %g seconds. Use \"%sms\" for %g milliseconds.", optarg, l / 1000.0, optarg, l / 1000.0);
if (l < 20)
error("WARNING: You specified a round-trip time timeout (%ld ms) that is EXTRAORDINARILY SMALL. Accuracy may suffer.", l);
delayed_options.pre_max_rtt_timeout = l;
} else if (optcmp(long_options[option_index].name, "min-rtt-timeout") == 0) {
l = tval2msecs(optarg);
if (l < 0)
fatal("Bogus --min-rtt-timeout argument specified");
if (l >= 50 * 1000 && tval_unit(optarg) == NULL)
fatal("Since April 2010, the default unit for --min-rtt-timeout is seconds, so your time of \"%s\" is %g seconds. Use \"%sms\" for %g milliseconds.", optarg, l / 1000.0, optarg, l / 1000.0);
delayed_options.pre_min_rtt_timeout = l;
} else if (optcmp(long_options[option_index].name, "initial-rtt-timeout") == 0) {
l = tval2msecs(optarg);
if (l <= 0)
fatal("Bogus --initial-rtt-timeout argument specified. Must be positive");
if (l >= 50 * 1000 && tval_unit(optarg) == NULL)
fatal("Since April 2010, the default unit for --initial-rtt-timeout is seconds, so your time of \"%s\" is %g seconds. Use \"%sms\" for %g milliseconds.", optarg, l / 1000.0, optarg, l / 1000.0);
delayed_options.pre_init_rtt_timeout = l;
} else if (strcmp(long_options[option_index].name, "excludefile") == 0) {
delayed_options.exclude_file = strdup(optarg);
} else if (strcmp(long_options[option_index].name, "exclude") == 0) {
delayed_options.exclude_spec = strdup(optarg);
} else if (optcmp(long_options[option_index].name, "max-hostgroup") == 0) {
o.setMaxHostGroupSz(atoi(optarg));
} else if (optcmp(long_options[option_index].name, "min-hostgroup") == 0) {
o.setMinHostGroupSz(atoi(optarg));
if (atoi(optarg) > 100)
error("Warning: You specified a highly aggressive --min-hostgroup.");
} else if (strcmp(long_options[option_index].name, "open") == 0) {
o.setOpenOnly(true);
} else if (strcmp(long_options[option_index].name, "scanflags") == 0) {
o.scanflags = parse_scanflags(optarg);
if (o.scanflags < 0) {
fatal("--scanflags option must be a number between 0 and 255 (inclusive) or a string like \"URGPSHFIN\".");
}
} else if (strcmp(long_options[option_index].name, "iflist") == 0) {
delayed_options.iflist = true;
} else if (strcmp(long_options[option_index].name, "nogcc") == 0) {
o.nogcc = 1;
} else if (optcmp(long_options[option_index].name, "release-memory") == 0) {
o.release_memory = true;
} else if (optcmp(long_options[option_index].name, "min-parallelism") == 0) {
o.min_parallelism = atoi(optarg);
if (o.min_parallelism < 1)
fatal("Argument to --min-parallelism must be at least 1!");
if (o.min_parallelism > 100) {
error("Warning: Your --min-parallelism option is pretty high! This can hurt reliability.");
}
} else if (optcmp(long_options[option_index].name, "host-timeout") == 0) {
l = tval2msecs(optarg);
if (l <= 0)
fatal("Bogus --host-timeout argument specified");
if (l >= 10000 * 1000 && tval_unit(optarg) == NULL)
fatal("Since April 2010, the default unit for --host-timeout is seconds, so your time of \"%s\" is %.1f hours. If this is what you want, use \"%ss\".", optarg, l / 1000.0 / 60 / 60, optarg);
delayed_options.pre_host_timeout = l;
} else if (strcmp(long_options[option_index].name, "ttl") == 0) {
o.ttl = atoi(optarg);
if (o.ttl < 0 || o.ttl > 255) {
fatal("ttl option must be a number between 0 and 255 (inclusive)");
}
} else if (strcmp(long_options[option_index].name, "datadir") == 0) {
o.datadir = strdup(optarg);
} else if (strcmp(long_options[option_index].name, "servicedb") == 0) {
o.requested_data_files["nmap-services"] = optarg;
o.fastscan++;
} else if (strcmp(long_options[option_index].name, "versiondb") == 0) {
o.requested_data_files["nmap-service-probes"] = optarg;
} else if (optcmp(long_options[option_index].name, "append-output") == 0) {
o.append_output = 1;
} else if (strcmp(long_options[option_index].name, "noninteractive") == 0) {
o.noninteractive = true;
} else if (optcmp(long_options[option_index].name, "spoof-mac") == 0) {
/* I need to deal with this later, once I'm sure that I have output
files set up, --datadir, etc. */
delayed_options.spoofmac = optarg;
} else if (strcmp(long_options[option_index].name, "allports") == 0) {
o.override_excludeports = 1;
} else if (optcmp(long_options[option_index].name, "version-intensity") == 0) {
o.version_intensity = atoi(optarg);
if (o.version_intensity < 0 || o.version_intensity > 9)
fatal("version-intensity must be between 0 and 9");
} else if (optcmp(long_options[option_index].name, "version-light") == 0) {
o.version_intensity = 2;
} else if (optcmp(long_options[option_index].name, "version-all") == 0) {
o.version_intensity = 9;
} else if (optcmp(long_options[option_index].name, "scan-delay") == 0) {
l = tval2msecs(optarg);
if (l < 0)
fatal("Bogus --scan-delay argument specified.");
if (l >= 100 * 1000 && tval_unit(optarg) == NULL)
fatal("Since April 2010, the default unit for --scan-delay is seconds, so your time of \"%s\" is %.1f minutes. Use \"%sms\" for %g milliseconds.", optarg, l / 1000.0 / 60, optarg, l / 1000.0);
delayed_options.pre_scan_delay = l;
} else if (optcmp(long_options[option_index].name, "defeat-rst-ratelimit") == 0) {
o.defeat_rst_ratelimit = 1;
} else if (optcmp(long_options[option_index].name, "max-scan-delay") == 0) {
l = tval2msecs(optarg);
if (l < 0)
fatal("Bogus --max-scan-delay argument specified.");
if (l >= 100 * 1000 && tval_unit(optarg) == NULL)
fatal("Since April 2010, the default unit for --max-scan-delay is seconds, so your time of \"%s\" is %.1f minutes. If this is what you want, use \"%ss\".", optarg, l / 1000.0 / 60, optarg);
delayed_options.pre_max_scan_delay = l;
} else if (optcmp(long_options[option_index].name, "max-retries") == 0) {
delayed_options.pre_max_retries = atoi(optarg);
if (delayed_options.pre_max_retries < 0)
fatal("max-retries must be positive");
} else if (optcmp(long_options[option_index].name, "randomize-hosts") == 0
|| strcmp(long_options[option_index].name, "rH") == 0) {
o.randomize_hosts = 1;
o.ping_group_sz = PING_GROUP_SZ * 4;
} else if (optcmp(long_options[option_index].name, "nsock-engine") == 0) {
if (nsock_set_default_engine(optarg) < 0)
fatal("Unknown or non-available engine: %s", optarg);
} else if ((optcmp(long_options[option_index].name, "proxies") == 0) || (optcmp(long_options[option_index].name, "proxy") == 0)) {
if (nsock_proxychain_new(optarg, &o.proxy_chain, NULL) < 0)
fatal("Invalid proxy chain specification");
} else if (optcmp(long_options[option_index].name, "osscan-limit") == 0) {
o.osscan_limit = 1;
} else if (optcmp(long_options[option_index].name, "osscan-guess") == 0
|| strcmp(long_options[option_index].name, "fuzzy") == 0) {
o.osscan_guess = 1;
} else if (optcmp(long_options[option_index].name, "packet-trace") == 0) {
o.setPacketTrace(true);
#ifndef NOLUA
o.scripttrace = 1;
#endif
} else if (optcmp(long_options[option_index].name, "version-trace") == 0) {
o.setVersionTrace(true);
o.debugging++;
} else if (optcmp(long_options[option_index].name, "data-length") == 0) {
o.extra_payload_length = (int)strtol(optarg, NULL, 10);
if (o.extra_payload_length < 0 || o.extra_payload_length > MAX_PAYLOAD_ALLOWED)
fatal("data-length must be between 0 and %d", MAX_PAYLOAD_ALLOWED);
if (o.extra_payload_length > 1400) /* 1500 - IP with opts - TCP with opts. */
error("WARNING: Payloads bigger than 1400 bytes may not be sent successfully.");
o.extra_payload = (char *) safe_malloc(MAX(o.extra_payload_length, 1));
get_random_bytes(o.extra_payload, o.extra_payload_length);
} else if (optcmp(long_options[option_index].name, "send-eth") == 0) {
o.sendpref = PACKET_SEND_ETH_STRONG;
} else if (optcmp(long_options[option_index].name, "send-ip") == 0) {
o.sendpref = PACKET_SEND_IP_STRONG;
} else if (strcmp(long_options[option_index].name, "stylesheet") == 0) {
o.setXSLStyleSheet(optarg);
} else if (optcmp(long_options[option_index].name, "no-stylesheet") == 0) {
o.setXSLStyleSheet(NULL);
} else if (optcmp(long_options[option_index].name, "system-dns") == 0) {
o.mass_dns = false;
} else if (optcmp(long_options[option_index].name, "dns-servers") == 0) {
o.dns_servers = strdup(optarg);
} else if (optcmp(long_options[option_index].name, "log-errors") == 0) {
/*Nmap Log errors is depreciated and is now always enabled by default.
This option is left in so as to not break anybody's scanning scripts.
However it does nothing*/
} else if (optcmp(long_options[option_index].name, "deprecated-xml-osclass") == 0) {
o.deprecated_xml_osclass = true;
} else if (strcmp(long_options[option_index].name, "webxml") == 0) {
o.setXSLStyleSheet("https://svn.nmap.org/nmap/docs/nmap.xsl");
} else if (strcmp(long_options[option_index].name, "oN") == 0) {
delayed_options.normalfilename = logfilename(optarg, local_time);
} else if (strcmp(long_options[option_index].name, "oG") == 0
|| strcmp(long_options[option_index].name, "oM") == 0) {
delayed_options.machinefilename = logfilename(optarg, local_time);
} else if (strcmp(long_options[option_index].name, "oS") == 0) {
delayed_options.kiddiefilename = logfilename(optarg, local_time);
} else if (strcmp(long_options[option_index].name, "oH") == 0) {
fatal("HTML output is not directly supported, though Nmap includes an XSL for transforming XML output into HTML. See the man page.");
} else if (strcmp(long_options[option_index].name, "oX") == 0) {
delayed_options.xmlfilename = logfilename(optarg, local_time);
} else if (strcmp(long_options[option_index].name, "oA") == 0) {
char buf[MAXPATHLEN];
Snprintf(buf, sizeof(buf), "%s.nmap", logfilename(optarg, local_time));
delayed_options.normalfilename = strdup(buf);
Snprintf(buf, sizeof(buf), "%s.gnmap", logfilename(optarg, local_time));
delayed_options.machinefilename = strdup(buf);
Snprintf(buf, sizeof(buf), "%s.xml", logfilename(optarg, local_time));
delayed_options.xmlfilename = strdup(buf);
} else if (strcmp(long_options[option_index].name, "thc") == 0) {
log_write(LOG_STDOUT, "!!Greets to Van Hauser, Plasmoid, Skyper and the rest of THC!!\n");
exit(0);
} else if (strcmp(long_options[option_index].name, "badsum") == 0) {
o.badsum = 1;
} else if (strcmp(long_options[option_index].name, "iR") == 0) {
o.generate_random_ips = 1;
o.max_ips_to_scan = strtoul(optarg, &endptr, 10);
if (*endptr != '\0') {
fatal("ERROR: -iR argument must be the maximum number of random IPs you wish to scan (use 0 for unlimited)");
}
} else if (strcmp(long_options[option_index].name, "sI") == 0) {
o.idlescan = 1;
o.idleProxy = strdup(optarg);
} else if (strcmp(long_options[option_index].name, "vv") == 0) {
/* Compatibility hack ... ugly */
o.verbose += 2;
} else if (strcmp(long_options[option_index].name, "ff") == 0) {
o.fragscan += 16;
} else if (strcmp(long_options[option_index].name, "privileged") == 0) {
o.isr00t = 1;
} else if (strcmp(long_options[option_index].name, "unprivileged") == 0) {
o.isr00t = 0;
} else if (strcmp(long_options[option_index].name, "mtu") == 0) {
o.fragscan = atoi(optarg);
if (o.fragscan <= 0 || o.fragscan % 8 != 0)
fatal("Data payload MTU must be >0 and multiple of 8");
} else if (optcmp(long_options[option_index].name, "port-ratio") == 0) {
char *ptr;
o.topportlevel = strtod(optarg, &ptr);
if (!ptr || o.topportlevel < 0 || o.topportlevel >= 1)
fatal("--port-ratio should be between [0 and 1)");
} else if (optcmp(long_options[option_index].name, "top-ports") == 0) {
char *ptr;
o.topportlevel = strtod(optarg, &ptr);
if (!ptr || o.topportlevel < 1 || ((double)((int)o.topportlevel)) != o.topportlevel)
fatal("--top-ports should be an integer 1 or greater");
} else if (optcmp(long_options[option_index].name, "ip-options") == 0) {
o.ipoptions = (u8*) safe_malloc(4 * 10 + 1);
if ( (o.ipoptionslen = parse_ip_options(optarg, o.ipoptions, 4 * 10 + 1, &o.ipopt_firsthop, &o.ipopt_lasthop, errstr, sizeof(errstr))) == OP_FAILURE)
fatal("%s", errstr);
if (o.ipoptionslen > 4 * 10)
fatal("Ip options can't be more than 40 bytes long");
if (o.ipoptionslen % 4 != 0)
fatal("Ip options must be multiple of 4 (read length is %i bytes)", o.ipoptionslen);
} else if (strcmp(long_options[option_index].name, "traceroute") == 0) {
o.traceroute = true;
} else if (strcmp(long_options[option_index].name, "reason") == 0) {
o.reason = true;
} else if (optcmp(long_options[option_index].name, "min-rate") == 0) {
if (sscanf(optarg, "%f", &o.min_packet_send_rate) != 1 || o.min_packet_send_rate <= 0.0)
fatal("Argument to --min-rate must be a positive floating-point number");
} else if (optcmp(long_options[option_index].name, "max-rate") == 0) {
if (sscanf(optarg, "%f", &o.max_packet_send_rate) != 1 || o.max_packet_send_rate <= 0.0)
fatal("Argument to --max-rate must be a positive floating-point number");
} else if (optcmp(long_options[option_index].name, "adler32") == 0) {
o.adler32 = true;
} else if (optcmp(long_options[option_index].name, "stats-every") == 0) {
d = tval2secs(optarg);
if (d < 0)
fatal("Argument to --stats-every cannot be negative.");
o.stats_interval = d;
} else if (optcmp(long_options[option_index].name, "disable-arp-ping") == 0) {
o.implicitARPPing = false;
} else if (optcmp(long_options[option_index].name, "route-dst") == 0) {
/* The --route-dst debugging option: push these on a list to be
resolved later after options like -6 and -S have been parsed. */
route_dst_hosts.push_back(optarg);
} else {
fatal("Unknown long option (%s) given@#!$#$", long_options[option_index].name);
}
break;
case '6':
#if !HAVE_IPV6
fatal("I am afraid IPv6 is not available because your host doesn't support it or you chose to compile Nmap w/o IPv6 support.");
#else
o.setaf(AF_INET6);
#endif /* !HAVE_IPV6 */
break;
case 'A':
o.servicescan = true;
#ifndef NOLUA
o.script = 1;
#endif
if (o.isr00t) {
o.osscan++;
o.traceroute = true;
}
break;
case 'b':
o.bouncescan++;
if (parse_bounce_argument(&ftp, optarg) < 0) {
fatal("Your argument to -b is b0rked. Use the normal url style: user:pass@server:port or just use server and use default anon login\n Use -h for help");
}
break;
case 'D':
p = optarg;
do {
q = strchr(p, ',');
if (q)
*q = '\0';
if (!strcasecmp(p, "me")) {
if (o.decoyturn != -1)
fatal("Can only use 'ME' as a decoy once.\n");
o.decoyturn = o.numdecoys++;
} else if (!strcasecmp(p, "rnd") || !strncasecmp(p, "rnd:", 4)) {
int i = 1;
/* 'rnd:' is allowed and just gives them one */
if (strlen(p) > 4)
i = atoi(&p[4]);
if (i < 1)
fatal("Bad 'rnd' decoy \"%s\"", p);
if (o.numdecoys + i >= MAX_DECOYS - 1)
fatal("You are only allowed %d decoys (if you need more redefine MAX_DECOYS in nmap.h)", MAX_DECOYS);
while (i--) {
do {
o.decoys[o.numdecoys].s_addr = get_random_u32();
} while (ip_is_reserved(&o.decoys[o.numdecoys]));
o.numdecoys++;
}
} else {
if (o.numdecoys >= MAX_DECOYS - 1)
fatal("You are only allowed %d decoys (if you need more redefine MAX_DECOYS in nmap.h)", MAX_DECOYS);
/* Try to resolve it */
struct sockaddr_in decoytemp;
size_t decoytemplen = sizeof(struct sockaddr_in);
int rc = resolve(p, 0, (sockaddr_storage*)&decoytemp, &decoytemplen, AF_INET);
if (rc != 0)
fatal("Failed to resolve decoy host \"%s\": %s", p, gai_strerror(rc));
o.decoys[o.numdecoys] = decoytemp.sin_addr;