Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: BigBear en 1 Diciembre 2011, 22:11 pm



Título: [Perl] FinderText 0.1
Publicado por: BigBear en 1 Diciembre 2011, 22:11 pm
Un simple programa para buscar cierto texto en un archivo o directorio.

Código
  1. #!usr/bin/perl
  2. #FinderText 0.1
  3. #Written by Doddy H
  4.  
  5. print "\n-- == FinderText 0.1 == --\n\n";
  6. unless($ARGV[0]) {
  7. print "\n[+] sintax : $0 <file/dir> <text>\n";
  8. } else {
  9. print "\n[+] Searching text\n\n";
  10. if (-f $ARGV[0]) {
  11. verificar($ARGV[0],$ARGV[1]);
  12. }
  13. if (-d $ARGV[0]) {
  14. goodbye($ARGV[0],$ARGV[1]);
  15. }
  16. print "\n[+] Finished\n";
  17. }
  18. print "\n\n[+] Written By Doddy H\n\n";
  19.  
  20. sub verificar {
  21.  
  22. my ($file,$text) = @_;
  23. my $numero_linea = 0;
  24.  
  25. open(FILE,$file);
  26. my @words = <FILE>;
  27. close FILE;
  28.  
  29. chomp @words;
  30.  
  31. for my $linea(@words) {
  32. chomp $linea;
  33. $numero_linea++;
  34. if ($linea=~/$text/ig) {
  35. print "[+] Text $text Found in file $file in line $numero_linea\n";
  36. }}}
  37.  
  38. sub goodbye {
  39.  
  40. opendir DIR,$_[0];
  41. my @archivos = readdir DIR;
  42. close DIR;
  43.  
  44. for (@archivos) {
  45. next if $_ eq "." or $_ eq "..";
  46. my $fichero = $_[0]."/".$_;
  47.  
  48. if (-f $fichero) {
  49. verificar($fichero,$_[1]);
  50. }
  51.  
  52. if (-d $fichero) {
  53. &goodbye($fichero);
  54. }}}
  55.  
  56. # The End ?