Exemplo n.º 1
0
        void _remove()
        {
            var credential   = default(KeyValuePair <string, TokenAccess>);
            var currentToken = _getCurrentToken();

            if (_isMobile())
            {
                credential = _credentials
                             .FirstOrDefault(c => c.Value.Token == currentToken && c.Value.IsMobile);
                if (!_isAvoid(credential))
                {
                    _tryRemove(credential.Value.Token);
                }
                else
                {
                    credential = _credentials.FirstOrDefault(c => c.Value.Token == currentToken);
                    _tryRemove(credential.Value.Token);
                }
            }
            else
            {
                var currentIp = _getCurrentIp();
                credential = _credentials.FirstOrDefault(c => c.Value.Token == currentToken && c.Key == currentIp);
                if (!_isAvoid(credential))
                {
                    _tryRemove(credential.Value.Token);
                }
                else
                {
                    TokenAccess aux = null;
                    _credentials.TryRemove(currentIp, out aux);
                }
            }
        }
Exemplo n.º 2
0
        static async Task getAccessToken()
        {
            string toHash = reqtoken + privateKey;

            using (SHA1Cng sha = new SHA1Cng())
            {
                var hash = sha.ComputeHash(Encoding.UTF8.GetBytes(toHash));
                var sb   = new StringBuilder(hash.Length * 2);
                foreach (byte b in hash)
                {
                    sb.Append(b.ToString("x2"));
                }
                password = sb.ToString();
            };
            TokenAccess         acc      = null;
            HttpResponseMessage response = await client.GetAsync(
                $"oauth/accesstoken?oauth_token={reqtoken}&grant_type=api&username={username}&password={password}");

            if (response.IsSuccessStatusCode)
            {
                acc = await response.Content.ReadAsAsync <TokenAccess>();

                acctoken = acc.AccessToken;
            }
        }
Exemplo n.º 3
0
 public static extern bool DuplicateTokenEx(
     IntPtr hExistingToken,
     TokenAccess dwDesiredAccess,
     SecurityAttributes lpThreadAttributes,
     SecurityImpersonationLevel impersonationLevel,
     TokenType dwTokenType,
     out IntPtr phNewToken);
Exemplo n.º 4
0
 public extern static bool DuplicateTokenEx(
     IntPtr hExistingToken,
     TokenAccess dwDesiredAccess,
     IntPtr lpTokenAttributes,
     SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
     TOKEN_TYPE TokenType,
     out IntPtr phNewToken);
Exemplo n.º 5
0
 public extern static bool DuplicateTokenEx(
     IntPtr hExistingToken,
     TokenAccess dwDesiredAccess,
     //uint dwDesiredAccess,
     ref SECURITY_ATTRIBUTES lpTokenAttributes,
     SecurityImpersonationLevel ImpersonationLevel,
     TokenType TokenType,
     out IntPtr phNewToken);
Exemplo n.º 6
0
 public ElevPriv(string[] privs, HPROCESS hProc = default, TokenAccess access = TokenAccess.TOKEN_ADJUST_PRIVILEGES | TokenAccess.TOKEN_QUERY)
 {
     if (hProc.IsNull)
     {
         hProc = GetCurrentProcess();
     }
     tok = SafeHTOKEN.FromProcess(hProc, access);
     ElevatePrivileges(privs);
 }
Exemplo n.º 7
0
        void _tryRemove(string token)
        {
            var credential = _credentials.FirstOrDefault(c => c.Value.Token == token);

            if (!_isAvoid(credential))
            {
                TokenAccess aux = null;
                _credentials.TryRemove(credential.Key, out aux);
            }
        }
Exemplo n.º 8
0
 public bool IsValidToken(TokenAccess _token)
 {
     for (int i = 0; i < tokens.Count; i++)
     {
         if (tokens[i].token == _token.token && tokens[i].id_idx == _token.id_idx && tokens[i].hero_order == _token.hero_order)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 9
0
        public static TokenHandle OpenProcessToken(IntPtr hProcess, TokenAccess desiredAccess)
        {
            TokenHandle ret;
            bool        success = OpenProcessToken(hProcess, (int)desiredAccess, out ret);

            if (!success)
            {
                throw new Win32Exception();
            }
            return(ret);
        }
Exemplo n.º 10
0
        public int KphOpenProcessToken(ProcessHandle processHandle, TokenAccess desiredAccess)
        {
            byte *inData  = stackalloc byte[8];
            byte *outData = stackalloc byte[4];

            *(int *)inData        = processHandle;
            *(uint *)(inData + 4) = (uint)desiredAccess;

            _fileHandle.IoControl(CtlCode(Control.KphOpenProcessToken), inData, 8, outData, 4);

            return(*(int *)outData);
        }
Exemplo n.º 11
0
        public IntPtr KphOpenProcessToken(ProcessHandle processHandle, TokenAccess desiredAccess)
        {
            KphOpenProcessTokenInput input;
            IntPtr tokenHandle;

            input.ProcessHandle = processHandle;
            input.DesiredAccess = (int)desiredAccess;
            input.TokenHandle   = &tokenHandle;
            _fileHandle.IoControl(IoCtlOpenProcessToken, &input, sizeof(KphOpenProcessTokenInput), null, 0);

            return(tokenHandle);
        }
Exemplo n.º 12
0
        public static TokenHandle DuplicateTokenEx(TokenHandle hExistingToken, TokenAccess desiredAccess,
                                                   SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType)
        {
            TokenHandle ret;
            bool        result = DuplicateTokenEx(hExistingToken, (uint)desiredAccess, IntPtr.Zero, ImpersonationLevel, TokenType, out ret);

            if (!result)
            {
                throw new Win32Exception();
            }
            return(ret);
        }
Exemplo n.º 13
0
        public IntPtr KphOpenProcessJob(ProcessHandle processHandle, TokenAccess desiredAccess)
        {
            KphOpenProcessJobInput input;
            IntPtr jobHandle;

            input.ProcessHandle = processHandle;
            input.DesiredAccess = (int)desiredAccess;
            input.JobHandle     = &jobHandle;
            _fileHandle.IoControl(IoCtlOpenProcessJob, &input, sizeof(KphOpenProcessJobInput), null, 0);

            return(jobHandle);
        }
Exemplo n.º 14
0
        private AuthorizationType _getAuthorizationType(UserInfoViewModel userInfoModel)
        {
            var authorizeToken    = new TokenAccess();
            var encodedJwt        = authorizeToken.CreateTokenAccess(userInfoModel);
            var authorizationType = new AuthorizationType
            {
                userModel    = userInfoModel,
                access_token = encodedJwt,
            };

            return(authorizationType);
        }
Exemplo n.º 15
0
        public ActionResult <TokenAccess> CreateTokenAccess([FromForm] string key)
        {
            var  item       = context.payments.Where(w => w.Key == key.ToString()).FirstOrDefault();
            var  access     = context.TokenAccesss.Where(w => w.Key == key.ToString());
            int  count      = access.Count();
            bool haveSerial = false;

            if (item.MaxUsed <= count)
            {
                return(BadRequest("Maximum used key are " + item.MaxUsed));
            }
            else
            {
                // Get Serial Number
                ManagementClass            mangnmt = new ManagementClass("Win32_LogicalDisk");
                ManagementObjectCollection mcol    = mangnmt.GetInstances();
                string result = "";
                foreach (ManagementObject strt in mcol)
                {
                    result += Convert.ToString(strt["VolumeSerialNumber"]);
                }

                foreach (var a in access.ToList())
                {
                    if (a.SerialNumber == result)
                    {
                        haveSerial = true;
                        break;
                    }
                }

                if (haveSerial == true)
                {
                    access.FirstOrDefault().Created_At = DateTime.Now;
                }
                else
                {
                    TokenAccess tok = new TokenAccess();
                    tok.PaymentId    = item.Id;
                    tok.Key          = key;
                    tok.SerialNumber = result;
                    tok.Created_At   = DateTime.Now;
                    context.Add(tok);
                }

                context.SaveChanges();

                return(Ok("Success TokenAccess" + result));
            }
        }
Exemplo n.º 16
0
        private string GetTokenSensedia()
        {
            TokenAccess token = _tokenCache.Get(_sensediaKey);

            if (token == null)
            {
                token = GetAcessTokenSensediaInternal();
                if (token != null)
                {
                    _tokenCache.Add(_sensediaKey, token, TimeSpan.FromSeconds(token.expires_in));
                }
            }

            return(token?.access_token);
        }
Exemplo n.º 17
0
 void Update()
 {
     if (tokenAccess == TokenAccess.BeginAttempt)
     {
         if (token.Length > 0 && state.Length > 0)
         {
             this.gameObject.SendMessageUpwards("SuccessFacebookLink");
             tokenAccess = TokenAccess.Success;
         }
         else if ((Time.timeSinceLevelLoad - time) % 60 > 5)
         {
             this.gameObject.SendMessageUpwards("FailedFacebookLink");
             tokenAccess = TokenAccess.Failed;
         }
     }
 }
Exemplo n.º 18
0
        public ElevPriv(string priv, HPROCESS hProc = default, TokenAccess access = TokenAccess.TOKEN_ADJUST_PRIVILEGES | TokenAccess.TOKEN_QUERY)
        {
            if (hProc.IsNull)
            {
                hProc = GetCurrentProcess();
            }
            tok = SafeHTOKEN.FromProcess(hProc, access);
            var newPriv = new PTOKEN_PRIVILEGES(LUID.FromName(priv), PrivilegeAttributes.SE_PRIVILEGE_ENABLED);

            prevState = PTOKEN_PRIVILEGES.GetAllocatedAndEmptyInstance();
            if (!AdjustTokenPrivileges(tok, false, newPriv, (uint)prevState.Size, prevState, out var retLen))
            {
                Win32Error.ThrowLastError();
            }
            prevState.Size = (int)retLen;
        }
Exemplo n.º 19
0
        public static bool OpenProcessToken(IntPtr ProcessHandle, TokenAccess Access, out IntPtr TokenHandle, [CallerMemberName] string callerName = "")
        {
            if (!PInvokeDebugger.LoggingEnabled)
            {
                return(PInvoke_OpenProcessToken(ProcessHandle, Access, out TokenHandle));
            }

            bool             returnValue = PInvoke_OpenProcessToken(ProcessHandle, Access, out TokenHandle);
            PInvokeDebugInfo debugInfo   = PInvokeDebugInfo.TraceDebugInfo(
                ModuleName,
                nameof(OpenProcessToken),
                callerName,
                returnValue,
                false,
                nameof(ProcessHandle), ProcessHandle,
                nameof(Access), Access,
                nameof(TokenHandle), TokenHandle
                );

            PInvokeDebugger.SafeCapture(debugInfo);
            return(returnValue);
        }
 internal static extern bool OpenProcessToken(IntPtr ProcessToken, TokenAccess DesiredAccess, IntPtr* TokenHandle);
Exemplo n.º 21
0
 public extern static Boolean DuplicateTokenEx(IntPtr existingTokenHandle, TokenAccess desiredAccess, IntPtr tokenAttributes, SECURITY_IMPERSONATION_LEVEL impersonationLevel, TOKEN_TYPE tokenType, out IntPtr newTokenHandle);
Exemplo n.º 22
0
 public static extern Boolean OpenProcessToken(IntPtr processHandle, TokenAccess desiredAccess, out IntPtr tokenHandle);
Exemplo n.º 23
0
 public static extern bool OpenThreadToken(
     IntPtr hThread,
     TokenAccess dwDesiredAccess,
     [MarshalAs(UnmanagedType.Bool)]
     bool bOpenAsSelf,
     out IntPtr phToken);
Exemplo n.º 24
0
 public TokenHandle GetToken(TokenAccess access)
 {
     return this.GetToken();
 }
Exemplo n.º 25
0
 public static extern bool OpenThreadToken([In] HTHREAD ThreadHandle, TokenAccess DesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool OpenAsSelf, out SafeHTOKEN TokenHandle);
Exemplo n.º 26
0
 static extern bool DuplicateTokenEx(IntPtr hExistingToken, TokenAccess dwDesiredAccess, ref SECURITY_ATTRIBUTES lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out IntPtr phNewToken);
Exemplo n.º 27
0
 public TokenHandle GetToken(TokenAccess access)
 {
     return new TokenHandle(this.GetHandle((int)access), true);
 }
Exemplo n.º 28
0
        public IntPtr KphOpenProcessJob(ProcessHandle processHandle, TokenAccess desiredAccess)
        {
            KphOpenProcessJobInput input;
            IntPtr jobHandle;

            input.ProcessHandle = processHandle;
            input.DesiredAccess = (int)desiredAccess;
            input.JobHandle = &jobHandle;
            _fileHandle.IoControl(IoCtlOpenProcessJob, &input, sizeof(KphOpenProcessJobInput), null, 0);

            return jobHandle;
        }
Exemplo n.º 29
0
 public ElevPriv(string priv, HPROCESS hProc = default, TokenAccess access = TokenAccess.TOKEN_ADJUST_PRIVILEGES | TokenAccess.TOKEN_QUERY) :
     this(new[] { priv }, hProc, access)
 {
 }
Exemplo n.º 30
0
 public static extern bool OpenProcessToken([In] IntPtr ProcessHandle, TokenAccess DesiredAccess, out IntPtr TokenHandle);
Exemplo n.º 31
0
 public static extern bool OpenProcessToken(
     IntPtr processHandle, // handle to process
     TokenAccess desiredAccess, // desired access to process
     ref IntPtr tokenHandle // handle to open access token
 );
Exemplo n.º 32
0
 public void InsertToken(TokenAccess _token)
 {
     tokens.Add(_token);
 }
Exemplo n.º 33
0
 void Update()
 {
     if (tokenAccess == TokenAccess.BeginAttempt)
     {
         if (token.Length > 0 && state.Length > 0)
         {
             this.gameObject.SendMessageUpwards("SuccessFacebookLink");
             tokenAccess = TokenAccess.Success;
         }
         else if ((Time.timeSinceLevelLoad - time) % 60 > 5)
         {
             this.gameObject.SendMessageUpwards("FailedFacebookLink");
             tokenAccess = TokenAccess.Failed;
         }
     }
 }
Exemplo n.º 34
0
 public static extern bool OpenProcessToken([In] HPROCESS ProcessHandle, TokenAccess DesiredAccess, out SafeHTOKEN TokenHandle);
Exemplo n.º 35
0
        public int KphOpenProcessToken(ProcessHandle processHandle, TokenAccess desiredAccess)
        {
            byte* inData = stackalloc byte[8];
            byte* outData = stackalloc byte[4];

            *(int*)inData = processHandle;
            *(uint*)(inData + 4) = (uint)desiredAccess;

            _fileHandle.IoControl(CtlCode(Control.KphOpenProcessToken), inData, 8, outData, 4);

            return *(int*)outData;
        }
Exemplo n.º 36
0
 public static extern bool DuplicateTokenEx(
     IntPtr hExistingToken,
     TokenAccess dwDesiredAccess,
     SecurityAttributes lpThreadAttributes,
     SecurityImpersonationLevel impersonationLevel,
     TokenType dwTokenType,
     out IntPtr phNewToken);
 public TokenHandle GetToken(TokenAccess access)
 {
     return(new TokenHandle(this.GetHandle((int)access), true));
 }
Exemplo n.º 38
0
 public TokenHandle GetToken(TokenAccess access)
 {
     return(this.GetToken());
 }
Exemplo n.º 39
0
 internal static extern bool OpenProcessToken(IntPtr ProcessHandle, TokenAccess DesiredAccess, out IntPtr TokenHandle);
Exemplo n.º 40
0
 public static extern bool OpenProcessToken(
     IntPtr processHandle,      // handle to process
     TokenAccess desiredAccess, // desired access to process
     ref IntPtr tokenHandle     // handle to open access token
     );
Exemplo n.º 41
0
        public IntPtr KphOpenProcessToken(ProcessHandle processHandle, TokenAccess desiredAccess)
        {
            KphOpenProcessTokenInput input;
            IntPtr tokenHandle;

            input.ProcessHandle = processHandle;
            input.DesiredAccess = (int)desiredAccess;
            input.TokenHandle = &tokenHandle;
            _fileHandle.IoControl(IoCtlOpenProcessToken, &input, sizeof(KphOpenProcessTokenInput), null, 0);

            return tokenHandle;
        }