示例#1
0
        public void AthenticateUser()
        {
            string token = "";

            //try getting token from the Header
            IEnumerable <string> values = null;

            try{ values = HttpContext.Current.Request.Headers.GetValues(KeyWords.XAuthToken); }catch {}
            if (values != null)
            {
                try
                {
                    token = values.First();
                }
                catch (Exception e) { }
            }
            //try getting token from cookie in Header
            else
            {
                try
                {
                    IEnumerable <string> cookies = HttpContext.Current.Request.Headers.GetValues("Cookie");
                    string info = KeyWords.CookieToken + "=";
                    foreach (string cookie in cookies)
                    {
                        if (cookie.Contains(info))
                        {
                            string tok = cookie.Split(';').Where((i => i.Contains(info))).First().Trim();
                            token = tok.Remove(tok.IndexOf(info), info.Length);
                        }
                    }
                }
                catch { }
            }
            //try getting token from the URI:
            if (HttpContext.Current.Request.Url != null && String.IsNullOrEmpty(token))
            {
                try
                {
                    NameValueCollection col = HttpContext.Current.Request.Url.ParseQueryString();
                    token = col.Get("token");
                }
                catch { }
            }


            if (!String.IsNullOrEmpty(token))
            {
                try
                {
                    Token = token;
                    var userAccess = Keystone.Authenticate(token);
                    userid      = userAccess.User.Id;
                    user_name   = userAccess.User.Name;
                    IsValidUser = true;
                }
                catch { IsValidUser = false; }
            }
            HasAthenticatedWithActivityInfo = false;
        }
示例#2
0
        private void _asm_Click(object sender, EventArgs e)
        {
            Keystone key = new Keystone(Keystone.ks_arch.KS_ARCH_X86, Keystone.ks_mode.KS_MODE_64);

            Console.WriteLine(_asmBox.Text);
            PS4.WriteMemory(PID, address, key.Assemble(_asmBox.Text, address: address));
        }
示例#3
0
        public void GivenAnInstanceOfKeystoneBuiltForInMode(string p0, string p1)
        {
            var arch = (KeystoneArchitecture)Enum.Parse(typeof(KeystoneArchitecture), $"KS_ARCH_{p0}");
            var mode = (KeystoneMode)Enum.Parse(typeof(KeystoneMode), $"KS_MODE_{p1}");

            var keystone = new Keystone(arch, mode, false);

            ScenarioContext.Current.Add("keystoneInstance", keystone);
        }
示例#4
0
        private void tbAsm_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            ulong.TryParse(tbAddress.Text, NumberStyles.AllowHexSpecifier, System.Globalization.CultureInfo.InvariantCulture, out DisAddr);

            // setup dropdown for options
            // read assembly and output to box
            CurrAss = Keystone.Assemble(tbAsm.Text, DisAddr, ks_opt_value.KS_OPT_SYNTAX_INTEL | ks_opt_value.KS_OPT_SYNTAX_RADIX16);
            string hex = BitConverter.ToString(CurrAss).Replace("-", " ");

            tbAsmOut.Text = hex;
        }
示例#5
0
        /// Upload table
        public HttpResponseMessage uploadTest(ApiController api, string queryType, string positionType, string casjobsMessage)
        {
            try
            {
                IEnumerable <string> values;
                if (api.ControllerContext.Request.Headers.TryGetValues(KeyWords.XAuthToken, out values))
                {
                    // Keystone authentication
                    string token      = values.First();
                    var    userAccess = Keystone.Authenticate(token);

                    Dictionary <String, String> dictionary = api.Request.GetQueryNameValuePairs().ToDictionary(kv => kv.Key, kv => kv.Value, StringComparer.OrdinalIgnoreCase);
                    String query = "";

                    string radiusDefault = "1";// in arcminutes
                    try { radiusDefault = float.Parse(dictionary["radiusDefault"]).ToString(); }
                    catch { }

                    if (dictionary["radecTextarea"] != null)
                    {
                        UploadDataReader up = new UploadDataReader(radiusDefault);
                        query += up.UploadTo(dictionary["radecTextarea"], queryType, dictionary["nearBy"]);
                    }
                    else
                    {
                        var task = api.Request.Content.ReadAsStreamAsync();
                        task.Wait();
                        Stream stream = task.Result;

                        using (UploadDataReader up = new UploadDataReader(new StreamReader(stream), radiusDefault))
                        {
                            query += up.UploadTo(queryType, dictionary["nearBy"]);
                        }
                    }

                    HttpResponseMessage resp = new HttpResponseMessage();
                    query += QueryTools.BuildQuery.buildQuery(queryType, dictionary, positionType);
                    //RunCasjobs run = new RunCasjobs();
                    //resp.Content = new StringContent(run.postCasjobs(query, token, casjobsMessage).Content.ReadAsStringAsync().Result);
                    return(resp);
                }
                else
                {
                    // No authentication (anonymous) // Logg
                    throw new UnauthorizedAccessException("Check the token you are using.");
                }
            }
            catch (Exception exp) {
                throw new Exception("Exception while uploading data to create temp table." + exp.Message);
            }
        }
示例#6
0
        void CodeCave(string[] input)
        {
            InstructionData data  = new InstructionData(_a(stBox.Text));
            InstructionData pData = new InstructionData(data.nAddress);

            string[] GetLines = new string[input.Length + 1];
            bool     l        = true;
            string
                initialJmp = $"jmp 0x{cBox.Text.Replace("0x", "")}",
                over       = null;

            if (data.Length >= 5) //adds nop if instruction is greater than 5 byte length
            {
                for (int i = 0; i < (data.Length - 5); i++)
                {
                    initialJmp += $"\nnop";
                }
            }
            else if (data.Length <= 5) //adds nop to next insrtuction, adds next instruction to bottom of cave
            {
                l = false;
                if (_li.Checked)
                {
                    over = pData.Operation;
                }
                for (int i = 0; i < ((data.Length + pData.Length) - 5); i++)
                {
                    initialJmp += $"\nnop";
                }
            }
            for (int i = 0; i < input.Length; i++)
            {
                GetLines[i] = input[i];
            }
            if (over != null)
            {
                GetLines[GetLines.Length - 1] = l ? $"{over}\njmp 0x{ data.nAddress.ToString("X").Replace("0x", "")}" : $"{over}\njmp 0x{pData.nAddress.ToString("X").Replace("0x", "")}";
            }
            else
            {
                GetLines[GetLines.Length - 1] = l ? $"jmp 0x{data.nAddress.ToString("X").Replace("0x", "")}" : $"jmp 0x{pData.nAddress.ToString("X").Replace("0x", "")}";
            }
            Keystone key = new Keystone(Keystone.ks_arch.KS_ARCH_X86, Keystone.ks_mode.KS_MODE_64);

            PS4.WriteMemory(PID, _a(stBox.Text), key.Assemble(initialJmp, _a(stBox.Text)));
            PS4.WriteMemory(PID, _a(cBox.Text), key.Assemble(string.Join(" \n", GetLines), _a(cBox.Text)));
        }
        // GET api/keystoneauth
        public HttpResponseMessage Get()
        {
            IEnumerable <string> values;

            if (ControllerContext.Request.Headers.TryGetValues("X-Auth-Token", out values))
            {
                // Keystone authentication
                string token      = values.First();
                var    userAccess = Keystone.Authenticate(token);
                return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK, "Keystone authentication"));
            }
            else
            {
                // No authentication (anonymous)
                return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK, "Anonymous"));
            }
        }
示例#8
0
 private void AssembleButton_Click(object sender, EventArgs e)
 {
     using (Keystone keystone = new Keystone(KeystoneArchitecture.KS_ARCH_X86, KeystoneMode.KS_MODE_MIPS64, true))
         this.result = keystone.Assemble(this.AssemblerTextBox.Text, this._address).Buffer;
     this.Close();
 }
示例#9
0
        public UserHistory(Dictionary <string, string> requestDir, Dictionary <string, string> ExtraInfo, HttpRequest Request)
        {
            if (requestDir.Keys.Count == 0)
            {
                throw new ArgumentException("Request has no input parameters.");
            }

            foreach (string key in requestDir.Keys)
            {
                string keyL = key.ToLower();

                if (keyL == "limit")
                {
                    if (!String.IsNullOrEmpty(requestDir[key]))
                    {
                        try { limit = Convert.ToInt64(requestDir[key]); }
                        catch { throw new Exception("The row limit parameter does not have a valid numerical value."); }
                        if (limit <= 0 || limit > Int64.Parse(KeyWords.MaxRows))
                        {
                            throw new Exception("The row limit parameter has to be an integer greater than 0 and smaller than " + Int64.Parse(KeyWords.MaxRows));
                        }
                    }
                }
                if (keyL == "date_low")
                {
                    if (!String.IsNullOrEmpty(requestDir[key]))
                    {
                        try { Time1 = DateTime.Parse(requestDir[key]); }
                        catch { throw new Exception("Lower date limit does not have a valid format"); }
                    }
                }
                if (keyL == "date_high")
                {
                    if (!String.IsNullOrEmpty(requestDir[key]))
                    {
                        try { Time2 = DateTime.Parse(requestDir[key]); }
                        catch { throw new Exception("Upper date limit does not have a valid format"); }
                    }
                }
                if (keyL == "token")
                {
                    try { UriToken = requestDir[key]; }
                    catch {}
                }
                if (keyL == "application")
                {
                    try { Application = requestDir[key]; }
                    catch {}
                }
                if (keyL == "format")
                {
                    try { format = requestDir[key]; }
                    catch {}
                }
                if (keyL == "doshowallhistory")
                {
                    try { DoShowAllHistory = requestDir[key] == "true" ? true : false; }
                    catch { }
                }
                if (keyL == "contentsearchtext")
                {
                    try { ContentSearchText = requestDir[key]; }
                    catch { }
                }
            }

            if (Request.Headers.AllKeys.Contains(KeyWords.XAuthToken))
            {
                HeaderToken = Request.Headers.Get(KeyWords.XAuthToken);
            }

            //Authenticating the Token. Token in header has priority over token in URI
            if (!String.IsNullOrEmpty(HeaderToken))
            {
                try
                {
                    var userAccess = Keystone.Authenticate(HeaderToken);
                    UserID = userAccess.User.Id;
                }
                catch { };
            }
            else if (!String.IsNullOrEmpty(UriToken))
            {
                try
                {
                    var userAccess = Keystone.Authenticate(UriToken);
                    UserID = userAccess.User.Id;
                }
                catch { };
            }
            else
            {
                throw new UnauthorizedAccessException("Unable to find user. Token was not provided.");
            }

            if (String.IsNullOrEmpty(UserID))
            {
                throw new UnauthorizedAccessException("Unable to find user. Token could not be authenticated. Try getting a new token.");
            }

            try
            {
                using (oConn = new SqlConnection(KeyWords.SciserverLogDBconnection))
                {
                    oConn.Open();
                    SqlCommand Cmd = BuildCommand(oConn);
                    query = Cmd.CommandText;
                    Cmd.CommandTimeout = Int32.Parse(KeyWords.DatabaseSearchTimeout);
                    var Adapter = new SqlDataAdapter(Cmd);
                    Adapter.Fill(ResultDataSet);
                    oConn.Close();
                }
            }
            catch { throw; }
            PrepareResultSet(ref ResultDataSet, requestDir);
        }
        public GraywulfPrincipal CreateAuthenticatedPrincipal(Keystone.User user, bool isMasterAuthority)
        {
            // TODO: role logic might be added here

            var identity = new GraywulfIdentity()
            {
                Protocol = Constants.ProtocolNameKeystone,
                AuthorityName = authorityName,
                AuthorityUri = authorityUri.ToString(),
                Identifier = user.ID,
                IsAuthenticated = true,
                IsMasterAuthority = isMasterAuthority,
            };

            // Accept users without the following parameters set but
            // this is not a good practice in general to leave them null
            // in Keystone
            identity.User = new Registry.User()
            {
                Name = user.Name,
                Comments = user.Description ?? String.Empty,
                Email = user.Email ?? String.Empty,
                DeploymentState = user.Enabled.Value ? Registry.DeploymentState.Deployed : Registry.DeploymentState.Undeployed,
            };

            return new GraywulfPrincipal(identity);
        }