#!/usr/bin/perl -w use strict; use Net::Pcap; use NetPacket::Ethernet qw(:strip); use NetPacket::IP qw(:protos :strip); use NetPacket::TCP; use NetPacket::UDP; # Knock Knock Neo.... matrixz hasz youz :D ################################################# my $ethx = $ARGV[0]; # my $address = $ARGV[1]; # # # my @fil = ("7", "3", "5", "10"); # List of port to be k +nocked my $MAXCO = @fil; # # # my %sex; # Glob Vars ################################################# sub exe { system("iptables -A INPUT -p tcp -s 0.0.0.0 --dport 22 -j ACCEPT\n +"); } sub check { my ($user_data, $header, $packet) = @_; # Via Ethernet Quindi Ip (Ip) $packet = NetPacket::IP->decode(eth_strip($packet)); my $d_ip = $packet->{dest_ip}; my $p_ip = $packet->{src_ip}; if ($d_ip eq $address) { my $s_ip=$packet->{src_ip}; # Qui va via un altro incapsulamento $packet=NetPacket::TCP->decode($packet->{data}); my $port = $packet->{dest_port}; print "$port\n"; if (!$sex{$s_ip}) { print"uNdEf\n"; $sex{$s_ip}++; } if ($packet->{dest_port} == $fil[$sex{$s_ip}]) { $sex{$s_ip}++; print"...\n"; if ($sex{$s_ip}= $MAXCO) { exe; } } } } sub create_obj { my $err; my $objz = Net::Pcap::open_live($ethx, 1500, 1, 0, \$err) || die " +Cannot create packet descriptor: \$err, $!\n"; return $objz; } sub noparam { print "\n"; print "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"; print "\n"; print "usage: perl portknockerz.pl <interface>\n"; print "\n"; print "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"; print "-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"; print "\n"; exit; } sub main { if (!defined $ARGV[0]) { noparam;} while (1) { my $pid=fork(); if (not defined $pid) { die "Unable to fork. $!\n";} if ($pid) { wait(); sleep(1); }else { print"fork success\n"; my $pack=create_obj(); print"Packet descriptor created\n"; Net::Pcap::loop($pack, -1, \&check, ""); Net::Pcap::close($pack); } } } main; ###################################################################### +##### # Need to improve TCP or UDP packet flow.. ---> I don't know how to d +o it ##########

In reply to PortKnockerz by LordScinawa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.