Skip to content

Commit

Permalink
Version 1.3-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsLibra committed Oct 31, 2021
1 parent 4381164 commit 616c4b2
Show file tree
Hide file tree
Showing 26 changed files with 627 additions and 198 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# MalPull
A CLI interface to search for a MD-5/SHA-1/SHA-256 hash on multiple malware databases and download the sample from the first hit. More information can be found <a href="https://maxkersten.nl/projects/malpull/">here</a>. If there are any questions, feature suggestions, or bug reports: please send me a direct message <a href="https://twitter.com/Libranalysis">@Libranalysis</a>,
A CLI interface to search for a MD-5/SHA-1/SHA-256 hash on multiple malware databases and download the sample from the first hit. More information can be found <a href="https://maxkersten.nl/projects/malpull/">here</a>.If there are any questions, feature suggestions, or bug reports: please send me a message my Twitter (<a href="https://twitter.com/Libranalysis">@Libranalysis</a>).
38 changes: 35 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>malwarepuller</groupId>
<groupId>malpull</groupId>
<artifactId>MalPull</artifactId>
<version>1.2.1-stable</version>
<version>1.3-stable</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -42,14 +42,40 @@
<configuration>
<archive>
<manifest>
<mainClass>malpull.MalPull</mainClass>
<mainClass>malpull.cli.MalPullCli</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>3.2.1</version>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>3.2.0</version>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
Expand All @@ -63,6 +89,12 @@
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.lingala.zip4j/zip4j -->
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>2.7.0</version>
</dependency>
</dependencies>
<name>MalPull</name>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Max 'Libra' Kersten [@LibraAnalysis, https://maxkersten.nl]
* Copyright (C) 2020 Max 'Libra' Kersten [@Libranalysis, https://maxkersten.nl]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,10 +14,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package concurrency;
package malpull;

import endpoints.*;
import exceptions.SampleNotFoundException;
import malpull.endpoints.IEndpoint;
import malpull.exceptions.SampleNotFoundException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -30,10 +30,15 @@
* of the endpoints in the list. If it fails, the hash is added to the missing
* hashes list in the main class.
*
* @author Max 'Libra' Kersten [@LibraAnalysis, https://maxkersten.nl]
* @author Max 'Libra' Kersten [@Libranalysis, https://maxkersten.nl]
*/
public class DownloadWorker implements Runnable {

/**
* The instance of MalPull to connect back to
*/
private MalPull malPull;

/**
* The list of endpoints iterate through in an attempt to download the hash
*/
Expand Down Expand Up @@ -64,14 +69,16 @@ public class DownloadWorker implements Runnable {
/**
* Creates a worker object, which can be queued for the thread pool
*
* @param malPull the MalPull instance to connect back to
* @param endpoints the list of endpoints to attempt to download from
* @param path the location to write the file to the disk
* @param hash the hash to look for
* @param count the queue number of this worker, remains unchanged after
* creation
* @param total the total number of samples to be downloaded
*/
public DownloadWorker(List<IEndpoint> endpoints, String path, String hash, int count, int total) {
public DownloadWorker(MalPull malPull, List<IEndpoint> endpoints, String path, String hash, int count, int total) {
this.malPull = malPull;
this.endpoints = endpoints;
this.path = path;
this.hash = hash;
Expand Down Expand Up @@ -110,26 +117,29 @@ public void run() {
//The file is written to disk
writeToDisk(output, filePath);
//A message is printed for the user
System.out.println("Wrote " + output.length + " bytes to " + filePath + " from " + endpoint.getName() + " (" + count + " / " + total + ")");
malPull.log("(" + count + " / " + total + ") Wrote " + output.length + " bytes to " + filePath + " from " + endpoint.getName());
//Add the hash to the log
malPull.addDownloadedHash(hash, endpoint.getName());
//The boolean is set to true, causing the next iteration to break out of the loop
isDownloaded = true;
}
} catch (SampleNotFoundException e) {
} catch (SampleNotFoundException ex) {
/**
* The exception message can be ignored, as failure to
* download the sample results in the missing hash, but only
* if none of the configured endpoints has the hash
*/
//System.out.println(e.getMessage());
}
}
//If the sample is not downloaded after the loop, it is missing
if (isDownloaded == false) {
//This method is thread safe
MalPull.addMissingHash(hash);
malPull.addMissingHash(hash);
malPull.log("(" + count + " / " + total + ") Added \"" + hash + "\" to the missing hashes");
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
String message = "(" + count + " / " + total + ") An error occured when downloading " + hash + ":\n" + ex.getMessage();
malPull.log(message);
}
}

Expand All @@ -143,7 +153,7 @@ private void writeToDisk(byte[] output, String path) {
try (FileOutputStream fos = new FileOutputStream(path)) {
fos.write(output);
} catch (IOException ex) {
System.out.println("An error occured when writing the sample to \"" + path + "\". Verify your permissions and try again!");
malPull.log("An error occured when writing the sample to \"" + path + "\". Check the permissions and try again! Error:\n" + ex.getMessage());
}
}
}
Loading

0 comments on commit 616c4b2

Please sign in to comment.