Пример #1
0
        public async Task <bool> AddVulnerabilityAsync(OSSIndexVulnerability v)
        {
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(@"https://ossindex.net/");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("user-agent", "vbot");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", this.Credentials);
                ServicePointManager.ServerCertificateValidationCallback += (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) =>
                {
                    //logger.Debug("Certificate details for host:\nIssuer: {0}\nSubject: {1}\nPublic key: {2}", certificate.Issuer, certificate.Subject, certificate.GetPublicKeyString());
                    return(true);
                };
                HttpResponseMessage response = await client.PostAsync(this.Url,
                                                                      new StringContent(JsonConvert.SerializeObject(v), Encoding.UTF8, "application/json"));

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }
                else
                {
                    logger.Info("Did not receive success status code from server. Server returned: {0}. Reason phrase: {1}", response.StatusCode, response.ReasonPhrase);
                    return(false);
                }
            }
        }
Пример #2
0
 public static void PrintAllVulnerabilities()
 {
     if (!Environment.IsOpened)
     {
         Environment.MapSize = 2L * 1024L * 1024L * 1024L;
         Environment.Open(EnvironmentOpenFlags.None);
     }
     using (LightningTransaction tx = Environment.BeginTransaction(TransactionBeginFlags.ReadOnly))
     {
         LightningDatabase db = tx.OpenDatabase();
         using (LightningCursor cursor = tx.CreateCursor(db))
         {
             foreach (KeyValuePair <byte[], byte[]> r in cursor)
             {
                 string id = Encoding.UTF8.GetString(r.Key);
                 OSSIndexVulnerability v = JsonConvert.DeserializeObject <OSSIndexVulnerability>(Encoding.UTF8.GetString(r.Value));
                 logger.Info("Id: {0}), Package: {1}, CVEs: {2}", id, v.Name, string.Join(" ", v.CVEs));
             }
         }
     }
 }
Пример #3
0
 public static bool GetVulnerability(string id, out OSSIndexVulnerability v)
 {
     if (!Environment.IsOpened)
     {
         Environment.MapSize = 2L * 1024L * 1024L * 1024L;
         Environment.Open(EnvironmentOpenFlags.None);
     }
     using (LightningTransaction tx = Environment.BeginTransaction(TransactionBeginFlags.ReadOnly))
     {
         LightningDatabase db  = tx.OpenDatabase();
         byte[]            ret = null;
         if (!tx.TryGet(db, Encoding.UTF8.GetBytes(id), out ret))
         {
             v = null;
             return(false);
         }
         else
         {
             v = JsonConvert.DeserializeObject <OSSIndexVulnerability>(Encoding.UTF8.GetString(ret));
             return(true);
         }
     }
 }
Пример #4
0
 public bool EqualValues(OSSIndexVulnerability r)
 {
     return(JsonConvert.SerializeObject(this) == JsonConvert.SerializeObject(r));
 }