Skip to content

Commit

Permalink
multish-discover-hosts - search for devices in network
Browse files Browse the repository at this point in the history
New option in multish to collect devices with 22 open port
Only put example in /etc/multish/group if directory empty
  • Loading branch information
raultm committed May 31, 2022
1 parent 6374a99 commit 1630bf0
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 9 deletions.
4 changes: 2 additions & 2 deletions DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: multish
Version: 0.2.1
Version: 0.3.0
Architecture: all
Maintainer: Raul Tierno<[email protected]>
Depends: tmux,sshpass
Depends: tmux,sshpass,nmap
Description: multish allows you to connect and act in multiple ssh connection simultaneously
24 changes: 24 additions & 0 deletions DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
# file name preinst

echo "Pre Installation code here ..."


function createFolderIfNotExists {
if [ ! -d $1 ]; then
mkdir -p $1
fi
}

function checkifDirectoryIsEmpty {
if [ -z "$(ls -A $1)" ]; then
echo "The directory $1 is empty"
cp /usr/share/multish/files/example $1/example
else
echo "The directory $1 is not empty. No Action"
fi
}

FOLDER="/etc/multish/group"
createFolderIfNotExists $FOLDER
checkifDirectoryIsEmpty $FOLDER
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ al instalar tener por defecto en `/etc/multish/groups` los archivos de grupos a
En la carpeta donde hayas descargado el archivo .deb apt/apt-get install instala el paquete y las dependencias. Poner './' para que sepa que es un archivo local y no un paquete de los repositorios

```sh
apt install ./multish_0.2.1_all.deb
apt install ./multish_0.3.0_all.deb
```

Si usas dpkg debes ejecutar despues apt para instalar las dependencias y finalizar la instalación

```sh
dpkg -i multish_X.Y.Z_all.deb
dpkg -i multish_0.3.0_all.deb
apt-get -f install
```

Expand Down
Binary file renamed multish_0.2.1_all.deb → multish_0.3.0_all.deb
Binary file not shown.
14 changes: 9 additions & 5 deletions usr/bin/multish
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# multissh - create a tmux-cssh connection from parameter or selected option
#
# Authors: Raul Tierno <[email protected]>
# Fernando Lorenzo
# Fernando Lorenzo <[email protected]>
#
#

Expand Down Expand Up @@ -39,21 +39,25 @@ function checkargument {
}

function selectoption {
prompt="Select group: "
prompt="Select Option: "
options=( $(find /etc/multish/group -type f -name "*" -print0 | xargs -0) )

echo ""
echo "Create a multiple ssh connection to group"
echo "-----------------------------------------"
PS3="$prompt "

select opt in "${options[@]}" "Copy SSH public key to group" "Quit" ; do
if (( REPLY == 2 + ${#options[@]} )) ; then
select opt in "${options[@]}" "Find hosts with port 22 open in network" "Copy SSH public key to group" "Quit" ; do
if (( REPLY == 3 + ${#options[@]} )) ; then
break
elif (( REPLY == 1 + ${#options[@]} )); then
elif (( REPLY == 2 + ${#options[@]} )); then
echo
multish-copy-id
exit
elif (( REPLY == 1 + ${#options[@]} )); then
echo
multish-discover-hosts
exit
elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
echo "You picked $opt which is file $REPLY"
cssh $opt
Expand Down
56 changes: 56 additions & 0 deletions usr/bin/multish-discover-hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
#
# multissh-discovers-hosts - search for devices with 22 open port to store and connect to them
#
# Authors: Raul Tierno <[email protected]>
#
#

function findAllHostsWithPort22OpenInNetwork {
sudo nmap 192.168.1.1-254 -p22 -oG - | awk '/22\//{print $2 " # " $5}'
}

function readFromCLIWithDefaultOption {
read -p "$1 [$2]: " result
if [ -z $result ]; then
result=$2
fi
echo $result
}

function getSuggestedNetwork {
echo $(ip -4 -o addr | awk ' {print $4}' | grep -v "127.0.0.1" | head -n 1)
}

function getSuggestedName {
date +"%Y-%m-%d-%H-%M-%S-discover-results"
}

function createFolderIfNotExists {
if [ ! -d $1 ]; then
mkdir -p $1
fi
}

SUGGESTEDNETWORK=$(getSuggestedNetwork)
SUGGESTEDNAME=$(getSuggestedName)

NETWORK=$(readFromCLIWithDefaultOption "Define la red que quieres explorar" $SUGGESTEDNETWORK)
FILENAME=$(readFromCLIWithDefaultOption "Nombre de archivo donde se guardarán los resultados" $SUGGESTEDNAME)
FOLDER="/etc/multish/group/network-discoveries"

echo "Explorando $NETWORK. Los resultados se guardarán en $FILENAME. Espere a que termine el proceso..."

createFolderIfNotExists $FOLDER

sudo nmap $NETWORK -p22 -oG - | awk '/22\/open/{print "root@" $2 " # " $5}' > $FOLDER/$FILENAME

echo "Exploración Finalizada. Los resultados se han guardado en $FOLDER/$FILENAME"

RUN=$(readFromCLIWithDefaultOption "¿Quieres conectarte ahora a los equipos encontrados? y/n " "y")
if [[ $RUN =~ ^[YySs]$ ]]
then
multish "$FOLDER/$FILENAME"
else
multish
fi
File renamed without changes.

0 comments on commit 1630bf0

Please sign in to comment.