# # This script was written by H D Moore # if(description) { script_id(11003); script_version ("$Revision$"); name["english"] = "IIS Possible Compromise"; name["francais"] = "IIS Possible Compromise"; script_name(english:name["english"], francais:name["francais"]); desc["english"] = " One or more files were found on this host that indicate a possible compromise. Solution: Investigate the discovered files Risk factor : High "; script_description(english:desc["english"]); summary["english"] = "Searches for traces of a system compromise."; summary["francais"] = "Searches for traces of a system compromise."; script_summary(english:summary["english"], francais:summary["francais"]); script_category(ACT_ATTACK); script_copyright( english:"This script is Copyright (C) 2003 Digital Defense Inc.", francais:"Ce script est Copyright (C) 2003 Digital Defense Inc."); family["english"] = "Backdoors"; family["francais"] = "Backdoors"; script_family(english:family["english"], francais:family["francais"]); script_dependencie("webmirror.nasl", "http_version.nasl"); script_require_keys("www/iis"); script_dependencies("find_service.nes", "http_version.nasl", "no404.nasl", "DDI_Directory_Scanner.nasl"); exit(0); } # # The script code starts here # include("http_func.inc"); include("http_keepalive.inc"); port = get_kb_item("Services/www"); if(!port) port = 80; if(!get_port_state(port))exit(0); if(http_is_dead(port:port))exit(0); function check(url, arg, pat) { local_var str, r; if(debug)display("check(", url, ",", arg, ",", pat, ")\n"); str = http_get(item:string(url, arg), port:port); r = http_keepalive_send_recv(port:port, data:str); if(r == NULL)exit(0); # cache files that dont exist if(ereg(pattern:"HTTP/1\.[01] 40[34]", string:r)) { add_cache(url:url); return(FALSE); } if (egrep(string:r, pattern:pat)) { if(debug)display("found '", pat, "' for ", url, " [", arg, "]\n"); return(TRUE); } return(FALSE); } function headcheck(req) { local_var str, r; str = http_head(item:req, port:port); r = http_keepalive_send_recv(port:port, data:str); if(r == NULL)exit(0); if(ereg(pattern:"^HTTP/1\.[01] (2|502)", string:r)) { if (debug) display("HEAD FOUND: ", req, "\n"); return(TRUE); } return(FALSE); } function dllcheck(req) { local_var str, r; str = http_get(item:req, port:port); r = http_keepalive_send_recv(port:port, data:str); if(r == NULL)exit(0); # cache missing dll's if ("module could not be found" >< r) add_cache(url:req); if ("procedure could not be found" >< r) { if (debug) display("DLL FOUND: ", url, "\n"); return(TRUE); } return(FALSE); } # this exploit hijacks the socket used to make the # web request, spawning a command shell over it, so we # cant use the normal detection methods function iisecheck(req) { str = http_get(item:req, port:port); soc = http_open_socket(port); if(soc) { send(socket:soc, data:str); r = recv_line(socket:soc, length:1024); if(egrep(pattern:"We Got It", string:r)) { send(socket:soc, data:string("\r\n\r\nexit\r\n\r\n")); http_close_socket(soc); return(TRUE); } else { r2 = http_recv(socket:soc); if ( ereg(pattern:"HTTP/1\.[01] 40[34]", string:r) || egrep(pattern:"module could not be found", string:r2) ) { add_cache(url:req); return(FALSE); } } http_close_socket(soc); } return(FALSE); } # # directory list management # dirs[0] = "/"; num_dirs = 0; function initialize_dirs () { local_var dirs, d, tmp; tmp = get_kb_list(string("www/", port, "/content/directories")); if(!isnull(tmp))dirs = make_list(tmp); else dirs = make_list(); _dir_idx = 0; foreach d (dirs) { if(debug)display("adding discovered directory: ", d, "\n"); add_dir_list(dir:d); _dir_idx = _dir_idx + 1; } return(_dir_idx); } function check_dir_list (dir) { for (CDL=0; dirs[CDL]; CDL=CDL+1) { if (dirs[CDL] == dir) return(1); } return(0); } function add_dir_list (dir) { if (check_dir_list(dir:dir) == 0) { dirs[num_dirs] = dir; num_dirs = num_dirs + 1; } } # # cached url list management # cache[0] = 0; num_cache = 0; function check_cache (url) { for (CLI=0; cache[CLI]; CLI=CLI+1) { if (cache[CLI] == url) return(1); } return(0); } function add_cache (url) { if (check_cache(url:url) == 0) { cache[num_cache] = url; num_cache = num_cache + 1; return(1); } return(0); } # # report management # reported_urls[0] = 0; reported_urls_cnt = 0; reported_tests[0] = 0; report_header = ""; report_footer = ""; function reported(url) { found_it = 0; for (rep_idx=0; rep_idx