-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgencfg.sh
executable file
·227 lines (195 loc) · 4.74 KB
/
gencfg.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
#
# See LICENSE for copyright information
#
usage()
{
cat <<EOF
Trafgen configuration generator and syntax testing tool
Generation:
-G <type> packet type "syslog/beacon/rfc2544/arp_request/arp_reply/ntp":
\`\`rfc2544'' writes each frame size to dir
-s <ip> Source IP
-d <ip> Destination IP
-m <mac> Source Mac, aa:bb:cc...
-M <mac> Destination Mac, 00:11:22
-p <num> Source Port
-P <num> Destination Port
-T <ssid> for type "beacon" e.g. \`\`-T "Awesome!"''
if "random", generate random SSID of length 8
-n <num> of random generations for \`\`-T random'' only
Input:
-c <file> Exported C array (Wireshark)
-r <file> PCAP file (requires netsniff-ng)
Output:
-S <type> Separator:
"comma/white/noendwhite/noendcomma"
-o <file> Write to file (default: stdout)
Usage: $0 -h
$0 -c array.txt -S comma | trafgen --in - --out eth0 --num 100
$0 -G syslog -s 10.1.1.1 -d 10.1.1.2 -M 00:0c:29:8d:4d:a2
$0 -G beacon -T random -n 1000 -m de:ad:be:ef:00:00 -o beacon.cfg
EOF
}
argcheck() {
# if less than n argument
if [ $ARGC -lt $1 ]; then
echo "Missing arguments! Use \`\`-h'' for help."
exit 1
fi
}
output()
{
if [[ $OUT == "comma" ]]; then
cat - > ${OUTFILE:-/dev/stdout}
fi
if [[ $OUT == "white" ]]; then
tr -d ',' > ${OUTFILE:-/dev/stdout}
fi
if [[ $OUT == "noendwhite" ]]; then
sed 's/,//10' > ${OUTFILE:-/dev/stdout}
fi
if [ -z $OUT ]; then
cat - > ${OUTFILE:-/dev/stdout}
fi
}
coutput()
{
if [[ $OUT == "comma" ]]; then
sed 's/.*{$/{/g;/0x/s/^/ /;s/;//;s/\/\*.*\*\///;s/\(0x[a-z0-9]\{2\}\) /\1,/' $INFILE > ${OUTFILE:-/dev/stdout}
fi
if [[ $OUT == "noendcomma" ]]; then
sed 's/.*{$/{/g;/0x/s/^/ /;s/;//;s/\/\*.*\*\///' $INFILE > ${OUTFILE:-/dev/stdout}
fi
if [[ $OUT == "white" ]]; then
sed 's/.*{$/{/g;/0x/s/^/ /;s/;//;s/\/\*.*\*\///;s/,/ /g' $INFILE > ${OUTFILE:-/dev/stdout}
fi
if [[ $OUT == "noendwhite" ]]; then
sed 's/.*{$/{/g;/0x/s/^/ /;s/;//;s/\/\*.*\*\///' $INFILE > ${OUTFILE:-/dev/stdout}
fi
if [ -z $OUT ]; then
cat - < $INFILE > ${OUTFILE:-/dev/stdout}
fi
}
# Load plugins
. ./plugins/arp.sh
. ./plugins/beacon.sh
. ./plugins/ntp.sh
. ./plugins/rfc2544.sh
. ./plugins/syslog.sh
# Initialize variables
ARGC=$#
argcheck 1
# option and argument handling
while getopts "hc:d:G:m:M:n:o:r:p:P:s:S:T:" OPTION
do
case $OPTION in
h)
usage
exit
;;
c)
INTYPE="$OPTION"
INFILE="$OPTARG"
;;
G)
if [[ "$OPTARG" == syslog ]]; then
TYPE="$OPTARG"
elif [[ "$OPTARG" == beacon ]]; then
TYPE="$OPTARG"
elif [[ "$OPTARG" == rfc2544 ]]; then
TYPE="$OPTARG"
elif [[ "$OPTARG" == ntp ]]; then
TYPE="$OPTARG"
elif [[ "$OPTARG" == arp_request ]]; then
TYPE="$OPTARG"
OPCODE="0x00,0x01,"
elif [[ "$OPTARG" == arp_reply ]]; then
TYPE="$OPTARG"
OPCODE="0x00,0x02,"
else
echo "Unknown type!"
exit 1
fi
;;
n)
NUM="$OPTARG"
;;
o)
OUTFILE="$OPTARG"
;;
S)
if [[ "$OPTARG" == comma ]]; then
OUT="$OPTARG"
elif [[ "$OPTARG" == white ]]; then
OUT="$OPTARG"
elif [[ "$OPTARG" == noendwhite ]]; then
OUT="$OPTARG"
elif [[ "$OPTARG" == noendcomma ]]; then
OUT="$OPTARG"
else
echo "Unknown separator!"
exit 1
fi
;;
s)
SRCIP=$(echo $OPTARG | tr '.' ',')
;;
d)
DSTIP=$(echo $OPTARG | tr '.' ',')
;;
M)
DSTMAC=$(echo $OPTARG | sed 's/^/0x/;s/:/0x/g;s/\(0x[a-zA-Z0-9]\{2\}\)/\1,/g')
;;
m)
SRCMAC=$(echo $OPTARG | sed 's/^/0x/;s/:/0x/g;s/\(0x[a-zA-Z0-9]\{2\}\)/\1,/g')
;;
p)
SRCPORT="$OPTARG"
;;
P)
DSTPORT="$OPTARG"
;;
r)
INTYPE="$OPTION"
INFILE="$OPTARG"
;;
T)
if [[ "$OPTARG" == random ]]; then
SSID="random"
fi
SSID=$(echo $OPTARG | cut -c1-8)
;;
\?)
;;
esac
done
# meat
# C array
if [[ "$INTYPE" == "c" ]]; then
coutput
fi
# PCAP
if [[ "$INTYPE" == "r" ]]; then
netsniff-ng --in $INFILE --out - | output
fi
# Syslog
if [[ "$TYPE" == "syslog" ]]; then
syslog ${DSTMAC:-""} ${SRCMAC:-""} ${SRCIP:-""} ${DSTIP:-""} ${SRCPORT:-""} ${DSTPORT:-""} | output
fi
# RFC2544
if [[ "$TYPE" == "rfc2544" ]]; then
rfc2544 ${DSTMAC:-""} ${SRCMAC:-""} ${SRCIP:-""} ${DSTIP:-""} ${SRCPORT:-""} ${DSTPORT:-""} | output
fi
# Beacon
if [[ "$TYPE" == "beacon" ]]; then
beacon ${DSTMAC:-""} ${SRCMAC:-""} ${SSID:-""} | output
fi
# ARP
if [[ "$TYPE" == "arp_request" ]] || [[ "$TYPE" == "arp_reply" ]]; then
arp ${DSTMAC:-""} ${SRCMAC:-""} ${SRCIP:-""} ${DSTIP:-""} | output
fi
# NTP
if [[ "$TYPE" == "ntp" ]]; then
ntp ${DSTMAC:-""} ${SRCMAC:-""} ${SRCIP:-""} ${DSTIP:-""} ${SRCPORT:-""} ${DSTPORT:-""} | output
fi