Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
            // ProcessDirectory("C");
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            string dir;

            //     DialogResult result = fbd.ShowDialog();
            if (fbd.ShowDialog() == DialogResult.OK)
            {
                //   dir = .SelectedPath;
                dir = fbd.SelectedPath;
                ProcessDirectory(dir);
            }

            swMalewares.Close();
            swNormals.Close();
            swExceptions.Close();
            StreamWriter finalOutput = new StreamWriter("final.csv");

            finalOutput.WriteLine("link name" + "," + "viruses");
            foreach (KeyValuePair <string, MalwareReport> entry in scannedItems)
            {
                MalwareReport rep = entry.Value;

                finalOutput.WriteLine(entry.Key + "," + rep.getPerInf());
                int k = 0;
                for (k = 0; k < rep.getInf().Count(); k++)
                {
                    finalOutput.Write("," + rep.getInf()[k]);
                }

                finalOutput.WriteLine();
            }

            finalOutput.Flush();
            finalOutput.Close();
            StreamWriter finalOutput1 = new StreamWriter("final1.csv");

            finalOutput1.WriteLine("link name" + "," + "unrated");
            foreach (KeyValuePair <string, MalwareReport> entry in scannedItems)
            {
                MalwareReport rep = entry.Value;
                finalOutput1.WriteLine(entry.Key + "," + rep.getPerUnr());

                int k = 0;
                for (k = 0; k < rep.getunrated().Count(); k++)
                {
                    finalOutput.Write("," + rep.getunrated()[k]);
                }
                finalOutput.WriteLine();
            }
            finalOutput1.Flush();
            finalOutput1.Close();
            MessageBox.Show("Done");
        }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            Stream         myStream        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            string         result2         = "";

            openFileDialog1.InitialDirectory = "C:\\Users\\ialsmadi\\Desktop\\Malware\\SQL_Injection_Projects\\Main\\SQL_Injection-master\\SQL_Injection-master\\SQL注入\\bin\\Debug";
            openFileDialog1.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                inputFilename = openFileDialog1.FileName;
                //    string path = @"C:\Users\ialsmadi\Desktop\Malware\";
                result2 = Path.GetFileNameWithoutExtension(inputFilename);
                string malwares   = "maleware" + result2 + ".csv";
                string exceptions = "exceptions" + result2 + ".csv";
                string normals    = "normals" + result2 + ".csv";
                swMalewares  = new StreamWriter(malwares);
                swExceptions = new StreamWriter(exceptions);
                swNormals    = new StreamWriter(normals);
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        ProcessDirectory1(openFileDialog1.FileName);
                    }
                }
                catch (Exception ex)
                {
                }
            }

            swMalewares.Close();
            swNormals.Close();
            swExceptions.Close();

            string       final       = "final" + result2 + ".csv";
            StreamWriter finalOutput = new StreamWriter(final);

            finalOutput.WriteLine("link name" + "," + "Websites that decalre this link as malecious");
            foreach (KeyValuePair <string, MalwareReport> entry in scannedItems)
            {
                //    finalOutput.WriteLine(entry.Key + "," + entry.Value);

                MalwareReport rep = entry.Value;
                finalOutput.WriteLine(entry.Key + "," + rep.getPerInf());
                int k = 0;
                for (k = 0; k < rep.getInf().Count; k++)
                {
                    finalOutput.Write("," + rep.getInf()[k]);
                }

                finalOutput.WriteLine();
            }
            finalOutput.Flush();
            finalOutput.Close();
            string       final1       = "final_unrated" + result2 + ".csv";
            StreamWriter finalOutput1 = new StreamWriter(final1);

            finalOutput1.WriteLine("link name" + "," + "Websites that decalre this link as unrated");
            foreach (KeyValuePair <string, MalwareReport> entry in scannedItems)
            {
                //    finalOutput.WriteLine(entry.Key + "," + entry.Value);

                MalwareReport rep = entry.Value;
                finalOutput1.WriteLine(entry.Key + "," + rep.getPerUnr());
                int k = 0;
                for (k = 0; k < rep.getunrated().Count; k++)
                {
                    finalOutput1.Write("," + rep.getunrated()[k]);
                }

                finalOutput1.WriteLine();
            }
            finalOutput1.Flush();
            finalOutput1.Close();
            MessageBox.Show("Done");
        }
Ejemplo n.º 3
0
        public void ProcessDirectory1(string targetFile)
        {
            List <string> lines = new List <string>();

            // 2
            // Use using StreamReader for disposing.
            using (StreamReader r = new StreamReader(targetFile))
            {
                // 3
                // Use while != null pattern for loop
                string line;
                while ((line = r.ReadLine()) != null)
                {
                    // 4
                    // Insert logic here.
                    // ...
                    // "line" is a line in the file. Add it to our List.
                    lines.Add(line);
                    extract(line);
                    try
                    {
                        foreach (LinkItem line1 in LinkFinder.Find(line))
                        {
                            extract(line1.Text);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            swExceptions.Flush();
            swMalewares.Flush();
            swNormals.Flush();
            string       final       = "final_infected" + inputFilename + ".csv";
            string       final1      = "final_unrated" + inputFilename + ".csv";
            StreamWriter finalOutput = new StreamWriter(final);

            finalOutput.WriteLine("link name" + "," + "Websites that decalre this link as malecious");
            foreach (KeyValuePair <string, MalwareReport> entry in scannedItems)
            {
                //  finalOutput.WriteLine(entry.Key + "," + entry.Value);

                MalwareReport rep = entry.Value;
                finalOutput.WriteLine(entry.Key + "," + rep.getPerInf());
                int k = 0;
                for (k = 0; k < rep.getInf().Count; k++)
                {
                    finalOutput.Write("," + rep.getInf()[k]);
                }

                finalOutput.WriteLine();
            }
            StreamWriter finalOutput1 = new StreamWriter(final1);

            finalOutput.WriteLine("link name" + "," + "Websites that decalre this link as unrated");
            foreach (KeyValuePair <string, MalwareReport> entry in scannedItems)
            {
                //  finalOutput.WriteLine(entry.Key + "," + entry.Value);

                MalwareReport rep = entry.Value;
                finalOutput1.WriteLine(entry.Key + "," + rep.getPerUnr());

                int k = 0;
                for (k = 0; k < rep.getunrated().Count; k++)
                {
                    finalOutput1.Write("," + rep.getunrated()[k]);
                }

                finalOutput1.WriteLine();
            }
            MessageBox.Show("Done");
            // Recurse into subdirectories of this directory.

            /*       string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
             *     foreach (string subdirectory in subdirectoryEntries)
             *     {
             *         ProcessDirectory(subdirectory);
             *         swExceptions.Flush();
             *         swMalewares.Flush();
             *         swNormals.Flush();
             *     }
             */
        }
Ejemplo n.º 4
0
        private bool scanLink1(String fileName) // true - File is virus
        {
            string        viruses = "";
            bool          test    = false;
            MalwareReport rep;
            string        r        = string.Empty;
            List <string> clean    = new List <string>();
            List <string> infected = new List <string>();
            double        clenct   = 0.0;
            List <string> unrated  = new List <string>();
            //string infected = "";
            //double clenct = 0.0;
            double unratedct = 0.0;
            double infcount  = 0.0;
            double tot       = 0.0;

            if (scannedItems.ContainsKey(fileName))
            {
                return(false);                                                                          // Already scanned this file so just skip it...
            }
            var    data  = string.Format("resource={0}&key={1}", GetMD5HashFromFile(fileName), apiKey); // MD5 and API Key to send
            var    c     = new WebClient();                                                             // WebClient used for connection to API
            var    data1 = fileName;
            string s     = c.UploadString(results1, "POST", data1);                                     // Connect to the API and POST the data

            try
            {
                JObject o = JObject.Parse(s);
                viruses = "";
                foreach (JProperty jp in o["report"].Last)
                {
                    tot++;
                    string value = jp.Value.ToString();
                    if (value.Contains("clean"))
                    {
                        clean.Add(jp.Name);
                        clenct++;
                    }
                    else if (value.Contains("unrated"))
                    {
                        unrated.Add(jp.Name);
                        unratedct++;
                    }
                    else
                    {
                        infected.Add(jp.Name);
                        infcount++;
                    }
                    // this.results += jp.Name + "," + jp.First + "\n";
                }

                double infPer = infcount / tot;
                double unrper = unratedct / tot;
                rep = new MalwareReport(infected, clean, unrated, infPer, unrper);
            }
            catch (Exception ex)
            {
                return(test);
            }
            scannedItems.Add(fileName, rep);
            return(test);

            /* var r = ParseJSON(s); // Parse the response
             * string tests = "";
             * int nonBlank = 0; // If a line is blank, it is safe, numerous non-blanks = multiple virus confirmations
             * foreach (string str in r.Values) // Cycle through response lines
             * {
             *   //  if (Regex.Replace(str, @"\s+", "") != "") nonBlank++; // Count positive results (non-blank lines)
             *   //MessageBox.Show(str);
             *   tests += r.Values;
             * }
             *
             * //   scannedItems.Add(fileName, nonBlank >= 20); // Say this item was scanned and store the result
             * scannedItems.Add(fileName, tests); // Say this item was scanned and store the result
             * return scannedItems[fileName]; // Return final scan result */
        }
Ejemplo n.º 5
0
        public MalwareReport getURLScanReport(string nResource, bool autoScan)
        {
            MalwareReport rep;
            string        r            = string.Empty;
            List <string> clean        = new List <string>();
            List <string> unrated      = new List <string>();
            List <string> infected     = new List <string>();
            double        clenct       = 0.0;
            double        unratedct    = 0.0;
            double        infcount     = 0.0;
            double        tot          = 0.0;
            Random        random       = new Random();
            int           randomNumber = random.Next(10, 1000);

            if (autoScan)
            {
                r = this.httpPost("https://www.virustotal.com/api/get_url_report.json", "resource=" + nResource + "&key=" + this.apiKey + "&scan=1");
                System.Threading.Thread.Sleep(randomNumber);
            }
            else
            {
                r = this.httpPost("https://www.virustotal.com/api/get_url_report.json", "resource=" + nResource + "&key=" + this.apiKey + "&scan=0");
                System.Threading.Thread.Sleep(randomNumber);
            }

            //  again;
            JObject o = JObject.Parse(r);

            try
            {
                foreach (JProperty jp in o["report"].Last)
                {
                    tot++;
                    string value = jp.Value.ToString();
                    if (value.Contains("clean"))
                    {
                        clean.Add(jp.Name);
                        clenct++;
                    }
                    else if (value.Contains("unrated"))
                    {
                        unrated.Add(jp.Name);
                        unratedct++;
                    }

                    else
                    {
                        infected.Add(jp.Name);
                        infcount++;
                    }
                    // this.results += jp.Name + "," + jp.First + "\n";
                }
            }
            catch (Exception ex)
            {
                r = this.httpPost("https://www.virustotal.com/api/get_url_report.json", "resource=" + nResource + "&key=" + this.apiKey + "&scan=0");
                System.Threading.Thread.Sleep(500);
                foreach (JProperty jp in o["report"].Last)
                {
                    tot++;
                    string value = jp.Value.ToString();
                    if (value.Contains("clean"))
                    {
                        clean.Add(jp.Name);
                        clenct++;
                    }
                    else if (value.Contains("unrated"))
                    {
                        unrated.Add(jp.Name);
                        unratedct++;
                    }
                    else
                    {
                        infected.Add(jp.Name);
                        infcount++;
                    }
                    // this.results += jp.Name + "," + jp.First + "\n";
                }
                System.Threading.Thread.Sleep(randomNumber);
            }

            double infPer = infcount / tot;
            double unrper = unratedct / tot;

            rep = new MalwareReport(infected, clean, unrated, infPer, unrper);
            return(rep);
        }
Ejemplo n.º 6
0
        private bool scanFile(String fileName) // true - File is virus
        {
            MalwareReport rep1;
            bool          test    = false;
            List <string> infects = new List <string>();
            List <string> cleans  = new List <string>();
            List <string> unrated = new List <string>();
            //string infected = "";
            //double clenct = 0.0;
            double unratedct   = 0.0;
            int    infectcount = 0;
            int    totCount    = 0;
            double infper      = 0.0;
            double unrper      = 0.0;

            if (scannedItems.ContainsKey(fileName))
            {
                return(false);                                                                         // Already scanned this file so just skip it...
            }
            var    data = string.Format("resource={0}&key={1}", GetMD5HashFromFile(fileName), apiKey); // MD5 and API Key to send
            var    c    = new WebClient();                                                             // WebClient used for connection to API
            string s    = c.UploadString(results, "POST", data);                                       // Connect to the API and POST the data

            try
            {
                JObject o = JObject.Parse(s);
                //  viruses = "";
                foreach (JProperty jp in o["report"].Last)
                {
                    totCount++;
                    string value = jp.Value.ToString();
                    //viruses += jp.Name + ",";
                    if (value.Contains("clean"))
                    {
                        cleans.Add(jp.Name);
                    }
                    if (value.Contains("unrated"))
                    {
                        unrated.Add(jp.Name);
                        unratedct++;
                    }
                    else
                    {
                        infectcount++;
                        infects.Add(jp.Name);
                    }
                }
                infper = infectcount / totCount;
                unrper = unratedct / totCount;
                if (infper > 0.0)
                {
                    test = true;
                }


                rep1 = new MalwareReport(infects, cleans, unrated, infper, unrper);
            }
            catch (Exception ex)
            {
                return(test);
            }
            scannedItems.Add(fileName, rep1);
            return(test);

            // var r = ParseJSON(s); // Parse the response

            //          int nonBlank = 0; // If a line is blank, it is safe, numerous non-blanks = multiple virus confirmations
            //        foreach (string str in r.Values) // Cycle through response lines
            //      {
            //        if (Regex.Replace(str, @"\s+", "") != "") nonBlank++; // Count positive results (non-blank lines)
            //MessageBox.Show(str);
            //    }

            //   scannedItems.Add(fileName, nonBlank >= 20); // Say this item was scanned and store the result
            //      scannedItems.Add(fileName, nonBlank > 1); // Say this item was scanned and store the result
            //    return scannedItems[fileName]; // Return final scan result
        }