• Publicidad

SecurityFocus Manager

¿Estás desarrollando un proyecto, o piensas hacerlo? Pon aquí tu propuesta, lo más seguro es que alguien esté interesado en ayudarte.

SecurityFocus Manager

Notapor BigBear » 2011-11-17 20:41 @903

Bueno, quería mostrar el código que con la ayuda de explorer logré terminar.

Este simple programa lista las últimas vulnerabilidades publicadas en securityfocus.com y podremos verlas desde consola viendo la información, exploit, solución...

El código es el siguiente:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2. #SecurityFocus Manager 0.3
  3. #(C) Doddy Hackman 2011
  4. ##ppm install http://www.bribes.org/perl/ppm/HTML-Strip.ppd
  5.  
  6. use LWP::UserAgent;
  7. use HTML::Parser;
  8. use HTML::Strip;
  9.  
  10. my $nave = LWP::UserAgent->new;
  11. $nave->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8.1.12) Gecko/20080201Firefox/2.0.0.12");
  12. $nave->timeout(5);
  13.  
  14. head();
  15. refrescar();
  16.  
  17. sub refrescar {
  18.  
  19. clean();
  20. head();
  21.  
  22. print "\n\n[+] List of vulnerabilities\n\n\n";
  23.  
  24. my %links = getlinks($code);
  25. my $contador = -1;
  26.  
  27. for my $da(keys %links) {
  28. $contador++;
  29. print "[$contador] : $da\n";
  30. }
  31. print qq(
  32.  
  33. [1] : Refresh
  34. [2] : Info
  35. [3] : Discussion
  36. [4] : Exploit
  37. [5] : Solution
  38. [6] : References
  39. [7] : Exit
  40.  
  41. );
  42.  
  43. print "\n[Option] : ";
  44. chomp(my $op = <stdin>);
  45.  
  46. if ($op eq 1) {
  47. clean();
  48. refrescar();
  49. }
  50. elsif ($op eq 2) {
  51.  
  52. print "\n[+] Number : ";
  53. chomp(my $se=<stdin>);
  54.  
  55. my $fin = (keys %links)[$se];
  56. my $pro = (values %links)[$se];
  57.  
  58. dar($fin,$pro,"tres");
  59.  
  60. }
  61. elsif($op eq 3) {
  62.  
  63. print "\n[+] Number : ";
  64. chomp(my $se=<stdin>);
  65.  
  66. my $fin = (keys %links)[$se];
  67. my $pro = (values %links)[$se];
  68.  
  69. dar($fin,$pro,"cuatro");
  70.  
  71. }
  72. elsif($op eq 4) {
  73.  
  74. print "\n[+] Number : ";
  75. chomp(my $se=<stdin>);
  76.  
  77. my $fin = (keys %links)[$se];
  78. my $pro = (values %links)[$se];
  79.  
  80. dar($fin,$pro,"cinco");
  81.  
  82. }
  83. elsif ($op eq 5) {
  84.  
  85. print "\n[+] Number : ";
  86. chomp(my $se=<stdin>);
  87.  
  88. my $fin = (keys %links)[$se];
  89. my $pro = (values %links)[$se];
  90.  
  91. dar($fin,$pro,"seis");
  92.  
  93. }
  94. elsif ($op eq 6) {
  95.  
  96. print "\n[+] Number : ";
  97. chomp(my $se=<stdin>);
  98.  
  99. my $fin = (keys %links)[$se];
  100. my $pro = (values %links)[$se];
  101.  
  102. dar($fin,$pro,"siete");
  103.  
  104. }
  105. elsif ($op eq 7) {
  106. copyright();
  107. exit(1);
  108. }
  109. else {
  110. refrescar();
  111. }
  112. }
  113.  
  114. sub dar {
  115.  
  116. my($title,$numero,$op) = @_;
  117.  
  118. print "\n\n[+] Getting data\n\n";
  119.  
  120. if ($op eq "tres") {
  121. $link = "http://www.securityfocus.com/bid/$numero/info";
  122. }
  123. if ($op eq "cuatro") {
  124. $link = "http://www.securityfocus.com/bid/$numero/discuss";
  125. }
  126. if ($op eq "cinco") {
  127. $link = "http://www.securityfocus.com/bid/$numero/exploit";
  128. }
  129. if ($op eq "seis") {
  130. $link = "http://www.securityfocus.com/bid/$numero/solution";
  131. }
  132. if ($op eq "siete") {
  133. $link = "http://www.securityfocus.com/bid/$numero/references";
  134. }
  135.  
  136. my $code = toma($link);
  137.  
  138. if ($code=~/<div id="vulnerability">(.*?)<\/div>/s){
  139. my $code = $1;
  140. chomp $code;
  141. my $uno = HTML::Strip->new(emit_spaces =>1);
  142. my $final = $uno->parse($code);
  143. $final =~ s/^[\t\f ]+|[\t\f ]+$//mg;
  144. $final =~s/$title/ /;
  145. print $final;
  146. }
  147.  
  148. print "\n\n[+] Press any key to continue\n\n";
  149. <stdin>;
  150. refrescar();
  151.  
  152. }
  153.  
  154. sub getlinks {
  155.  
  156. my $code = toma("http://www.securityfocus.com/");
  157.  
  158. my $test = HTML::Parser->new(
  159. start_h => [\&start, "tagname,attr"],
  160. text_h  => [\&text, "dtext"],
  161. );
  162. $test->parse($code);
  163.  
  164. sub start {
  165. my($a,$b) = @_;
  166. my %e = %$b;
  167. unless($a ne "a") {
  168. $d = $e{href};
  169. $c = $a;
  170. }}
  171.  
  172. sub text {
  173. my $title = shift;
  174. chomp $title;
  175. unless($c ne "a") {
  176. if ($d=~/\/bid\/(.*)/) {
  177. my $id = $1;
  178. unless($title=~/www.securityfocus.com/) {
  179. $links{$title} = $id;
  180. }}
  181. $d = "";
  182. }}
  183. return %links;
  184. }
  185.  
  186. sub toma {
  187. return $nave->get($_[0])->content;
  188. }
  189.  
  190. sub repes {
  191. foreach $test(@_) {
  192. push @limpio,$test unless $repe{$test}++;
  193. }
  194. return @limpio;
  195. }
  196.  
  197. sub clean {
  198. #if ($^O =~/Win32/ig) {
  199. system("cls");
  200. #} else {
  201. #system("clear");
  202. #}
  203. }
  204.  
  205. sub head {
  206. print "\n\n-- == SecurityFocus Manager 0.3 == --\n\n";
  207. }
  208.  
  209. sub copyright {
  210. print "\n\n\n(C) Doddy Hackman 2011\n\n";
  211. }
  212.  
  213. #Credits: Thanks to explorer (perlenespanol)
  214. # The End ?
  215.  
Coloreado en 0.006 segundos, usando GeSHi 1.0.8.4
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Publicidad

Re: SecurityFocus Manager

Notapor explorer » 2011-11-17 21:01 @917

Gracias por el reconocimiento.

Hummm... ¿no hay mucho código repetido?
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: SecurityFocus Manager

Notapor BigBear » 2011-11-18 08:22 @390

Sí, en la parte del menú hay mucho código repetido pero no se me ocurrió cómo reducirlo...
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Re: SecurityFocus Manager

Notapor explorer » 2011-11-18 19:44 @864

Esta es mi versión, aunque hay alguna cosilla que no me gusta cómo ha quedado.
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2. #
  3. # SecurityFocus Manager 0.3.1
  4. # (C) Doddy Hackman 2011
  5. #
  6. # Show lastest vulnerabilities from SecurityFocus.
  7. #
  8. # JF version.
  9.  
  10. use 5.010;
  11. use strict;
  12. use autodie;
  13. use warnings;
  14. use diagnostics;
  15.  
  16. ### Modules ###
  17. use HTML::Strip;
  18. use Term::Menus;
  19. use WWW::Mechanize;
  20.  
  21.  
  22. ### Constants ###
  23. my $SECURITYFOCUS_URL     = 'http://www.securityfocus.com';
  24. my @SECURITYFOCUS_OPTIONS = qw(Info Discuss Exploit Solution References);
  25.  
  26.  
  27. ### Init ###
  28. my $html_strip_parser = HTML::Strip->new( emit_spaces => 0 );
  29. my $mech = WWW::Mechanize->new();
  30. $mech->agent_alias('Linux Mozilla');
  31. $Term::Menus::noclear    = 1;
  32. $Term::Menus::blanklines = "\n";
  33.  
  34.  
  35. ### Program ###
  36. print "\n\n-- == SecurityFocus Manager 0.3.1 == --\n\n";
  37.  
  38. my $to_end = 0;
  39. my @vulnerabilities;
  40.  
  41. do {
  42.     if (!@vulnerabilities) {
  43.         say "Refreshing...";
  44.  
  45.         $mech->get($SECURITYFOCUS_URL);
  46.  
  47.         for my $url_ref ($mech->find_all_links( url_regex => qr(^/bid/))) {
  48.             my($url, $text) = ($url_ref->url, $url_ref->text);
  49.  
  50.             next if $text =~ /^http/;
  51.  
  52.             push @vulnerabilities, [ $url, $text ];
  53.         }
  54.     }
  55.  
  56.     say '[++] List of vulnerabilities: ';
  57.     my $i = 1;
  58.     for (@vulnerabilities) {
  59.         printf "[%2d] : %s\n", $i++, $_->[1];
  60.     }
  61.  
  62.     # Menu
  63.     my $selection = pick(
  64.         [   'Refresh',
  65.             @SECURITYFOCUS_OPTIONS,
  66.         ],
  67.         '[Option] : '
  68.     );
  69.  
  70.     given ($selection) {
  71.         when ('Refresh') {
  72.             system('clear');
  73.             undef @vulnerabilities;
  74.         }
  75.         when (']quit[') {
  76.             $to_end = 'yes!';
  77.         }
  78.         when (@SECURITYFOCUS_OPTIONS) {
  79.             print "\n[$selection] Number? : ";
  80.             chomp(my $sel = <>);
  81.  
  82.             say "\n[+] Getting data...\n";
  83.  
  84.             if ($sel <= @vulnerabilities) {
  85.                 $sel--;
  86.  
  87.                 $mech->get( $SECURITYFOCUS_URL
  88.                           . $vulnerabilities[$sel]->[0]
  89.                           . "/\L$selection"
  90.                 );
  91.  
  92.                 if ( $mech->content =~ /^<div id="vulnerability">(.*?)^<\/div>/sm ) {
  93.                     my $final = $html_strip_parser->parse($1);
  94.                     $final =~ s/^\s+$//gm;
  95.                     $final =~ s/\n+/\n/g;
  96.                     say $final;
  97. #                    open my $LESS, "|less -F -S -- -";
  98. #                    print $LESS $final;
  99. #                    close $LESS;
  100.                     say "[+] Press Enter key to continue"; <>;
  101.                 }
  102.             }
  103.         }
  104.     }
  105. } while (not $to_end);
  106.  
  107. print "\n\n\n(C) Doddy Hackman 2011\n\n";
  108.  
  109. # Credits: Thanks to explorer (perlenespanol.com)
  110. # The End ?
  111.  
  112. __END__
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: SecurityFocus Manager

Notapor BigBear » 2011-11-19 12:38 @568

Yo había pensado algo así.

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!usr/bin/perl
  2. #SecurityFocus Manager 0.3
  3. #(C) Doddy Hackman 2011
  4. ##ppm install http://www.bribes.org/perl/ppm/HTML-Strip.ppd
  5.  
  6. use LWP::UserAgent;
  7. use HTML::Parser;
  8. use HTML::Strip;
  9.  
  10. my $nave = LWP::UserAgent->new;
  11. $nave->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8.1.12) Gecko/20080201Firefox/2.0.0.12");
  12. $nave->timeout(5);
  13.  
  14. head();
  15. refrescar();
  16.  
  17. sub refrescar {
  18.  
  19. clean();
  20. head();
  21.  
  22. print "\n\n[+] List of vulnerabilities\n\n\n";
  23.  
  24. my %links = getlinks($code);
  25. my $contador = -1;
  26.  
  27. for my $da(keys %links) {
  28. $contador++;
  29. print "[$contador] : $da\n";
  30. }
  31. print qq(
  32.  
  33. [1] : Refresh
  34. [2] : Info
  35. [3] : Discussion
  36. [4] : Exploit
  37. [5] : Solution
  38. [6] : References
  39. [7] : Exit
  40.  
  41. );
  42.  
  43. print "\n[Option] : ";
  44. chomp(my $op = <stdin>);
  45.  
  46. if ($op eq 1) {
  47. clean();
  48. refrescar();
  49. }
  50. elsif ($op eq 2) {
  51. my $se = preguntar();
  52. dar((keys %links)[$se],(values %links)[$se],"tres");
  53. }
  54. elsif($op eq 3) {
  55. my $se = preguntar();
  56. dar((keys %links)[$se],(values %links)[$se],"cuatro");
  57. }
  58. elsif($op eq 4) {
  59. my $se = preguntar();
  60. dar((keys %links)[$se],(values %links)[$se],"cinco");
  61. }
  62. elsif ($op eq 5) {
  63. my $se = preguntar();
  64. dar((keys %links)[$se],(values %links)[$se],"seis");
  65. }
  66. elsif ($op eq 6) {
  67. my $se = preguntar();
  68. dar((keys %links)[$se],(values %links)[$se],"siete");
  69. }
  70. elsif ($op eq 7) {
  71. copyright();
  72. exit(1);
  73. }
  74. else {
  75. refrescar();
  76. }
  77. }
  78.  
  79. sub preguntar {
  80. print "\n[+] Number : ";
  81. chomp(my $se=<stdin>);
  82. return $se;
  83. }
  84.  
  85. sub dar {
  86.  
  87. my($title,$numero,$op) = @_;
  88.  
  89. print "\n\n[+] Getting data\n\n";
  90.  
  91. if ($op eq "tres") {
  92. $link = "http://www.securityfocus.com/bid/$numero/info";
  93. }
  94. if ($op eq "cuatro") {
  95. $link = "http://www.securityfocus.com/bid/$numero/discuss";
  96. }
  97. if ($op eq "cinco") {
  98. $link = "http://www.securityfocus.com/bid/$numero/exploit";
  99. }
  100. if ($op eq "seis") {
  101. $link = "http://www.securityfocus.com/bid/$numero/solution";
  102. }
  103. if ($op eq "siete") {
  104. $link = "http://www.securityfocus.com/bid/$numero/references";
  105. }
  106.  
  107. my $code = toma($link);
  108.  
  109. if ($code=~/<div id="vulnerability">(.*?)<\/div>/s){
  110. my $code = $1;
  111. chomp $code;
  112. my $uno = HTML::Strip->new(emit_spaces =>1);
  113. my $final = $uno->parse($code);
  114. $final =~ s/^[\t\f ]+|[\t\f ]+$//mg;
  115. $final =~s/$title/ /;
  116. print $final;
  117. }
  118.  
  119. print "\n\n[+] Press any key to continue\n\n";
  120. <stdin>;
  121. refrescar();
  122.  
  123. }
  124.  
  125. sub getlinks {
  126.  
  127. my $code = toma("http://www.securityfocus.com/");
  128.  
  129. my $test = HTML::Parser->new(
  130. start_h => [\&start, "tagname,attr"],
  131. text_h  => [\&text, "dtext"],
  132. );
  133. $test->parse($code);
  134.  
  135. sub start {
  136. my($a,$b) = @_;
  137. my %e = %$b;
  138. unless($a ne "a") {
  139. $d = $e{href};
  140. $c = $a;
  141. }}
  142.  
  143. sub text {
  144. my $title = shift;
  145. chomp $title;
  146. unless($c ne "a") {
  147. if ($d=~/\/bid\/(.*)/) {
  148. my $id = $1;
  149. unless($title=~/www.securityfocus.com/) {
  150. $links{$title} = $id;
  151. }}
  152. $d = "";
  153. }}
  154. return %links;
  155. }
  156.  
  157. sub toma {
  158. return $nave->get($_[0])->content;
  159. }
  160.  
  161. sub repes {
  162. foreach $test(@_) {
  163. push @limpio,$test unless $repe{$test}++;
  164. }
  165. return @limpio;
  166. }
  167.  
  168. sub clean {
  169. #if ($^O =~/Win32/ig) {
  170. system("cls");
  171. #} else {
  172. #system("clear");
  173. #}
  174. }
  175.  
  176. sub head {
  177. print "\n\n-- == SecurityFocus Manager 0.3 == --\n\n";
  178. }
  179.  
  180. sub copyright {
  181. print "\n\n\n(C) Doddy Hackman 2011\n\n";
  182. }
  183.  
  184. #Credits: Thanks to explorer (perlenespanol)
  185. # The End ?
  186.  
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Re: SecurityFocus Manager

Notapor explorer » 2011-11-19 14:19 @638

¿Qué diferencias hay entre esta versión y la que publicaste más arriba?
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: SecurityFocus Manager

Notapor BigBear » 2011-11-19 15:12 @675

Agregué una función para cuando se pregunte el número.
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818


Volver a Proyectos

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 1 invitado

cron