4 # Copyright © 2015 Apple Inc.
8 # Collect network information.
11 PATH
=/bin
:/usr
/bin
:/sbin
:/usr
/sbin
13 # __SETUP_ROUTINES_BEGIN__
22 COLLECT_SENSITIVE_INFO
="Y"
25 COLLECT_CONFIGURATION_FILES
="Y"
30 REQUESTED_OUTDIR
="${i}"
40 if [ ${EUID} -ne 0 ]; then
53 cd "${REQUESTED_OUTDIR}"
57 # __SETUP_ROUTINES_END__
60 # __COMMAND_ROUTINES_BEGIN__
62 # note: the daemons dump to syslog so you need to wait a bit before
64 collect_state_dump
() {
66 ${PRIV} /usr
/bin
/killall
-INFO networkd
2>/dev
/null
71 collect_state_dump_sensitive
() {
73 ${PRIV} /usr
/bin
/killall
-INFO mDNSResponder
2>/dev
/null
80 # network interface configuration
84 if [ ! -x /sbin
/ifconfig
]; then
88 /sbin
/ifconfig
-a -L -b -m -r -v -v > ifconfig.txt
2>&1
90 /sbin
/ifconfig
-a > ifconfig.txt
2>&1
96 # network route configuration and statistics
100 if [ ! -x /usr
/sbin
/netstat
]; then
104 echo "#" > netstat.txt
105 echo "# netstat -n -r -a -l" >> netstat.txt
106 echo "#" >> netstat.txt
107 /usr
/sbin
/netstat
-n -r -a -l >> netstat.txt
2>&1
109 echo "#" >> netstat.txt
110 echo "# netstat -A -a -l -n -v" >> netstat.txt
111 echo "#" >> netstat.txt
112 /usr
/sbin
/netstat
-A -a -l -n -v >> netstat.txt
2>&1
114 echo "#" >> netstat.txt
115 echo "# netstat -s" >> netstat.txt
116 echo "#" >> netstat.txt
117 /usr
/sbin
/netstat
-s >> netstat.txt
2>&1
119 echo "#" >> netstat.txt
120 echo "# netstat -mmm" >> netstat.txt
121 echo "#" >> netstat.txt
122 /usr
/sbin
/netstat
-mmm >> netstat.txt
2>&1
124 echo "#" >> netstat.txt
125 echo "# netstat -i -n -d" >> netstat.txt
126 echo "#" >> netstat.txt
127 /usr
/sbin
/netstat
-i -n -d >> netstat.txt
2>&1
129 echo "#" >> netstat.txt
130 echo "# netstat -i -x R" >> netstat.txt
131 echo "#" >> netstat.txt
132 /usr
/sbin
/netstat
-i -x R
>> netstat.txt
2>&1
134 echo "#" >> netstat.txt
135 echo "# netstat -a -n -p mptcp" >> netstat.txt
136 echo "#" >> netstat.txt
137 /usr
/sbin
/netstat
-anp mptcp
>> netstat.txt
2>&1
139 echo "#" >> netstat.txt
140 echo "# netstat -s -p mptcp" >> netstat.txt
141 echo "#" >> netstat.txt
142 /usr
/sbin
/netstat
-s -p mptcp
>> netstat.txt
2>&1
144 echo "#" >> netstat.txt
145 echo "# netstat -g -n -s" >> netstat.txt
146 echo "#" >> netstat.txt
147 /usr
/sbin
/netstat
-g -n -s >> netstat.txt
2>&1
149 if [ -x /sbin
/ifconfig
]; then
152 IF_INFO
=`/sbin/ifconfig -v ${if}`
153 `echo $IF_INFO | grep -q TXSTART`
154 if [ $?
-eq 0 ]; then
155 echo "#" >> netstat.txt
156 echo "# netstat -qq -I ${if}" >> netstat.txt
157 echo "#" >> netstat.txt
158 /usr
/sbin
/netstat
-qq -I ${if} >> netstat.txt
2>&1
160 `echo $IF_INFO | grep -q RXPOLL`
161 if [ $?
-eq 0 ]; then
162 echo "#" >> netstat.txt
163 echo "# netstat -Q -I ${if}" >> netstat.txt
164 echo "#" >> netstat.txt
165 /usr
/sbin
/netstat
-Q -I ${if} >> netstat.txt
2>&1
174 if [ ! -x /usr
/sbin
/ndp
]; then
178 echo "#" > ndp
-info.txt
179 echo "# ndp -n -a" >> ndp
-info.txt
180 echo "#" >> ndp
-info.txt
181 /usr
/sbin
/ndp
-n -a >> ndp
-info.txt
2>&1
183 echo "#" >> ndp
-info.txt
184 echo "# ndp -n -p" >> ndp
-info.txt
185 echo "#" >> ndp
-info.txt
186 /usr
/sbin
/ndp
-n -p >> ndp
-info.txt
2>&1
188 echo "#" >> ndp
-info.txt
189 echo "# ndp -n -r" >> ndp
-info.txt
190 echo "#" >> ndp
-info.txt
191 /usr
/sbin
/ndp
-n -r >> ndp
-info.txt
2>&1
193 if [ -x /sbin
/ifconfig
]; then
196 echo "#" >> ndp
-info.txt
197 echo "# ndp -i ${if}" >> ndp
-info.txt
198 echo "#" >> ndp
-info.txt
199 /usr
/sbin
/ndp
-i ${if} >> ndp
-info.txt
2>&1
207 if [ ! -x /usr
/sbin
/arp
]; then
211 echo "#" > arp
-info.txt
212 echo "# arp -n -a" >> arp
-info.txt
213 echo "#" >> arp
-info.txt
214 /usr
/sbin
/arp
-n -a >> arp
-info.txt
2>&1
223 if [ ! -x /usr
/sbin
/ipconfig
]; then
232 echo "#" >> ipconfig
-info.txt
233 echo "# INTERFACE ${if}" >> ipconfig
-info.txt
234 echo "#" >> ipconfig
-info.txt
236 echo "DHCPv4 information:" >> ipconfig
-info.txt
238 IPCONFIG_INFO
=`/usr/sbin/ipconfig getpacket ${if}`
239 if [ "${IPCONFIG_INFO}" != "" ]; then
240 echo "${IPCONFIG_INFO}" >> ipconfig
-info.txt
242 echo "not available" >> ipconfig
-info.txt
245 echo"" >> ipconfig
-info.txt
247 echo "DHCPv6 information:" >> ipconfig
-info.txt
249 IPCONFIG_INFO
=`/usr/sbin/ipconfig getv6packet ${if}`
250 if [ "${IPCONFIG_INFO}" != "" ]; then
251 echo "${IPCONFIG_INFO}" >> ipconfig
-info.txt
253 echo "not available" >> ipconfig
-info.txt
256 echo"" >> ipconfig
-info.txt
264 # IPsec configuration
268 if [ ! -x /usr
/sbin
/setkey
-o ! -x /usr
/bin
/perl
]; then
273 echo "# setkey -D" >> ipsec.txt
274 echo "#" >> ipsec.txt
275 ${PRIV} /usr
/sbin
/setkey
-D \
276 | /usr
/bin
/perl
-l -n -e '
277 if (/^(\s+[AE]:\s+\S+\s+)"?(.*)"?\s*$/) {
278 printf "%s[redacted]%s\n", $1, $3;
285 echo "#" >> ipsec.txt
286 echo "# setkey -Pp -D" >> ipsec.txt
287 echo "#" >> ipsec.txt
288 ${PRIV} /usr
/sbin
/setkey
-Pp -D >> ipsec.txt
290 for CF
in /var
/run
/racoon
/*.conf
292 if [ ! -r "${CF}" ]; then
297 echo "#" >> ipsec.txt
298 echo "# ${CF}" >> ipsec.txt
299 echo "#" >> ipsec.txt
301 | /usr
/bin
/perl
-l -n -e '
302 if (/^(\s+shared_secret\s+use\s+)"?([^\s;"]+)"?(.*)/) {
303 printf "%s[redacted]%s\n", $1, $3;
313 # Network preferences
315 collect_configuration_files
() {
318 /Library
/Preferences
/com.apple.networkextension.plist \
319 /Library
/Preferences
/com.apple.networkextension.control.plist \
320 /Library
/Preferences
/com.apple.networkextension.necp.plist \
321 /Library
/Preferences
/SystemConfiguration
/com.apple.nat.plist \
322 /Library
/Preferences
/SystemConfiguration
/com.apple.RemoteAccessServers.plist \
323 /Library
/Preferences
/SystemConfiguration
/com.apple.smb.server.plist \
324 /Library
/Preferences
/com.apple.mDNSResponder.plist \
325 /Library
/Preferences
/SystemConfiguration
/NetworkInterfaces.plist \
326 /Library
/Preferences
/SystemConfiguration
/preferences.plist \
329 if [ -e "${f}" ]; then
331 cat "${f}" > "${b}" 2>&1
335 if [ -e /etc
/resolv.conf
]; then
336 cat /etc
/resolv.conf
> etc
-resolv-conf.txt
2>&1
338 if [ -e /var
/run
/resolv.conf
]; then
339 cat /var
/run
/resolv.conf
> var
-run-resolv-conf.txt
2>&1
341 if [ -e /etc
/resolver
]; then
342 tar -c -H /etc
/resolver
> etc
-resolver.
tar 2>/dev
/null
346 collect_vpn_logs
() {
350 /var
/log
/racoon.log \
353 if [ -e "${f}" ]; then
355 ${PRIV} cat "${f}" > "${b}".txt
2>&1
361 # Network, DNS, Proxy, Reachability, Cache information
365 if [ ! -x /usr
/sbin
/scutil
]; then
369 echo "#" > network
-information.txt
370 echo "# scutil -d -v --nwi" >> network
-information.txt
371 echo "#" >> network
-information.txt
372 /usr
/sbin
/scutil
-d -v --nwi >> network
-information.txt
2>&1
375 echo "" >> network
-information.txt
376 echo "#" >> network
-information.txt
377 echo "# scutil --nwi ${if}" >> network
-information.txt
378 echo "#" >> network
-information.txt
379 scutil
--nwi ${if} >> network
-information.txt
2>&1
382 echo "#" > dns
-configuration.txt
383 echo "# scutil -d -v --dns" >> dns
-configuration.txt
384 echo "#" >> dns
-configuration.txt
385 /usr
/sbin
/scutil
-d -v --dns >> dns
-configuration.txt
2>&1
387 echo "#" > proxy
-configuration.txt
388 echo "# scutil -d -v --proxy" >> proxy
-configuration.txt
389 echo "#" >> proxy
-configuration.txt
390 /usr
/sbin
/scutil
-d -v --proxy >> proxy
-configuration.txt
2>&1
392 echo "#" > reachability
-info.txt
393 echo '# scutil -d -v -r www.apple.com' >> reachability
-info.txt
394 echo "#" >> reachability
-info.txt
395 /usr
/sbin
/scutil
-d -v -r www.apple.com
>> reachability
-info.txt
2>&1
397 echo "#" >> reachability
-info.txt
398 echo '# scutil -d -v -r 0.0.0.0' >> reachability
-info.txt
399 echo "#" >> reachability
-info.txt
400 /usr
/sbin
/scutil
-d -v -r 0.0.0.0 >> reachability
-info.txt
2>&1
402 ${PRIV} /usr
/sbin
/scutil
-p --snapshot
403 if [ -f /var
/tmp
/configd
-store.plist
]; then
404 cat /var
/tmp
/configd
-store.plist
> configd
-store.plist
2>&1
406 if [ -f /var
/tmp
/configd
-pattern.plist
]; then
407 cat /var
/tmp
/configd
-pattern.plist
> configd
-pattern.plist
2>&1
409 if [ -f /var
/tmp
/configd
-session.plist
]; then
410 cat /var
/tmp
/configd
-session.plist
> configd
-session.plist
2>&1
412 if [ -f /var
/tmp
/configd
-state ]; then
413 cat /var
/tmp
/configd
-state > configd
-state 2>&1
420 if [ ! -x /sbin
/route
]; then
424 echo "#" > route
-info.txt
425 echo '# route -n -v get www.apple.com' >> route
-info.txt
426 echo "#" >> route
-info.txt
427 /sbin
/route
-n -v get www.apple.com
>> route
-info.txt
2>&1
429 echo "#" >> route
-info.txt
430 echo '# route -n -v get 0.0.0.0' >> route
-info.txt
431 echo "#" >> route
-info.txt
432 /sbin
/route
-n -v get
0.0.0.0 >> route
-info.txt
2>&1
438 if [ ! -x /usr
/bin
/dig -o ! -f /etc
/resolv.conf
]; then
442 echo "#" > dig-info.txt
443 echo '# dig -t any -c any www.apple.com' >> dig-info.txt
444 echo "#" >> dig-info.txt
445 /usr
/bin
/dig +time=2 -t any
-c any www.apple.com
>> dig-info.txt
2>/dev
/null
454 if [ ! -x /bin
/hostname
]; then
458 /bin
/hostname
> hostname.txt
2>&1
462 collect_sensitive_info
() {
463 collect_state_dump_sensitive
471 if [ "${COLLECT_SENSITIVE_INFO}" == "Y" ]; then
472 collect_sensitive_info
485 if [ "${COLLECT_CONFIGURATION_FILES}" == "Y" ]; then
486 collect_configuration_files
490 # __COMMAND_ROUTINES_END__
492 # __HELPER_ROUTINES_BEGIN__
496 echo "Usage: get-network-info [-s] [-c] <info-directory>"
497 echo " -s collects sensitive information (ARP/NDP/mDNS cache)"
498 echo " -c collects system configuration files"
499 echo " <info-directory> path to directory where all the information will be collected"
505 if [ ! -d ${REQUESTED_OUTDIR} ] ||
506 [ "${REQUESTED_OUTDIR}" = "" ]; then
511 if [ ! -w ${REQUESTED_OUTDIR} ]; then
512 echo "${REQUESTED_OUTDIR} is write-protected"
518 # Collect most used command output to be used later
522 if [ ! -x /sbin
/ifconfig
]; then
526 IF_LIST
=`/sbin/ifconfig -l`
532 COLLECT_SENSITIVE_INFO
=""
533 COLLECT_CONFIGURATION_FILES
=""
536 # __HELPER_ROUTINES_END__
555 #TO-DO: Add packet trace