Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - leogtz

#1221
Código (bash) [Seleccionar]
#!/bin/bash
# Menu de opciones con select
OPCIONES="Hola Lala Salir"
select opt in $OPCIONES;
do
if [ "$opt" = "Hola" ]
then
echo -e "Hola";
elif [ "$opt" = "Lala" ]
then
echo -e "Lala";
elif [ "$opt" = "Salir" ]
then
echo -e "Has salido";
exit 0;
else
echo -e "Opción errónea";
fi
done
         



En vez del condicional IF, se podría usar un case.

En bash no hay goto, pero se puede sustituir facilmente con llamadas a funciones y loops.

Código (bash) [Seleccionar]

#!/bin/bash
# Menu de opciones con select
OPCIONES="Hola Lala Salir"
select opt in $OPCIONES;
do
case "$opt" in
"Hola")
echo -e "Hola";
break;
;;
"Lala")
echo -e "Lala";
break;
;;
"Salir")
echo -e "Salir";
exit 0;
;;
*)
echo -e "Opcion erronea";
;;
esac
done

echo -e "Continua";
#1222
Foro Libre / Re: Que hacer?
2 Noviembre 2010, 23:29 PM
Yo me sentía igual hace mucho, lo único que me alivianaba era el código.

Después me enamoré y ahora estoy perfecto, todo tiene sentido :D
#1223
De nada.  ;)
#1224
Cita de: moikanolaplana en  1 Noviembre 2010, 18:38 PM
Nadie tiene una idea de como hacerlo?  :-\

Tranquilo que también tenemos vidas sociales.


Código (bash) [Seleccionar]
#!/bin/bash
ifconfig -a
gnome-terminal -x bash -c "ls|less"
#1225
Foro Libre / Re: Felicidades Novlucker
1 Noviembre 2010, 18:29 PM
Código (bash) [Seleccionar]
#!/bin/bash
while :
do
echo "Felicidades !";
done
#1226
Scripting / RAR brute force [bash]
1 Noviembre 2010, 09:34 AM
Hola, viendo algunos proyectos en sourceforge en shell script, hallé este:

Funciona bien, pero no me gustó el código, así que lo rehice siguiendo la idea del autor.

Código (bash) [Seleccionar]
#!/bin/bash
#===============================================================================
#
#          FILE:  bruto.sh
#
#         USAGE:  ./bruto.sh
#
#   DESCRIPTION:  Found passwords in RAR files using a word list
#  Idea original de http://sourceforge.net/projects/rarbrute/
#       OPTIONS:  ---
#  REQUIREMENTS:  rar, sed, wc,
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  Leo Gutierrez Ramirez (), leorocko13@hotmail.com
#       VERSION:  1.0
#       CREATED:  31/10/10 22:15:40 MST
#      REVISION:  ---
#===============================================================================
function usage()
{
cat <<EOF

`basename $0` file.rar [-d word-list | -n number-limit | -h]

-h : Help

Author : Leo Gutiérrez R (leorocko13@hotmail.com),  idea from aciddata:
http://sourceforge.net/projects/rarbrute/files/

EOF
exit 1
}

function isRAR()
{
[[ -f "$1" ]] && {
if [ "`file -b "$1" | awk '{print $1}'`" = "RAR" ]
then
return 1;
else
return 0;
fi
} || {
echo -e "Can't find or read file - $1 -";
return 0;
}
}


args=`getopt d:n:h $* 2> /dev/null`
if test $? != 0
then
usage;
fi

set -- $args

for i
do
case "$i" in
# -n ##############################################################
-n)
shift;

RARFILE="$3";
NLIMIT="$1";

# Checar que -n sean números :
n=`echo ${NLIMIT} | tr -d "[0-9]"`
if [[ ! -z $n ]]
then
echo -e "`basename $0` -> ${NLIMIT} Number needed ";
exit 1;
fi

isRAR ${RARFILE}
if [ $? -ne 1 ]
then
echo -e "\n\t`basename ${RARFILE}` This is no RAR file\n";
exit 1;
fi

((i = 0));

while((i <= $NLIMIT))
do
test=`rar x -p"${i}" "${RARFILE}" 1>/dev/null 2>/dev/null`
test2=$?
if [ "$test2" = 0 ]
then
echo -e "\n file "${RARFILE}" is successfully broken the used key is: \"${i}\"\n\a"
exit 0;
fi
((i++));

done

echo -e "\n\tKey not found\n";

shift;

# Romper el ciclo :
break;

shift;
;;
# -d #############################################################
-d)
shift;

WORDLIST="$1";
RARFILE="$3";
LINES=`wc -l "${WORDLIST}" | awk '{print $1}'`

((n = 1));
while [ "$LINES" -gt "$n" ]
do

line=`head -"$n" "${WORDLIST}" | tail -1`
testing=`rar x -p"$line" "${RARFILE}" 1>/dev/null 2>/dev/null`
testing2=`echo $?`
if [ "$testing2" = 0 ]
then
echo -e "\n\tfile "${RARFILE}" is successfully broken";
echo -e "\tthe used keyword is: $line\n\a";
exit 0;
fi
((n++));
done

# Romper el ciclo :
break;

shift;
;;

-h)
usage;
;;
*)
echo -e "[Unknow Option\a]";
usage;
;;
esac
done


Para que funcione bien, el formato del diccionario debe ser totalmente UNIX, por lo que hay que remover los CR/LF.

Usen dos2unix:

Código (bash) [Seleccionar]
leo@leo-desktop:~/proyectos/brutorar$ dos2unix -a -d -vv -b -o dic.dic
dos2unix: Converting dic.dic
leo@leo-desktop:~/proyectos/brutorar$


Ahora sí:

Código (bash) [Seleccionar]
leo@leo-desktop:~/proyectos/brutorar$ bash my_bruto.sh a.rar -d dic.dic

        file a.rar is successfully broken
        the used keyword is: leito

leo@leo-desktop:~/proyectos/brutorar$
#1227
Scripting / Re: Bucles tipo C/C++ en Bash
31 Octubre 2010, 19:03 PM
¿Qué shell estás usando?
#1228
Todo parece indicar que sí.
#1229
Foro Libre / Re: Acabo de darme cuenta
31 Octubre 2010, 07:03 AM
Yo una vez duré más de 35 horas despierto, no frente a la PC, pero sí despierto, recuerdo que el cerebro me zumbaba  :o

Luego de eso me fui a dormir inmediatamente, sugiero hagas lo mismo.
#1230
[offtopic] Saludos desde Chihuahua [/offtopic]