Quantcast
Viewing all articles
Browse latest Browse all 1729

New Post: su command

thanks Olegkap, I roselved using a ShellStream, here is the code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Renci.SshNet;
using System.IO;
using System.Text.RegularExpressions;

namespace DBA95
{
    class ServerUtil
    {
        public void sshTest(Server server)
        {
            try
            {
                using (var client = new SshClient(server.Host, server.User, server.Password))
                {
                    ShellStream shells = client.CreateShellStream("test", 80, 24, 800, 600, 1024);
                    Regex regex = new Regex(@"\[.*@.*\][\$|\#]");

                    shells.WriteLine("su - root");
                    String outp = "";
                    var match = regex.Match(outp);
                    while (shells.DataAvailable || !match.Success || outp == "")
                    {
                        outp += shells.Read();
                        match = regex.Match(outp);
                    }
                    shells.WriteLine("rootpwd");
                    outp = "";
                    match = regex.Match(outp);
                    while (shells.DataAvailable || !match.Success || outp == "")
                    {
                        outp += shells.Read();
                        match = regex.Match(outp);
                    }
                    shells.WriteLine("pwd");
                    outp = "";
                    match = regex.Match(outp);
                    while (shells.DataAvailable || !match.Success || outp == "")
                    {
                        outp += shells.Read();
                        match = regex.Match(outp);
                    }
                    shells.WriteLine("pwd");
                    outp = "";
                    match = regex.Match(outp);
                    while (shells.DataAvailable || !match.Success || outp == "")
                    {
                        outp += shells.Read();
                        match = regex.Match(outp);
                    }
                    client.Disconnect();
                }
            }
            catch (Exception e)
            {
            }
        }
    }
}


Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>