Имя каталога помещается там, где стоят фигурные скобки, и затем подчиняется оболочке; рассмотрим mkdir '$(reboot)'
, где find
найдет его. Затем вы заканчиваете выполнением sh
:cd $(reboot)
--или любой другой команды, которую вы хотели бы представить. Команда cd
, вероятно, потерпит неудачу, если злоумышленник не будет чрезвычайно хитрым и повторит там имя действительного каталога, но ущерб нанесен, несмотря ни на что. Для менее -радикального тестирования от имени пользователя root попробуйте что-то вроде:
$ mkdir '$(touch.evil_file; echo directory-name)'`
Вы получите этот вывод:
something
sh: line 0: cd:./directory-name: No such file or directory
... и:
$ ls -a
. .. .evil_file $(touch.evil_file; echo directory-name)
Использование Perl-скрипта:
Предполагается, что вы ищете файл2 на основе файла1 , а не наоборот -. Если вы хотите искать файл1 на основе файла2 также, вам нужно добавить еще один цикл for для словаря файла2 (хэш ).
Файлы данных:
$ cat file1.txt
test1 marco;polo;angus
test2 mike;zen;liza
test3 tom;harry;alan
test4 bob;june;janet
$ cat file2.txt
test1 polo;angus
test2 mike
test4 bob;janet
Скрипт:
#!/usr/bin/perl
use warnings;
use strict;
my $file1=$ARGV[0];
my $file2=$ARGV[1];
my %dict1; #Stores file1 unique key and value pairs in this dictionary ( HASH in perl )
my %dict2; #Stores file2 unique key and value pairs in this dictionary ( HASH in perl )
my %output; #This is output dictionary after processing all the data to print it out
open(F1,'<',$file1) or die "File not found $file1";
open(F2,'<',$file2) or die "File not found $file2";
#Store both file's contents in %dict1 and %dict2 respectively
while(<F1>)
{
my ($key,$value) = split(/\s+/,$_);
$dict1{$key} = $value;
}
while(<F2>)
{
my ($key,$value) = split(/\s+/,$_);
$dict2{$key} = $value;
}
#Get the unique(difference) value from file2 based in the values in file1
foreach my $k ( keys %dict1 )
{
if ( defined $dict2{$k} )
{
my @dict1values=split(";",$dict1{$k});
my @dict2values=split(";",$dict2{$k});
foreach (@dict1values)
{
if ( $dict2{$k} !~ /[;]*?$_[;]*?/) {
$output{$k}.=$_.";";
}
}
} else {
$output{$k}=$dict1{$k};
}
}
foreach my $ke (sort(keys(%output)))
{
print "$ke $output{$ke}\n" if ( defined($output{$ke}) );
}
Выход:
$./testing.pl file1.txt file2.txt
test1 marco;
test2 zen;liza;
test3 tom;harry;alan
test4 june;