Repository navigation
Expand file tree
/
Copy pathostest
More file actions
executable file
·177 lines (142 loc) · 3.69 KB
/
Copy pathostest
File metadata and controls
executable file
·177 lines (142 loc) · 3.69 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
usage()
{
echo "Usage: ./ostest nmap-os-db ifname ip-addr"
echo -e "\tnmap-os-db = Path to the nmap-os-db file that you wish to test against"
echo -e "\tifname = The network interface on which to do the testing"
echo -e "\tip-addr = The IP address to put the honeyd VM on"
}
printout()
{
echo "Exiting now. Cleaning up honeyd and nmap processes..."
killall honeyd
killall nmap
echo -e "\nTotal $count Lines read"
echo Total successful personalities: $WIN
echo Total failed personalities: $LOSE
exit
}
trap printout SIGINT
trap printout KILL
trap printout TERM
#Assert root user
if [ $USER != "root" ]; then
echo "Execute with root privileges: sudo $0"
exit 1
fi
if [ -z $1 ]; then
usage
exit 1
else
FILENAME=$1
fi
if [ -z $2 ]; then
usage
exit 1
else
IFNAME=$2
fi
if [ -z $3 ]; then
usage
exit 1
else
VMIP=$3
fi
rm -f result
mkdir -p results
TOTALFINGERPRINTS=0
count=0
WIN=0
LOSE=0
PERSONALITY=""
# Figure out total count for status so far/percent complete
while read LINE ; do
#Only consider Fingerprint lines
if [[ "$LINE" == Fingerprint* ]]
then
((TOTALFINGERPRINTS++))
fi
done < $FILENAME
while read LINE ; do
#Only consider Fingerprint lines
if [[ "$LINE" == Fingerprint* ]]
then
((count++))
#Chop off the "Fingerprint " prefix
LINE=${LINE:12}
PERSONALITY=$LINE
echo "Testing personality $count/$TOTALFINGERPRINTS ($((100*$count/$TOTALFINGERPRINTS))%) : $PERSONALITY"
CONFIG="
create default
set default default tcp action filtered
set default default udp action filtered
set default default icmp action closed
create test\n
set test personality \"$LINE\"\n
set test uptime 1728650\n
set test maxfds 35\n
add test tcp port 80 open\n
add test udp port 139 open\n
set test ethernet \"dell\"\n
set test default tcp action closed\n
set test default udp action closed\n
set test default icmp action closed\n\n
bind \"$VMIP\" test\n"
configFile=$(pwd)
configFile="$configFile/test.config"
echo -e $CONFIG > test.config
#cat test.config
echo -e "START PERSONALITY $PERSONALITY \n" >> results/honeyd.txt
honeyd -p $FILENAME -i $IFNAME -f $configFile &>> results/honeyd.txt
echo -e "STOP PERSONALITY $PERSONALITY \n" >> results/honeyd.txt
sleep 2
nmap -F -O --fuzzy $VMIP &> "results/nmap.temp"
killall honeyd
#cat nmap.out
#compare results!
found="false"
while read INNERLINE ; do
if [[ "$INNERLINE" == "Aggressive OS guesses: "* ]]; then
found=true
# Cut off everything past the first comma if there is one
PERC=$(expr index "$INNERLINE" "'%'")
if [[ $PERC != 0 ]]; then
PERCENTMATCH=${INNERLINE:$(expr $PERC - 3):3}
INNERLINE=${INNERLINE:0:$(expr $PERC - 5)}
fi
INNERLINE=${INNERLINE:23}
#echo "INNERLINE IS '$INNERLINE'"
if [[ $INNERLINE == $LINE ]]; then
echo SUCCESS ${INNERLINE:$END:2} $LINE >> result
WIN=$((WIN+1))
found="Correct Partial Match $PERCENTMATCH"
else
echo FAIL $LINE >> result
LOSE=$((LOSE+1))
found="Incorrect Partial Match"
fi
fi
if [[ "$INNERLINE" == "OS details: "* ]]; then
if [[ $INNERLINE == *"$LINE"* ]]; then
echo SUCCESS 100 $LINE >> result
WIN=$((WIN+1))
found="Correct Exact Match"
else
echo FAIL $LINE >> result
LOSE=$((LOSE+1))
found="Incorrect Exact Match"
fi
fi
done < "results/nmap.temp"
# Aggregate our nmap output for later analysis
echo -e "START PERSONALITY $PERSONALITY \n" >> results/nmap.txt
cat results/nmap.temp >> results/nmap.txt
echo -e "STOP PERSONALITY $PERSONALITY \n" >> results/nmap.txt
if [[ $found == "false" ]]; then
echo -e "FAILED! No OS lines found in nmap output. \n"
else
echo -e "$found \n"
fi
fi
done < $FILENAME
printout