diff --git a/README.md b/README.md index e16a3d5..f03fd0b 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Add the script as a source file in your shell prompt, exporting any config varia ``` # Tab Sorcery -export SORC_GEOM_RDP='1600x900' #(Optional) Sets the window resolution for RDP connections +export SORC_GEOM_RDP="1600x900" #(Optional) Sets the window resolution for RDP connections . $HOME/git/tab-sorcery/tab-sorcery.sh example.com 127.0.0.1 bob.user ``` @@ -18,17 +18,42 @@ Scan Domain (example.com) Nameserver address (127.0.0.1) Default username (bob.user) ``` +**Important:** While a hostname may be used in lieu of an IP address for the DNS server used by this script, it is not advised. If this hostname fails to resolve, it may have unintended consequences that could be avoided by using an IP address. There may be an update at a later time to enforce a sanity check to prevent this, but this is not yet in place. Once done, all hostnames in the DNS zone should be available for SSH/Telnet/RDP by a tab-completable alias of just the hostname (in new shell sessions). -#### Can I change the window geometry for rdesktop? -Yes! You simply need to export a variable *before* calling the tab-sorcery.sh script. The variable to export is called **SORC_GEOM_RDP**, which will take the form of [width]x[height]. +### Options +Options can be configured as exported variables, set in your shell RC files before calling the tab-sorcery script itself. So far there are two options: +##### Windows RDP Window Geometry +###### Variable: SORC_GEOM_RDP +This option sets the resolution of your Windows RDP connections. If left unset or an invalid value is detected, the default is **1600x900**. Example: ``` -export SORC_GEOM_RDP='1280x720' +export SORC_GEOM_RDP="1280x720" +``` + +##### Windows Password File (INSECURE) +###### Variable: SORC_PASS_FILE +This option supplies the path to a plain text file containing a list of hostnames and passwords in the following format: +``` +hostname=password +``` +If this option is provided, hosts marked as Windows hosts will check this file for a password and pass it on to the alias for the host in order to make logging into Windows almost as painless as *nix hosts. +**This feature should be considered temporary and used only at your own risk.** This is a **very insecure** thing to do, and the intent is to replace this later with LastPass support or similar instead, and was added mostly as a personal exercise. + +To configure, once you have your password file set up, just export the location as a variable in your shell RC before sourcing the __Tab Sorcery__ script like so: +``` +export SORC_PASS_FILE="$HOME/.some_file" +``` + +### Full Example of How to Call the Tab Sorcery Script +Here is a full example utilizing all available options. Please note that only the last line, beginning with a dot, is absolutely required. +``` +export SORC_GEOM_RDP="1280x720" +export SORC_PASS_FILE="$HOME/.some_file" . $HOME/git/tab-sorcery/tab-sorcery.sh example.com 127.0.0.1 bob.user ``` -The default window geometry that is used if this variable is either unset, or if an invalid value is detected is **1600x900**. + ## DNS Setup You'll likely want to create a DNS zone specifically for this script for better control over the hosts included. I would recommend using a TLD not normally available, to be sure you don't have any overlap with existing DNS names. This domain doesn't need to be publicly queried, and actually it's probably in interest of security if it isn't. diff --git a/tab-sorcery.sh b/tab-sorcery.sh index 3162ace..8545007 100644 --- a/tab-sorcery.sh +++ b/tab-sorcery.sh @@ -8,18 +8,38 @@ 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}'` } -zone_xfer=`dig $scan_domain @$scan_ns AXFR | egrep -v 'SOA|NS|MX|DiG' | grep $scan_domain | awk '{print $1,$4,$5}'` +##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" @@ -30,7 +50,16 @@ while read host <&3; do 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 - connect_cmd="rdesktop -g $geom_rdp" + 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