Coder Social home page Coder Social logo

Comments (15)

ravelund avatar ravelund commented on August 26, 2024 5

from ssh.net.

drieseng avatar drieseng commented on August 26, 2024

On what line would it actually block?
Can you build SSH.NET from source and do some troubleshooting yourself, or can you provide me access to a Cisco ASA that is not in use?

from ssh.net.

ravelund avatar ravelund commented on August 26, 2024

Hello. I have already downloaded the source and can do some simple troubleshooting tommorow. I will look into it i maybe have ASA we can test on.
Also thanks for the library it works very well on the Catalysts switches.

from ssh.net.

ravelund avatar ravelund commented on August 26, 2024

Hello. Again after some stepping the command highlighted is where it hangs for eternity.
sshstop

from ssh.net.

ravelund avatar ravelund commented on August 26, 2024

Have fixed an asa you can test on. Should i send the login information to the email on your profile?

from ssh.net.

drieseng avatar drieseng commented on August 26, 2024

Yes, that's ok. I'm not sure I'll have time today, but I'll look into it asap.
Please include the command that you were trying to execute as well.
Thanks!

from ssh.net.

pincho3xxx avatar pincho3xxx commented on August 26, 2024

I've exactly the same problem when I try acces to Mitrastar FTTH router.

from ssh.net.

drieseng avatar drieseng commented on August 26, 2024

The problem with the ASA was that it does not properly support the "exec" channel request message.
Perhaps this is a scenario that the ASA - and similar devices - do not want to support.
Instead of executing the command you specify, it:

  • creates a shell
  • writes the command to the shell
  • continues waiting for input

I've supplied @ravelund with a solution offline, which uses our ShellStream - with its Expect capabilities - instead.

from ssh.net.

darinkes avatar darinkes commented on August 26, 2024

@drieseng seems to be correct.

Found this via google:
http://www.carbon60.com/it-advice/powershell-ssh-module-nonstandard-devices-like-cisco-asa

Sounds like you have to work with Shell + Expect.

from ssh.net.

ravelund avatar ravelund commented on August 26, 2024

Also with @drieseng input i have created this function:

    /// <summary>
    /// Execute a command on a host using ssh
    /// </summary>
    /// <param name="host">Ip address or Hostname</param>
    /// <param name="port">Ssh port</param>
    /// <param name="username">Username</param>
    /// <param name="password">Password</param>
    /// <param name="commands">Commands to execute</param>
    /// <param name="sendUsernameAndPasswordAsCommand">If set to true the query will send the username and password before running main command. For cisco catalyst and Firewalls False.</param>
    /// <returns>String with line shifts</returns>
    public string ExecuteCommandSsh(string host,int port, string username, string password, string[] commands, bool sendUsernameAndPasswordAsCommand)
    {
        string returnString = "";
        try
        {
            using (var client = new SshClient(host, port, username, password))
            {
                //Create the command string
                string command = "";
                foreach (var com in commands)
                {
                    command += com + "\n";
                }
                client.Connect();
                SshCommand runcommand = client.CreateCommand(command);
                if (sendUsernameAndPasswordAsCommand)
                {
                    runcommand = client.CreateCommand($"{username}\n{password}\n{command}");


                }
                runcommand.CommandTimeout = CommandTimeOut;

                try
                {
                    runcommand.Execute();
                    returnString = runcommand.Result;
                }
                catch (SshOperationTimeoutException)
                {
                    ErrorMessage += "ExecuteCommandSsh: Command timeout.";
                    returnString = runcommand.Result;
                }


               client.Disconnect();
            }
        }
        catch (Exception e)
        {

            DidThrowError = true;
            ErrorMessage += $"ExecuteCommandSsh Exception: {e.ToString()}";

        }

        return returnString;
    } //ExecuteCommandSsh end

By suppling the commands string array with
enable
"enablepassword"
terminal pager 0
sh ver
sh run

The terminal pager 0 command on the asa skips the more question. And this works.

The only - here is that you have to wait for the command to timeout.
I have set the timeout to 30 seconds at this moment.

from ssh.net.

drieseng avatar drieseng commented on August 26, 2024

I actually sent you a basic implemention that uses ShellStream and Except.
If you prefer the code above, then that's fine by me.

from ssh.net.

NNskelly avatar NNskelly commented on August 26, 2024

Would you mind posting the workaround solution, @drieseng ? I'm encountering what looks like the same issue, but working from a prebuilt dll that I don't have the luxury of picking apart in the debugger. I'm going to try @ravelund 's solution for now, but if there's a more correct/compact implementation, that would be useful.

from ssh.net.

ravelund avatar ravelund commented on August 26, 2024

from ssh.net.

NNskelly avatar NNskelly commented on August 26, 2024

Thanks! Trying an explicitly constructed command with a timeout as per the first example still jammed up for me for the duration of the timeout, and returned without apparently having executed anything. It's nice to have the Expect solution on record as an alternative.
I ultimately sorted my use case out by realizing there was a dedicated SshNet.Sftp module already available and I didn't need to be doing commands manually to begin with. I would have gone so far as questioning my use of ftp syntax/protocol, except things as simple as a cd or a pwd were also jamming.

from ssh.net.

li379395535 avatar li379395535 commented on August 26, 2024

@ravelund the second solution worked for me, Thank a lot!!

from ssh.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.