Skip to content

Commit 4189c00

Browse files
author
Katja Hahn
committed
maldet 0.2
1 parent 9043ebf commit 4189c00

File tree

4 files changed

+69
-53
lines changed

4 files changed

+69
-53
lines changed

progs/maldet.jar

443 Bytes
Binary file not shown.

src/main/java/com/github/katjahahn/tools/DetectionHeuristic.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import scala.None
2727
import scala.None
2828
import scala.None
2929
import com.github.katjahahn.parser.PESignature
30+
import com.github.katjahahn.parser.FileFormatException
3031

3132
//TODO implement new good file stats
3233
//TODO remove dependend anomalies from /data/stats file
@@ -71,11 +72,11 @@ object DetectionHeuristic {
7172
val threshold = 500
7273
lazy val probabilities = readProbabilities()
7374

74-
private val version = """version: 0.1
75+
private val version = """version: 0.2
7576
|author: Katja Hahn
7677
|last update: 21.Jun 2014""".stripMargin
7778

78-
private val title = """MalDet v0.1
79+
private val title = """MalDet v0.2
7980
|-----------
8081
|Please note:
8182
|MalDet uses statistical information about file anomalies to assign a probability to a file for being malicious.
@@ -92,7 +93,7 @@ object DetectionHeuristic {
9293
private type OptionMap = scala.collection.mutable.Map[Symbol, String]
9394

9495
def main(args: Array[String]): Unit = {
95-
testHeuristics();
96+
invokeCLI(args)
9697
}
9798

9899
private def invokeCLI(args: Array[String]): Unit = {
@@ -165,7 +166,7 @@ object DetectionHeuristic {
165166
}
166167
}
167168
private def testHeuristics(): Unit = {
168-
val folder = new File("/home/deque/portextestfiles/goodfiles")
169+
val folder = new File("/home/deque/portextestfiles/badfiles")
169170
val threshholdA = 0.99
170171
val threshholdB = 0.80
171172
val threshholdC = 0.50
@@ -194,7 +195,8 @@ object DetectionHeuristic {
194195
println("malicious by threshhold 0.50: " + malcounterC + " ratio " + (malcounterC.toDouble / total.toDouble))
195196
}
196197
} catch {
197-
case e: Exception => notLoaded += 1; System.err.println(e.getMessage);
198+
case e: FileFormatException => notLoaded +=1; System.err.println("file is no PE file: " + file.getName());
199+
case e: Exception => notLoaded += 1; e.printStackTrace();
198200
}
199201
}
200202
total -= notLoaded
Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
UNUSUAL_SEC_NAME;3589;16.380648105887722
2-
DEPRECATED_FILE_CHARACTERISTICS;5591;25.51802829758101
3-
NOT_FILEALIGNED_SIZE_OF_RAW;21;0.09584664536741214
4-
TOO_SMALL_OPTIONAL_HEADER;1;0.004564125969876769
5-
TOO_MANY_SECTIONS;1;0.004564125969876769
6-
ZERO_IMAGE_BASE;1;0.004564125969876769
7-
ZERO_VIRTUAL_SIZE;5;0.022820629849383843
8-
DEPRECATED_PTR_OF_LINE_NR;15;0.06846188954815152
9-
OVERLAPPING_SEC;414;1.8895481515289823
10-
NOT_FILEALIGNED_PTR_TO_RAW;14;0.06389776357827476
11-
DEPRECATED_PTR_TO_SYMB_TABLE;425;1.9397535371976267
12-
SECTIONLESS;1;0.004564125969876769
13-
NOT_SEC_ALIGNED_SIZE_OF_IMAGE;7;0.03194888178913738
14-
UNINIT_DATA_CONTRAINTS_VIOLATION;40;0.18256503879507074
15-
ZERO_EP;16;0.0730260155180283
16-
TOO_LARGE_OPTIONAL_HEADER;1;0.004564125969876769
17-
DEPRECATED_NR_OF_LINE_NR;14;0.06389776357827476
18-
TOO_SMALL_SECALIGN;9;0.041077133728890915
19-
NON_DEFAULT_SIZE_OF_HEADERS;11472;52.35965312642629
20-
RESERVED_SEC_CHARACTERISTICS;37;0.16887266088544045
21-
NOT_FILEALIGNED_SIZE_OF_HEADERS;23;0.10497489730716568
22-
ZERO_SIZE_OF_RAW_DATA;1511;6.8963943404837975
23-
DEPRECATED_SEC_CHARACTERISTICS;2;0.009128251939753538
24-
RESERVED_DATA_DIR;3;0.013692377909630305
25-
VIRTUAL_EP;5889;26.87813783660429
26-
DEPRECATED_PTR_TO_RELOC;4;0.018256503879507075
27-
COLLAPSED_OPTIONAL_HEADER;1;0.004564125969876769
28-
COLLAPSED_MSDOS_HEADER;3;0.013692377909630305
29-
UNUSUAL_DATA_DIR_NR;2;0.009128251939753538
30-
DEPRECATED_NR_OF_RELOC;3;0.013692377909630305
31-
TOO_LARGE_SIZE_OF_RAW;5;0.022820629849383843
32-
LOW_ALIGNMENT_MODE;282;1.2870835235052487
33-
OBJECT_ONLY_SEC_CHARACTERISTICS;55;0.25102692834322227
34-
TOO_LARGE_IMAGE_BASE;6502;29.67594705613875
35-
DUPLICATE_SEC;9;0.041077133728890915
36-
DEPRECATED_NR_OF_SYMB;321;1.4650844363304427
37-
NON_DEFAULT_FILEALIGN;2649;12.09036969420356
38-
TOO_SMALL_FILEALIGN;280;1.2779552715654952
39-
CTRL_SYMB_IN_SEC_NAME;609;2.779552715654952
40-
NON_DEFAULT_IMAGE_BASE;20112;91.79370150616157
1+
DEPRECATED_PTR_OF_LINE_NR;23;0.06932304539152451
2+
NOT_SEC_ALIGNED_SIZE_OF_IMAGE;7;0.021098318162637894
3+
SECTIONLESS;1;0.0030140454518054133
4+
LOW_ALIGNMENT_MODE;380;1.145337271686057
5+
CTRL_SYMB_IN_SEC_NAME;757;2.281632407016698
6+
DUPLICATE_SEC;13;0.03918259087347037
7+
DEPRECATED_NR_OF_SYMB;327;0.9855928627403702
8+
COLLAPSED_OPTIONAL_HEADER;1;0.0030140454518054133
9+
NON_DEFAULT_SIZE_OF_HEADERS;18207;54.87672554102116
10+
COLLAPSED_MSDOS_HEADER;3;0.009042136355416239
11+
TOO_LARGE_OPTIONAL_HEADER;1;0.0030140454518054133
12+
DEPRECATED_FILE_CHARACTERISTICS;7598;22.90071734281753
13+
OBJECT_ONLY_SEC_CHARACTERISTICS;55;0.16577249984929773
14+
VIRTUAL_EP;9572;28.850443064681414
15+
DEPRECATED_PTR_TO_RELOC;4;0.012056181807221653
16+
DEPRECATED_PTR_TO_SYMB_TABLE;428;1.290011453372717
17+
TOO_LARGE_IMAGE_BASE;7531;22.698776297546566
18+
OVERLAPPING_SEC;509;1.5341491349689553
19+
UNUSUAL_DATA_DIR_NR;2;0.006028090903610827
20+
NOT_FILEALIGNED_PTR_TO_RAW;15;0.0452106817770812
21+
ZERO_SIZE_OF_RAW_DATA;1596;4.810416541081439
22+
NON_DEFAULT_IMAGE_BASE;31154;93.89957200554585
23+
ZERO_EP;16;0.04822472722888661
24+
ZERO_IMAGE_BASE;1;0.0030140454518054133
25+
NOT_FILEALIGNED_SIZE_OF_RAW;21;0.06329495448791368
26+
TOO_LARGE_SIZE_OF_RAW;5;0.015070227259027066
27+
ZERO_VIRTUAL_SIZE;5;0.015070227259027066
28+
TOO_MANY_SECTIONS;1;0.0030140454518054133
29+
UNUSUAL_SEC_NAME;5100;15.371631804207608
30+
RESERVED_SEC_CHARACTERISTICS;37;0.1115196817168003
31+
NON_DEFAULT_FILEALIGN;3920;11.81505817107722
32+
NOT_FILEALIGNED_SIZE_OF_HEADERS;29;0.08740731810235698
33+
RESERVED_DATA_DIR;3;0.009042136355416239
34+
DEPRECATED_NR_OF_RELOC;3;0.009042136355416239
35+
TOO_SMALL_OPTIONAL_HEADER;1;0.0030140454518054133
36+
TOO_SMALL_SECALIGN;10;0.03014045451805413
37+
DEPRECATED_NR_OF_LINE_NR;22;0.06630899993971909
38+
DEPRECATED_SEC_CHARACTERISTICS;2;0.006028090903610827
39+
UNINIT_DATA_CONTRAINTS_VIOLATION;57;0.17180059075290854
40+
TOO_SMALL_FILEALIGN;368;1.1091687262643921

src/test/java/com/github/katjahahn/PortexStats.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
import com.github.katjahahn.tools.anomalies.PEAnomalyScanner;
4242

4343
public class PortexStats {
44-
45-
//TODO add D:\\ partition files from Win 7 machine!
44+
45+
// TODO add D:\\ partition files from Win 7 machine!
4646

4747
private static final Logger logger = LogManager.getLogger(PortexStats.class
4848
.getName());
@@ -62,9 +62,9 @@ public class PortexStats {
6262
private static int written = 0;
6363

6464
public static void main(String[] args) throws IOException {
65-
anomalyCount(new File(GOOD_FILES).listFiles(), "GOOD FILES");
65+
anomalyCount(new File(GOOD_FILES).listFiles(), "GOOD FILES");
6666
}
67-
67+
6868
public static void entropies(File[] files) {
6969
int total = 0;
7070
int hasHighE = 0;
@@ -91,15 +91,19 @@ public static void entropies(File[] files) {
9191
if (entropies.size() != 0) {
9292
entAverage += (entSum / entropies.size());
9393
}
94-
if (hasHighEFlag) hasHighE++;
95-
if (hasLowEFlag) hasLowE++;
94+
if (hasHighEFlag)
95+
hasHighE++;
96+
if (hasLowEFlag)
97+
hasLowE++;
9698
total++;
9799
if (total % 1000 == 0) {
98100
double highPercent = hasHighE / (double) total;
99101
double lowPercent = hasLowE / (double) total;
100102
System.out.println("files read: " + total);
101-
System.out.println("has high entropy: " + hasHighE + " " + highPercent);
102-
System.out.println("has low entropy: " + hasLowE + " " + lowPercent);
103+
System.out.println("has high entropy: " + hasHighE + " "
104+
+ highPercent);
105+
System.out.println("has low entropy: " + hasLowE + " "
106+
+ lowPercent);
103107
System.out.println();
104108
}
105109
} catch (Exception e) {
@@ -319,6 +323,16 @@ public static void anomalyCount(File[] files, String base) {
319323
System.out.println("Files read: " + total + "/"
320324
+ files.length);
321325
}
326+
} catch (FileFormatException e) {
327+
if (!file.isDirectory()) {
328+
file.delete();
329+
logger.error("file " + file.getAbsolutePath()
330+
+ " deleted, no PE");
331+
} else {
332+
logger.error("problem with file " + file.getAbsolutePath()
333+
+ " file was not loaded!");
334+
}
335+
notLoaded++;
322336
} catch (Exception e) {
323337
logger.error("problem with file " + file.getAbsolutePath()
324338
+ " file was not loaded!");

0 commit comments

Comments
 (0)