From ea93ad7d2511db4b6eedf40062f7771f64a8e426 Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Sun, 16 Sep 2018 22:38:19 -0500 Subject: [PATCH 1/3] Added telnet/RDP ability, and TXT record parsing --- README.md | 11 ++++++++--- tab-sorcery.sh | 27 ++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) mode change 100755 => 100644 tab-sorcery.sh diff --git a/README.md b/README.md index f187d71..beeb382 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,13 @@ This is still under development and will eventually cover more variables and con ## To use: Add the script as a source file in your shell prompt, such as a line similar to this: -```. $HOME/git/tab-sorcery/tab-sorcery.sh example.com 127.0.0.1``` +```. $HOME/git/tab-sorcery/tab-sorcery.sh example.com 127.0.0.1 bob.user``` +Arguments are: +``` +Scan Domain (example.com) +Nameserver address (127.0.0.1) +Default username (bob.user) +``` -The arguments in the example show the domain to scan for hostnames, and the IP address of the name server providing them. -Once done, all hostnames in the DNS zone should be available for SSH by a tab-completable alias of just the hostname. +Once done, all hostnames in the DNS zone should be available for SSH/Telnet/RDP by a tab-completable alias of just the hostname. diff --git a/tab-sorcery.sh b/tab-sorcery.sh old mode 100755 new mode 100644 index 6dcd78e..3ffe0be --- a/tab-sorcery.sh +++ b/tab-sorcery.sh @@ -6,10 +6,31 @@ scan_domain=$1 scan_ns=$2 +user_name=$3 -dig skyfall.gear @$scan_ns AXFR | egrep -v 'SOA|NS|MX|DiG' | grep $scan_domain | awk '{print $1,$5}' > /tmp/.tab-sorcery -for i in `awk -F. '{print $1}' /tmp/.tab-sorcery`; do alias $i="ssh `grep $i /tmp/.tab-sorcery | awk '{print $2}'`"; done -\rm -f /tmp/.tab-sorcery +zone_xfer=`dig $scan_domain @$scan_ns AXFR | egrep -v 'SOA|NS|MX|DiG' | grep $scan_domain | awk '{print $1,$4,$5}'` +for host in `echo $zone_xfer | awk -F. '{print $1}'`; do + user_name=$3 + connect_cmd="ssh -t" + 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" + host_ip=`echo $zone_xfer | grep $host | grep A | awk '{print $3}'` + alias ${host}="${connect_cmd} ${user_name}@${host_ip}" + elif [ "`echo $zone_xfer | grep $host | grep TXT | awk '{print $3}'`" = '"windows"' ]; then + connect_cmd="rdesktop -g 1600x900" + host_ip=`echo $zone_xfer | grep $host | grep A | awk '{print $3}'` + alias ${host}="${connect_cmd} -u ${user_name} ${host_ip}" + elif [ "`echo $zone_xfer | grep $host | grep TXT | awk '{print $3}'`" = '"cisco"' ]; then + connect_cmd="telnet" + host_ip=`echo $zone_xfer | grep $host | grep A | awk '{print $3}'` + alias ${host}="${connect_cmd} ${host_ip}" + fi + else + host_ip=`echo $zone_xfer | grep $host | grep A | awk '{print $3}'` + alias ${host}="${connect_cmd} ${user_name}@${host_ip}" + fi >/dev/null +done return 0 From 9a0a7f1375ef33849927dabbf32bd6ccf634e565 Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Sun, 16 Sep 2018 23:38:23 -0500 Subject: [PATCH 2/3] Fixed multi-IP bug. --- README.md | 6 ++++-- tab-sorcery.sh | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index beeb382..6e0ba33 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ # Tab Sorcery -This is still under development and will eventually cover more variables and connection types. +A helpful script for simplifying connections to servers and devices on your network. ## To use: Add the script as a source file in your shell prompt, such as a line similar to this: -```. $HOME/git/tab-sorcery/tab-sorcery.sh example.com 127.0.0.1 bob.user``` +``` +. $HOME/git/tab-sorcery/tab-sorcery.sh example.com 127.0.0.1 bob.user +``` Arguments are: ``` Scan Domain (example.com) diff --git a/tab-sorcery.sh b/tab-sorcery.sh index 3ffe0be..a956b8f 100644 --- a/tab-sorcery.sh +++ b/tab-sorcery.sh @@ -3,32 +3,33 @@ # ARGUMENTS: # $1 == Domain to scan # $2 == Nameserver to do the zone transfer from +# $3 == Default username for connections scan_domain=$1 scan_ns=$2 -user_name=$3 zone_xfer=`dig $scan_domain @$scan_ns AXFR | egrep -v 'SOA|NS|MX|DiG' | grep $scan_domain | awk '{print $1,$4,$5}'` -for host in `echo $zone_xfer | awk -F. '{print $1}'`; do +for host in `echo $zone_xfer | awk '{print $1}'`; 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" - host_ip=`echo $zone_xfer | grep $host | grep A | awk '{print $3}'` - alias ${host}="${connect_cmd} ${user_name}@${host_ip}" + host_ip=`echo $zone_xfer | grep ${host} | grep A | awk '{print $3}'` + 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 1600x900" - host_ip=`echo $zone_xfer | grep $host | grep A | awk '{print $3}'` - alias ${host}="${connect_cmd} -u ${user_name} ${host_ip}" + host_ip=`echo $zone_xfer | grep ${host} | grep A | awk '{print $3}'` + 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" - host_ip=`echo $zone_xfer | grep $host | grep A | awk '{print $3}'` - alias ${host}="${connect_cmd} ${host_ip}" + host_ip=`echo $zone_xfer | grep ${host} | grep A | awk '{print $3}'` + alias ${host_short}="${connect_cmd} ${host_ip}" fi else host_ip=`echo $zone_xfer | grep $host | grep A | awk '{print $3}'` - alias ${host}="${connect_cmd} ${user_name}@${host_ip}" + alias ${host_short}="${connect_cmd} ${user_name}@${host_ip}" fi >/dev/null done From dca065ccec6404d28daa60d9ad0c3f1771ff4f98 Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Sun, 16 Sep 2018 23:39:43 -0500 Subject: [PATCH 3/3] Updated README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e0ba33..486dabe 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,11 @@ A helpful script for simplifying connections to servers and devices on your netw ## To use: Add the script as a source file in your shell prompt, such as a line similar to this: + ``` . $HOME/git/tab-sorcery/tab-sorcery.sh example.com 127.0.0.1 bob.user ``` + Arguments are: ``` Scan Domain (example.com) @@ -15,5 +17,5 @@ Nameserver address (127.0.0.1) Default username (bob.user) ``` -Once done, all hostnames in the DNS zone should be available for SSH/Telnet/RDP by a tab-completable alias of just the hostname. +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).