コード例 #1
0
        /* goodG2B() - use goodsource and badsink */
        private static void GoodG2B(HttpRequest req, HttpResponse resp)
        {
            string data;

            /* FIX: Set the path as the "system" path */
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                data = "/bin";
            }
            else
            {
                data = "%SystemRoot%\\system32";
            }
            /* serialize data to a byte array */
            byte[] dataSerialized = null;
            try
            {
                BinaryFormatter bf = new BinaryFormatter();
                using (var ms = new MemoryStream())
                {
                    bf.Serialize(ms, data);
                    dataSerialized = ms.ToArray();
                }
                CWE427_Uncontrolled_Search_Path_Element__Get_Cookies_Web_75b.GoodG2BSink(dataSerialized, req, resp);
            }
            catch (SerializationException exceptSerialize)
            {
                IO.Logger.Log(NLog.LogLevel.Warn, "Serialization exception in serialization", exceptSerialize);
            }
        }
コード例 #2
0
        public override void Bad(HttpRequest req, HttpResponse resp)
        {
            string data;

            data = ""; /* initialize data in case there are no cookies */
            /* Read data from cookies */
            {
                HttpCookieCollection cookieSources = req.Cookies;
                if (cookieSources != null)
                {
                    /* POTENTIAL FLAW: Read data from the first cookie value */
                    data = cookieSources[0].Value;
                }
            }
            /* serialize data to a byte array */
            byte[] dataSerialized = null;
            try
            {
                BinaryFormatter bf = new BinaryFormatter();
                using (var ms = new MemoryStream())
                {
                    bf.Serialize(ms, data);
                    dataSerialized = ms.ToArray();
                }
                CWE427_Uncontrolled_Search_Path_Element__Get_Cookies_Web_75b.BadSink(dataSerialized, req, resp);
            }
            catch (SerializationException exceptSerialize)
            {
                IO.Logger.Log(NLog.LogLevel.Warn, "Serialization exception in serialization", exceptSerialize);
            }
        }