Tuesday, April 17, 2007

Script to exchange ssh keys

 1 #!/usr/bin/perl
2 use Expect;
3 #USAGE: ssh-key-exchange.pl <IP> <USERNAME> <PASSWORD>
4
5 my $ip = $ARGV[0];
6 my $login = $ARGV[ 1];
7 my $password = $ARGV[2 ];
8 my $private_key='/root/.ssh/id_rsa ';
9 my $public_key='/root/.ssh/id_rsa.pub ';
10 my $authorisedkeyfile='/root/.ssh/authorized_keys ';
11 my $timeout = 10;
12 my $aft = new Expect;
13
14 #Generate the public and private key on the local m/c A
15 if(!(( -e $public_key ) &&( -e $private_key ))) {
16 print "Generating the Public and Private Key:\n ";
17 @result=`ssh-keygen -t rsa -f /root/.ssh/id_rsa -P "" `;
18 #print @result;
19 }
20 #Copy the file to m/c B
21 print "Copying Public Key from A to B.\n ";
22 $aft->spawn("scp $public_key $login\@$ip:/tmp/");
23 $aft->expect($timeout,[ qr'\? $' , sub { my $fh=shift; $fh->send("yes\n"); exp_continue; } ],
24 [ 'Password: $',sub { my $fh=shift;$fh->send("$password \n");exp_continue;} ],
25 # '-re','\# $'
26 );
27 $aft->do_soft_close();
28
29
30 #Add Keys to authorised keys in B
31 print " Adding Keys to authorised key in B with IP=$ip,[ $login $password ] \n";
32 my $aft = new Expect;
33 $aft->log_file("/tmp/expect_log" ,"w");
34 $aft->spawn( "ssh $login\@$ip") or die "Cannot ssh to the machine \n";
35 $aft->expect($timeout,[ qr'\? $', sub { my $fh=shift;$fh ->send("yes\n"); exp_continue; } ],
36 [ 'Password: $',sub { my $fh=shift;$fh->send("$password\n ");exp_continue;} ],
37 '-re', '\# $'
38 );
39 $aft ->send("touch $authorisedkeyfile\n");
40 $aft->expect($timeout,'-re' ,'\# $');
41 $aft->send( "cat /tmp/id_rsa.pub >> $authorisedkeyfile\n");
42 $aft->expect($timeout,'-re', '\# $');
43 $aft->send(" exit\n");
44 $aft->do_soft_close();
45

6 comments:

Carder International said...

I found useful tutorial blog that contains many software, tools, scripts to hack e-gold, paypal, ATM, credit cards and thousands valid credit card accounts as well as Paypal. This blog also sell many softwares that might be useful for hackers and carders. Check this blog:
http://www.hacking-egold.co.cc/

Chaoooo.....

Mayur Vaghasia said...

visit http://hacking26.blogspot.com/ for more info.

Dushyant Kotadia said...

For Windows Hack, Tips & Tricks visit

http://windows-tips44.blogspot.com/



.

Palm Pixi Plus Verizon Only Cell Phone with WebOS, Touch Screen said...

good article

Imran Hosen said...

Too Stressed ??
Money can bring the "Peace" in your "soul"!!
Your life can 'Recover'!!
Get this 100% free method, Which will earn money for you by using PayPal Hack tool and earn UP TO 500$ ADDING EVERY 5 HOURS.TOTALLY UNTRACEABLE!!!!!!!!!!!!!!!!!!!!!!
So Download the Tool......
Paypal Account Hack
Paypal Money Adder
Paypal Money Generate
Paypal Money Hack

Elizabeth Ramirez said...

Simple Steps to start making money online with PayPal Money Generator Hack Tool
Starting Today, You’ll Make $200-$400 and More Every Day.
Full Functionality will promise you to get your merited cash!
Download the PayPal Money Generator 2015! The Adder works like a Generator. You have to turn it on to carry out the occupation! Along these lines you will get your Money! This PayPal Money Generator 2015 is the main working Money Adder to get Money!
It's simple and quick! You don't need to hold up days or weeks to get your cash! Hold up 20 minutes and check your Account! You will be flabbergasted subsequent to seeing the sum you have recently gotten for you! You will be exceptionally glad that you have downloaded the Generator and you will make us cheerful that a someone else out there can pay his bills or stuff and appreciate the great locales of life!
So click to Download Hack
Hacking