On Mon, Nov 26, 2001 at 12:23:56PM -0800, [EMAIL PROTECTED] wrote:
> Can and or how do I connect from a Linux server to a Microsoft SQL server??

You can use Perl DBI with DBD::Sybase and freetds (http://www.freetds.org/) to access
ms-sql databases.  Here's a little script I wrote when I was doing some pen-testing
on a site with ms-sql servers.  Read the Perl documentation on DBI for lots of 
information.

#!/usr/bin/perl -w

use DBI;
use strict;

my $server=shift;
my $user=shift || 'sa';
my $pass=shift;

my $dbh=DBI->connect("dbi:Sybase::server=$server",$user,$pass) || die "$!\n";
print "Connected!\n" if $dbh;
my ($sql,$sth,@res);
my $shell=-1;
print "sql:";
while (<>) {

    chomp;
    last if m!/quit!;

    if (m!/shell!) {

        $shell *= -1;
        print (($shell!=1) ? 'sql:' : 'shell:');
        next;

    }

    $sql= (($shell!=1) ? $_ : "xp_cmdshell '$_'");
    $sth=$dbh->prepare($sql);
    $sth->execute;

    while (@res=$sth->fetchrow_array) {

        print join "  ",map($_ || '-',@res);
        print "\n";

    }

    print (($shell!=1) ? 'sql:' : 'shell:');

}

$dbh->disconnect();

exit 0; 
 

And remember, password that 'sa' account, way too many sites don't.


Peace.

Garrick.
--
I wish no living thing to suffer pain.
Percy Bysshe Shelley (1792-1822)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to