+
    jHàjØ  ã                  ó0  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIHt ]! 0 Rm4      t	]P                  ! R]P                  4      t]P                  ! R]P                  4      t]P                  ! R]P                  4      tRtR R ltR	 R
 ltR R ltR R ltR# )u©  Security checks for user-configured MCP server entries.

Blocks three narrow shapes (see ``validate_mcp_server_entry``), including a hardcoded IOC blocklist
for the June 2026 hermes-0day campaign. Runs BOTH at save time (``_save_mcp_server`` â€” dashboard API +
CLI) and at spawn time (``tools.mcp_tool._filter_suspicious_mcp_servers``), so a hand-edited or
pre-planted ``config.yaml`` entry is caught before it can execute.
)ÚannotationsN)ÚAnyz�(?<![\w.-])(?:curl|wget|nc|ncat|socat)(?![\w.-])|/dev/tcp/|\bInvoke-WebRequest\b|\bInvoke-RestMethod\b|\bSystem\.Net\.WebClient\bzB\.env\b|--data-binary|--data-raw|\b-X\s+POST\b|\bPOST\b|<\s*[^\s]+z­authorized_keys|\.ssh/|/etc/ssh\b|/etc/pam\.d\b|pam_[\w-]+\.so|/etc/sudoers|/etc/cron|crontab\b|/etc/rc\.local|/etc/systemd|\.bashrc\b|\.bash_profile\b|\.profile\b|\.zshrc\bc               ó    € V ^8„  d   QhRRRR/# )é   Úcommandr   ÚreturnÚstr© )Úformats   "Ú</home/ubuntu/.hermes/hermes-agent/hermes_cli/mcp_security.pyÚ__annotate__r   ;   s   € ÷ 	+ñ 	+˜sð 	+ sñ 	+ó    c                ór  € \        T ;'       g    R 4      P                  4       pV'       g   R #  \        P                  ! V\        P
                  R8g  R7      pV'       d
   V^ ,          MTp\        P                  P                  V4      P                  4       #   \         d    TP                  4       p L]i ; i)Ú Únt)Úposix)
r   ÚstripÚshlexÚsplitÚosÚnameÚ
ValueErrorÚpathÚbasenameÚlower)r   ÚtextÚpartsÚfirsts   &   r   Ú_command_basenamer   ;   s‡   € Üˆw�}ˆ}˜"Ó×#Ñ#Ó%€DßÙðÜ—’˜D¬¯©°D©Ô:ˆ÷ ˆE�!ŽH 4€EÜ�7‰7×Ñ˜EÓ"×(Ñ(Ó*Ð*øô ô Ø—
‘
“Šðús   ¯)B ÂB6Â5B6c               ó    € V ^8„  d   QhRRRR/# )r   Úargsr   r   r   r	   )r
   s   "r   r   r   G   s   € ÷ ñ ˜ð  ñ r   c                óŒ   € V f   R# \        V \        \        34      '       d   RP                  R V  4       4      # \	        V 4      # )Nr   Ú c              3  ó8   "  € T F  p\        V4      x € K  	  R # 5i©N©r   )Ú.0Úitems   & r   Ú	<genexpr>Ú!_inline_script.<locals>.<genexpr>K   s   é € Ð3©d dœ˜DŸ	˜	«dùó   ‚)Ú
isinstanceÚlistÚtupleÚjoinr   )r    s   &r   Ú_inline_scriptr/   G   s:   € Ø‚|ÙÜ�$œœu˜×&Ò&Ø�x‰xÑ3©dÓ3Ó3Ð3Üˆt‹9Ðr   c               ó    € V ^8„  d   QhRRRR/# )r   Úentryúdict[str, Any]r   r   r	   )r
   s   "r   r   r   O   s   € ÷ ñ �~ð ¨#ñ r   c                óZ  € \        V P                  R4      ;'       g    R4      .pVP                  \        V P                  R4      4      4       V P                  R4      p\	        V\
        4      '       d'   VP                  R VP                  4        4       4       RP                  V4      # )zEFlatten command + args + env values into one string for IOC scanning.r   r   r    Úenvc              3  ó8   "  € T F  p\        V4      x € K  	  R # 5ir$   r%   )r&   Úvs   & r   r(   Ú_entry_text.<locals>.<genexpr>U   s   é € Ð2¡\ ”S˜—V�V£\ùr*   r"   )	r   ÚgetÚappendr/   r+   ÚdictÚextendÚvaluesr.   )r1   r   r4   s   &  r   Ú_entry_textr=   O   s{   € ä˜EŸI™I iÓ0×6Ð6°BÓ7Ð8€EØ	‡L�L” §	¡	¨&Ó 1Ó2Ô3Ø
�)‰)�EÓ
€CÜ�#”t×ÒØ�‰Ñ2 S§Z¡Z¤\Ó2Ô2Ø�8‰8�E‹?Ðr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   r1   r2   r   z	list[str]r	   )r
   s   "r   r   r   Y   s!   € ÷ .ñ . Cð .°ð .À9ñ .r   c                ó\  € \        V\        4      '       g   . # . p\        V4      p\         F%  pWC9   g   K  VP	                  RV  RV R24       Vu # 	  VP                  R4      p\        V4      \        9  d   V# \        VP                  R4      4      pV'       g   V# \        P                  V4      '       d?   RV  RV R2p\        P                  V4      '       d
   VR,          pVP	                  V4       \        P                  V4      '       d   VP	                  RV  RV R	24       V# )
u  Return security warnings for an MCP server entry (empty = not suspicious).

Intentionally not a whitelist â€” custom commands, Python scripts, npx, uvx stay legal. Only three
narrow shapes are blocked: (1) a known IOC anywhere in command/args/env, (2) a shell interpreter
with network egress in its inline script, (3) a shell interpreter writing an OS persistence surface.

* a shell interpreter whose inline script writes to an OS persistence surface (June 2026 hermes-0day
SSH/PAM/sudoers/cron shape). See #45620.
zMCP server 'z9' contains a known hermes-0day indicator-of-compromise ('z')r   r    z' uses shell interpreter 'z' with network egress in argsz" and exfiltration-shaped argumentsu–   ' to write to an OS persistence surface (SSH keys / PAM / sudoers / cron / shell rc) â€” this is the hermes-0day backdoor shape, not a real MCP server)r+   r:   r=   Ú_IOC_SUBSTRINGSr9   r8   r   Ú_SHELL_INTERPRETERSr/   Ú_EGRESS_PATTERNÚsearchÚ_EXFIL_HINT_PATTERNÚ_PERSISTENCE_PATTERN)r   r1   ÚissuesÚflatÚiocr   ÚscriptÚissues   &&      r   Úvalidate_mcp_server_entryrK   Y   s3  € ô �eœT×"Ò"Øˆ	à€FÜ�uÓ€DßˆØŽ;à�M‰MØ˜t˜fð %-Ø-0¨E°ð5ôð ŠMñ ð �i‰i˜	Ó"€GÜ˜Ó!Ô)<Ô<ØˆÜ˜EŸI™I fÓ-Ó.€FßØˆä×Ñ˜f×%Ò%à˜4˜&Ð :¸7¸)ð D%ð &ð 	ô ×%Ñ% f×-Ò-ØÐ9Õ9ˆEØ�‰�eÔÜ×"Ñ" 6×*Ò*Ø�‰Ø˜4˜&Ð :¸7¸)ð Dð ô	
ð €Mr   >   ÚshÚcmdÚzshÚbashÚdashÚfishÚpwshÚ
powershellúcmd.exeúpwsh.exeúpowershell.exe)Ú7AAAAC3NzaC1lZDI1NTE5AAAAICBoh1oDC4DnsO1m5mJ4yfEKrQebaFhzhermes-0dayz60.165.167.z118.182.244.156z61.178.123.196)Ú__doc__Ú
__future__r   r   Úrer   Útypingr   Ú	frozensetrA   ÚcompileÚ
IGNORECASErB   rD   rE   r@   r   r/   r=   rK   r	   r   r   Ú<module>r_      sž   ðñõ #ã 	Û 	Û Ý áò !ó Ð ð —*’*ð#ð
 ‡M�Mó€ð —j’jØIØ‡M�MóÐ ð —z’zð:ð ‡M�Mó
Ð ð€õ	+õõ÷.r   