File size: 3,181 Bytes
a7841c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Trusted environment setup. Run before exposing screenshots/actions to a model."""
import json
import os
from pathlib import Path
import subprocess
import xml.etree.ElementTree as ET

BLOCKED = 'xterm uxterm lxterm koi8rxterm x-terminal-emulator xfce4-terminal gnome-terminal gnome-terminal-server konsole mate-terminal lxterminal qterminal terminator tilix sakura rxvt urxvt zutty xfce4-appfinder xfrun4 exo-desktop-item-edit xfce4-settings-editor xfce4-settings-manager thunar Thunar mousepad xfce4-keyboard-settings xfce4-mime-settings'.split()
stub = Path('/usr/local/bin/gui-only-denied')
stub.write_text('''#!/bin/sh
mkdir -p /logs/artifacts
printf '%s %s\\n' "$(date -u +%FT%TZ)" "$0" >> /logs/artifacts/gui-only-denied.log
exit 126
''')
stub.chmod(0o755)
for name in BLOCKED:
 for directory in ['/usr/bin','/usr/local/bin','/bin']:
  p = Path(directory)/name
  if directory == '/bin' and Path('/bin').resolve() == Path('/usr/bin'):continue
  if p.exists() or p.is_symlink():p.unlink()
  p.symlink_to(stub)
# Remove shell launch surfaces without removing native editor file dialogs.
for root in ['/root/Desktop','/usr/share/applications','/usr/local/share/applications','/root/.local/share/applications']:
 for p in Path(root).glob('*.desktop'):
  text=p.read_text(errors='replace').lower()
  if any(x in text for x in ['terminal','appfinder','xfrun','settings-editor','keyboard-settings','mime-settings','desktop-item-edit','text-editor','mousepad','chromium','web-browser']):p.unlink()
# Only the harness launches the editor; disable duplicate session autostarts.
for root in ['/root/.config/autostart','/etc/xdg/autostart']:
 for p in Path(root).glob('*.desktop'):
  if any(x in p.read_text(errors='replace').lower() for x in ['shotcut','filmcraft','x11vnc']):
   p.write_text('[Desktop Entry]\nType=Application\nHidden=true\n')
for root in ['/etc/xdg/xfce4/xfconf/xfce-perchannel-xml','/root/.config/xfce4/xfconf/xfce-perchannel-xml']:
 p=Path(root)/'xfce4-keyboard-shortcuts.xml'
 if p.exists():
  tree=ET.parse(p)
  for parent in tree.iter():
   for child in list(parent):
    if any(x in child.get('value','').lower() for x in ['terminal','appfinder','xfrun']):parent.remove(child)
  tree.write(p,encoding='unicode')
kiosk=Path('/etc/xdg/xfce4/kiosk/kioskrc');kiosk.parent.mkdir(parents=True,exist_ok=True)
kiosk.write_text('[xfce4-panel]\nCustomizePanel=NONE\n[xfdesktop]\nCustomizeDesktopMenu=NONE\nCustomizeWindowlist=NONE\nUserMenu=NONE\n[xfce4-session]\nCustomizeCompatibility=NONE\nCustomizeSecurity=NONE\n')
# Custom file-manager commands can launch shells. Keep file navigation/native dialogs.
actions=Path('/root/.config/Thunar/uca.xml');actions.parent.mkdir(parents=True,exist_ok=True);actions.write_text('<actions/>\n')
for name in BLOCKED:
 r=subprocess.run(['/usr/bin/'+name,'--version'],capture_output=True,timeout=5)
 if r.returncode !=126:raise RuntimeError('GUI-only guard failed: '+name)
Path('/logs/artifacts').mkdir(parents=True,exist_ok=True)
Path('/logs/artifacts/gui-only-policy.json').write_text(json.dumps({'version':1,'terminal_tools':False,'blocked_launchers':BLOCKED,'self_check':'passed'},indent=2))
print('GUI_ONLY_SELF_CHECK_PASSED')