public void start() { try { SSHConnectionParameter f = new SSHConnectionParameter(); f.UserName = userName; f.Password = passwordWord; f.Protocol = SSHProtocol.SSH2; f.AuthenticationType = AuthenticationType.Password; f.WindowSize = 0x1000; _objTmp = new Dictionary<TextBox, StringBuilder>(); Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //s.Blocking = false; s.Connect(new IPEndPoint(IPAddress.Parse(ip), _port)); _conn = SSHConnection.Connect(f, this, s); this._conn = _conn; SSHChannel ch = _conn.OpenShell(this); this._pf = ch; _linePool = new List<string>(); SSHConnectionInfo ci = _conn.ConnectionInfo; } catch (Exception e1) { SetText(_objTmp, form.consoleBox, e1.Message); } }
private void Connect(string hostname, string user, string pass, string private_key_file) { SSHConnectionParameter f = new SSHConnectionParameter(); f.UserName = user; f.Password = pass; f.Protocol = Routrek.SSHC.SSHProtocol.SSH2; if(string.IsNullOrWhiteSpace(private_key_file)) { f.AuthenticationType = Routrek.SSHC.AuthenticationType.Password; } else { f.AuthenticationType = Routrek.SSHC.AuthenticationType.PublicKey; f.IdentityFile = private_key_file; } f.WindowSize = 0x1000; f.Protocol = SSHProtocol.SSH2; Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ip = Dns.GetHostEntry(hostname).AddressList[0]; // Dns.GetHostByName(hostname).AddressList[0]; s.Connect(new IPEndPoint(ip, 22)); _conn = Routrek.SSHC.SSHConnection.Connect(f, reader, s); Routrek.SSHC.SSHChannel ch = _conn.OpenShell(reader); ch.ResizeTerminal(80, 24, 14, 14); reader._pf = ch; Routrek.SSHC.SSHConnectionInfo ci = _conn.ConnectionInfo; if (!eReadyToRoll.WaitOne(60000)) { //prompt not received throw new Exception("Connected to the target OK, but have not received the clear command prompt ($ or #)."); } isOpen = true; }
static void Main(string[] args) { /* string cn = System.Threading.Thread.CurrentThread.CurrentUICulture.Name; string t1 = Routrek.SSHC.Strings.GetString("NotSSHServer"); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ja"); Routrek.SSHC.Strings.Reload(); string t2 = Routrek.SSHC.Strings.GetString("NotSSHServer"); */ #if false //RSA keygen //RSA KEY GENERATION TEST byte[] testdata = Encoding.ASCII.GetBytes("CHRISTIAN VIERI"); RSAKeyPair kp = RSAKeyPair.GenerateNew(2048, new Random()); byte[] sig = kp.Sign(testdata); kp.Verify(sig, testdata); new SSH2UserAuthKey(kp).WritePublicPartInOpenSSHStyle(new FileStream("C:\\IOPort\\newrsakey", FileMode.Create)); //SSH2UserAuthKey newpk = SSH2PrivateKey.FromSECSHStyleFile("C:\\IOPort\\newrsakey", "nedved"); #endif #if false //DSA keygen //DSA KEY GENERATION TEST byte[] testdata = Encoding.ASCII.GetBytes("CHRISTIAN VIERI 0000"); DSAKeyPair kp = DSAKeyPair.GenerateNew(2048, new Random()); byte[] sig = kp.Sign(testdata); kp.Verify(sig, testdata); new SSH2UserAuthKey(kp).WritePublicPartInOpenSSHStyle(new FileStream("C:\\IOPort\\newdsakey", FileMode.Create)); //SSH2PrivateKey newpk = SSH2PrivateKey.FromSECSHStyleFile("C:\\IOPort\\newdsakey", "nedved"); #endif SSHConnectionParameter f = new SSHConnectionParameter(); f.UserName = "******"; #if false //SSH1 //SSH1 f.Password = ""; f.Protocol = SSHProtocol.SSH2; f.AuthenticationType = AuthenticationType.Password; f.PreferableCipherAlgorithms = new CipherAlgorithm[] { CipherAlgorithm.Blowfish, CipherAlgorithm.TripleDES }; #else //SSH2 f.Password = ""; f.Protocol = SSHProtocol.SSH2; f.AuthenticationType = AuthenticationType.Password; f.WindowSize = 0x1000; #endif Reader reader = new Reader(); Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //s.Blocking = false; s.Connect(new IPEndPoint(IPAddress.Parse("192.168.1.1"), 22)); _conn = SSHConnection.Connect(f, reader, s); reader._conn = _conn; #if false //Remote->Local _conn.ListenForwardedPort("0.0.0.0", 29472); #elif false //Local->Remote SSHChannel ch = _conn.ForwardPort(reader, "www.yahoo.co.jp", 80, "localhost", 0); reader._pf = ch; while(!reader._ready) System.Threading.Thread.Sleep(100); reader._pf.Transmit(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n\r\n")); #elif false //SSH over SSH f.Password = "******"; SSHConnection con2 = _conn.OpenPortForwardedAnotherConnection(f, reader, "kuromatsu", 22); reader._conn = con2; SSHChannel ch = con2.OpenShell(reader); reader._pf = ch; #else //normal shell SSHChannel ch = _conn.OpenShell(reader); reader._pf = ch; #endif //Debug.WriteLine(_conn.ConnectionInfo.DumpHostKeyInKnownHostsStyle()); SSHConnectionInfo ci = _conn.ConnectionInfo; Thread.Sleep(1000); //((SSH2Connection)_conn).ReexchangeKeys(); byte[] b = new byte[1]; while(true) { int input = System.Console.Read(); b[0] = (byte)input; //Debug.WriteLine(input); reader._pf.Transmit(b); } }