/// <exception cref="WinrtCifs.Smb.SmbException"></exception> /// <exception cref="UnknownHostException"></exception> public static byte[] GetChallenge(UniAddress dc, int port) { SmbTransport trans = SmbTransport.GetSmbTransport(dc, port); trans.Connect(); return(trans.Server.EncryptionKey); }
internal static SmbTransport GetSmbTransport(UniAddress address, int port , IPAddress localAddr, int localPort, string hostName) { lock (typeof(SmbTransport)) { SmbTransport conn; lock (SmbConstants.Connections) { if (SmbConstants.SsnLimit != 1) { conn = SmbConstants.Connections.FirstOrDefault( c => c.Matches(address, port, localAddr, localPort, hostName) && (SmbConstants.SsnLimit == 0 || c.Sessions.Count < SmbConstants.SsnLimit)); if (conn != null) { return(conn); } } conn = new SmbTransport(address, port, localAddr, localPort); SmbConstants.Connections.Insert(0, conn); } return(conn); } }
public override Server creack(string ip, int port, string username, string password, int timeOut) { Server server = new Server(); try { if ("".Equals("空")) { password = ""; } UniAddress ud = UniAddress.GetByName(ip); NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(ip, username, password); SmbConstants.DefaultConnTimeout = timeOut * 1000; SmbConstants.DefaultResponseTimeout = timeOut * 1000; SmbConstants.DefaultSoTimeout = timeOut * 1000; SmbSession.Logon(ud, port, auth);//验证是否能够成功登录 server.isSuccess = true; } catch (SmbAuthException fe) { server.isSuccess = false; } catch (Exception e) { throw e; } return(server); }
internal static SmbTransport GetSmbTransport(UniAddress address, int port , IPAddress localAddr, int localPort, string hostName) { lock (typeof(SmbTransport)) { SmbTransport conn; lock (SmbConstants.Connections) { if (SmbConstants.SsnLimit != 1) { conn = SmbConstants.Connections.FirstOrDefault( c => c.Matches(address, port, localAddr, localPort, hostName) && (SmbConstants.SsnLimit == 0 || c.Sessions.Count < SmbConstants.SsnLimit)); if (conn != null) { return conn; } } conn = new SmbTransport(address, port, localAddr, localPort); SmbConstants.Connections.Insert(0, conn); } return conn; } }
internal static SmbTransport GetSmbTransport(UniAddress address, int port ) { lock (typeof(SmbTransport)) { return GetSmbTransport(address, port, SmbConstants.Laddr, SmbConstants.Lport, null); } }
internal static SmbTransport GetSmbTransport(UniAddress address, int port ) { lock (typeof(SmbTransport)) { return(GetSmbTransport(address, port, SmbConstants.Laddr, SmbConstants.Lport, null)); } }
internal SmbTransport(UniAddress address, int port, IPAddress localAddr, int localPort ) { Server = new ServerData(this); this.Address = address; this.Port = port; this.LocalAddr = localAddr; this.LocalPort = localPort; }
internal SmbTransport(UniAddress address, int port, IPAddress localAddr, int localPort ) { Server = new ServerData(this); this.Address = address; this.Port = port; this.LocalAddr = localAddr; this.LocalPort = localPort; }
internal virtual bool Matches(UniAddress address, int port, IPAddress localAddr, int localPort, string hostName) { if (hostName == null) { hostName = address.GetHostName(); } return((TconHostName == null || Runtime.EqualsIgnoreCase(hostName, TconHostName)) && address.Equals(this.Address) && (port == 0 || port == this.Port || (port == 445 && this.Port == 139)) && (localAddr == this.LocalAddr || (localAddr != null && localAddr.Equals(this.LocalAddr))) && localPort == this.LocalPort); }
internal SmbSession(UniAddress address, int port, IPAddress localAddr, int localPort , NtlmPasswordAuthentication auth) { // Transport parameters allows trans to be removed from CONNECTIONS this._address = address; this._port = port; this._localAddr = localAddr; this._localPort = localPort; this.Auth = auth; Trees = new List <object>(); ConnectionState = 0; }
internal SmbSession(UniAddress address, int port, IPAddress localAddr, int localPort , NtlmPasswordAuthentication auth) { // Transport parameters allows trans to be removed from CONNECTIONS this._address = address; this._port = port; this._localAddr = localAddr; this._localPort = localPort; this.Auth = auth; Trees = new List<object>(); ConnectionState = 0; }
/// <exception cref="WinrtCifs.Smb.SmbException"></exception> public static void Logon(UniAddress dc, int port, NtlmPasswordAuthentication auth ) { SmbTree tree = SmbTransport.GetSmbTransport(dc, port).GetSmbSession(auth).GetSmbTree (LogonShare, null); if (LogonShare == null) { tree.TreeConnect(null, null); } else { Trans2FindFirst2 req = new Trans2FindFirst2("\\", "*", SmbFile.AttrDirectory); Trans2FindFirst2Response resp = new Trans2FindFirst2Response(); tree.Send(req, resp); } }
/// <exception cref="SharpCifs.Smb.SmbAuthException"></exception> public virtual Hashtable GetTrustedDomains(NtlmPasswordAuthentication auth) { if (Disabled || auth.Domain == "?") { return(null); } if (Domains != null && Runtime.CurrentTimeMillis() > Domains.Expiration) { Domains = null; } if (Domains != null) { return(Domains.Map); } try { UniAddress addr = UniAddress.GetByName(auth.Domain, true); SmbTransport trans = SmbTransport.GetSmbTransport(addr, 0); CacheEntry entry = new CacheEntry(Ttl * 10L); DfsReferral dr = trans.GetDfsReferrals(auth, string.Empty, 0); if (dr != null) { DfsReferral start = dr; do { string domain = dr.Server.ToLower(); entry.Map.Put(domain, new Hashtable()); dr = dr.Next; }while (dr != start); Domains = entry; return(Domains.Map); } } catch (IOException ioe) { if (Log.Level >= 3) { Runtime.PrintStackTrace(ioe, Log); } if (StrictView && ioe is SmbAuthException) { throw (SmbAuthException)ioe; } } return(null); }
/// <exception cref="SharpCifs.Smb.SmbAuthException"></exception> public virtual SmbTransport GetDc(string domain, NtlmPasswordAuthentication auth) { if (Disabled) { return(null); } try { UniAddress addr = UniAddress.GetByName(domain, true); SmbTransport trans = SmbTransport.GetSmbTransport(addr, 0); DfsReferral dr = trans.GetDfsReferrals(auth, "\\" + domain, 1); if (dr != null) { DfsReferral start = dr; IOException e = null; do { try { addr = UniAddress.GetByName(dr.Server); return(SmbTransport.GetSmbTransport(addr, 0)); } catch (IOException ioe) { e = ioe; } dr = dr.Next; }while (dr != start); throw e; } } catch (IOException ioe) { if (Log.Level >= 3) { Runtime.PrintStackTrace(ioe, Log); } if (StrictView && ioe is SmbAuthException) { throw (SmbAuthException)ioe; } } return(null); }
// This is NOT best-practice code, just showing a demo Jcifs api call public async Task getFileContents2() { await Task.Run(() => { var lan = new SmbFile("smb://", NtlmPasswordAuthentication.Anonymous); // var workgroups = lan.ListFiles(); UniAddress u = UniAddress.GetByName("ALEXEY-PC"); Button button = FindViewById <Button>(Resource.Id.myButton); RunOnUiThread(() => { button.Text = u.ToString(); }); } ).ContinueWith((Task arg) => { Console.WriteLine(arg.Status); if (arg.Status == TaskStatus.Faulted) { Console.WriteLine(arg.Exception); } } ); }
/// <exception cref="SharpCifs.Smb.SmbException"></exception> private static NtlmChallenge Interrogate(NbtAddress addr) { UniAddress dc = new UniAddress(addr); SmbTransport trans = SmbTransport.GetSmbTransport(dc, 0); if (Username == null) { trans.Connect(); if (SmbTransport.LogStatic.Level >= 3) { SmbTransport.LogStatic.WriteLine("Default credentials (jcifs.smb.client.username/password)" + " not specified. SMB signing may not work propertly." + " Skipping DC interrogation." ); } } else { SmbSession ssn = trans.GetSmbSession(NtlmPasswordAuthentication.Default ); ssn.GetSmbTree(LogonShare, null).TreeConnect(null, null); } return new NtlmChallenge(trans.Server.EncryptionKey, dc); }
/// <exception cref="WinrtCifs.Smb.SmbException"></exception> private static NtlmChallenge Interrogate(NbtAddress addr) { UniAddress dc = new UniAddress(addr); SmbTransport trans = SmbTransport.GetSmbTransport(dc, 0); if (Username == null) { trans.Connect(); if (SmbTransport.LogStatic.Level >= 3) { SmbTransport.LogStatic.WriteLine("Default credentials (jcifs.smb.client.username/password)" + " not specified. SMB signing may not work propertly." + " Skipping DC interrogation." ); } } else { SmbSession ssn = trans.GetSmbSession(NtlmPasswordAuthentication.Default ); ssn.GetSmbTree(LogonShare, null).TreeConnect(null, null); } return(new NtlmChallenge(trans.Server.EncryptionKey, dc)); }
private void RemoveCurrentAddress() { if (AddressIndex >= 1) { UniAddress[] aux = new UniAddress[Addresses.Length - 1]; Array.Copy(Addresses, 1, aux, 0, Addresses.Length - 1); Addresses = aux; AddressIndex--; } }
/// <exception cref="UnknownHostException"></exception> internal virtual UniAddress GetFirstAddress() { AddressIndex = 0; string host = Url.GetHost(); string path = Url.AbsolutePath; string query = Url.GetQuery(); if (Addresses != null && Addresses.Length > 0) { return GetNextAddress(); } if (query != null) { string server = QueryLookup(query, "server"); if (!string.IsNullOrEmpty(server)) { Addresses = new UniAddress[1]; Addresses[0] = UniAddress.GetByName(server); return GetNextAddress(); } string address = QueryLookup(query, "address"); if (!string.IsNullOrEmpty(address)) { byte[] ip = Extensions.GetAddressByName(address).GetAddressBytes(); Addresses = new UniAddress[1]; //addresses[0] = new UniAddress(IPAddress.Parse(host, ip)); Addresses[0] = new UniAddress(IPAddress.Parse(host)); return GetNextAddress(); } } if (host.Length == 0) { try { NbtAddress addr = NbtAddress.GetByName(NbtAddress.MasterBrowserName, 0x01, null); Addresses = new UniAddress[1]; Addresses[0] = UniAddress.GetByName(addr.GetHostAddress()); } catch (UnknownHostException uhe) { NtlmPasswordAuthentication.InitDefaults(); if (NtlmPasswordAuthentication.DefaultDomain.Equals("?")) { throw; } Addresses = UniAddress.GetAllByName(NtlmPasswordAuthentication.DefaultDomain, true ); } } else { if (path.Length == 0 || path.Equals("/")) { Addresses = UniAddress.GetAllByName(host, true); } else { Addresses = UniAddress.GetAllByName(host, false); } } return GetNextAddress(); }
/// <summary> /// Authenticate arbitrary credentials represented by the /// <tt>NtlmPasswordAuthentication</tt> object against the domain controller /// specified by the <tt>UniAddress</tt> parameter. /// </summary> /// <remarks> /// Authenticate arbitrary credentials represented by the /// <tt>NtlmPasswordAuthentication</tt> object against the domain controller /// specified by the <tt>UniAddress</tt> parameter. If the credentials are /// not accepted, an <tt>SmbAuthException</tt> will be thrown. If an error /// occurs an <tt>SmbException</tt> will be thrown. If the credentials are /// valid, the method will return without throwing an exception. See the /// last <a href="../../../faq.html">FAQ</a> question. /// <p> /// See also the <tt>jcifs.smb.client.logonShare</tt> property. /// </remarks> /// <exception cref="SmbException"></exception> public static void Logon(UniAddress dc, NtlmPasswordAuthentication auth) { Logon(dc, -1, auth); }
/// <exception cref="SharpCifs.Smb.SmbException"></exception> public static void Logon(UniAddress dc, int port, NtlmPasswordAuthentication auth ) { SmbTree tree = SmbTransport.GetSmbTransport(dc, port).GetSmbSession(auth).GetSmbTree (LogonShare, null); if (LogonShare == null) { tree.TreeConnect(null, null); } else { Trans2FindFirst2 req = new Trans2FindFirst2("\\", "*", SmbFile.AttrDirectory); Trans2FindFirst2Response resp = new Trans2FindFirst2Response(); tree.Send(req, resp); } }
/// <exception cref="SharpCifs.Smb.SmbException"></exception> /// <exception cref="UnknownHostException"></exception> public static byte[] GetChallenge(UniAddress dc) { return GetChallenge(dc, 0); }
/// <exception cref="SharpCifs.Smb.SmbException"></exception> /// <exception cref="UnknownHostException"></exception> public static byte[] GetChallenge(UniAddress dc, int port) { SmbTransport trans = SmbTransport.GetSmbTransport(dc, port); trans.Connect(); return trans.Server.EncryptionKey; }
internal NtlmChallenge(byte[] challenge, UniAddress dc) { this.Challenge = challenge; this.Dc = dc; }
internal virtual bool Matches(UniAddress address, int port, IPAddress localAddr, int localPort, string hostName) { if (hostName == null) { hostName = address.GetHostName(); } return (TconHostName == null || Runtime.EqualsIgnoreCase(hostName, TconHostName)) && address.Equals(this.Address) && (port == -1 || port == this.Port || (port == 445 && this.Port == 139)) && (localAddr == this.LocalAddr || (localAddr != null && localAddr.Equals(this.LocalAddr))) && localPort == this.LocalPort; }
/// <summary> /// Authenticate arbitrary credentials represented by the /// <tt>NtlmPasswordAuthentication</tt> object against the domain controller /// specified by the <tt>UniAddress</tt> parameter. /// </summary> /// <remarks> /// Authenticate arbitrary credentials represented by the /// <tt>NtlmPasswordAuthentication</tt> object against the domain controller /// specified by the <tt>UniAddress</tt> parameter. If the credentials are /// not accepted, an <tt>SmbAuthException</tt> will be thrown. If an error /// occurs an <tt>SmbException</tt> will be thrown. If the credentials are /// valid, the method will return without throwing an exception. See the /// last <a href="../../../faq.html">FAQ</a> question. /// <p> /// See also the <tt>jcifs.smb.client.logonShare</tt> property. /// </remarks> /// <exception cref="SmbException"></exception> public static void Logon(UniAddress dc, NtlmPasswordAuthentication auth) { Logon(dc, -1, auth); }
internal NtlmChallenge(byte[] challenge, UniAddress dc) { this.Challenge = challenge; this.Dc = dc; }
/// <exception cref="WinrtCifs.Smb.SmbException"></exception> /// <exception cref="UnknownHostException"></exception> public static byte[] GetChallenge(UniAddress dc) { return(GetChallenge(dc, 0)); }