VB icon

pcap generator

Email
Submitted on: 8/3/2016 1:37:09 PM
By: Bruno Ramalhete 
Level: Intermediate
User Rating: Unrated
Compatibility: 5.0 (all versions)
Views: 1414
author picture
 
     This Perl source code can generate some pcap files and data. This script file needs some modules to work correctly that are described in the comments. For educational purposes.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
=**************************************
= Name: pcap generator
= Description:This Perl source code can generate some pcap files and data. This script file needs some modules to work correctly that are described in the comments. For educational purposes.
= By: Bruno Ramalhete
=**************************************

#!/usr/bin/perl
# vim:ft=perl
# pcap generator
# (C) 2014 Bruno Ramalhete <bram.512@gmail.com>
use strict;
use warnings;
# sudo cpan install Net::PcapWriter
use Net::PcapWriter;
# sudo cpan install WWW::UserAgent::Random
use WWW::UserAgent::Random;
# sudo cpan install String::Random
use String::Random;
my $random = new String::Random;
# https://metacpan.org/pod/Net::PcapWriter
my $writer = Net::PcapWriter->new('test.pcap');
my $dst= "www.az.gov";
my $dst_ip = "1.3.3.7";
my $n = 1;
while ( $n <= 1337 ) {
my $ip_src = join( ".", map int rand 256, 1 .. 4 );
my $conn = $writer->tcp_conn( $ip_src, rand(65535), $dst_ip, 80 );
my $login = $random->randpattern("ccccc");
my $pass= $random->randpattern("cCc!Ccnn");
my $http_post_body = "login=$login&password=$pass";
my $content_length = length($http_post_body);
my $user_agent = rand_ua('browsers');
# this will automatically add syn..synack..ack handshake to pcap
# each write will be a single packet
$conn->write(
0,
"POST http://$dst/index.php?action=login HTTP/1.1
Host: $dst
Proxy-Connection: keep-alive
Content-Length: $content_length
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin: http://$dst
User-Agent: $user_agent
Content-Type: application/x-www-form-urlencoded
Referer: http://$dst
Accept-Encoding: sdch
Accept-Language: en-US;q=0.6,en;q=0.4\r\n\r\n"
);
$conn->write( 0, "$http_post_body\r\n\r\n" );
$conn->ack(1);# force ack from server
# client will no longer write
$conn->shutdown(0);
# this will automatically add ack to last packet
$conn->write( 1, "HTTP/1.1 200 OK\r\nContent-length: 10\r\n\r\n" );
$conn->write( 1, "success" );
# will automatically add remaining FIN+ACK
undef $conn;
$n++;
}


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.