Archive for category Linux

My first perl script…

Posted by vanyell on Monday, 23 November, 2009

As a technical support engineer,  I would need to send multiple spam samples through our product for detection rate.  I initially used a bash script to send the samples through via telnet command.  The drawback was that the processing was sequential (slow).  I was already thinking of how to use threading to send the samples through in large batches which finishes the job a lot faster and at the same time enables me to tune the performance of our product when handling multiple connections.  Finally, after a great deal of procastrination, I finally hacked together a perl script to do the job, after googling and modifying some ther perl scripts.  I used the script from http://pentestit.com/2009/05/20/source-code-perl-multithreaded-scanner-webdavenabled-servers/ as basis for my script.


#!/usr/bin/perl -w

$|++;
use strict;
use 5.008;
use threads;
use threads::shared;
use Thread::Queue;
use Net::SMTP;

our $thrnum:shared=100;
our $q:shared;
our @threads;

sub smtp_send {

    my $target='192.168.50.135';
    my $filename;
    my $line;
    my @message;

    my $dir = shift;

    if ($dir =~ m/\/$/) { } else { $dir = $dir."/";};

    $filename  = shift;
#   print "Opening connection to target : ".$target."\n";
#   print "Filename: ".$dir.$filename."\n";
    $filename=$dir.$filename;

    open FILE, $filename or die $!;
    @message=
    close FILE;

    if (my $smtp = Net::SMTP->new($target,Hello=>'peters.eatsc.ts',Timeout=>30,Debug=>0)) {;
        $smtp->mail('test@test.bng');
        $smtp->to('peters@eatsc.ts');
        $smtp->data(@message);
        $smtp->quit;
        } else {
            die;
               };
}

sub main {
    my $dir;
		my $spamfile;
		my $running;

		$q = new Thread::Queue;
		$dir = shift;

		opendir (DH, $dir);
		while (defined ($spamfile=readdir(DH))) {
				unless ($spamfile =~ /^.{1,2}$/) {
						$q->enqueue($spamfile);
				}
		}
		closedir(DH);

		while (1){

				@threads = threads->list;
				if ($q->pending > 0) {
#       		print "Pending items: ".$q->pending." \n";
						if ($#threads <= $thrnum+1) {
								threads->new(\&spam_send,$dir,$q->dequeue);
#            		print "Adding new thread ".$#threads." \n";
						} else {
								foreach $running(@threads) {
										$running->join;
#                   print "Freeing thread: ".$#threads." \n";
								};
						};
				} else {
						if ($#threads >= 0) {
								foreach $running(@threads) {
										$running->join;
#                   print "Freeing thread: ".$#threads." \n";
								};
        		exit;
				    };
    };
#    print "\nThread count:" .$#threads;
}

&main($ARGV[0]); #input directory name as command-line parameter.

I will be recoding this script in python and ruby to check which one will run faster (not that I expect that there will be a huge change in performance, but a programming exercise for me).


How to run VMware ESX WebAccess plugin in Firefox under CentOS 5.3

Posted by vanyell on Tuesday, 16 June, 2009

Background:

Accessing VMware ESX via website (webAccess) is easy. Using IE under Windows, installation and execution of the plugin encounters no problems. But installing the Firefox plugin under CentOS, while this doesn’t show any problems, getting the virtual console to come up is a different matter. The main issue here is that the console plugin is looking for one particular library, the libXcomposite package. Installing this package would now let you open up the virtual console.

Troubleshooting:
1. Go to ~/.mozilla/firefox//extensions/VMwareVMRC@vmware.com/plugins
2. run ./vmware-vmrc
3. will print out an error referring to a missing libXcomposite.so.1
4. running yum whatprovides libXcomposite.so.1 will provide you with the correct package name to install


Iptraf – removing a dead iptraf session

Posted by vanyell on Thursday, 14 May, 2009

I was running iptraf via ssh on my box when the connection soured on me. After logging back in, running iptraf to do a detailed monitoring of ppp0 device, I got an error message saying “Detailed interface stats already monitoring ppp0″.

Running ps aux, reveals that no iptraf process is currently running. After thinking about it for a while, I started looking for a lock file. I found it under /var/run/iptraf directory, iptraf-detstat.tag.ppp0. Removing the lock file enabled iptraf to start monitoring ppp0 again.