File: ngen

package info (click to toggle)
ndiff 0.05beta4-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 300 kB
  • ctags: 254
  • sloc: perl: 1,806; makefile: 56
file content (288 lines) | stat: -rw-r--r-- 6,948 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl
#
# $Id: ngen,v 1.10 2001/07/02 21:33:06 levine Exp $
#
#
# Copyright (C) 2000, 2001  James D. Levine (jdl@vinecorp.com)
#
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version 2
#   of the License, or (at your option) any later version.
# 
#   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
#   GNU General Public License for more details.
# 
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
#   02111-1307, USA.
#
####################################################################

use strict;
use Getopt::Long;
use PortScan::ScannedHost;
use PortScan::ScanContext;
use PortScan::DataStore;
use PortScan::ScanSet;
use PortScan::IPAddress;

sub usage
{
    print <<DONE;

 ngen [-o|-output <filename-or-:tag>] [-p|-ports <port list>] 
      [-h|-host <specification> ... -h|-host <specification N>]

      <specification> = 
      [!]<host spec>[:<port spec>][:ignored state] 

DONE
    ;
    exit 1;
}

my $pspecs;
my @hspecs = ();
my $output_tag = "%F-baseline";
my $help = 0;

GetOptions(
	   "p|ports=s"    => \$pspecs,
	   "h|host=s@"    => \@hspecs,
	   "o|output=s"   => \$output_tag,
	   "help"         => \$help,
	   );

usage() if $help || ! scalar ( @hspecs );

$output_tag = PortScan::DataStore::prepare_tag($output_tag);

my ($processed_output_tag, $output) = PortScan::DataStore::data_store_for($output_tag);

my $results_set = &PortScan::IPAddress::make_scanset( \@hspecs, $pspecs, "closed" );

$results_set->tag($processed_output_tag);

exit $output->put_scanset($results_set);


sub tests
{
    my $plist = sub { my $f = shift; foreach my $i (@$f) { print $i->nmap_format, "\n"; } };

    my $ports = &expand_port("22222fx");

    &$plist($ports);
    
    my $iplist = sub { my $f = shift; foreach my $i (@$f) { print $i, "\n"; } };
#    my $ips = &expand_ip("1-20");
#    &$iplist($ips);


    my $ips = &expand_host_range("248.2.3.4/20");
    &$iplist($ips);

}




=head1 NAME

ngen - create a baseline set of nmap results from command-line
specifications and/or an nmap results file.

=head1 SYNOPSIS

 ngen [-o|-output <filename-or-:tag>] [-p|-ports <port list>] 
      [-h|-host <specification> ... -h|-host <specification N>]

      <specification> = 
      [!]<host spec>[:<port spec>][:ignored state] 


=head1 DESCRIPTION

The ngen utility creates an nmap-style machine-readable results
file for use as a baseline for ndiff comparision.  

=head1 OPTIONS

=over 4

=item -o <filename-or-:tag>

=item -output <filename-or-:tag>

Specifies the output filename, or optionally a data store
tag, if begins with a colon (:).  See L<"DATA STORES"> below
for more information.


=item -p <port list>

=item -ports <port list>


Specifies the set of all ports scanned, comma-separated.  Ranges may be
specified.  For example:

    -p 80,443,6000-6010,22
    -ports 53

By default, tcp is assumed; udp may be specified by appending the "u" flag.
("t" may be specified but is redundant)

    -p 323u,80,6000-6010t

If the B<-p> option is omitted, ngen will grab the set of ports from
/usr/local/lib/nmap/nmap-services and /etc/services.

The default, "Ignored" specified for a given host is applied to all
ports in this list, except for "interesting" ports, which are
specified below with the B<-h> option.

See the description of port specifications with the B<-h> option
below for more information.


=item -h [!]<host ranges>[:<port ranges>][:<ignored state>]

=item -host  [!]<host ranges>[:<port ranges>][:<ignored state>]


Adds a host or range of hosts.  For example

    -h 192.168.2.2                   # one host
    -h 10.0.2.0-64                   # 65 hosts
    -host 192.168.1.0/26             # 64 hosts
    -host 192.168.*.*                # 65536 hosts

  
The above examples add hosts with all ports closed.  To add
ports to the hosts, append a colon and a port spec.  For example
to add localhost with tcp ports 80 and 53 open, ignored state "closed",
the specification would be

    -host 127.0.0.1:80,53

Flags may be appended to change the protocol or state for a given port, for example:

    -host 127.0.0.1:7uf

which adds echo service, udp port 7 filtered state.  


The full list of port flags are as follows:


    t - tcp port  (default)
    u - udp port

    o - port is in open state (default)
    c - port is in closed state 
    f - port is in filtered state
    x - port is in unfiltered state


The ignored state for the host may be specified by appending a colon and 
the state to the host spec.   Acceptable state labels are "open", "closed",
"filtered", and "unfiltered".

  -h 10.0.2.0:80f:closed

which says all scanned ports default to closed state, except for 80/tcp which
is filtered.

A host spec is treated as a negation if it starts with "!".  If ports are specified
as part of the host spec, those ports are deleted from any hosts previously added
which fall in the host range.  

Host specs are applied in order as they appear on the command line, and their
effects are cumulative.

=back

=head1 DATA STORES

Nrun and its related tools can manipulate results in regular nmap-format
files, in any user-specified location, or they can handle storing and organizing
the data on behalf of the user, through a user-configurable "data store".  

Whenever you precede a results tag with a colon (:), the tag will be treated
as a unique key into a data store, identifying the results set.  

Currently the only supported data store is  nmap format files placed
in a preconfigured directory.  Other types may be added at a later date.  

A legal tag may contain any alphanumeric string, plus dash, underscore, and dot.
%-style substitutions in the ilk of the "date" command are also supported,
allowing a tag to contain date, time, or the local hostname.  See L<"SUBSTITUTIONS">
below for more information.

=head1 SUBSTITUTIONS


%-style substitutions supported in tags as follows:

=over 4

=item %H = hour

=item %M = minute

=item %S = second 

=item %D = day of month

=item %m = month of year (01-12)

=item %Y = year, four digits

=item %j = day of year, three digits

=item %w = day of week (0-6) one digit

=back

Except where noted, the above items are two digits, and local time.  All are zero-padded
as appropriate.

In addtion-

=over 4

=item %F = output of "hostname" on the local machine

=back


=head1 BUGS

It is possible to create invalid nmap result files with ngen if you really
try to.
No support for human-readable hostnames and portnames.

=head1 AUTHOR

James Levine <jdl@vinecorp.com>

=cut