You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tab-sorcery/tab-sorcery.sh

79 lines
2.5 KiB

#!/usr/bin/env sh
# ARGUMENTS:
# $1 == Domain to scan
# $2 == Nameserver to do the zone transfer from
# $3 == Default username for connections
scan_domain=$1
scan_ns=$2
# Static Configuration (Do not edit)
dns_time=5
dns_tries=1
#icmp_fail_text="$(tput bold)Tab Sorcery: $(tput setaf 1)ICMP connection to ${scan_ns} failed!$(tput sgr0)"
dns_fail_text="$(tput bold)Tab Sorcery: $(tput setaf 1)DNS connection to ${scan_ns} failed!$(tput sgr0)"
# Check for and set RDP geometry config
case "$SORC_GEOM_RDP" in
[0123456789]*x*[0123456789]) geom_rdp=$SORC_GEOM_RDP;;
*) geom_rdp='1600x900';;
esac
# Check for a plain text password files for Windows hosts
# (Disclaimer: This is highly insecure and unrecommended.)
case "$SORC_PASS_FILE" in
[~$/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]*) pass_file=$SORC_PASS_FILE;;
*) pass_file=/dev/null;;
esac
get_hostip () {
#host_ip=`echo $zone_xfer | grep ${host} | grep A | awk '{print $3}'`
host_ip=`echo $zone_xfer | grep $1 | grep A | awk '{print $3}'`
}
##Check network
#if ! ping -c1 -t3 $scan_ns >/dev/null 2>&1
#then
# echo $icmp_fail_text >&2
# return 1
#fi
zone_xfer=`{dig $scan_domain @$scan_ns +time=$dns_time +tries=$dns_tries AXFR || echo $dns_fail_text >&2} | egrep -v 'SOA|NS|MX|DiG' | grep $scan_domain | awk '{print $1,$4,$5}'`
while read host <&3; do
user_name=$3
connect_cmd="ssh -t"
host_short=`echo ${host} | awk -F. '{print $1}'`
if echo $zone_xfer | grep $host | grep TXT; then
if [ "`echo $zone_xfer | grep $host | grep TXT | awk '{print $3}'`" = '"lxc"' ]; then
user_name="root"
get_hostip ${host}
alias ${host_short}="${connect_cmd} ${user_name}@${host_ip}"
elif [ "`echo $zone_xfer | grep $host | grep TXT | awk '{print $3}'`" = '"windows"' ]; then
if [ -f $pass_file ]; then
if pass_line=`grep $host_short $pass_file`; then
winpass=`awk -F= '{print $2}' <<< "$pass_line"`
connect_cmd="rdesktop -g $geom_rdp -p $winpass"
else
connect_cmd="rdesktop -g $geom_rdp"
fi
else
connect_cmd="rdesktop -g $geom_rdp"
fi
get_hostip ${host}
alias ${host_short}="${connect_cmd} -u ${user_name} ${host_ip}"
elif [ "`echo $zone_xfer | grep $host | grep TXT | awk '{print $3}'`" = '"cisco"' ]; then
connect_cmd="telnet"
get_hostip ${host}
alias ${host_short}="${connect_cmd} ${host_ip}"
fi
else
get_hostip ${host}
alias ${host_short}="${connect_cmd} ${user_name}@${host_ip}"
fi >/dev/null
done 3< <(echo $zone_xfer | awk '{print $1}' | uniq)
unset -f get_hostip
return 0