Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: BigBear en 14 Abril 2012, 19:49 pm



Título: [Perl] Mysql Manager 0.5
Publicado por: BigBear en 14 Abril 2012, 19:49 pm
Nueva version de un mysql manager que hice hace un largo tiempo.

Código
  1. #!usr/bin/perl
  2. #Mysql Manager 0.5
  3. #Coded By Doddy H
  4. #Modules
  5. #ppm install http://www.bribes.org/perl/ppm/Scalar-List-Utils.ppd
  6. #ppm install http://www.bribes.org/perl/ppm/Storable.ppd
  7. #ppm install http://www.bribes.org/perl/ppm/DBI.ppd
  8. #ppm install http://theoryx5.uwinnipeg.ca/ppms/DBD-mysql.ppd
  9.  
  10. use DBI;
  11.  
  12. sub head {
  13.    print "\n\n -- == Mysql Manager 0.5 == --\n\n";
  14. }
  15.  
  16. sub copyright {
  17.    print "\n\n-- == (C) Doddy Hackman 2012 == --\n\n";
  18.    exit(1);
  19. }
  20.  
  21. sub sintax {
  22.    print "\n[+] Sintax : $0 <host> <user> <pass>\n";
  23. }
  24.  
  25. head();
  26. unless ( @ARGV > 2 ) {
  27.    sintax();
  28. }
  29. else {
  30.    enter( $ARGV[0], $ARGV[1], $ARGV[2] );
  31. }
  32. copyright();
  33.  
  34. sub enter {
  35.  
  36.    print "\n[+] Connecting to the server\n";
  37.  
  38.    $info = "dbi:mysql::" . $_[0] . ":3306";
  39.    if ( my $enter = DBI->connect( $info, $_[1], $_[2], { PrintError => 0 } ) )
  40.    {
  41.  
  42.        print "\n[+] Enter in the database";
  43.  
  44.        while (1) {
  45.            print "\n\n\n[+] Query : ";
  46.            chomp( my $ac = <stdin> );
  47.  
  48.            if ( $ac eq "exit" ) {
  49.                $enter->disconnect;
  50.                print "\n\n[+] Closing connection\n\n";
  51.                copyright();
  52.            }
  53.  
  54.            $re = $enter->prepare($ac);
  55.            $re->execute();
  56.            my $total = $re->rows();
  57.  
  58.            my @columnas = @{ $re->{NAME} };
  59.  
  60.            if ( $total eq "-1" ) {
  61.                print "\n\n[-] Query Error\n";
  62.                next;
  63.            }
  64.            else {
  65.                print "\n\n[+] Result of the query\n";
  66.                if ( $total eq 0 ) {
  67.                    print "\n\n[+] Not rows returned\n\n";
  68.                }
  69.                else {
  70.                    print "\n\n[+] Rows returned : " . $total . "\n\n\n";
  71.                    for (@columnas) {
  72.                        print $_. "\t\t";
  73.                    }
  74.                    print "\n\n";
  75.                    while ( @row = $re->fetchrow_array ) {
  76.                        for (@row) {
  77.                            print $_. "\t\t";
  78.                        }
  79.                        print "\n";
  80.                    }
  81.                }
  82.            }
  83.        }
  84.    }
  85.    else {
  86.        print "\n[-] Error connecting\n";
  87.    }
  88. }
  89.  
  90. # ¿ The End ?
  91.  
  92.