This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfIRstview.sh
270 lines (246 loc) · 8.05 KB
/
fIRstview.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/bash
#
# fIRstview - fIRstview is a Live Response/Incident Response automation tool that collects several information from a Linux based system.
#
# Author: Leandro Fróes
#
# Copyright (C) 2019 Leandro Fróes
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
[[ $EUID -ne 0 ]] && echo "[!] You must be root!" && exit 1
usage(){
cat << EOF
NAME:
fIRstview - fIRstview is a Live Response/Incident Response automation tool that collects several information from a Linux based system.
SYNOPSIS:
fIRstview.sh [-h] [-a] [-l] [-u USER] [-p PID] [-f FILE]
OPTIONS:
-u,--user USER
Specify the user which you want to investigate and generate a report.
-p,--pid PID
Specify the process which you want to investigate and generate a report.
-f,--file FILE
Specify a file which you want to investigate and generate a report.
-l,--logs
Dump several system logs.
-a,--all
Generate a full report with no filter.
-h,--help
Display this help menu.
EOF
}
if [ $# -eq 0 ]; then
usage
exit 1
fi
OUTDIR=$PWD/fIRstview_output
[[ ! -d $OUTDIR ]] && mkdir $OUTDIR
cd $OUTDIR
f(){
FILEREPORT=$(echo $FILE | rev | cut -d/ -f1 | rev)-file-report
ERRORLOG=$(echo $FILE | rev | cut -d/ -f1 | rev)-file-report-error.log
echo "Report generated at `date`" >> $FILEREPORT
echo "Running as `whoami`" >> $FILEREPORT
( for i in \
"ls -la $FILE" \
"file -p $FILE" \
"stat $FILE" \
"lsof $FILE" \
"md5sum $FILE" \
"sha1sum $FILE" \
"readelf -a $FILE"
do
echo -e "\n\n[+] $i\n-----------------------------------"
eval $i 2>> $ERRORLOG
done) >> $FILEREPORT
}
user(){
USERREPORT=$USR-report
ERRORLOG=$USR-report-error.log
echo "Report generated at `date`" >> $USERREPORT
echo "Running as `whoami`" >> $USERREPORT
( for i in \
"id $USR" \
"who -a | grep $USR" \
"lastlog | grep $USR" \
"ls -rthla ~$USR" \
"grep $USR /etc/passwd" \
"grep $USR /etc/group" \
"cat /var/spool/cron/crontabs/$USR" \
"lsof -u $USR" \
"lsof -i | grep $USR" \
"ps -fU $USR"
do
echo -e "\n\n[+] $i\n-----------------------------------"
eval $i 2>> $ERRORLOG
done) >> $USERREPORT
ERRORLOGS=user-home-files-error.log
cat /home/$USR/.bash_history > $USR-user-history.log 2>> $ERRORLOGS
cat ~$USR/.ssh/known_hosts > $USR-user-known_hosts.log 2>> $ERRORLOGS
cat ~$USR/.bashrc > $USR-user-bashrc.log 2>> $ERRORLOGS
cat ~$USR/.profile > $USR-user-profile.log 2>> $ERRORLOGS
cat ~$USR/.bash_logout > $USR-user-bash_logout.log 2>> $ERRORLOGS
}
pid(){
PIDREPORT=$PID-pid-report
ERRORLOG=$PID-pid-report-error.log
echo "Report generated at `date`" >> $PIDREPORT
echo "Running as `whoami`" >> $PIDREPORT
( for i in \
"ps -p $PID -wo %p%P%C%x%t%U%u%c%a" \
"lsof -p $PID" \
"cat /proc/$PID/cmdline" \
"cat /proc/$PID/comm" \
"ls -la /proc/$PID/exe" \
"ls -la /proc/$PID/cwd" \
"cat /proc/$PID/environ" \
"ss -ltp | grep 'pid=$PID'"
do
echo -e "\n\n[+] $i\n-----------------------------------"
eval $i 2>> $ERRORLOG
done) >> $PIDREPORT
}
logs(){
ERRORLOGS=error_logs.log
cat /var/log/dmesg > dmesg.log 2>> $ERRORLOGS
cat /var/log/auth.log > auth.log 2>> $ERRORLOGS
cat /var/log/secure > secure.log 2>> $ERRORLOGS
cat /var/log/dpkg.log > dpkg.log 2>> $ERRORLOGS
cat /var/log/kern.log > kern.log 2>> $ERRORLOGS
cat /var/log/lastlog > lastlog.log 2>> $ERRORLOGS
cat /var/log/syslog > syslog.log 2>> $ERRORLOGS
cat /var/log/alternative.log > alternative.log 2>> $ERRORLOGS
cat /var/log/cron.log > cron.log 2>> $ERRORLOGS
cat /var/log/messages > messages.log 2>> $ERRORLOGS
cat /var/log/debug > debug.log 2>> $ERRORLOGS
cat /var/log/daemon.log > daemon.log 2>> $ERRORLOGS
cat /var/log/boot.log > boot.log 2>> $ERRORLOGS
cat /var/log/user.log > user.log 2>> $ERRORLOGS
cat /var/log/apache2/access.log > apache_access.log 2>> $ERRORLOGS
}
all(){
FULLREPORT=full-system-report
ERRORLOG=full-system-report-error.log
echo "Report generated at `date`" >> $FULLREPORT
echo "Running as `whoami`" >> $FULLREPORT
( for i in \
"##### SYSTEM #####\n" \
"uname -a" \
"uptime" \
"df -h" \
"fdisk -l" \
"mount -l" \
"cat /etc/fstab" \
"free" \
"lsusb" \
"lsmod" \
"env" \
"set | grep 'LD_PRELOAD'" \
"##### NETWORKING #####\n" \
"hostname" \
"ip a" \
"ip link show" \
"cat /etc/network/interfaces" \
"ip r s" \
"ip n" \
"cat /etc/hosts" \
"cat /etc/resolv.conf" \
"ss -putan" \
"iptables -L" \
"##### USERS #####\n" \
"who -a" \
"lastlog" \
"grep -E ':0+' /etc/passwd" \
"getent passwd {1000..65535}" \
"cat /etc/sudoers" \
"ls -lrth /etc/cron.d" \
"ls -lrth /etc/cron.hourly" \
"ls -lrth /etc/cron.daily" \
"ls -lrth /etc/cron.weekly" \
"ls -lrth /etc/cron.monthly" \
"##### PROCESSES AND SERVICES #####\n" \
"ls -lrth /etc/*.d" \
"service --status-all" \
"ps -ewo %p%P%C%x%t%U%u%c%a" \
"jobs -l" \
"##### FILES #####\n" \
"lsof" \
"lsof -i" \
"find / \\( -nouser -o -nogroup \\) -exec ls -lah {} +" \
"lsattr / -R | grep '\\----i'" \
"##### MISC #####\n" \
"ls -lrtha /tmp" \
"find / -name 'authorized_keys'" \
"find /var/log -size 0b -exec ls -lah {} +" \
"find / -type p -exec ls -lah {} +"
do
echo -e "\n\n[+] $i\n-----------------------------------"
eval $i 2>> $ERRORLOG
done) >> $FULLREPORT
ERRORLOGS=error_logs.log
cat /var/log/dmesg > dmesg.log 2>> $ERRORLOGS
cat /var/log/auth.log > auth.log 2>> $ERRORLOGS
cat /var/log/dpkg.log > dpkg.log 2>> $ERRORLOGS
cat /var/log/kern.log > kern.log 2>> $ERRORLOGS
cat /var/log/lastlog > lastlog.log 2>> $ERRORLOGS
cat /var/log/syslog > syslog.log 2>> $ERRORLOGS
cat /var/log/alternative.log > alternative.log 2>> $ERRORLOGS
cat /var/log/cron.log > cron.log 2>> $ERRORLOGS
cat /var/log/messages > messages.log 2>> $ERRORLOGS
cat /var/log/debug > debug.log 2>> $ERRORLOGS
cat /var/log/daemon.log > daemon.log 2>> $ERRORLOGS
cat /var/log/boot.log > boot.log 2>> $ERRORLOGS
cat /var/log/user.log > user.log 2>> $ERRORLOGS
cat /var/log/apache2/access.log > apache_access.log 2>> $ERRORLOGS
}
while getopts u:p:f:lah opt; do
case "$opt" in
u|--user) USR=$OPTARG
if grep -qw ^$USR /etc/passwd; then
user
else
echo "ERROR: This user does not exist.";
exit 1
fi
;;
p|--pid) PID=$OPTARG
if ps -p $PID > /dev/null; then
pid
else
echo "ERROR: This pid does not exist.";
exit 1
fi
;;
f|--file) FILE=$OPTARG
if [ ! -f $FILE ]; then
echo "ERROR: This file does not exist.";
exit 1;
fi
f
;;
l|--logs) logs
;;
a|--all) all
;;
h|--help) usage
exit 0
;;
*) usage
exit 1
;;
esac
done
cd ..
zip -P novirus -r fIRstview_output.zip $OUTDIR > /dev/null
echo "[+] Report generated at $PWD."
echo "[+] Done!"
exit 0