Parcourir la source

Fetching information about malware injected from Virustotal API

Shreyas Srinivasa il y a 9 ans
Parent
commit
9e1235fddd

+ 1 - 1
build.gradle

@@ -29,7 +29,7 @@ dependencies {
     compile files('libs/cryptix-jce-provider.jar')
     compile 'org.snmp4j:snmp4j:1.10.1'
     compile files('libs/snmp4j-agent-2.3.3.jar')
-    compile files('libs/VirustotalPublicV2.0-1.1.GA-SNAPSHOT-jar-with-dependencies.jar')
+    compile files('libs/VirusTotalAPI.jar')
 }
 
 android {

BIN
libs/VirusTotalAPI.jar


+ 4 - 1
src/de/tudarmstadt/informatik/hostage/ui/fragment/FileAlertDialogFragment.java

@@ -76,9 +76,11 @@ public class FileAlertDialogFragment extends DialogFragment {
                 LogFilter filter = new LogFilter();
                 filter.setESSIDs(ssids);
 
+               // ScanFileFragment.path = HelperUtils.getFilePath();
+
 
                 ScanFileFragment scanFileFragment = new ScanFileFragment();
-                scanFileFragment.scanfile(HelperUtils.getFilePath());
+               // scanFileFragment.scanfile(HelperUtils.getFilePath());
                 MainActivity.getInstance().injectFragment(scanFileFragment);
 
 
@@ -91,5 +93,6 @@ public class FileAlertDialogFragment extends DialogFragment {
         builder.setNegativeButton(R.string.close, null);
 
         return builder.create();
+
     }
 }

+ 89 - 40
src/de/tudarmstadt/informatik/hostage/ui/fragment/ScanFileFragment.java

@@ -1,44 +1,27 @@
 package de.tudarmstadt.informatik.hostage.ui.fragment;
 
 import android.app.Activity;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.net.Uri;
-import android.os.Bundle;
 import android.app.Fragment;
-import android.text.method.LinkMovementMethod;
+import android.os.Bundle;
+import android.os.StrictMode;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.TextView;
 
-import com.kanishka.virustotal.dto.FileScanReport;
-import com.kanishka.virustotal.dto.ScanInfo;
-import com.kanishka.virustotal.dto.VirusScanInfo;
-import com.kanishka.virustotal.exception.APIKeyNotFoundException;
-import com.kanishka.virustotal.exception.UnauthorizedAccessException;
-import com.kanishka.virustotalv2.VirusTotalConfig;
-import com.kanishka.virustotalv2.VirustotalPublicV2;
-import com.kanishka.virustotalv2.VirustotalPublicV2Impl;
-
-import java.io.File;
-import java.io.UnsupportedEncodingException;
-import java.util.HashMap;
+import java.io.IOException;
+import java.util.Set;
 
-import de.tudarmstadt.informatik.hostage.Hostage;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
-import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
-
-/**
- * A simple {@link Fragment} subclass.
- * Activities that contain this fragment must implement the
- * {@link ScanFileFragment.OnFragmentInteractionListener} interface
- * to handle interaction events.
- * Use the {@link ScanFileFragment#newInstance} factory method to
- * create an instance of this fragment.
- */
+import virustotalapi.ReportScan;
+import virustotalapi.VirusTotal;
+
+
 public class ScanFileFragment extends Fragment {
+    public static String filePath;
+    public String result;
+
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         super.onCreateView(inflater, container, savedInstanceState);
 
@@ -58,8 +41,21 @@ public class ScanFileFragment extends Fragment {
 
 
         TextView scanResult = (TextView) rootView.findViewById(R.id.scanResult);
-        scanfile(path);
-        scanResult.setText(getFileScanReport());
+
+        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
+        StrictMode.setThreadPolicy(policy);
+        
+        try {
+            scanResult.setText(scanFile());
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+
+        //  scanfile(HelperUtils.filePath);
+      //  result=getFileScanReport();
+
+
 
 
 
@@ -74,18 +70,67 @@ public class ScanFileFragment extends Fragment {
 
 
 
-    public String result;
-    public String scanner;
-    public String path= HelperUtils.getFilePath();
+
+  //  public String scanner;
+  //  public String path= HelperUtils.getFilePath();
+
+
+
+
+    public String scanFile() throws IOException {
+
+        VirusTotal VT = new VirusTotal("111c226204f5de7228563bbca91c5860e4965fbe936307dffa8f2f2d575ff292"); // Your Virus Total API Key
+
+        Set<ReportScan> Report = VT.ReportScan(HelperUtils.fileMD5); //The SHA256 file
+
+        for (ReportScan report : Report) {
+
+            result=("AV: " + report.getVendor() + " Detected: " + report.getDetected() + " Update: " + report.getUpdate() + " Malware Name: " + report.getMalwarename());
+
+        }
+        return result;
+    }
+
+}
+
+
+
 
 
-    public void scanfile(String path){
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+    /*public String scanfile(String path){
+
+        String result ="";
 
         try {
             VirusTotalConfig.getConfigInstance().setVirusTotalAPIKey("111c226204f5de7228563bbca91c5860e4965fbe936307dffa8f2f2d575ff292");
             VirustotalPublicV2 virusTotalRef = new VirustotalPublicV2Impl();
 
-            ScanInfo scanInformation = virusTotalRef.scanFile(new File(path));
+            ScanInfo scanInformation = virusTotalRef.scanFile(new File(HelperUtils.filePath));
 
             System.out.println("___SCAN INFORMATION___");
             System.out.println("MD5 :\t" + scanInformation.getMd5());
@@ -97,7 +142,10 @@ public class ScanFileFragment extends Fragment {
             System.out.println("SHA256 :\t" + scanInformation.getSha256());
             System.out.println("Verbose Msg :\t" + scanInformation.getVerboseMessage());
             System.out.println("Response Code :\t" + scanInformation.getResponseCode());
+            result = String.valueOf(scanInformation.getResponseCode());
+
             System.out.println("done.");
+
         } catch (APIKeyNotFoundException ex) {
             System.err.println("API Key not found! " + ex.getMessage());
         } catch (UnsupportedEncodingException ex) {
@@ -107,16 +155,18 @@ public class ScanFileFragment extends Fragment {
         } catch (Exception ex) {
             System.err.println("Something Bad Happened! " + ex.getMessage());
         }
+        return result;
+
     }
 
 
 
     public String getFileScanReport() {
         try {
-            VirusTotalConfig.getConfigInstance().setVirusTotalAPIKey("APIKEY");
+            VirusTotalConfig.getConfigInstance().setVirusTotalAPIKey("111c226204f5de7228563bbca91c5860e4965fbe936307dffa8f2f2d575ff292");
             VirustotalPublicV2 virusTotalRef = new VirustotalPublicV2Impl();
 
-            String resource=(HelperUtils.getFileMD5());
+            String resource=(HelperUtils.fileMD5);
             FileScanReport report = virusTotalRef.getScanReport(resource);
 
             System.out.println("MD5 :\t" + report.getMd5());
@@ -138,7 +188,7 @@ public class ScanFileFragment extends Fragment {
                 System.out.println("\t\t Result : " + virusInfo.getResult());
                 System.out.println("\t\t Update : " + virusInfo.getUpdate());
                 System.out.println("\t\t Version :" + virusInfo.getVersion());
-                result = virusInfo.getResult();
+                result = report.getPermalink();
                 scanner = key;
             }
 
@@ -153,9 +203,8 @@ public class ScanFileFragment extends Fragment {
         }
         return result;
     }
+*/
 
 
 
 
-
-}