This file is indexed.

/usr/share/fex/cgi-bin/sex is in fex 20160104-1.

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

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
#!/usr/bin/perl -wT

# CGI for stream exchange
#
# Author: Ulli Horlacher <framstag@rus.uni-stuttgart.de>

use Fcntl 	qw':flock :seek :mode';
use POSIX	qw'mkfifo';
use Digest::MD5 qw'md5_hex';

# add fex lib
(our $FEXLIB) = $ENV{FEXLIB} =~ /(.+)/;
die "$0: no $FEXLIB\n" unless -d $FEXLIB;

$| = 1;

# import from fex.pp
our ($tmpdir,@logdir,$timeout,$fra,$bs);

# load common code, local config: $HOME/lib/fex.ph
require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";

chdir $spooldir or error(500,"$spooldir - $!");

# my $debuglog = "$tmpdir/sex.log";
my $ra = $ENV{REMOTE_ADDR}||0;
$fra .= '/'.$ENV{HTTP_X_FORWARDED_FOR} if $ENV{HTTP_X_FORWARDED_FOR};
$timeout *= 10;

# normal / public :
# in normal mode the recipient needs authentification, not the sender
# in public mode the sender needs authentification, not the recipient

$user = $id = $pmode = $type = '';
$stream = 'STDSTR';
$mode = $ENV{REQUEST_METHOD} eq 'POST' ? 'PUSH' : 'POP';

# parse HTTP QUERY_STRING
if (my $qs = $ENV{QUERY_STRING}) {
  $qs = decode_b64($qs) if $qs =~ /^\w+=*$/;
  foreach (split '&',$qs) { setparam(split '=',"$_=") };
}

unless ($user) { error(400,"Missing user") }
if ($mdomain and $user !~ /@/) { $user .= '@'.$mdomain }
if ($user =~ /^anonymous/) {
  if (@anonymous_upload and ipin($ra,@anonymous_upload)) {
    mkdirp($user);
  } else {
    error(403,"Forbidden");
  }
} else {
  unless (-f "$user/@") { error(404,"Unknown user $user") }
}
chdir $user or error(500,"$user - $!");

$stream = "STREAM/$stream";

if ($mode eq 'PUSH') {
  if ($pmode eq 'PUBLIC') {
    &authentificate;
    $stream =~ s:/STDSTR:/PUBLIC:;
  }
  mkdirp($stream);
  my $fifo = "$stream/fifo";
  unless (-p $fifo) {
    mkfifo($fifo,0600) or error(503,"Cannot create $fifo : $!");
  }

  sexlog($mode);

  my $lock = "$stream/lock";
  open $lock,'>>',$lock or error(503,"Cannot open $lock : $!");
  flock $lock,LOCK_EX|LOCK_NB or error(409,"$stream already in use");

  chmod 0600,$fifo;
  unlink "$stream/mode";
  unlink "$stream/type";
  symlink $pmode,"$stream/mode" if $pmode;
  symlink $type, "$stream/type" if $type;

  $SIG{PIPE} = sub {
    sleep 1;
    rmrf($stream);
    exit;
  };
  $SIG{ALRM} = sub {
    syswrite STDOUT,".";
    exit if $!;
    $ALARM = 1;
  };
  syswrite STDOUT,"HTTP/1.9 199 Hold on";
  for (my $i=0;$i<$timeout;$i++) {
    alarm(1);
    $ALARM = 0;
    # will hang until $stream is opend for reading by another process
    open $fifo,'>',$fifo and last;
    unless ($ALARM) { error(503,"Cannot open $fifo : $!") }
  }
  alarm(0);
  syswrite STDOUT,"\r\n";

  unless (fileno $fifo) {
    rmrf($stream);
    error(504,"Timeout");
  }

  header('200 OK');

  $B = 0;
  $shutdown = sub { sexlog($B); rmrf($stream); exit; };
  $SIG{PIPE} = sub { sleep 1; &$shutdown; };
  # syswrite $fifo,$data if $data;
  while ($b = sysread(STDIN,$_,$bs)) {
    $B += $b;
    syswrite $fifo,$_ or die $!;
  }

  &$shutdown;
}
elsif ($mode eq 'POP') {
  $stream =~ s:/STDSTR:/PUBLIC: if $id eq 'public';
  unless ($id eq 'public' and (readlink "$stream/mode"||'') eq 'PUBLIC'
          or $user =~ /^anonymous/) {
    &authentificate;
  }
  error(503,"No $stream for $user") unless -d $stream;
  $type = readlink "$stream/type" || '';
  $SIG{ALRM} = sub { error(504,"Timeout") };
  alarm($timeout);
  my $fifo = "$stream/fifo";
  if (-e $fifo and not -r $fifo) { error(503,"$stream already in use") }
  open $fifo,'<',$fifo or error(503,"Cannot open $fifo : $!");
  chmod 0,$fifo;
  alarm(0);
  header('200 OK',$type);
  sexlog($mode);

  while (sysread($fifo,$_,$bs)) {
    syswrite STDOUT,$_ or die $!;
  }
  exit;

}
else {
  error(405,"Unknown Request");
}

exit;


sub setparam {
  my ($v,$vv) = @_;

  $v = uc(despace($v));
  $vv = untaint(normalize($vv));
  # $param{$v} = $vv;
  if    ($v eq 'USER') { $user	= lc(despace($vv)) }
  elsif ($v eq 'ID') { $id = despace($vv) }
  elsif ($v eq 'MODE') { $pmode = uc(despace($vv)) }
  elsif ($v eq 'TYPE') { $type = uc(despace($vv)) }
  elsif ($v eq 'STREAM') { $stream = normalize_filename($vv) }
  elsif ($v eq 'BS' and $vv =~ /(\d+)/) { $bs = $1 }
  elsif ($v eq 'TIMEOUT' and $vv =~ /(\d+)/) { $timeout	= $1 }
  elsif ($v eq 'ANONYMOUS') { $id = $user ='anonymous'; $stream = $vv; }
}

sub sexlog {
  my $msg = "@_";

  $msg =~ s/\n/ /g;
  $msg =~ s/\s+$//;
  $msg = sprintf "%s [%s_%s] %s (%s) %s\n",
                  isodate(time),$$,$ENV{REQUESTCOUNT},$user,$fra,$msg;

  foreach my $log (@logdir) {
    if (open $log,'>>',"$log/sex.log") {
      flock $log,LOCK_EX;
      seek $log,0,SEEK_END;
      printf {$log} $msg;
      close $log;
    }
  }
}

sub sigdie {
  local $_ = shift;
  chomp;
  sigexit('DIE',$_);
}

sub sigexit {
  my ($sig) = @_;
  my $msg = "@_";

  $msg =~ s/\n/ /g;
  $msg =~ s/\s+$//;
  $msg = sprintf "%s %s (%s) caught SIGNAL %s\n",
                 isodate(time),$user||'-',$fra||'-',$msg;

  foreach my $log (@logdir) {
    if (open $log,'>>',"$log/sex.log") {
      flock $log,LOCK_EX;
      seek $log,0,SEEK_END;
      printf {$log} $msg;
      close $log;
    }
  }
  if ($sig eq 'DIE') {
    shift;
    die "@_\n";
  } else {
    die "SIGNAL @_\n";
  }
}

sub error {
  nvt_print("HTTP/1.1 @_");
  exit;
}

sub header {
  my ($status,$type) = @_;

  return if $HTTP_HEADER;
  $HTTP_HEADER = $status;

  nvt_print("HTTP/1.1 $status");
  if ($mode eq 'POP') {
    nvt_print("Server: sexsrv");
    if ($type eq 'GZIP') {
      nvt_print("Content-Type: application/gzip");
    } else {
      nvt_print("Content-Type: application/binary");
    }
    nvt_print("Expires: 0");
    nvt_print("Cache-Control: no-cache");
    nvt_print("Connection: close");
  }
  nvt_print("");
}

sub authentificate {
  my $rid;

  error(400,"Missing auth-ID") unless $id;
  open $id,'<','@' or error(401,"$user/@ - $!");
  chomp($rid = <$id>||'');
  close $id;
  if ($rid and $sid and $id =~ /^(MD5H:)/) {
    $rid = $1 . md5_hex($rid.$sid);
  }
  error(401,"Wrong auth-ID") if $rid ne $id;
}