2006-08-28 the security tool you've never heard of
From techtarget.com
"I often write about all the excellent tools for testing the security of Windows systems. There are excellent freeware, open source and commercial tools that all run on the Windows OS. They are, for the most part, easy to use and can ferret out a lot of security vulnerabilities that would be next to impossible to find otherwise. One tool that I haven't written much about -- and based on my informal research, one that most Windows administrators haven't heard of -- is a tool called BackTrack.
BackTrack is actually an entire Slackware Linux-based operating system with a suite of security tools that even the most die-hard Windows-o-files can appreciate and benefit from."
2006-08-24 attached to the job
Here's a perl script for testing a range of mail servers. It send an attachment to a given address via a given mailserver, just to make sure everything is ok.
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket;
use MIME::Base64;
use POSIX qw(strftime);
$|=1;
my @mx = ( "192.168.0.1", "192.168.0.10", "192.168.0.20" );
my $from = "ed\@example.com";
my $to = $from;
sub ms {
my $f = shift;
my $t = shift;
print( "$t\n" );
print( $f "$t\n" );
}
sub lz {
my $v = shift;
return( $v < 10 ? "0$v" : $v );
}
sub st {
my @t = @_;
return( ${t[5]}+1900 . lz($t[4]+1) . lz($t[3]) . lz($t[2]) .
lz($t[1] ) );
}
sub messagebody {
my $s = shift;
my $t="";
my $bound="Multipart_".time()."/$$";
my @t = localtime(time());
my $ds = strftime( "%a, %d %b %Y %H:%M:%S %z", localtime );
my $data;
my $pos;
$t = "To: $to\n";
$t .= "From: $from\n";
$t .= "Date: $ds\n";
$t .= "Subject: Test message [$s] " . st(@t) . "\n";
$t .= "Mime-Version: 1.0\nContent-Type: multipart/mixed;\n";
$t .=" boundary=\"$bound\"\n\n";
$t .= "--$bound\n";
$t .= "Content-Type: text/plain; charset=US-ASCII\n";
$t .= "Content-Transfer-Encoding: 7bit\n";
$t .= "Content-Disposition: inline\n\n";
$t .= "hosts\n\n";
$t .= "--$bound\n";
$t .= "Content-Type: application/octet-stream; name=hosts\n";
$t .= "Content-Transfer-Encoding: base64\n";
$t .= "Content-Disposition: attachment; ";
$t .= "filename=hosts\n\n";
open( F, "</etc/hosts" );
binmode(F);
while(1==1) {
my $c = read(F, $data, 1024, $pos );
last if( $c == 0 );
$pos += $c;
}
close(F);
$t .= encode_base64($data);
$t .= "\n--$bound--\n\n.\n";
$t =~ s/\n/\r\n/g;
return($t);
}
sub testaddr {
my $a = shift;
my $s=0;
my $f = IO::Socket::INET->new( PeerAddr => $a, PeerPort => 25 )
or return( "Could not connect: $!" );
$f->autoflush(1);
while(1==1) {
my $msg = <$f>;
print(">$msg\n");
if( $msg =~ /^([0-9]{1,3})(.*)$/ ) {
if( $1 >= 500 ) { # perm error
return( "$2" );
}
if( $1 >= 400 ) { # temp error
return( "$2" );
}
if( $s == 0 ) {
ms( $f, "helo" );
}
if( $s == 1 ) {
ms( $f, "mail from: $from" );
}
if( $s == 2 ) {
ms( $f, "rcpt to: $to" );
}
if( $s == 3 ) {
ms( $f, "data" );
}
if( $s == 4 ) {
ms( $f, messagebody($a) );
}
if( $s == 5 ) {
ms( $f, "quit" );
last;
}
}
else {
return( "Invalid response: $msg\n" );
}
$s++;
}
return(undef);
}
sub main {
foreach my $a (@mx) {
my $r = testaddr($a);
if(defined($r)) {
print($r);
}
}
}
main();
2006-08-20 wasted weekend, really
Most of Saturday was ill spent on a programming language comparison sheet. There's details on what that's all about at the link. Things which I have meant to do include:
- practise my Russian
- upload netmon to sourceforge
- wirte more articles
Who knows, maybe I'll get around to some of this next weekend!
One thing I have noticed during this break is that dotGNU is a .net project by the GNU foundation. I have to wonder to myself why Novel are pushing Mono, when dotGNU is there... Also, why are the community following it?
2006-08-18 openbsd 3.9 iso
Have you ever misplaced your instructions for making the openbsd iso? I have several times, so I'm posting this for my own purposes in the hope that someone else shall find it useful.
mkdir openbsdiso cd openbsdiso/ mkdir OpenBSD mkdir OpenBSD/3.9 mkdir OpenBSD/3.9/i386 cd OpenBSD/3.9/i386/ wget -cr http://ftp.belnet.be/packages/openbsd/3.9/i386/ mkisofs -r -b 3.9/i386/cdrom39.fs -c "boot.catalog" -o ../../../obsd3-9.cd.iso OpenBSD
2006-08-15 map function in c
Just a short post showing a map function in c. The possibilities are endless, if one were to do a complex operation on a list which might be expensive in a more highlevel operation, building a library in a lower level language might be sensible.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int operate( int i ) {
return( i * 2 );
}
void map( int (*f)(int), int i[10] ) {
int x;
for( x=0; x<10 ; x++ ) {
i[x] = f(i[x]);
printf( "%d -> %d\n", x, i[x] );
}
}
int main() {
int a[10];
int i;
for( i=0 ; i<10; i++ ) {
a[i] = i;
}
map( &operate, a );
return( EXIT_SUCCESS );
}
2006-08-12 mutt
Sometimes I wonder why the popular unix mail client is not named 'mutty' tty being terminal type, but never mind. Decided after some long and beautiful years with sylpheed to give something else a go. Most people have decided to flock to thunderbird, which is perfectly ok except that windows people use it now.
The setup that I have decided to work with is to have my mail on an IMAP box, which is fairly standard these days. Some people prefer mbox files but its just not for me.
Getting mutt is reasonably straight forward, apt-get install mutt... job done. The real work comes at configuring time. I'm going to save you some time and show how I've set things up, which may be the wrong way to do things given that I've not spent a huge amount of time with it.
I'm going to show you three files, .muttrc, my signature file, and my editor start file. Lets begin with the muttr.
# set my mailbox location set mbox=imap://username:password@192.168.0.1/ # set the default folder set folder=imap://username:password@192.168.0.1/ # set the editor set editor=/home/ed/nfs/code/scripts/muttmail.pl # check N seconds set mail_check=10 # set the spoolfile to inbox set spoolfile=imap://username:password@192.168.0.1/INBOX # i'm very disorganised! list your mailboxes here mailboxes ! mailboxes =INBOX # set a custom from header my_hdr From: ed <ed@example.com>
With the muttrc configured correctly you can get to your mail, but the default editor style might not be quite what you want. I personally like to remove existing signatures from mail and add a short custom quote from my database. Lets have a look at the editor script first though.
#!/usr/bin/perl
use strict;
use warnings;
if( !defined( $ARGV[0] ) ) {
print( "no arguments" );
exit;
}
open( F, $ARGV[0] ) or die( "Could not open source file" );
my @li = <F>;
close(F);
open( F, ">${ARGV[0]}" );
foreach my $l (@li) {
chomp($l);
if( $l eq "> -- " || $l eq "-- " ) {
last;
}
else {
print( F "$l\n" );
}
}
print( F "\n\n-- \n" );
open( FF, "/home/ed/nfs/code/perl/signature.pl|" );
foreach( <FF> ) {
print( F "$_" );
}
close(FF);
close(F);
system( "vim ${ARGV[0]}" );
What the above script does is read the first command line argument until it reaches a "-- " or "> -- " string, at which point it no longer writes the output. The script then executes my custom signature script and appends the output of that to the output file (contortion?). Finally the script runs vim via the system command. We could use exec, but at some point I plan to pass the mail through aspell before leaving. If you have read much of this blog one might realise that I am not a brilliant speller and that I don't check my posts through before leaving... I'm a bit like that with my mail also. You can make your own signature file if you wish.
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
sub randomquote {
my $host = "fw";
my $db = "dbname";
my $user = "username";
my $pw = "password";
my $conninfo = "dbi:mysql:$db;$host";
my $dbh = DBI->connect( $conninfo, $user, $pw );
my $sql = "select * from quotes order by rand() limit 1";
my $sth = $dbh->prepare($sql);
my $quotesid;
my $authorid;
my $quotestext;
my $quotesdate;
my $retval="";
$sth->execute();
$sth->bind_columns( \$quotesid, \$authorid, \$quotestext, \$quotesdate );
if( $sth->fetch() ) {
$retval = "$quotestext";
}
$sth->finish();
$dbh->disconnect();
return($retval);
}
my $linewidth = 70;
my @lines;
push( @lines, "Regards, Ed :: " );
push( @lines, "" );
my @urls;
push( @urls, "http://www.s5h.net" );
push( @urls, "http://www.bsdwarez.net" );
push( @urls, "http://www.linuxwarez.co.uk" );
push( @urls, "http://www.openbsdhacker.com" );
push( @urls, "http://www.usenix.org.uk" );
push( @urls, "http://www.gnunix.net" );
push( @urls, "http://www.ednevitable.co.uk" );
push( @urls, "http://s5h.net/u?l" );
push( @urls, "http://s5h.net/qf" );
$lines[0] = $lines[0] . $urls[rand(scalar(@urls)) % 100];
my @me;
push( @me, "proud" );
push( @me, "just another" );
my @thing;
push( @thing, "unix" );
push( @thing, "linux" );
push( @thing, "perl" );
push( @thing, "python" );
push( @thing, "java" );
push( @thing, "bash" );
push( @thing, "c++" );
my @type;
push( @type, "person" );
push( @type, "hacker" );
$lines[1] = $lines[1] . $me[rand(scalar(@me)) % 100] . " " . $thing[rand(scalar(@thing)) % 100] . " " . $type[rand(scalar(@type)) % 100];
my @quotes;
push( @quotes, randomquote() );
my $quote = $quotes[rand(scalar(@quotes)) % 100];
my @q = split( ' ', $quote );
print "$lines[0]\n";
print "$lines[1]\n";
my $c = 0;
my $op = "";
my $a = "";
for( my $i=0 ; $i<scalar(@q) ; $i++ ) {
$a = "$q[$i] ";
if( $linewidth < $c+length( $a ) ) {
$op .= "\n";
$c = 0 ;
}
$op .= $a;
$c += length( $a );
}
print "$op\n";
For what it's worth, lets take a look at my .vimrc.
set number set autoindent set ts=8 set sw=8 syntax enable colors torte set backspace=indent,eol,start set showcmd " Show (partial) command in status line. set showmatch " Show matching brackets. set ignorecase " Do case insensitive matching set smartcase " Do smart case matching set incsearch " Incremental search set autowrite " Automatically save before commands like :next and :make set hidden " Hide buffers when they are abandoned set mouse=a " Enable mouse usage (all modes) in terminals set background=dark set ru set textwidth=72
This vimrc works with the default settings in vim7.0.
why the pentium4 under performs
I stumbled upon a humourous site that takes computer modding to a new level. The p4 is not quite what we assume it to be.
2006-08-08 attachments (again)
Sometimes it can be useful on a unix system to send things via email, most hosts have sendmail installed for sending internet mail. Sendmail has been around since the very early days and should always be in /usr/sbin/sendmail and/or /usr/lib/sendmail.
This scripty below sends all files in ./files as individual emails to a given destination.
#!/usr/bin/perl
use warnings;
use strict;
use POSIX qw(strftime);
# pmail.pl - send email attachments
# Copyright (C) 2006, ed neville
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
$| = 1;
my $from_email="ed\@example.com";
my $to_email="ed\@example.com";
my $subject="file attached: ";
sub b64encode {
my $i = shift;
my $b64blksz = 54;
my $o = "";
my $op = "";
my @bytes = unpack("C*", $i);
while ((my $a, my $b, my $c) = splice(@bytes, 0, 3)) {
my $val = ($a << 16) | ($b << 8) | $c;
my $w = ($val & 077000000) >> 18;
my $x = ($val & 0770000) >> 12;
my $y = ($val & 07700) >> 6;
my $z = ($val & 077);
$o .= pack("C*", $w, $x,
(defined($b) ? $y : 64),
(defined($c) ? $z : 64));
}
$o =~ tr!\000-\100!A-Za-z0-9+/=!;
while( length( $o ) > 72 ) {
$op .= substr( $o, 0, 72 ) . "\n";
$o = substr( $o, 72 );
}
$op .= $o;
return($op);
}
sub messagebody {
my $filename = shift;
my $data = "";
my $pos = 0;
my $time = time();
my $pid = $$;
my $boundary = "Multipart_$time/$pid";
my $ret = "";
open( F, "$filename" ) or die( "cannot open" );
binmode(F);
while( 1==1 ) {
my $bytes = read(F, $data, 1024, $pos );
last if( $bytes == 0 );
$pos += $bytes;
}
my $b64 = b64encode( $data );
close(F);
$ret .= "Mime-Version: 1.0\nContent-Type: multipart/mixed;\n";
$ret .=" boundary=\"$boundary\"\n\n";
$ret .= "--$boundary\n";
$ret .= "Content-Type: text/plain; charset=US-ASCII\n";
$ret .= "Content-Transfer-Encoding: 7bit\n";
$ret .= "Content-Disposition: inline\n\n";
$ret .= "$filename\n\n";
$ret .= "--$boundary\n";
$ret .= "Content-Type: application/octet-stream; name=$filename\n";
$ret .= "Content-Transfer-Encoding: base64\n";
$ret .= "Content-Disposition: attachment; ";
$ret .= "filename=$filename\n\n";
$ret .= "$b64\n\n";
$ret .= "--$boundary--\n";
return( $ret );
}
sub listfiles {
my $body;
opendir( D, "./files" ) or die( "./files does not exist" );
while( my $f = readdir( D ) ) {
next if( $f eq "." || $f eq ".." );
print( "$f... " );
my @t = localtime( time() );
my $ds = strftime "%a, %d %b %Y %H:%M:%S %z", localtime;
$body .= "To: ${to_email}\n";
$body .= "Subject:${subject}$f\n";
$body .= "Date: $ds \n";
$body .= messagebody( "./files/$f" );
open( M, "|/usr/sbin/sendmail -f${from_email} ${to_email}" );
print( M $body );
close(M);
}
closedir(D);
}
listfiles();
2006-08-05 SCOX falls in value
The SCO stock has fallen in value now that almost all of the interest in the SCO vs IBM case has vanished. Seems the only thing to help that company since the dotcom burst was the stolen code case. I pitty their CEO's.
nice and short
There's now a short URL link on this page. It's possible for anyone to submit their own long URL to be shortend. I have seen some other people who do this with tinyurl etc, but since I own a reasonably short domain (s5h.net) I figure this could be of some use to people who have trouble remembering long URLs.
net-mon
I have merged the BSD and Linux network monitors into a single source ball which should compile on the main free UNIX/Linux platforms. It would be great to hear if this compiles on anything other than Linux/2.6 or Free/OpenBSD. This single project should now be visible on the qmail apge at net-mon. It's under qmail because it happens to help while monitoring large email flows, or backups, or webservers etc.
Info