import socket, json, sys

p = "/run/defence360agent/non_root_simple_rpc.sock"
path = sys.argv[1] if len(sys.argv) > 1 else "/home/john/public_html/test.php"
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.settimeout(20)
s.connect(p)
req = json.dumps({"command": ["malware", "on-demand", "start"],
                  "params": {"path": path, "scan_file": True, "scan_db": False}}) + "\n"
s.sendall(req.encode())
buf = b""
while b"\n" not in buf:
    try:
        chunk = s.recv(65536)
    except socket.timeout:
        break
    if not chunk:
        break
    buf += chunk
s.close()
line = buf.split(b"\n", 1)[0]
print("RESPONSE:", line[:600].decode(errors="replace"))
