Mailing List Archive

problem in executing SSH commands
>Hi ,
>Sorry to bug you but I'm new to NASL and my first
attempt to write a
>useful NASL script failed :(
>
>I've a problem regarding executing SSH commands in
NASl.
>I want to read a file on a remote machine using SSH
from my nasl
program.
>Here is what i wrote:
>##########################################################
> ssh_login
(socket:soc,login:"nsroot",password:"nsroot",pub:NULL,priv:NULL,passphrase:NULL);
>
>cmd1=ssh_cmd(socket:soc, cmd:"shell", timeout:5);
>display('\ncmd1:',cmd1);
>
>buf = ssh_cmd(socket:soc, cmd:"cat myfile",
timeout:5);
>display('\nbuf:',buf);
>############################################################
>
>i got the following output :
>cmd1:
>buf: Done
>ERROR: No such command
>-------------------------------------------------------------------------------------
>i know the second command(cat myfile ) is not
reaching the new shell
>which is forked,
>but i've tried a lot ,i still cudn't find out how to
execute commands
>on that newly forked shell.
>Someone please help me. I know its a silly doubt.
>If it cannot be done plz help me on how to read files
from a remote
>machine using SSH in a nasl program.
>Thanks
>
>

=====
-------------------------------------------
"I'm gonna live forever, or die trying."

*(`'·.¸(`'·.¸*!!~Sandy~!!*¸.·'´)¸.·'´)*



__________________________________
Do you Yahoo!?
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250
Re: problem in executing SSH commands [ In reply to ]
On Feb 24, 2005, at 4:55 AM, sandy wrote:
>> Here is what i wrote:
>> ##########################################################
>> ssh_login
> (socket:soc,login:"nsroot",password:"nsroot",pub:NULL,priv:
> NULL,passphrase:NULL);
>>
>> cmd1=ssh_cmd(socket:soc, cmd:"shell", timeout:5);
>> display('\ncmd1:',cmd1);
>>
>> buf = ssh_cmd(socket:soc, cmd:"cat myfile",
> timeout:5);
>> display('\nbuf:',buf);
>> ############################################################
>>

If you want to get the output of the file, so just do :


ret = ssh_login (socket:soc, login:"login",
password:"password",pub:NULL,priv:NULL,passphrase:NULL);
if (ret != 0)
{
display ("Error: login failed\n");
exit (0);
}

buf = ssh_cmd (socket:soc, cmd:"cat yourfile", timeout:10);
if (!buf)
{
display ("Error: cmd failed\n");
exit (0);
}

#display file if success
display (buf);


Nicolas