예제 #1
0
        public static NetrServerStatisticsGetResponse NetrServerStatisticsGet(ISMBClient client, string serverName, string service, uint level, uint options, out NTStatus status)
        {
            using (RPCCallHelper rpc = new RPCCallHelper(client, ServerService.ServicePipeName, ServerService.ServiceInterfaceGuid, ServerService.ServiceVersion))
            {
                status = rpc.BindPipe();
                if (status != NTStatus.STATUS_SUCCESS)
                {
                    return(null);
                }

                NetrServerStatisticsGetRequest netrServerStatisticsGetRequest = new NetrServerStatisticsGetRequest();
                netrServerStatisticsGetRequest.ServerName = serverName;
                netrServerStatisticsGetRequest.Service    = service;
                netrServerStatisticsGetRequest.Level      = level;
                netrServerStatisticsGetRequest.Options    = options;

                NetrServerStatisticsGetResponse netrServerStatisticsGetResponse;

                status = rpc.ExecuteCall((ushort)ServerServiceOpName.NetrServerStatisticsGet, netrServerStatisticsGetRequest, out netrServerStatisticsGetResponse);
                if (status != NTStatus.STATUS_SUCCESS)
                {
                    return(null);
                }

                return(netrServerStatisticsGetResponse);
            }
        }
예제 #2
0
        public Connection(PathSet pathSet, ParamSet paramSet) : base()
        {
            this.IsConnected = false;

            if (pathSet == null)
            {
                this.AddError("Constructor", "Required pathSet.");

                return;
            }

            this._pathSet = pathSet;
            var argParamSet = (paramSet == null)
                ? new ParamSet()
                : paramSet.Clone();

            if (argParamSet.SmbType == null)
            {
                this._client
                    = this.GetConnection(SmbType.Smb2)
                      ?? this.GetConnection(SmbType.Smb1);
            }
            else if (argParamSet.SmbType == SmbType.Smb2)
            {
                this._client = this.GetConnection(SmbType.Smb2);
            }
            else if (argParamSet.SmbType == SmbType.Smb1)
            {
                this._client = this.GetConnection(SmbType.Smb1);
            }
            else
            {
                this.AddError("Constructor", $"Unexpected ParamSet.SmbType: {argParamSet.SmbType}");

                return;
            }

            if (this._client == null)
            {
                this.AddError("Constructor", "Connection Failed.");

                return;
            }

            if (!this.Login(argParamSet))
            {
                this.AddError("Constructor", "Authentication Failed.");

                return;
            }

            this._paramSet = FixedParamSet.Parse(
                argParamSet,
                (this._client is SMB2Client)
                    ? SmbType.Smb2
                    : SmbType.Smb1
                );

            this.IsConnected = true;
        }
예제 #3
0
        public static DomainControllerInfo DsGetDCNames(ISMBClient client, string ServerName, string DomainName, string SiteName, uint Flags, out NTStatus status)
        {
            using (RPCCallHelper rpc = new RPCCallHelper(client, NetlogonService.ServicePipeName, NetlogonService.ServiceInterfaceGuid, NetlogonService.ServiceVersion))
            {
                status = rpc.BindPipe();
                if (status != NTStatus.STATUS_SUCCESS)
                {
                    return(null);
                }

                DsrGetDcNameRequest getDcNameRequest = new DsrGetDcNameRequest();
                getDcNameRequest.ServerName = ServerName;
                getDcNameRequest.DomainName = DomainName;
                getDcNameRequest.SiteName   = SiteName;
                getDcNameRequest.Flags      = Flags;

                DsrGetDcNameResponse getDcNameResponse;

                status = rpc.ExecuteCall((ushort)NetlogonServiceOpName.DsrGetDcName, getDcNameRequest, out getDcNameResponse);
                if (status != NTStatus.STATUS_SUCCESS)
                {
                    return(null);
                }
                return(new DomainControllerInfo(getDcNameResponse.DCInfo));
            }
        }
예제 #4
0
 public RPCCallHelper(ISMBClient client, string pipeName, Guid interfaceGuid, uint interfaceVersion)
 {
     Client               = client;
     ServicePipeName      = pipeName;
     ServiceInterfaceGuid = interfaceGuid;
     ServiceVersion       = interfaceVersion;
 }
 private SMBConnection(ISMBClientFactory smbClientFactory, IPAddress address, SMBTransportType transport,
                       ISMBCredential credential, int threadId, uint maxBufferSize)
 {
     SMBClient       = smbClientFactory.CreateClient(maxBufferSize);
     _address        = address;
     _transport      = transport;
     _credential     = credential;
     _referenceCount = 1;
     _threadId       = threadId;
 }
예제 #6
0
        public Connection(PathSet pathSet, FixedParamSet paramSet) : base()
        {
            this.IsConnected = false;

            if (pathSet == null)
            {
                this.AddError("Constructor", "Required pathSet.");

                return;
            }

            if (paramSet == null)
            {
                this.AddError("Constructor", "Required paramSet.");

                return;
            }

            this._pathSet = pathSet;

            if (paramSet.SmbType == SmbType.Smb2)
            {
                this._client = this.GetConnection(SmbType.Smb2);
            }
            else if (paramSet.SmbType == SmbType.Smb1)
            {
                this._client = this.GetConnection(SmbType.Smb1);
            }
            else
            {
                this.AddError("Constructor", $"Unexpected ParamSet.SmbType: {paramSet.SmbType}");

                return;
            }

            if (this._client == null)
            {
                this.AddError("Constructor", "Connection Failed.");

                return;
            }

            if (!this.Login(paramSet))
            {
                this.AddError("Constructor", "Authentication Failed.");

                return;
            }

            this._paramSet = paramSet;

            this.IsConnected = true;
        }
예제 #7
0
        public Connection(Node node) : base()
        {
            this.IsConnected = false;

            if (node == null)
            {
                this.AddError("Constructor", "Required node.");

                return;
            }

            if (node.ParamSet == null || node.PathSet == null)
            {
                this.AddError("Constructor", "Invalid Node.");

                return;
            }

            this._pathSet = node.PathSet;

            if (node.ParamSet.SmbType == SmbType.Smb2)
            {
                this._client = this.GetConnection(SmbType.Smb2);
            }
            else if (node.ParamSet.SmbType == SmbType.Smb1)
            {
                this._client = this.GetConnection(SmbType.Smb1);
            }
            else
            {
                this.AddError("Constructor", $"Unexpected ParamSet.SmbType: {node.ParamSet.SmbType}");

                return;
            }

            if (this._client == null)
            {
                this.AddError("Constructor", "Connection Failed.");

                return;
            }

            if (!this.Login(node.ParamSet))
            {
                this.AddError("Constructor", "Authentication Failed.");

                return;
            }

            this._paramSet = node.ParamSet;

            this.IsConnected = true;
        }
예제 #8
0
        public static IShare Get(ISMBClient client, string share)
        {
            if (client is SMB2Client)
            {
                return(new Smb2Share(client, share));
            }
            if (client is SMB1Client)
            {
                return(new Smb1Share(client, share));
            }

            // Returns Smb2Share object that holds the error.
            return(new Smb2Share(null, share));
        }
예제 #9
0
        public static List <SID> ResolveNames(ISMBClient client, List <string> names, out NTStatus status)
        {
            List <SID> output = null;

            using (RPCCallHelper rpc = new RPCCallHelper(client, LsaRemoteService.ServicePipeName, LsaRemoteService.ServiceInterfaceGuid, LsaRemoteService.ServiceVersion))
            {
                status = rpc.BindPipe();
                if (status != NTStatus.STATUS_SUCCESS)
                {
                    return(null);
                }

                LsaHandle handle = LsaOpenPolicy(rpc, (AccessMask)0x801, out status);
                if (handle != null)
                {
                    output = LsaLookupNames(rpc, handle, names, out status);

                    LsaClose(rpc, handle, out status);
                }
            }
            return(output);
        }
예제 #10
0
파일: ShareBase.cs 프로젝트: ume05rw/EzSmb
        public ShareBase(ISMBClient client, string name)
        {
            this.IsConnected = false;
            this._name       = name;

            if (client == null)
            {
                this.AddError("Constructor", "Required client.");

                return;
            }

            if (string.IsNullOrEmpty(name))
            {
                this.AddError("Constructor", "Required name.");

                return;
            }

            this._store      = client.TreeConnect(name, out var status);
            this.IsConnected = (status == NTStatus.STATUS_SUCCESS);
        }
예제 #11
0
        protected override void Dispose(bool disposing)
        {
            if (!this.disposedValue)
            {
                if (disposing)
                {
                    try
                    {
                        this._client?.Disconnect();
                    }
                    catch (Exception)
                    {
                    }

                    this._pathSet  = null;
                    this._paramSet = null;
                    this._client   = null;
                }

                this.disposedValue = true;
            }

            base.Dispose(disposing);
        }
예제 #12
0
        public static DateTime NetrRemoteTOD(ISMBClient client, string ServerName, out NTStatus status)
        {
            using (RPCCallHelper rpc = new RPCCallHelper(client, ServerService.ServicePipeName, ServerService.ServiceInterfaceGuid, ServerService.ServiceVersion))
            {
                status = rpc.BindPipe();
                if (status != NTStatus.STATUS_SUCCESS)
                {
                    return(DateTime.MinValue);
                }

                NetrRemoteTODRequest netrRemoteTODRequest = new NetrRemoteTODRequest();
                netrRemoteTODRequest.ServerName = ServerName;

                NetrRemoteTODResponse netrRemoteTODResponse;

                status = rpc.ExecuteCall((ushort)ServerServiceOpName.NetrRemoteTOD, netrRemoteTODRequest, out netrRemoteTODResponse);
                if (status != NTStatus.STATUS_SUCCESS)
                {
                    return(DateTime.MinValue);
                }

                return(netrRemoteTODResponse.TimeOfDayInfo.ToDateTime());
            }
        }
예제 #13
0
파일: Smb2Share.cs 프로젝트: ume05rw/EzSmb
 public Smb2Share(ISMBClient client, string share) : base(client, share)
 {
 }