Advertisement
Guest User

Untitled

a guest
Jul 31st, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.39 KB | None | 0 0
  1. I need help modifying this script to scan multi-able ranges i will post the complete script. it is in perl , however im sure you can help me figure out how to get it to take a start and finish and scan through all of the IP's between these 2 point. here is the script:
  2.  
  3.  
  4.  
  5.  
  6. #!C:Program FilesperlbinPerl.exe -w
  7. # ------------------------------------------------------------ #
  8. # check_console_defaults.pl v1.0 20121028 frank4dd GPLv3 #
  9. # #
  10. # This script checks for reachable server management console #
  11. # systems. Access to these systems should be restricted, and #
  12. # default user passwords should have been changed immediately. #
  13. # #
  14. # Currently identifies iDRAC v6, CIMC v1.2 and iLO v2 #
  15. # HP uses the serial printed on the servers service tag, since #
  16. # we don't know the HP serial, there is no login function... #
  17. # ------------------------------------------------------------ #
  18. use Net::Ping;
  19. use LWP::UserAgent;
  20.  
  21. # ------------------------------------------------------------ #
  22. # Below is the network range we will verify. This is typically #
  23. # a class-C network, sometimes a smaller subnet range. We give #
  24. # the values on the command line, but we could also hardcode.. #
  25. # my $basenet = "192.168.240"; #
  26. # my $start_host = 1; #
  27. # my $end_host = 25; #
  28. # ------------------------------------------------------------ #
  29. $num_args = $#ARGV + 1;
  30. if ($num_args != 3) {
  31. print "Usage: check_console_defaults.pl [network-base] [start_ip] [end_ip]nn";
  32. print "Example: check_console_defaults.pl 192.168.1 20 44n";
  33. print "This will run the check on these IP's: 192.168.1.20-44.n";
  34. exit -1;
  35. }
  36.  
  37. my $basenet=$ARGV[0];
  38. my $start_host=$ARGV[1];
  39. my $end_host=$ARGV[2];
  40.  
  41. # ------------------------------------------------------------ #
  42. # Below are the HTML signatures for server management console #
  43. # systems. The script checks 3 vendors: Cisco, Dell and HP as #
  44. # the most commonly available server vendors in the industry. #
  45. # #
  46. # Cisco is simple, because we get a login page right away. #
  47. # Dell is tricky, because the initial response is a empty page #
  48. # containing a conditional javasacript redirect to support SSO.#
  49. # ------------------------------------------------------------ #
  50. my $cimc_id = "<title>Cisco Integrated Management Controller Login</title>";
  51. my $idrac_id = " top.document.location.href = "/sclogin.html";";
  52. my $hpilo_id = "<TITLE>HP Integrated Lights-Out 2 Login</TITLE>";
  53.  
  54. my $host = $start_host;
  55. while($host<=$end_host) {
  56. $ip = $basenet.".".$host;
  57. print "Checking $ip... ";
  58.  
  59. # ------------------------------------------------------------ #
  60. # Before checking the web interface, we first ping the host to #
  61. # ensure it exists. Otherwise, the web check 'hangs' and waits #
  62. # with a long, hard to interrupt timeout. Our ping timeout is #
  63. # set to 1 second only, providing a fast scan (ptimeout = 1;). #
  64. # ------------------------------------------------------------ #
  65. my $p=Net::Ping->new('icmp');
  66. my $ptimeout = 1;
  67. if ($p->ping($ip, $ptimeout)) {
  68. print "Host $ip alive... ";
  69. } else {
  70. print "Host does not exist.n";
  71. $host++;
  72. next;
  73. }
  74. $p->close();
  75.  
  76. # ------------------------------------------------------------ #
  77. # All modern remote management console systems run under SSL, #
  78. # in 99.9% using the default selfsigned certs. We ignore them. #
  79. # Cisco CIMC web interface delivers content with compression, #
  80. # we need to accept & handle the gzip-encoded server response. #
  81. # ------------------------------------------------------------ #
  82. my $ua = LWP::UserAgent->new(ssl_opts =>{verify_hostname => 0});
  83. $ua->timeout(2);
  84. my $can_accept = HTTP::Message::decodable;
  85.  
  86. my $https_url = "https://".$ip."/";
  87. my $ssl_response = $ua->get($https_url, 'Accept-Encoding' => $can_accept,);
  88.  
  89. if(! $ssl_response->is_success) {
  90. print "No SSL web page found.n";
  91. $host++;
  92. next;
  93. }
  94.  
  95. # debug
  96. #print "n".$ssl_response->decoded_content."n";
  97.  
  98. if($ssl_response->decoded_content =~ m/$cimc_id/i) {
  99. print "CIMC found! ";
  100. &check_cimc_login;
  101. }
  102. elsif($ssl_response->decoded_content =~ m/$idrac_id/i) {
  103. print "iDrac found! ";
  104. &check_idrac_login;
  105. }
  106. elsif($ssl_response->decoded_content =~ m/$hpilo_id/i) {
  107. print "HP iLO found! ";
  108. }
  109. else {
  110. print "SSL Web page is not console mgmt.";
  111. }
  112. print "n";
  113. $host++;
  114. }
  115.  
  116. # ------------------------------------------------------------ #
  117. # CIMC login function to check access with default values #
  118. # Cisco CIMC default: admin/password works... :-) #
  119. # ------------------------------------------------------------ #
  120. sub check_cimc_login {
  121.  
  122. # ----------------------------------------------------------- #
  123. # The login attempt returns one of these two xml responses: #
  124. # ----------------------------------------------------------- #
  125. my $login_ok = "<authResult>0</authResult> <forwardUrl>index.html</forwardUrl> </root>";
  126. my $login_fail = "<authResult>1</authResult> <forwardUrl>index.html</forwardUrl> <errorMsg></errorMsg></root>";
  127. my $ua = LWP::UserAgent->new(ssl_opts =>{verify_hostname => 0});
  128. $ua->timeout(2);
  129. my $can_accept = HTTP::Message::decodable;
  130.  
  131. my $login_url = "https://".$ip."/data/login";
  132. my $login_res = $ua->post( $login_url, { 'user' => 'admin', 'password' => 'password' } );
  133. my $logindata = $login_res->decoded_content();
  134.  
  135. # debug
  136. # print "n".$logindata."n";
  137.  
  138. if($logindata =~ m/$login_ok/) {
  139. print "...Default Login success!";
  140. }
  141. elsif($logindata =~ m/$login_fail/) {
  142. print "...Default Login failed.";
  143. }
  144. else {
  145. print "Unknown response.";
  146. }
  147. }
  148.  
  149. # ------------------------------------------------------------ #
  150. # This login function checks the iDRAC default password access.#
  151. # Incidentally, the function is *very* similar to Cisco. DELL #
  152. # was first, so maybe Cisco engineers were doing some re-eng #
  153. # when they build their CIMC? Javascript looks copy&paste... #
  154. # Dell iDRAC default: root/calvin works... :-) #
  155. # ------------------------------------------------------------ #
  156. sub check_idrac_login {
  157.  
  158. # ----------------------------------------------------------- #
  159. # The login attempt returns one of these two xml responses: #
  160. # ----------------------------------------------------------- #
  161. my $login_ok = "<authResult>0</authResult> <forwardUrl>index.html</forwardUrl> </root>";
  162. my $login_fail = "<authResult>1</authResult> <forwardUrl>index.html</forwardUrl> <errorMsg></errorMsg></root>";
  163.  
  164. my $ua = LWP::UserAgent->new(ssl_opts =>{verify_hostname => 0});
  165. $ua->timeout(2);
  166. my $can_accept = HTTP::Message::decodable;
  167. my $login_url = "https://".$ip."/data/login";
  168.  
  169. # ----------------------------------------------------------- #
  170. # here we make the HTTP request, using DELL's default values: #
  171. # ----------------------------------------------------------- #
  172. my $login_res = $ua->post( $login_url, Content => 'user=root&password=calvin' );
  173. my $logindata = $login_res->decoded_content();
  174.  
  175. # debug
  176. # print "n".$logindata."n";
  177.  
  178. if($logindata =~ m/$login_ok/) {
  179. print "...Default Login success!";
  180. }
  181. elsif($logindata =~ m/$login_fail/) {
  182. print "...Default Login failed.";
  183. }
  184. else {
  185. print "Unknown response.";
  186. }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement