-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnipe-hunt.sh
executable file
·96 lines (83 loc) · 2.16 KB
/
snipe-hunt.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
#!/bin/bash
NAME="glusterfs"
CASE="-autocase"
declare -A CONF
CONF=( ["case sensitive"]="auto" ["preserve case"]="yes" ["short preserve case"]="yes" ) #["store dos attributes"]="no" ["map archive"]="no" )
PROT="NT1"
if [[ $# > 0 ]]; then
case $1 in
yescase)
CASE="-$1"
CONF["case sensitive"]="yes"
shift
;;
nocase)
CASE="-$1"
CONF["case sensitive"]="no"
shift
;;
largedir)
CASE="-$1"
CONF["case sensitive"]="yes"
CONF["preserve case"]="no"
CONF["short preserve case"]="no"
shift
;;
nomangle)
CASE="-$1"
CONF["case sensitive"]="no"
CONF["preserve case"]="no"
CONF["short preserve case"]="no"
shift
;;
esac
fi
if [[ $# > 0 ]]; then
case $1 in
SMB3)
PROT="$1"
shift
;;
SMB2)
PROT="$1"
shift
;;
esac
fi
if [[ $# > 0 ]]; then
NAME="$1"
shift
fi
LOG_DIRS="/var/log/samba"
if [[ $NAME == glusterfs* ]]; then
LOG_DIRS+=" /var/log/glusterfs"
SHARE="share1"
else
SHARE="share2"
fi
for OPT in "${!CONF[@]}"; do
sed -i "s/\\(:${OPT}: \\).*/\\1'${CONF[${OPT}]}'/" vagrant.yaml
done
RUN_NAME="${NAME}-${PROT}${CASE}"
vagrant provision || exit 1
rm -f scripts/${RUN_NAME}.pcap
rm -f scripts/${RUN_NAME}_logs.tgz
tcpdump -w scripts/${RUN_NAME}.pcap -i virbr0 -s 0 tcp &
PID=$!
smbclient -m ${PROT} -U vagrant%vagrant -L ganesh || true
echo "Connecting to ${SHARE}..."
smbclient -m ${PROT} -U vagrant%vagrant //ganesh/${SHARE} -c "put scripts/foo foo; q;" && SAVE=true || SAVE=false
kill -INT $PID
if [ $SAVE == true ]; then
vagrant ssh ganesh -c "sudo tar -czvf ${RUN_NAME}_logs.tgz ${LOG_DIRS}"
vagrant ssh-config >scripts/ssh_config
scp -F scripts/ssh_config vagrant@ganesh:${RUN_NAME}_logs.tgz scripts/
cd scripts
tar -xzvf ${RUN_NAME}_logs.tgz -O var/log/samba/log.jarrpa >${RUN_NAME}.samba.log.jarrpa.csv
sed -i "s/\"/'/g" ${RUN_NAME}.samba.log.jarrpa.csv
sed -i "s/^\[/\"[/" ${RUN_NAME}.samba.log.jarrpa.csv
sed -i "s/\] \.\./]\",\"../" ${RUN_NAME}.samba.log.jarrpa.csv
sed -i 'N;s/)\n /)","/;P;D' ${RUN_NAME}.samba.log.jarrpa.csv
sed -i "s/^ /,,\"/" ${RUN_NAME}.samba.log.jarrpa.csv
sed -i "s/$/\"/" ${RUN_NAME}.samba.log.jarrpa.csv
fi