| 1 |
#! /usr/bin/env -S perl -wT |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Sys::Syslog(); |
| 6 |
use Fcntl(); |
| 7 |
use FileHandle(); |
| 8 |
use Symbol(); |
| 9 |
use Getopt::Long(); |
| 10 |
use English qw( -no_match_vars ); |
| 11 |
use File::Spec(); |
| 12 |
|
| 13 |
delete $ENV{PATH}; |
| 14 |
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; |
| 15 |
|
| 16 |
my %os_paths = ( |
| 17 |
freebsd => '/usr/local/bin', |
| 18 |
dragonfly => '/usr/local/bin', |
| 19 |
netbsd => '/usr/pkg/bin', |
| 20 |
openbsd => '/usr/local/bin', |
| 21 |
); |
| 22 |
local $ENV{PATH} = '/usr/bin:/bin:/usr/sbin:/sbin' |
| 23 |
. ( |
| 24 |
defined $os_paths{$OSNAME} |
| 25 |
? q[:] . $os_paths{$OSNAME} |
| 26 |
: q[] |
| 27 |
); |
| 28 |
|
| 29 |
our $VERSION = '1.70'; |
| 30 |
|
| 31 |
my $binary = 'firefox'; |
| 32 |
my $ident = 'ssh-auth-cmd-marionette'; |
| 33 |
my %options = ( facility => 'LOG_LOCAL0' ); |
| 34 |
|
| 35 |
sub _origin { |
| 36 |
my ( |
| 37 |
$source_ip_address, $source_port, |
| 38 |
$destination_ip_address, $destination_port |
| 39 |
) = split q[ ], $ENV{SSH_CONNECTION}; |
| 40 |
return $source_ip_address; |
| 41 |
} |
| 42 |
|
| 43 |
sub _tmp_directory_regex { |
| 44 |
my (%parameters) = @_; |
| 45 |
my $regex = qr{(?:/var)?/tmp}smx; |
| 46 |
if ( $OSNAME eq 'darwin' ) { # getconf DARWIN_USER_TEMP_DIR |
| 47 |
my $handle = FileHandle->new(); |
| 48 |
my $command = 'getconf'; |
| 49 |
my @arguments = qw(DARWIN_USER_TEMP_DIR); |
| 50 |
if ( my $pid = $handle->open(q[-|]) ) { |
| 51 |
my $content; |
| 52 |
while ( my $line = <$handle> ) { |
| 53 |
$content .= $line; |
| 54 |
} |
| 55 |
close $handle |
| 56 |
or die "Failed to successfully complete:$EXTENDED_OS_ERROR\n"; |
| 57 |
chomp $content; |
| 58 |
$content =~ s/\/$//smx; # remove trailing / for darwin |
| 59 |
my $quoted_content = quotemeta $content; |
| 60 |
$regex = qr/$quoted_content/smx; |
| 61 |
} |
| 62 |
elsif ( defined $pid ) { |
| 63 |
eval { |
| 64 |
exec {$command} $command, @arguments |
| 65 |
or die "Failed to exec '$command':$EXTENDED_OS_ERROR\n"; |
| 66 |
} or do { |
| 67 |
chomp $EVAL_ERROR; |
| 68 |
Sys::Syslog::openlog( $ident, 'cons', $parameters{facility} ); |
| 69 |
Sys::Syslog::syslog( Sys::Syslog::LOG_ERR(), $EVAL_ERROR ); |
| 70 |
Sys::Syslog::closelog(); |
| 71 |
}; |
| 72 |
exit 1; |
| 73 |
} |
| 74 |
else { |
| 75 |
die "Failed to fork:$EXTENDED_OS_ERROR\n"; |
| 76 |
} |
| 77 |
} |
| 78 |
return $regex; |
| 79 |
} |
| 80 |
|
| 81 |
eval { |
| 82 |
Getopt::Long::GetOptions( |
| 83 |
\%options, 'help', |
| 84 |
'version', 'facility:s', |
| 85 |
'allow-binary:s@', 'force-binary:s', |
| 86 |
'regex-allow-binary-directories:s', 'regex-allow-binary-paths:s', |
| 87 |
'regex-allow-binary:s', 'scp-only', |
| 88 |
); |
| 89 |
if ( $options{help} ) { |
| 90 |
require Pod::Simple::Text; |
| 91 |
my $parser = Pod::Simple::Text->new(); |
| 92 |
$parser->parse_from_file($PROGRAM_NAME); |
| 93 |
exit 0; |
| 94 |
} |
| 95 |
elsif ( $options{version} ) { |
| 96 |
print "$VERSION\n" |
| 97 |
or die "Failed to print to STDOUT:$EXTENDED_OS_ERROR\n"; |
| 98 |
exit 0; |
| 99 |
} |
| 100 |
my $tmp_directory_regex = _tmp_directory_regex(%options); |
| 101 |
my $tmp_directory = $ENV{TMPDIR} || '/tmp'; |
| 102 |
$tmp_directory =~ s/\/$//smx; # remove trailing / for darwin |
| 103 |
my $root_dir_regex; |
| 104 |
my $quoted_tmp_directory = quotemeta $tmp_directory; |
| 105 |
if ( $tmp_directory =~ |
| 106 |
s/^(${tmp_directory_regex}\/firefox_marionette_remote\w+)(?:\/tmp)?$/$1/smx |
| 107 |
) |
| 108 |
{ |
| 109 |
$quoted_tmp_directory = quotemeta $tmp_directory; |
| 110 |
$root_dir_regex = qr/$quoted_tmp_directory/smx; |
| 111 |
} |
| 112 |
else { |
| 113 |
$quoted_tmp_directory = quotemeta $tmp_directory; |
| 114 |
$root_dir_regex = |
| 115 |
qr/${$tmp_directory_regex}\/firefox_marionette_remote\w+/smx; |
| 116 |
} |
| 117 |
%options = _validate_parameters(%options); |
| 118 |
my ( $allowed_binary_directories_regex, |
| 119 |
$allowed_binary_paths_regex, $allowed_binary_regex ) |
| 120 |
= _filesystem_regexes(%options); |
| 121 |
my $sub_directory_regex = qr/(?:profile|downloads|tmp|addons|certs)/smx; |
| 122 |
my $profile_names = q[(?:] . ( |
| 123 |
join q[|], |
| 124 |
map { quotemeta } ( |
| 125 |
qw( |
| 126 |
bookmarks.html |
| 127 |
prefs.js |
| 128 |
mimeTypes.rdf |
| 129 |
search.json.mozlz4 |
| 130 |
) |
| 131 |
) |
| 132 |
) . q[)]; |
| 133 |
my $profile_file_regex = qr/profile\/$profile_names/smx; |
| 134 |
my $file_regex = qr/[+\w\-()]{1,255}(?:[.][+\w\-()]{1,255})*/smx; |
| 135 |
my $downloads_regex = qr/downloads\/$file_regex/smx; |
| 136 |
my $addons_regex = qr/(?:addons|profile)\/$file_regex/smx; |
| 137 |
my $ca_name_regex = qr/Firefox::Marionette[ ]Root[ ]CA/smx; |
| 138 |
my $version_updates_regex = q[(?:] |
| 139 |
. ( |
| 140 |
join q[|], qr/active\-update[.]xml/smx, qr/application[.]ini/smx, |
| 141 |
qr/updates\/\d+\/update[.]status/smx |
| 142 |
) . q[)]; |
| 143 |
my $xvfb_regex = |
| 144 |
qr/xvfb\-run[ ]\-a[ ]\-s[ ]"-screen[ ]0[ ]\d+x\d+x\d+"[ ]/smx; |
| 145 |
my $certutil_arguments_regex = join q[], |
| 146 |
qr/[ ]\-A/smx, |
| 147 |
qr/[ ]\-d[ ](?:dbm|sql):$root_dir_regex\/profile/smx, |
| 148 |
qr/[ ]\-i[ ]$root_dir_regex\/certs\/root_ca_\d{1,10}[.]cer/smx, |
| 149 |
qr/[ ]\-n[ ]$ca_name_regex[ ]\d{1,10}[ ]\-t[ ]TC,,/smx; |
| 150 |
my $firefox_arguments_regex = join q[], |
| 151 |
qr/[ ]\-marionette/smx, |
| 152 |
qr/(?:[ ]\-remote\-allow\-system\-access)?/smx, |
| 153 |
qr/(?:[ ]\-width[ ]\d{1,8})?/smx, |
| 154 |
qr/(?:[ ]\-height[ ]\d{1,8})?/smx, |
| 155 |
qr/(?:[ ]\-\-jsconsole)?/smx, |
| 156 |
qr/(?:[ ]\-MOZ_LOG=[[:alnum:],:]+)?/smx, |
| 157 |
qr/(?:[ ]-safe\-mode)?/smx, |
| 158 |
qr/(?:[ ]\-headless)?/smx, |
| 159 |
qr/[ ](?:\-profile[ ]$root_dir_regex\/profile|\-P[ ][[:alnum:]]+)/smx, |
| 160 |
qr/(?:[ ]\-\-no\-remote)?/smx, |
| 161 |
qr/(?:[ ]\-\-new\-instance)?/smx, |
| 162 |
qr/(?:[ ]\-\-devtools)?/smx, |
| 163 |
qr/(?:[ ]\-\-kiosk)?/smx; |
| 164 |
my $prefs_grep_patterns_regex = join q[], |
| 165 |
qr/\-e[ ]marionette[ ]/smx, |
| 166 |
qr/\-e[ ]security[ ]/smx; |
| 167 |
my @darwin_regexes; |
| 168 |
|
| 169 |
if ( $OSNAME eq 'darwin' ) { |
| 170 |
my $plist_prefix_regex = |
| 171 |
_get_plist_prefix_regex( @{ $options{'allow-binary'} } ); |
| 172 |
@darwin_regexes = ( |
| 173 |
qr/ls[ ]-1[ ]"$allowed_binary_regex"/smx, |
| 174 |
qr/plutil[ ]-convert[ ]json[ ]-o[ ]-[ ]"(?:$plist_prefix_regex)\/Info[.]plist"/smx, |
| 175 |
); |
| 176 |
} |
| 177 |
|
| 178 |
my @sftp_server_regexs; |
| 179 |
if ( !$options{'scp-only'} ) { |
| 180 |
@sftp_server_regexs = ( |
| 181 |
map { qr/${_}[ ]?/smx } |
| 182 |
( # Adding a space for new sftp-server in Fedora 40 (openssh-9.6p1) |
| 183 |
quotemeta '/usr/libexec/openssh/sftp-server', # Redhat, Debian |
| 184 |
quotemeta '/usr/libexec/sftp-server', # FreeBSD |
| 185 |
) |
| 186 |
); |
| 187 |
} |
| 188 |
my $darwin_profile_regex = |
| 189 |
qr/Library\/Application\\[ ]Support\/Firefox\/Profiles/smx; |
| 190 |
my $named_profile_regex = |
| 191 |
qr/(?:[.]mozilla\/firefox|$darwin_profile_regex)/smx; |
| 192 |
my $profile_path_regex = |
| 193 |
qr/(?:$root_dir_regex\/profile|$named_profile_regex\/[[:alnum:].\-]+)/smx; |
| 194 |
my $scp_parameters_regex = |
| 195 |
qr/(?:[ ]\-v)?[ ]\-p[ ]\-[tf][ ](?:-P[ ]\d{2}[ ])?(?:\-v[ ])?/smx; |
| 196 |
my $quoted_linux_profiles_ini = quotemeta q[.mozilla/firefox]; |
| 197 |
my $quoted_darwin_profiles_ini = |
| 198 |
quotemeta q[Library/Application Support/Firefox]; |
| 199 |
my $profiles_ini_regex = |
| 200 |
qr/(?:$quoted_linux_profiles_ini|$quoted_darwin_profiles_ini)\/profiles[.]ini/smx; |
| 201 |
my $allowed_commands_regex = join q[|], |
| 202 |
qr/"$allowed_binary_regex"[ ]\-\-version/smx, |
| 203 |
@darwin_regexes, |
| 204 |
@sftp_server_regexs, |
| 205 |
qr/uname[ ][|][|][ ]ver/smx, |
| 206 |
qr/echo[ ]"TMPDIR=\\"\$TMPDIR\\""/smx, |
| 207 |
qr/echo[ ]"DISPLAY=\\"\$DISPLAY\\""/smx, |
| 208 |
qr/echo[ ]"TMP=\\"\$TMP\\""/smx, |
| 209 |
qr/mkdir[ ](?:\-m[ ]700[ ])?$root_dir_regex/smx, |
| 210 |
qr/mkdir[ ](?:\-m[ ]700[ ])?$root_dir_regex\/$sub_directory_regex/smx, |
| 211 |
qr/scp$scp_parameters_regex"?$root_dir_regex\/$profile_file_regex"?/smx, |
| 212 |
qr/scp(?:[ ]\-v)?[ ]\-p[ ]\-t[ ]"?$root_dir_regex\/$addons_regex"?/smx, |
| 213 |
qr/scp[ ]\-p[ ]\-t[ ]$root_dir_regex\/certs\/root_ca_\d{1,10}[.]cer/smx, |
| 214 |
qr/scp[ ]\-p[ ]\-[fT][ ](?:\-P[ ])?$allowed_binary_directories_regex\/$version_updates_regex/smx, |
| 215 |
qr/scp(?:[ ]\-v)?[ ]\-p[ ]\-[tf][ ]"?$root_dir_regex\/$downloads_regex"?/smx, |
| 216 |
qr/scp[ ]\-p[ ]\-[tf][ ]"?$profiles_ini_regex"?/smx, |
| 217 |
qr/kill[ ]\-0[ ]\d{1,8}/smx, |
| 218 |
qr/which[ ]$allowed_binary_regex/smx, |
| 219 |
qr/readlink[ ]\-f[ ]$allowed_binary_paths_regex/smx, |
| 220 |
qr/rm[ ]\-Rf[ ]$root_dir_regex(?:[ ]$quoted_tmp_directory\/Temp\-[\d\-a-f]{1,255})*/smx, |
| 221 |
qr/ls[ ]-1[ ]"$allowed_binary_directories_regex(?:\/updates(?:\/\d+)?)?"/smx, |
| 222 |
qr/ls[ ]-1[ ]"$root_dir_regex\/downloads"/smx, |
| 223 |
qr/certutil$certutil_arguments_regex/smx, |
| 224 |
qr/(?:$xvfb_regex)?"$allowed_binary_regex"$firefox_arguments_regex/smx, |
| 225 |
qr/grep[ ]$prefs_grep_patterns_regex$profile_path_regex\/prefs[.]js/smx; |
| 226 |
|
| 227 |
my $user_name = getpwuid $EFFECTIVE_USER_ID; |
| 228 |
if ( $ENV{SSH_ORIGINAL_COMMAND} =~ m/^($allowed_commands_regex)$/smx ) { |
| 229 |
my ($command_and_arguments) = ($1); |
| 230 |
if ( $options{'force-binary'} ) { |
| 231 |
$command_and_arguments =~ |
| 232 |
s/^"$allowed_binary_regex"/"$options{'force-binary'}"/smx; |
| 233 |
} |
| 234 |
Sys::Syslog::openlog( $ident, 'cons', $options{facility} ); |
| 235 |
Sys::Syslog::syslog( Sys::Syslog::LOG_INFO(), |
| 236 |
"Executing '$command_and_arguments' as '$user_name' from " |
| 237 |
. _origin() ); |
| 238 |
Sys::Syslog::closelog(); |
| 239 |
exec $command_and_arguments |
| 240 |
or die "Failed to '$command_and_arguments':$EXTENDED_OS_ERROR\n"; |
| 241 |
} |
| 242 |
else { |
| 243 |
my $origin = _origin(); |
| 244 |
Sys::Syslog::openlog( $ident, 'cons', $options{facility} ); |
| 245 |
Sys::Syslog::syslog( Sys::Syslog::LOG_WARNING(), |
| 246 |
'Unrecognisable command "' |
| 247 |
. $ENV{SSH_ORIGINAL_COMMAND} |
| 248 |
. "\" as '$user_name' from $origin with a quoted TMPDIR of \"$quoted_tmp_directory\" and a root directory regex of \"$root_dir_regex\"" |
| 249 |
); |
| 250 |
Sys::Syslog::closelog(); |
| 251 |
} |
| 252 |
1; |
| 253 |
} or do { |
| 254 |
my $eval_error = $EVAL_ERROR; |
| 255 |
chomp $eval_error; |
| 256 |
Sys::Syslog::openlog( $ident, 'cons', $options{facility} ); |
| 257 |
Sys::Syslog::syslog( Sys::Syslog::LOG_ERR(), $eval_error ); |
| 258 |
Sys::Syslog::closelog(); |
| 259 |
}; |
| 260 |
exit 1; |
| 261 |
|
| 262 |
sub _validate_parameters { |
| 263 |
my (%parameters) = @_; |
| 264 |
my $facility = $parameters{facility}; |
| 265 |
eval { $parameters{facility} = Sys::Syslog->$facility(); } or do { |
| 266 |
my $original = $parameters{facility}; |
| 267 |
$parameters{facility} = Sys::Syslog::LOG_LOCAL0(); |
| 268 |
Sys::Syslog::openlog( $ident, 'cons', $parameters{facility} ); |
| 269 |
Sys::Syslog::syslog( Sys::Syslog::LOG_WARNING(), |
| 270 |
"Failed to parse --facility argument of '$original':$EVAL_ERROR" ); |
| 271 |
Sys::Syslog::closelog(); |
| 272 |
}; |
| 273 |
if ( !defined $ENV{SSH_ORIGINAL_COMMAND} ) { |
| 274 |
die |
| 275 |
"$PROGRAM_NAME requires the SSH_ORIGINAL_COMMAND environment variable to be defined\n"; |
| 276 |
} |
| 277 |
if ( !defined $parameters{'allow-binary'} ) { |
| 278 |
$parameters{'allow-binary'} = ['firefox']; |
| 279 |
if ( $OSNAME eq 'darwin' ) { |
| 280 |
push @{ $parameters{'allow-binary'} }, |
| 281 |
'/Applications/Firefox.app/Contents/MacOS/firefox', |
| 282 |
'/Applications/Firefox Developer Edition.app/Contents/MacOS/firefox', |
| 283 |
'/Applications/Firefox Nightly.app/Contents/MacOS/firefox', |
| 284 |
'/Applications/Waterfox Current.app/Contents/MacOS/waterfox'; |
| 285 |
} |
| 286 |
} |
| 287 |
if ( ( defined $parameters{'force-binary'} ) |
| 288 |
&& ( $parameters{'force-binary'} =~ /^(.*)$/smx ) ) |
| 289 |
{ |
| 290 |
my ($untainted) = ($1); |
| 291 |
$parameters{'force-binary'} = |
| 292 |
$untainted; # passed in on the command line from .authorized_keys file |
| 293 |
Sys::Syslog::openlog( $ident, 'cons', $parameters{facility} ); |
| 294 |
Sys::Syslog::syslog( Sys::Syslog::LOG_DEBUG(), |
| 295 |
"Untainting --force-binary of '$parameters{'force-binary'}'" ); |
| 296 |
Sys::Syslog::closelog(); |
| 297 |
} |
| 298 |
return %parameters; |
| 299 |
} |
| 300 |
|
| 301 |
sub _filesystem_regexes { |
| 302 |
my (%parameters) = @_; |
| 303 |
if ( ( $parameters{'regex-allow-binary-directories'} ) |
| 304 |
&& ( $parameters{'regex-allow-binary-paths'} ) |
| 305 |
&& ( $parameters{'regex-allow-binary'} ) ) |
| 306 |
{ |
| 307 |
my $allowed_binary_directories_regex; |
| 308 |
if ( $parameters{'regex-allow-binary-directories'} =~ /^(.*)$/smx ) { |
| 309 |
($allowed_binary_directories_regex) = ($1); # untaint |
| 310 |
} |
| 311 |
my $allowed_binary_paths_regex; |
| 312 |
if ( $parameters{'regex-allow-binary-paths'} =~ /^(.*)$/smx ) { |
| 313 |
($allowed_binary_paths_regex) = ($1); # untaint |
| 314 |
} |
| 315 |
my $allowed_binary_regex; |
| 316 |
if ( $parameters{'regex-allow-binary'} =~ /^(.*)$/smx ) { |
| 317 |
($allowed_binary_regex) = ($1); # untaint |
| 318 |
} |
| 319 |
return ( $allowed_binary_directories_regex, |
| 320 |
$allowed_binary_paths_regex, $allowed_binary_regex ); |
| 321 |
} |
| 322 |
if ( $parameters{'regex-allow-binary-directories'} ) { |
| 323 |
Sys::Syslog::openlog( $ident, 'cons', $parameters{facility} ); |
| 324 |
Sys::Syslog::syslog( Sys::Syslog::LOG_WARNING(), |
| 325 |
'Ignoring --regex-allow-binary-directories parameter. --regex-allow-binary-directories must be combined with --regex-allow-binary-paths and --regex-allow-binary' |
| 326 |
); |
| 327 |
Sys::Syslog::closelog(); |
| 328 |
} |
| 329 |
if ( $parameters{'regex-allow-binary-paths'} ) { |
| 330 |
Sys::Syslog::openlog( $ident, 'cons', $parameters{facility} ); |
| 331 |
Sys::Syslog::syslog( Sys::Syslog::LOG_WARNING(), |
| 332 |
'Ignoring --regex-allow-binary-paths parameter. --regex-allow-binary-paths must be combined with --regex-allow-binary-directories and --regex-allow-binary' |
| 333 |
); |
| 334 |
Sys::Syslog::closelog(); |
| 335 |
} |
| 336 |
if ( $parameters{'regex-allow-binary'} ) { |
| 337 |
Sys::Syslog::openlog( $ident, 'cons', $parameters{facility} ); |
| 338 |
Sys::Syslog::syslog( Sys::Syslog::LOG_WARNING(), |
| 339 |
'Ignoring --regex-allow-binary parameter. --regex-allow-binary must be combined with --regex-allow-binary-directories and --regex-allow-binary-paths' |
| 340 |
); |
| 341 |
Sys::Syslog::closelog(); |
| 342 |
} |
| 343 |
my @allowed_binaries; |
| 344 |
my @allowed_binary_paths; |
| 345 |
my @allowed_binary_directories; |
| 346 |
foreach my $binary ( @{ $parameters{'allow-binary'} } ) { |
| 347 |
if ( $binary eq 'firefox' ) { |
| 348 |
push @allowed_binaries, 'firefox'; |
| 349 |
push @allowed_binary_paths, '/usr/bin/firefox'; |
| 350 |
push @allowed_binary_directories, '/usr/bin'; |
| 351 |
my %os_allowed_binary_paths = ( |
| 352 |
freebsd => '/usr/local/bin/firefox', |
| 353 |
dragonfly => '/usr/local/bin/firefox', |
| 354 |
netbsd => '/usr/pkg/bin/firefox', |
| 355 |
openbsd => '/usr/local/bin/firefox', |
| 356 |
); |
| 357 |
if ( $os_allowed_binary_paths{$OSNAME} ) { |
| 358 |
push @allowed_binary_paths, $os_allowed_binary_paths{$OSNAME}; |
| 359 |
} |
| 360 |
my %os_allowed_binary_directories = ( |
| 361 |
freebsd => '/usr/local/lib/firefox', |
| 362 |
dragonfly => '/usr/local/lib/firefox', |
| 363 |
netbsd => '/usr/pkg/bin', |
| 364 |
openbsd => '/usr/local/lib/firefox', |
| 365 |
); |
| 366 |
if ( $os_allowed_binary_directories{$OSNAME} ) { |
| 367 |
push @allowed_binary_directories, |
| 368 |
$os_allowed_binary_directories{$OSNAME}; |
| 369 |
} |
| 370 |
} |
| 371 |
else { |
| 372 |
push @allowed_binaries, $binary; |
| 373 |
push @allowed_binary_paths, $binary; |
| 374 |
my ( $volume, $directories ) = File::Spec->splitpath($binary); |
| 375 |
push @allowed_binary_directories, |
| 376 |
File::Spec->catdir( $volume, $directories ); |
| 377 |
if ( $OSNAME eq 'darwin' ) { |
| 378 |
$directories =~ s{/Contents/MacOS/$}{/Contents/Resources/}smx; |
| 379 |
push @allowed_binary_directories, |
| 380 |
File::Spec->catdir( $volume, $directories ); |
| 381 |
} |
| 382 |
} |
| 383 |
} |
| 384 |
my $allowed_binaries = |
| 385 |
q[(?:] . ( join q[|], map { quotemeta } @allowed_binaries ) . q[)]; |
| 386 |
my $allowed_binary_paths = |
| 387 |
q[(?:] . ( join q[|], map { quotemeta } @allowed_binary_paths ) . q[)]; |
| 388 |
my $allowed_binary_directories = q[(?:] |
| 389 |
. ( join q[|], map { quotemeta } @allowed_binary_directories ) . q[)]; |
| 390 |
my $allowed_binary_directories_regex = qr/$allowed_binary_directories/smx; |
| 391 |
my $allowed_binary_paths_regex = qr/$allowed_binary_paths/smx; |
| 392 |
my $allowed_binary_regex = qr/$allowed_binaries/smx; |
| 393 |
return ( $allowed_binary_directories_regex, |
| 394 |
$allowed_binary_paths_regex, $allowed_binary_regex ); |
| 395 |
} |
| 396 |
|
| 397 |
sub _get_plist_prefix_regex { |
| 398 |
my (@allow_binaries) = @_; |
| 399 |
my %allowed_plist_prefixes; |
| 400 |
foreach my $binary (@allow_binaries) { |
| 401 |
my $prefix = $binary; |
| 402 |
if ( $prefix =~ s/Contents\/MacOS\/(?:water|fire)fox$/Contents/smx ) { |
| 403 |
$allowed_plist_prefixes{$prefix} = 1; |
| 404 |
} |
| 405 |
} |
| 406 |
my $regex = join q[|], |
| 407 |
map { quotemeta } sort { $a cmp $b } keys %allowed_plist_prefixes; |
| 408 |
return $regex; |
| 409 |
} |
| 410 |
|
| 411 |
__END__ |
| 412 |
=head1 NAME |
| 413 |
|
| 414 |
ssh-auth-cmd-marionette - ssh ~/.ssh/authorized_keys command for Firefox::Marionette |
| 415 |
|
| 416 |
=head1 VERSION |
| 417 |
|
| 418 |
Version 1.70 |
| 419 |
|
| 420 |
=head1 USAGE |
| 421 |
|
| 422 |
~/.ssh/authorized_keys entry to allow the remote user to run a default firefox as user@server (all syslog entries go to LOG_LOCAL0) |
| 423 |
|
| 424 |
no-agent-forwarding,no-pty,no-X11-forwarding,permitopen="127.0.0.1:*",command="/usr/local/bin/ssh-auth-cmd-marionette" ssh-rsa AAAA ... == user@server |
| 425 |
|
| 426 |
~/.ssh/authorized_keys entry to allow the remote user to run a default firefox as user@server (all syslog entries go to LOG_LOCAL1) |
| 427 |
|
| 428 |
no-agent-forwarding,no-pty,no-X11-forwarding,permitopen="127.0.0.1:*",command="/usr/local/bin/ssh-auth-cmd-marionette --facility=LOG_LOCAL1" ssh-rsa AAAA ... == user@server |
| 429 |
|
| 430 |
~/.ssh/authorized_keys entry to force the remote user to run /path/to/firefox when logging in as user@server (all syslog entries go to LOG_LOCAL0) |
| 431 |
|
| 432 |
no-agent-forwarding,no-pty,no-X11-forwarding,permitopen="127.0.0.1:*",command="/usr/local/bin/ssh-auth-cmd-marionette --force-binary=/path/to/firefox" ssh-rsa AAAA ... == user@server |
| 433 |
|
| 434 |
~/.ssh/authorized_keys entry to allow the remote user to run /path/to/firefox or /path/to/waterfox when logging in as user@server (all syslog entries go to LOG_LOCAL0) |
| 435 |
|
| 436 |
no-agent-forwarding,no-pty,no-X11-forwarding,permitopen="127.0.0.1:*",command="/usr/local/bin/ssh-auth-cmd-marionette --allow-binary=/path/to/firefox --allow-binary=/path/to/waterfox" ssh-rsa AAAA ... == user@server |
| 437 |
|
| 438 |
=head1 DESCRIPTION |
| 439 |
|
| 440 |
This program is intended to allow secure remote usage of the perl Firefox::Marionette library via ssh. It allows a list |
| 441 |
of pre-defined commands that can be permitted via ssh public key authentication. |
| 442 |
|
| 443 |
Be default, it will log all commands that the remote perl library requests to run on this machine to the LOG_LOCAL0 syslog |
| 444 |
facility. If desired, syslog messages can be sent to a facility of your choosing, using the syslog(3) documentation for |
| 445 |
a list of allowed facilities and the --facility argument for this program. |
| 446 |
|
| 447 |
An example .ssh/authorized_keys file using this program would look like this |
| 448 |
|
| 449 |
no-agent-forwarding,no-pty,no-X11-forwarding,permitopen="127.0.0.1:*",command="/usr/local/bin/ssh-auth-cmd-marionette" ssh-rsa AAAA ... == user@server |
| 450 |
|
| 451 |
By default, the only firefox version that may be used will be present in the PATH environment variable. However, the remote user may be permitted to specify the |
| 452 |
path to a different firefox binary with (multiple) --allow-binary parameters, or simply forced to use the firefox that the local user is setup for with the |
| 453 |
--force-binary parameter. |
| 454 |
|
| 455 |
=head1 REQUIRED ARGUMENTS |
| 456 |
|
| 457 |
None |
| 458 |
|
| 459 |
=head1 OPTIONS |
| 460 |
|
| 461 |
Option names can be abbreviated to uniqueness and can be stated with singe or double dashes, and option values can be separated from the option name by a space or '=' (as with Getopt::Long). Option names are also case- |
| 462 |
sensitive. |
| 463 |
|
| 464 |
=over 4 |
| 465 |
|
| 466 |
=item * --help - This page. |
| 467 |
|
| 468 |
=item * --version - print the version of ssh-auth-cmd-marionette. |
| 469 |
|
| 470 |
=item * --facility - use L<facility|https://metacpan.org/pod/Sys::Syslog#Facilities> for L<syslog|https://linux.die.net/man/3/syslog> messages, instead of the default LOG_LOCAL0. |
| 471 |
|
| 472 |
=item * --allow-binary - allow this path to be used in calls to L<new|Firefox::Marionette#new>. This option may be specified multiple times |
| 473 |
|
| 474 |
=item * --force-binary - regardless of the settings that L<new()|Firefox::Marionette#new> requests, send all requests for the firefox binary to the path requested. |
| 475 |
|
| 476 |
=item * --scp-only - do not allow use of the SFTP protocol. See the scp parameter in the L<new()|Firefox::Marionette#new> method. |
| 477 |
|
| 478 |
=back |
| 479 |
|
| 480 |
=head1 CONFIGURATION |
| 481 |
|
| 482 |
ssh-auth-cmd-marionette requires no configuration files or environment variables. |
| 483 |
|
| 484 |
=head1 DEPENDENCIES |
| 485 |
|
| 486 |
ssh-auth-cmd-marionette requires the following non-core Perl modules |
| 487 |
|
| 488 |
=over |
| 489 |
|
| 490 |
=item * |
| 491 |
L<Pod::Simple::Text|Pod::Simple::Text> |
| 492 |
|
| 493 |
=back |
| 494 |
|
| 495 |
=head1 DIAGNOSTICS |
| 496 |
|
| 497 |
Check syslog for any errors |
| 498 |
|
| 499 |
The following command will show syslog on OS X. |
| 500 |
|
| 501 |
C<log show --info --predicate 'process=="perl5.18"' --last 10m> |
| 502 |
|
| 503 |
=head1 INCOMPATIBILITIES |
| 504 |
|
| 505 |
This program depends on L<exec|https://linux.die.net/man/3/exec> and hence will not work in a Windows environment. Always interested in any ssh incompatibilities. Patches welcome. |
| 506 |
|
| 507 |
=head1 EXIT STATUS |
| 508 |
|
| 509 |
This program will either L<exec|https://linux.die.net/man/3/exec> a permitted program or exit with a 1. |
| 510 |
|
| 511 |
=head1 BUGS AND LIMITATIONS |
| 512 |
|
| 513 |
To report a bug, or view the current list of bugs, please visit L<https://github.com/david-dick/firefox-marionette/issues> |
| 514 |
|
| 515 |
=head1 AUTHOR |
| 516 |
|
| 517 |
David Dick C<< <[email protected]> >> |
| 518 |
|
| 519 |
=head1 LICENSE AND COPYRIGHT |
| 520 |
|
| 521 |
Copyright (c) 2024, David Dick C<< <[email protected]> >>. All rights reserved. |
| 522 |
|
| 523 |
This module is free software; you can redistribute it and/or |
| 524 |
modify it under the same terms as Perl itself. See L<perlartistic/perlartistic>. |
| 525 |
|
| 526 |
=head1 DISCLAIMER OF WARRANTY |
| 527 |
|
| 528 |
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
| 529 |
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
| 530 |
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
| 531 |
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER |
| 532 |
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 533 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE |
| 534 |
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH |
| 535 |
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL |
| 536 |
NECESSARY SERVICING, REPAIR, OR CORRECTION. |
| 537 |
|
| 538 |
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
| 539 |
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
| 540 |
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE |
| 541 |
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, |
| 542 |
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE |
| 543 |
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
| 544 |
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
| 545 |
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
| 546 |
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
| 547 |
SUCH DAMAGES. |