-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathapproximate.sh
executable file
·147 lines (119 loc) · 2.51 KB
/
approximate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
tmpdir=astroid-output
sig=$1
sample=$2
limit=$3
function=$4
declare -a family
declare -a score
declare -a seen
index=0
max=0
fmax='ADRD'
getmax()
{
counter=0
max=0
imax=0
while [ $counter -lt $index ]; do
if [ ${seen[$counter]} -eq 0 ]; then
if [ ${score[$counter]} -gt $max ]; then
max=${score[$counter]}
fmax=${family[$counter]}
imax=$counter
fi
fi
(( counter++ ))
done
seen[$imax]=1
}
zero()
{
rm -f *.json
rm -rf "$tmpdir"
mkdir "$tmpdir"
cp $sig "$tmpdir"
cp $sample "$tmpdir"
ant sigGen -Dtarget.loc=$tmpdir -Dencoding=basic -Dsize=2 -Dfreq=frequency.txt > /dev/null
count=`ls -1 *.json 2>/dev/null | wc -l`
if [ $count != 0 ] ; then
rm $tmpdir/*
mv *.json $tmpdir/zero.json
cp $sig $tmpdir
ant score -Dsig=$sig -Dzero=$tmpdir/zero.json -Dlimit=$limit -Dfunction=$function -Dfreq=frequency.txt > "$tmpdir"/output.txt
value=`grep SCORE: "$tmpdir"/output.txt | cut -d ':' -f 2 | cut -d ' ' -f 2`
score[$index]=$value
family[$index]=$(basename $sig .json)
(( index++ ))
fi
rm -rf $tmpdir
}
if [[ $# -eq 0 ]] ; then
echo 'Usage: ./approximate.sh <signature> <sample> <cutoff> <function>'
echo 'Cutoff: [0--10000]; Function: {0=lexico, 1=frequency}'
echo 'WARNING: No .json files can exist in the current directory!'
exit 0
fi
if [[ $# -lt 4 ]] ; then
echo 'Usage: ./approximate.sh <signature> <sample> <cutoff> <function>'
echo 'Cutoff: [0--10000]; Function: {0=lexico, 1=frequency}'
echo 'WARNING: No .json files can exist in the current directory!'
exit 0
fi
count=`ls -1 *.json 2>/dev/null | wc -l`
if [ $count != 0 ]
then
echo 'No .json file should exist in the current directory!'
exit 0
fi
if [ -d $sig ]; then
l=`ls -1 $sig/* 2>/dev/null | wc -l`
counter=0
while [ $counter -lt $l ]; do
seen[$counter]=0
(( counter++ ))
done
dir=$sig
for f in $dir/*; do
sig=$f
zero
done
c=0
while [ $c -lt $l ]; do
getmax
if [ $c -eq 0 ]; then
if [ $max -ge $limit ]; then
echo 'Malware'
else
echo 'Benign'
fi
fi
if [ $max -gt 0 ]; then
echo "$max $fmax"
fi
(( c++ ))
done
else
zero
counter=0
while [ $counter -lt $index ]; do
seen[$counter]=0
(( counter++ ))
done
c=0
while [ $c -lt 1 ]; do
getmax
if [ $c -eq 0 ]; then
if [ $max -ge $limit ]; then
echo 'Malware'
else
echo 'Benign'
fi
fi
if [ $max -gt 0 ]; then
echo "$max $fmax"
fi
(( c++ ))
done
fi
exit 0