Net::SSH:Perl can't login SSH1 - perl

I'm trying to connect me to a switch using SSH1 (the switch is old and does not support ssh2) and after the firsts steps, my program dosen't do nothing and i have to Ctrl+C to stop it
# Perl v5.8.8 built for MSWin32-x86-multi-thread
#!perl
use strict;
use warnings;
use Net::SSH::Perl;
my $host = "10.*.*.*";
my $username = "***";
my $password = "***";
my $cmd = 'show version';
my $ssh = Net::SSH::Perl->new($host, debug => 1);
$ssh->login($username, $password);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd); #the script stops here
print $stdout;
logs :
Connecting to 10.*.*.*, port 22.
Remote version string: SSH-1.5-OpenSSH_2.9p1
Remote protocol version 1.5, remote software version OpenSSH_2.9p1
Net::SSH::Perl Version 1.42, protocol version 1.5.
No compat match: OpenSSH_2.9p1.
Connection established.
Waiting for server public key.
Received server public key (512 bits) and host key (896 bits).
Host '10.*.*.*' is known and matches the host key.
Encryption type: DES3
Sent encrypted session key.
Received encryption confirmation.
Trying password authentication.
Sending command: show version
Entering interactive session.
Terminating on signal SIGINT(2) #Ctrl-C
i can log me in with putty and it works.
I used wiresharck and we can see that the password and maybe the login are not used counter to putty http://image.noelshack.com/fichiers/2016/31/1470038197-troubleshooting2-ssh1.png, packets are too lights.
I don't understand what's going wrong, why the connection failed and logs say nothing about it.

It seems that it's a problem about my 3 HP switch (2524,5304, 5130). I finally tested on a cisco switch and it works perfeclty........
I will search a solution in they key size or something like that
Edit : i'm using python now and its the same problem but i found the solution here http://forums.juniper.net/t5/ScreenOS-Firewalls-NOT-SRX/Python-Paramiko-with-netscreen/m-p/294864

Related

Perl and Selenium::Remote::Driver

EDITED AGAIN
I have a server on AWS somewhere in Northern Virginia and this is my monitoring server. I ssh into this Ubuntu server from another State to do system administration. I want to do web automation tests on this server which will test a web application on the Internet hitting a URL and verify that I can selenium test a login and authenticate successfully. This server is on an AWS cloud I'm not quite sure which Perl module to use since I'm accessing it remotely.
There are two CPAN modules: Selenium::Remote::Driver and WWW::Selenium. I have tried both and they are giving me issues. And I really don't know which is appropriate for my scenario. When I use Selenium::Remote::Driver, I get the following error:
Selenium server did not return proper status at /usr/local/share/perl/5.18.2/Selenium/Remote/Driver.pm line 401.
When I use WWW::Selenium, I get this error:
Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException: Error while launching browser
I was able to launch firefox manually from the AWS monitoring server by exporting the DISPLAY but it was really slow. I have heard that I can use a headless browser but I would have to export the DISPLAY by:
export DISPLAY=:5
But remember, I'm sshing into this AWS/Selenium server from my desktop so I'm assuming I use the above command on the AWS/Selenium Server while I'm ssh into it from my desktop? Actually, at this point, I'm not sure I'm doing here. Can somebody help?
The problem in this type of questions is that the variety of configurations and binaries in your setup might be so broad that the it is hard to actually provide a straight and correct answer for YOUR SETUP.
This answer has the following assumptions:
you have downloaded the selenium-server-standalone.jar into /usr/lib/
you have jdk 1.8 ( run the java -version in the shell
you have installed and configured the xvfb-run ( it is a fight on it's own )
So :
```
# ssh to your server , obs the -X !
ssh -X user-name#server-name
# start the selenium-server-standalone on the server
xvfb-run -e /dev/stdout java -Dwebdriver.chrome.driver=/usr/bin/chromedriver -jar /usr/lib/selenium-server-standalone.jar &
# one liner test - this is one veery long one
perl -e 'use strict ; use warnings ; use Data::Printer ; my $host="127.0.0.1"; use Selenium::Remote::Driver;my $driver = Selenium::Remote::Driver->new( "browser_name" =>"chrome", "error_handler" => sub { print $_[1]; croak 'goodbye'; }, "remote_server_addr" => "$host","port"=> "4444");$driver->debug_on();$driver->get("http://www.google.com"); print $driver->get_title();$driver->quit();' &
```
Here is the code in the one-liner as a perl script
#!/usr/bin/env perl
use strict ;
use warnings ;
use Carp ;
use Data::Printer ;
use Selenium::Remote::Driver;
my $host="127.0.0.1";
my $driver = Selenium::Remote::Driver->new(
"browser_name" =>"chrome"
, "error_handler" => sub { print $_[1]; croak 'goodbye' ; }
, "remote_server_addr" => "$host"
, "port"=> "4444") ;
$driver->debug_on() ;
$driver->get("http://www.google.com");
print $driver->get_title();
$driver->quit();
The output should look something like:
```
Prepping get
Executing get
REQ: POST, http://127.0.0.1:4444/wd/hub/session/ddb9c2575ab026cdb8c640bdc554181b/url, {"url":"http://www.google.com"}
RES: {"sessionId":"ddb9c2575ab026cdb8c640bdc554181b","status":0,"value":null}
Prepping getTitle
Executing getTitle
REQ: GET, http://127.0.0.1:4444/wd/hub/session/ddb9c2575ab026cdb8c640bdc554181b/title, {}
RES: {"sessionId":"ddb9c2575ab026cdb8c640bdc554181b","status":0,"value":"Google"}
GooglePrepping quit
Executing quit
REQ: DELETE, http://127.0.0.1:4444/wd/hub/session/ddb9c2575ab026cdb8c640bdc554181b, {}
RES: {"sessionId":"ddb9c2575ab026cdb8c640bdc554181b","status":0,"value":null}
```
Try running the below code:
#!/usr/bin/perl
use warnings;
use strict;
use Selenium::Remote::Driver;
my $host = "10.10.1.1"; //Enter your server IP in this place
my $driver = new Selenium::Remote::Driver('remote_server_addr' => $host,
'port' => '4444',
'auto_close' => 0);
$driver->get('http://www.google.com');

How read Gmail via POP3 with ActivePerl 5.10 on Windows XP?

I'm using Windows XP SP3 with ActiveState Perl 5.10.0, and I've written this function--taken/edited from CPAN's Net::POP3--in an attempt to read Gmail via POP3:
my $pop = Net::POP3->new('pop.gmail.com',
Timeout => 60,
Port => 995,
Debug => 1) || die "$!";
my $num = $pop->login('xyz#gmail.com', 'password');
if (!defined($num))
{
die "Error: couldn't sign-in to your email account.\n";
}
elsif ($num > 0)
{
warn "There are $num message(s) in your inbox.\n";
my $msgnums = $pop->list;
foreach my $msgnum (keys %$msgnums)
{
my $msg = $pop->get($msgnum);
print #$msg;
}
}
else
{
die "There are no messages in your inbox. (Nothing to do.)\n"
}
$pop->quit;
The code simply times-out with this error message:
Use of uninitialized value in numeric eq (==) at C:/Perl/lib/Net/POP3.pm line 59.
Bad file descriptor at pop3.pl line xxx (i.e., the Net::POP3->new() line)
The debug info from Net::POP3 before the timeout occurred was:
Net::POP3>>> Net::POP3(2.29)
Net::POP3>>> Net::Cmd(2.29)
Net::POP3>>> Exporter(5.62)
Net::POP3>>> IO::Socket::INET(1.31)
Net::POP3>>> IO::Socket(1.30_01)
Net::POP3>>> IO::Handle(1.27)
Net::POP3=GLOB(0x20d253c): Timeout at pop3.pl line xxx
I also tried using Mail::POP3Client; no joy on Windows XP because neither CPAN nor PPM would install it and its dependencies (IO::SOCKET::SSL and etc.).
Any ideas what's wrong with my code and/or how one can read Gmail via POP3 on Windows XP with ActivePerl 5.10.0?
According to Gmail, the standard configuration instructions are:
Incoming Mail (POP3) Server - requires SSL: pop.gmail.com
Use SSL: Yes
Port: 995
You need to use SSL to access GMail. This means you need to install the Perl module IO::Socket::SSL. But this is very simple. ActiveState ships a good cpan client and a huge amount of binary 'PPM' packages. It does require that you upgrade Perl to 5.14 or 5.16 or get some kind of contract they require for supporting older perls.
You can also use Strawberry Perl; it has an equally good cpan client + build tools.

SNMP v3 with NET::SNMP working, but snmpwalk/snmpget not?

I have the following (working) perl script:
use Net::SNMP;
# create session to the host
my ($session, $error) = Net::SNMP->session(
-hostname => $hostname,
-version => 'snmpv3',
-username => 'my_user_name',
-authkey => 'my_authkey',#actually, here stands the real authkey as configured on the switch
-privkey => 'my_privkey',#same as on switch
-authprotocol => 'sha',
-privProtocol => 'des'
);
if (!defined($session)) {
print $error . "\n";
last;
}
# retrieve a table from the remote agent
my $result = $session->get_table(
-baseoid => $MAC_OID
);
if (!defined($result)) {
print $session->error . "\n";
$session->close;
last;
}
#print out the result of the snmp query
#....
Now I wanted to use snmpwalk or snmpget with the same keys. For that, I created a snmp.conf file in .snmp of my home directory with the following content:
defSecurityName my_user_name
defContext ""
defAuthType SHA
defSecurityLevel authPriv
defAuthPassphrase my_auth_key here
defVersion 3
defPrivPassphrase my_privkey here
defPrivType DES
As I see it, I use the same credentials in the script and for snmpget. Why do I get snmpget: Authentication failure (incorrect password, community or key) ?
That depends on the version of snmpget and snmpset you use. When I tested an older version of net-snmp against my C# based SNMP agent http://sharpsnmplib.codeplex.com I noticed that for SHA authen mode + DES privacy mode a bug prevented the net-snmp command line tools from generating the correct message bytes (the encryption is wrong so that no agent can decrypt it).
My suggestion is that you try to use Net::SNMP instead, as like you found out, it is not affected by the same bug.
Your problem is that you're using an authentication key for Net::SNMP and a password for the command-line net-snmp tools. Based on your Net::SNMP usage you're actually using 'localized' keys. Which means the right tokens for your snmp.conf file are:
defAuthLocalizedKey 0xHEXSTRING
defPrivLocalizedKey 0xHEXSTRING
See the snmp.conf manual page for further details.

Perl script works OK in command prompt, but fails on ODBC as a CGI script

Issue: Perl script works fine in command prompt, but fails on ODBC as a CGI script
Settings:
Win XP Pro 64 bit version 2003 SP2
Apache 2.2.17 Win32
Active Perl 5.12.2 (not Perl64)
an ODBC DSN is created for SQL SERVER
Details: from command prompt, Phone.pl runs OK - it gets query results as expected - which means DBI works fine
as a CGI script, Phone.pl prints HTML as expected before ODBC init code. (Apache settings work OK for non-ODBC script.)
here's the msg in error.log of Apache
[Tue Nov 23 13:27:57 2010] [error] [client 127.0.0.1] DBI connect('SQLSVR206','administrator',...) failed: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (SQL-IM002) at C:/CGI/Phone.pl line 32
Any idea why it behaves differently?
#!c:/perl/bin/perl.exe
use CGI qw(:standard);
use strict;
use warnings;
use DBI;
my ($sqlstr, $sql_UNITED, $dbh206);
# 206
# select * from getProvFINON('270762789')#TIN
my #colUNITED = qw/ADR_LN_1_TXT PROV_SYS_ID ZIP_CD FULL_NM SOURCE PROV_TIN BILL_TEL/;
sub Init(){
$dbh206 = DBI->connect ("dbi:ODBC:SQLSVR206",'USER','PASSWORD',{RaiseError=>1})
or die $DBI::errstr;
$sqlstr = qq/ select * from getProvFINON(?) /; #parameters TIN
$sql_UNITED = $dbh206->prepare($sqlstr)
or die "prepare failed: " . $dbh206->errstr();
}
sub test1{
my $tin = shift();
$sql_UNITED->execute($tin) or die $sql_UNITED->errstr;
my $row = $sql_UNITED->fetchrow_hashref;
while(defined ($row)){
foreach(#colUNITED){
print $row->{$_}."~~~";
}
print "<p>";
$row = $sql_UNITED->fetchrow_hashref;
}
}
print header;
print "test text<p>";
Init();
test1('270762789');
print "999999999999<p>";
==========================================================
UPDATE: part of the problem is the 32-bit VS 64-bit ODBC issue
see http://support.microsoft.com/kb/942976
HOWEVER, after I set up ODBC, I still got following error in Apache log
[Wed Nov 24 01:38:48 2010] [error] [client 127.0.0.1] DBI connect('SQLSVR206-32','',...) failed: [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'MYDOMAIN\GARY$'. (SQL-28000) at C:/CGI/test.pl line 15
I logged in as MYDOMAIN\administrator and started Apache.
ODBC was set up to use "With Windows NT authentication using the network login ID" Where does this "MYDOMAIN\GARY$" come from? Thanks!
==========================================================
FINAL UPDATE: Apache services runs using "Local System account", and that's where the "MYDOMAIN\GARY$" comes from. The thing is GARY is not with the company and his ID has been dropped from SQL Server, but ODBC code in CGI inherited GARY from Apache, resulting in error 28000.
So the problem was a convolution of
1) 32/64 bit ODBC DSN and
2) default account used by Apache
Maybe the ODBC datasource is listed under 'User DSN' and not 'System DSN'. I think that the identity that your web server runs as only has access to System DSN.
In case my post doesn't make sense, I'm editing it in order to add a link to information about the difference between User vs. System DSN's: http://www.truthsolutions.com/sql/odbc/creating_a_new_odbc_dsn.htm
Something is up with Windows 7 ODBC connections that I can't figure out either. I'd set up the ODBC and it would test fine but get a similar error as you show. Even connecting MS SQL Server Mgmt Studio to some SQL servers I have to explicitly put in extra connection settings. Since I only have the issue on some SQL servers (which I don't own) I think it's a server side problem.
On PERL i finally gave up and just created the DSN file with said extra connection settings and pointed to it directly. Note how the server name is there twice.
use DBI;
use SQL::Abstract;
my $CONNECT = "FILEDSN=thefile.dsn";
my $dbh = DBI->connect("dbi:ODBC:$CONNECT", "myidsid", "passwordThatsNotUsed");
with the ODBC file looking something like:
[ODBC]
DRIVER=SQL Server Native Client 10.0
UID=myidsid
Address=servername,3180
Network=DBMSSOCN
APP=Microsoft® Windows® Operating System
Trusted_Connection=Yes
SERVER=servername
PWD=someTextInPlaceOfPasswordAsItsNotUsed

Why can't I connect to my CAS server with Perl's AuthCAS?

I'm attempting to use an existing CAS server to authenticate login for a Perl CGI web script and am using the AuthCAS Perl module (v 1.3.1). I can connect to the CAS server to get the service ticket but when I try to connect to validate the ticket my script returns with the following error from the IO::Socket::SSL module:
500 Can't connect to [CAS Server]:443 (Bad hostname '[CAS Server]')
([CAS Server] substituted for real server name)
Symptoms/Tests:
If I type the generated URL for the authentication into the web browser's location bar it returns just fine with the expected XML snippet. So it is not a bad host name.
If I generate a script without using the AuthCAS module but using the IO::Socket::SSL module directly to query the CAS server for validation on the generated service ticket the Perl script will run fine from the command line but not in the browser.
If I add the AuthCAS module into the script in item 2, the script no longer works on the command line and still doesn't work in the browser.
Here is the bare-bones script that produces the error:
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use AuthCAS;
use CGI::Carp qw( fatalsToBrowser );
my $id = $ENV{QUERY_STRING};
my $q = new CGI;
my $target = "http://localhost/cgi-bin/testCAS.cgi";
my $cas = new AuthCAS(casUrl => 'https://cas_server/cas');
if ($id eq ""){
my $login_url = $cas->getServerLoginURL($target);
printf "Location: $login_url\n\n";
exit 0;
} else {
print $q->header();
print "CAS TEST<br>\n";
## When coming back from the CAS server a ticket is provided in the QUERY_STRING
print "QUERY_STRING = " . $id . "</br>\n";
## $ST should contain the received Service Ticket
my $ST = $q->param('ticket');
my $user = $cas->validateST($target, $ST); #### This is what fails
printf "Error: %s\n", &AuthCAS::get_errors() unless (defined $user);
}
Any ideas on where the conflict might be?
The error is coming from the line directly above the snippet Cebjyre quoted namely
$ssl_socket = new IO::Socket::SSL(%ssl_options);
namely the socket creation. All of the input parameters are correct. I had edited the module to put in debug statements and print out all the parameters just before that call and they are all fine. Looks like I'm going to have to dive deeper into the IO::Socket::SSL module.
As usually happens when I post questions like this, I found the problem. It turns out the Crypt::SSLeay module was not installed or at least not up to date. Of course the error messages didn't give me any clues. Updating it and all the problems go away and things are working fine now.
Well, from the module source it looks like that IO::Socket error is coming from get_https2
[...]
unless ($ssl_socket) {
$errors = sprintf "error %s unable to connect https://%s:%s/\n",&IO::Socket::SSL::errstr,$host,$port;
return undef;
}
[...]
which is called by callCAS, which is called by validateST.
One option is to temporarily edit the module file to put some debug statements in if you can, but if I had to guess, I'd say the casUrl you are supplying isn't matching up to the _parse_url regex properly - maybe you have three slashes after the https?