Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.91 KB | None | 0 0
  1. ###############################################################################
  2. # OpenVAS Vulnerability Test
  3. # $Id: default_http_auth_credentials.nasl 6514 2017-07-04 10:45:28Z cfischer $
  4. #
  5. # HTTP Brute Force Logins With Default Credentials
  6. #
  7. # Authors:
  8. # Michael Meyer <michael.meyer@greenbone.net>
  9. #
  10. # Copyright:
  11. # Copyright (c) 2011 Greenbone Networks GmbH
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License version 2
  15. # (or any later version), as published by the Free Software Foundation.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. #
  22. # You should have received a copy of the GNU General Public License
  23. # along with this program; if not, write to the Free Software
  24. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  25. ###############################################################################
  26.  
  27. if(description)
  28. {
  29. script_oid("1.3.6.1.4.1.25623.1.0.108041");
  30. script_version("$Revision: 6514 $");
  31. script_tag(name:"cvss_base", value:"0.0");
  32. script_tag(name:"cvss_base_vector", value:"AV:N/AC:L/Au:N/C:N/I:N/A:N");
  33. script_tag(name:"last_modification", value:"$Date: 2017-07-04 12:45:28 +0200 (Di, 04 Jul 2017) $");
  34. script_tag(name:"creation_date", value:"2011-09-06 14:38:09 +0200 (Tue, 06 Sep 2011)");
  35. script_name("HTTP Brute Force Logins With Default Credentials");
  36. script_category(ACT_ATTACK);
  37. script_family("Default Accounts");
  38. script_copyright("This script is Copyright (C) 2011 Greenbone Networks GmbH");
  39. script_dependencies("find_service.nasl", "http_version.nasl",
  40. "gb_default_credentials_options.nasl", "cgi_directories.nasl"); # cgi_directories.nasl pulls in the NVTs setting a /content/auth_required
  41. script_require_ports("Services/www", 80);
  42. script_mandatory_keys("www/content/auth_required");
  43. script_exclude_keys("Settings/disable_cgi_scanning");
  44.  
  45. script_timeout(1800);
  46.  
  47. script_tag(name:"summary", value:"A number of known default credentials is tried for log in via HTTP Basic Auth.
  48.  
  49. As this NVT might run into a timeout the actual reporting of this vulnerability takes place in the
  50. NVT 'HTTP Brute Force Logins with default Credentials Reporting' (OID: 1.3.6.1.4.1.25623.1.0.103240)");
  51.  
  52. script_tag(name:"solution_type", value:"Mitigation");
  53. script_tag(name:"qod_type", value:"remote_active");
  54.  
  55. exit(0);
  56. }
  57.  
  58. include("http_func.inc");
  59. include("http_keepalive.inc");
  60. include("misc_func.inc");
  61. include("default_credentials.inc");
  62.  
  63. function _check_response( res ) {
  64.  
  65. local_var res;
  66.  
  67. if( res && ! isnull( res ) &&
  68. ( res =~ "^HTTP/1\.[01] [0-9]+" ) && # Just to be sure...
  69. ( res !~ "^HTTP/1\.[01] 50[0234]" ) &&
  70. ( res !~ "^HTTP/1\.[01] 40[0138]" ) &&
  71. ( res !~ "^HTTP/1\.[01] 429" ) ) { #Too Many Requests (RFC 6585)
  72. return TRUE;
  73. }
  74. return FALSE;
  75. }
  76.  
  77. port = get_http_port( default:80 );
  78.  
  79. if( ! urls = get_kb_list( "www/" + port + "/content/auth_required" ) ) exit( 0 );
  80.  
  81. replace_kb_item( name:"default_http_auth_credentials/started", value:TRUE );
  82.  
  83. host = http_host_name( port:port );
  84.  
  85. foreach url( urls ) {
  86.  
  87. req = http_get( item:url, port:port );
  88. res = http_keepalive_send_recv( port:port, data:req, bodyonly:FALSE );
  89.  
  90. if( res !~ "^HTTP/1\.[01] 401" ) continue; # just to be sure
  91.  
  92. c = 0;
  93.  
  94. foreach credential( credentials ) {
  95.  
  96. # to many successfull logins. something is wrong...
  97. if( c > 10 ) {
  98. set_kb_item( name:"default_http_auth_credentials/" + port + "/too_many_logins", value:c );
  99. exit( 0 );
  100. }
  101.  
  102. credential = str_replace( string:credential, find:"\;", replace:"#sem#" );
  103.  
  104. user_pass = split( credential, sep:";", keep:FALSE );
  105. if( isnull( user_pass[0] ) || isnull( user_pass[1] ) ) continue;
  106.  
  107. user = chomp( user_pass[0] );
  108. pass = chomp( user_pass[1] );
  109.  
  110. user = str_replace( string:user, find:"#sem#", replace:";" );
  111. pass = str_replace( string:pass, find:"#sem#", replace:";" );
  112.  
  113. if( tolower( pass ) == "none" ) pass = "";
  114. if( tolower( user ) == "none" ) user = "";
  115.  
  116. userpass = user + ":" + pass;
  117. userpass64 = base64( str:userpass );
  118.  
  119. req = string( "GET ", url, " HTTP/1.1\r\n",
  120. "Host: ", host, "\r\n",
  121. "User-Agent: ", OPENVAS_HTTP_USER_AGENT, "\r\n",
  122. "Authorization: Basic ", userpass64, "\r\n",
  123. "\r\n" );
  124. res = http_keepalive_send_recv( port:port, data:req, bodyonly:FALSE );
  125.  
  126. if( res =~ "^HTTP/1\.[01] 30[0-8]" ) {
  127.  
  128. url = extract_location_from_redirect( port:port, data:res );
  129.  
  130. if( url ) {
  131.  
  132. req = http_get( item:url, port:port );
  133. res = http_keepalive_send_recv( port:port, data:req, bodyonly:FALSE );
  134.  
  135. if( res =~ "^HTTP/1\.[01] 401" ) {
  136.  
  137. req = string( "GET ", url, " HTTP/1.1\r\n",
  138. "Host: ", host, "\r\n",
  139. "User-Agent: ", OPENVAS_HTTP_USER_AGENT, "\r\n",
  140. "Authorization: Basic ", userpass64, "\r\n",
  141. "\r\n" );
  142. res = http_keepalive_send_recv( port:port, data:req, bodyonly:FALSE );
  143.  
  144. if( _check_response( res:res ) ) {
  145. c++;
  146. set_kb_item( name:"default_http_auth_credentials/" + port + "/credentials", value:url + "#-#" + user + ":" + pass );
  147. }
  148. }
  149. }
  150. } else if( _check_response( res:res ) ) {
  151. c++;
  152. set_kb_item( name:"default_http_auth_credentials/" + port + "/credentials", value:url + "#-#" + user + ":" + pass );
  153. }
  154. }
  155. }
  156.  
  157. # Set kb entry that no timeout was happening for further reporting
  158. set_kb_item( name:"default_http_auth_credentials/" + port + "/no_timeout", value:TRUE );
  159.  
  160. exit( 0 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement