public KeyExchanger(SSH2Connection con, byte[] sessionID) { _con = con; _param = con.Param; _cInfo = (SSH2ConnectionInfo)con.ConnectionInfo; _sessionID = sessionID; _status = Status.INITIAL; }
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; }
public SSH2Connection(SSHConnectionParameter param, ISSHConnectionEventReceiver r, string serverversion, string clientversion) : base(param, r) { _cInfo = new SSH2ConnectionInfo(); _cInfo._serverVersionString = serverversion; _cInfo._clientVersionString = clientversion; _packetBuilder = new SSH2PacketBuilder(new SynchronizedSSH2PacketHandler()); }
private static void SendMyVersion(AbstractSocket stream, SSHConnectionParameter param) { string cv = SSHUtil.ClientVersionString(param.Protocol); if(param.Protocol==SSHProtocol.SSH1) cv += param.SSH1VersionEOL; else cv += "\r\n"; byte[] data = Encoding.Default.GetBytes(cv); stream.Write(data, 0, data.Length); }
public ProtocolNegotiationHandler(SSHConnectionParameter param) { _param = param; _errorMessage = Strings.GetString("NotSSHServer"); }
internal static SSHConnection Connect(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, ProtocolNegotiationHandler pnh, AbstractSocket s) { if(param.UserName==null) throw new InvalidOperationException("UserName property is not set"); if(param.Password==null) throw new InvalidOperationException("Password property is not set"); return ConnectMain(param, receiver, pnh, s); }
private static SSHConnection ConnectMain(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, ProtocolNegotiationHandler pnh, AbstractSocket s) { pnh.Wait(); if(pnh.State!=ReceiverState.Ready) throw new SSHException(pnh.ErrorMessage); string sv = pnh.ServerVersion; SSHConnection con = null; if(param.Protocol==SSHProtocol.SSH1) con = new SSH1Connection(param, receiver, sv, SSHUtil.ClientVersionString(param.Protocol)); else con = new SSH2Connection(param, receiver, sv, SSHUtil.ClientVersionString(param.Protocol)); s.SetHandler(con.PacketBuilder); SendMyVersion(s, param); if(con.Connect(s)!=AuthenticationResult.Failure) return con; else { s.Close(); return null; } }
//establishes a SSH connection in subject to ConnectionParameter public static SSHConnection Connect(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, Socket underlying_socket) { if(param.UserName==null) throw new InvalidOperationException("UserName property is not set"); if(param.Password==null) throw new InvalidOperationException("Password property is not set"); ProtocolNegotiationHandler pnh = new ProtocolNegotiationHandler(param); PlainSocket s = new PlainSocket(underlying_socket, pnh); s.RepeatAsyncRead(); return ConnectMain(param, receiver, pnh, s); }
/** * opens another SSH connection via port-forwarded connection */ public SSHConnection OpenPortForwardedAnotherConnection(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, string host, int port) { ProtocolNegotiationHandler pnh = new ProtocolNegotiationHandler(param); ChannelSocket s = new ChannelSocket(pnh); SSHChannel ch = ForwardPort(s, host, port, "localhost", 0); s.SSHChennal = ch; return SSHConnection.Connect(param, receiver, pnh, s); }
protected SSHConnection(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver) { _param = (SSHConnectionParameter)param.Clone(); _eventReceiver = receiver; _channel_entries = new ArrayList(16); _autoDisconnect = true; }
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); } }
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); } }
public object Clone() { SSHConnectionParameter n = new SSHConnectionParameter(); n._authtype = _authtype; n._cipherAlgorithms = _cipherAlgorithms; n._height = _height; n._hostkeyAlgorithms = _hostkeyAlgorithms; n._identityFile = _identityFile; n._keycheck = _keycheck; n._maxpacketsize = _maxpacketsize; n._password = _password; n._protocol = _protocol; n._random = _random; n._terminalname = _terminalname; n._username = _username; n._width = _width; n._windowsize = _windowsize; n._checkMACError = _checkMACError; return n; }