This file is indexed.

/usr/share/perl5/INetSim/Finger.pm is in inetsim 1.2.7+dfsg.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
# -*- perl -*-
#
# INetSim::Finger - A fake Finger server
#
# RFC 1288 - Finger User Information Protocol
#
# (c)2007-2010 Matthias Eckert, Thomas Hungenberg
#
# Version 0.16  (2010-04-12)
#
# For history/changelog see bottom of this file.
#
#############################################################

package INetSim::Finger;

use strict;
use warnings;
use base qw(INetSim::GenericServer);


my @DATA;
my $LASTREAD = 0;



sub configure_hook {
    my $self = shift;

    $self->{server}->{host}   = &INetSim::Config::getConfigParameter("Default_BindAddress"); # bind to address
    $self->{server}->{proto}  = 'tcp';                                      # TCP protocol
    $self->{server}->{user}   = &INetSim::Config::getConfigParameter("Default_RunAsUser");       # user to run as
    $self->{server}->{group}  = &INetSim::Config::getConfigParameter("Default_RunAsGroup");    # group to run as
    $self->{server}->{setsid} = 0;                                    # do not daemonize
    $self->{server}->{no_client_stdout} = 1;                          # do not attach client to STDOUT
    $self->{server}->{log_level} = 0;                                 # do not log anything
    $self->{server}->{port}   = &INetSim::Config::getConfigParameter("Finger_BindPort");  # bind to port
    # service name
    $self->{servicename} = &INetSim::Config::getConfigParameter("Finger_ServiceName");
    # timeout
    $self->{timeout} = &INetSim::Config::getConfigParameter("Default_TimeOut");
    # max childs
    $self->{maxchilds} = &INetSim::Config::getConfigParameter("Default_MaxChilds");
}



sub pre_loop_hook {
    my $self = shift;

    $0 = 'inetsim_' . $self->{servicename};
    &INetSim::Log::MainLog("started (PID $$)", $self->{servicename});
}



sub pre_server_close_hook {
    my $self = shift;

    &INetSim::Log::MainLog("stopped (PID $$)", $self->{servicename});
}



sub fatal_hook {
    my $self = shift;

    &INetSim::Log::MainLog("failed!", $self->{servicename});
    exit 0;
}



sub process_request {
    my $self = shift;
    my $client = $self->{server}->{client};
    my $rhost = $self->{server}->{peeraddr};
    my $rport = $self->{server}->{peerport};

    my $stat_success = 0;
    my $query;
    my @token;
    my $username;
    my $lasthop;
    my @dummy;

    if ($self->{server}->{numchilds} >= $self->{maxchilds}) {
	print $client "Maximum number of connections ($self->{maxchilds}) exceeded.\n";
	&INetSim::Log::SubLog("[$rhost:$rport] Connection refused - maximum number of connections ($self->{maxchilds}) exceeded.", $self->{servicename}, $$);
    }
    else {
        eval {
            local $SIG{'ALRM'} = sub { die "TIMEOUT" };
            alarm($self->{timeout});
	    &INetSim::Log::SubLog("[$rhost:$rport] connect", $self->{servicename}, $$);
	    while ($query = <$client>){
	        alarm($self->{timeout});
                if (defined ($query)) {
                    $query =~ s/^[\r\n\s\t]+//g;
                    $query =~ s/[\r\n\s\t]+$//g;
                    # remove '/W' strings
                    $query =~ s/\/W//g;
                    &INetSim::Log::SubLog("[$rhost:$rport] recv: ".$query, $self->{servicename}, $$);
                    &read_data_files(&INetSim::Config::getConfigParameter("Finger_DataDirName"));
                    # restricted charset (my decision)
                    if ($query && $query =~ /([^a-zA-Z0-9\-\_\@\.\s\t])/) {
                        print $client "Your request contains illegal characters.\r\n";
                        &INetSim::Log::SubLog("[$rhost:$rport] send: Your request contains illegal characters.", $self->{servicename}, $$);
                        last;
                    }
                    $query =~ s/[\t\s]+/\ /g;
                    if ($query =~ /^$/) {
                        foreach (@DATA) {
                            if (/^\=\=\=/) {
                                print $client "\r\n";
                                &INetSim::Log::SubLog("[$rhost:$rport] send: ", $self->{servicename}, $$);
                            }
                            else {
                                print $client "$_\r\n";
                                &INetSim::Log::SubLog("[$rhost:$rport] send: $_", $self->{servicename}, $$);
                            }
                        }
                        $stat_success = 1;
                        last;
                    }
                    else {
                        if ($query =~ /^.+$/) {
                            @token = ();
                            @token = split(/\@/, $query);
                            if ($token[0]) {
                                $username = $token[0];
                                $username =~ s/[\s]+//g;
                            }
                            if (@token >= 2) {
                                $lasthop = pop(@token);
                                $lasthop =~ s/[\s]+//g;
                            }
                            if ($username) {
                                @dummy = ();
                                @dummy = &search_name($username);
                                if (@dummy) {
                                    if ($lasthop) {
                                        print $client "[$lasthop]\r\n";
                                        &INetSim::Log::SubLog("[$rhost:$rport] send: [$lasthop]", $self->{servicename}, $$);
                                    }
                                    foreach (@dummy) {
                                        print $client "$_\r\n";
                                        &INetSim::Log::SubLog("[$rhost:$rport] send: $_", $self->{servicename}, $$);
                                    }
                                    $stat_success = 1;
                                    last;
                                }
                                else {
                                    if ($lasthop) {
                                        print $client "[$lasthop]\r\n";
                                        &INetSim::Log::SubLog("[$rhost:$rport] send: [$lasthop]", $self->{servicename}, $$);
                                    }
                                    print $client "finger: $username: no such user.\r\n";
                                    &INetSim::Log::SubLog("[$rhost:$rport] send: finger: $username: no such user.", $self->{servicename}, $$);
                                    last;
                                }
                            }
                            else {
                                if ($lasthop) {
                                    print $client "[$lasthop]\r\n";
                                    &INetSim::Log::SubLog("[$rhost:$rport] send: [$lasthop]", $self->{servicename}, $$);
                                    foreach (@DATA) {
                                        if (/^\=\=\=/) {
                                            print $client "\r\n";
                                            &INetSim::Log::SubLog("[$rhost:$rport] send: ", $self->{servicename}, $$);
                                        }
                                        else {
                                            print $client "$_\r\n";
                                            &INetSim::Log::SubLog("[$rhost:$rport] send: $_", $self->{servicename}, $$);
                                        }
                                    }
                                    $stat_success = 1;
                                    last;
                                }
                                else {
                                    print $client "finger: $query: no such user.\r\n";
                                    &INetSim::Log::SubLog("[$rhost:$rport] send: finger: $query: no such user.", $self->{servicename}, $$);
                                    last;
                                }
                            }
                        }
                        last;
                    }
                    last;
                }
                else {
                    print $client "finger: $query: no such user.\r\n";
                    &INetSim::Log::SubLog("[$rhost:$rport] send: finger: $query: no such user.", $self->{servicename}, $$);
                    last;
                }
                last;
	    }
            alarm(0);
        };
        if ($@ =~ /TIMEOUT/) {
            &INetSim::Log::SubLog("[$rhost:$rport] disconnect (timeout)", $self->{servicename}, $$);
        }
        else {
            &INetSim::Log::SubLog("[$rhost:$rport] disconnect", $self->{servicename}, $$);
        }
    }
    &INetSim::Log::SubLog("[$rhost:$rport] stat: $stat_success", $self->{servicename}, $$);
}



sub search_name {
    my $name = shift;
    my @tmp = ();
    my $match = 0;
    my $count = 0;

    foreach (@DATA) {
        if (/^\=\=\=/) {
            $match = 0;
        }
        if (m/^(Login.*?)(\s($name)\b)/i) {
            if ($count) {
                push (@tmp, "");
            }
            push (@tmp, $_);
            $match = 1;
            $count++;
            next;
        }
        if ($match) {
            push (@tmp, $_);
        }
    }

    return (@tmp);
}



sub datetime {
    my $now = &INetSim::FakeTime::get_faketime();
    my $delta = int(rand(3600) + 1);

    return (localtime ($now - $delta));
}



sub tty {
    my %prefix = ( 0 => "tty", 1 => "pty", 2 => "pts/", 3 => "ttyp");

    return ($prefix{int(rand(3))} . int(rand(6)));
}



sub shell {
    my %prefix = ( 0 => "/bin/sh", 1 => "/bin/bash", 2 => "/bin/zsh", 3 => "/bin/ksh");

    return ($prefix{int(rand(3))});
}



sub read_data_files {
    my $dir = shift;
    my @files;
    my @raw;
    my $content;
    my $time;
    my $tty;
    my $shell;
    my $now = &INetSim::FakeTime::get_faketime();
    my $diff = $now - $LASTREAD;

    if ($diff > 60) {
        if (-d $dir) {
            chomp(@files=<$dir/*.finger>);
            if (@files) {
                foreach (@files) {
                    next if (/^#/);
                    if (open (FH, $_)) {
                        chomp(@raw=<FH>);
                        close FH;
                        foreach (@raw) {
                            next if (/^\#/);
                            s/[\r\n]+$//g;
                            if (/\{DATETIME\}/) {
                                $time = &datetime;
                                s/\{DATETIME\}/$time/g;
                            }
                            if (/\{TTY\}/) {
                                $tty = &tty;
                                s/\{TTY\}/$tty/g;
                            }
                            if (/\{SHELL\}/) {
                                $shell = &shell;
                                s/\{SHELL\}/$shell/g;
                            }
                            push (@DATA, $_);
                        }
                    }
                }
            }
        }
        if (! @DATA) {
            push (@DATA, "Login: devel                            Name: Developer");
            push (@DATA, "Directory: /home/devel                  Shell: /bin/bash");
            push (@DATA, "Never logged in.");
            push (@DATA, "No mail.");
            push (@DATA, "No Plan.");
        }
    }
    $LASTREAD = $now;
}



1;
#############################################################
#
# History:
#
# Version 0.16   (2010-04-12) me
# - do not filter non-printable characters because it's already
#   implemented in the log module
# - some small changes
#
# Version 0.15   (2008-08-27) me
# - added logging of process id
#
# Version 0.14   (2008-03-25) me
# - added timeout after inactivity of n seconds, using new
#   config parameter Default_TimeOut
#
# Version 0.13 (2007-12-31) th
# - change process name
#
# Version 0.12 (2007-12-07) me
# - query charset restricted
# - added a check for 'illegal' chars
# - changed the regex in function 'search_name'
# - removed unused variables
# - removed some typos
#
# Version 0.11 (2007-11-09) me
# - added functions 'datetime', 'tty' and 'shell' for dynamic content
#   generation
# - changed function 'read_data_files' for work with variables in data files
# - added an example data file entry with new variables DATETIME, TTY
#   and SHELL
#
# Version 0.1  (2007-11-07) me
# - initial version with static content
#
#############################################################