Hello community, I have created the following sche...
# general
o
Hello community, I have created the following scheduled query in OSquery:
Copy code
"running_processes": {
      "query": "SELECT processes.name, processes.pid, processes.state AS process_state, process_open_sockets.remote_address AS destination_ip, process_open_sockets.remote_port AS destination_port, process_open_sockets.local_port AS source_port, process_open_sockets.state AS socket_state, processes.path, MAX(hash.md5) AS process_md5, MAX(hash.sha1) AS process_sha1, MAX(hash.sha256) AS process_sha256 FROM process_open_sockets JOIN processes USING (pid) LEFT JOIN hash ON processes.path = hash.path WHERE process_open_sockets.remote_address != '' AND process_open_sockets.remote_address != '0.0.0.0' AND process_open_sockets.remote_address != '0' AND processes.pid != 0 AND TRIM(process_open_sockets.remote_address) != '::' AND TRIM(process_open_sockets.remote_address) != '127.0.0.1' AND TRIM(process_open_sockets.remote_address) != '::1' AND processes.on_disk = 1 AND processes.path NOT IN ('C:\\Program Files\\Microsoft Office\\root\\Office16\\OUTLOOK.EXE','C:\\Program Files (x86)\\ossec-agent\\wazuh-agent.exe','C:\\Program Files\\Microsoft Office\\root\\Office16\\WINWORD.EXE','C:\\Program Files\\Microsoft Office\\root\\Office16\\ONENOTE.EXE','C:\\Program Files\\Microsoft Office\\root\\Office16\\msoadfsb.exe','C:\\Program Files\\Microsoft Office\\root\\Office16\\POWERPNT.EXE','C:\\Program Files\\Microsoft Office\\root\\Office16\\EXCEL.EXE','C:\\Program Files\\Bitdefender\\Endpoint Security\\EPHost.exe','C:\\Program Files\\Microsoft OneDrive\\OneDriveStandaloneUpdater.exe','C:\\Program Files\\Bitdefender\\Endpoint Security\\downloader.exe','C:\\Program Files\\Microsoft Office\\root\\Office16\\SDXHelper.exe','C:\\Program Files (x86)\\Splashtop\\Splashtop Remote\\Server\\SRManager.exe','C:\\Program Files\\Microsoft OneDrive\\OneDrive.exe','C:\\Program Files\\Microsoft Power BI Desktop\\bin\\PBIDesktop.exe','C:\\Program Files\\Bitdefender\\Endpoint Security\\bdredline.exe','C:\\Program Files (x86)\\mcfcmainoffice-5.3.3909\\NinjaRMMAgent.exe','C:\\Program Files\\SentinelOne\\Sentinel Agent 22.3.2.373\\SentinelAgent.exe','C:\\Program Files (x86)\\Dropbox\\Client\\Dropbox.exe','C:\\Program Files (x86)\\Splashtop\\Splashtop Remote\\Client for STB\\strwinclt.exe','C:\\Program Files (x86)\\Splashtop\\Splashtop Remote\\Server\\SRManager.exe','C:\\Program Files\\Bitdefender\\Endpoint Security\\EPIntegrationService.exe','C:\\Program Files\\Bitdefender\\Endpfoint Security\\EPSecurityService.exe') AND processes.name NOT IN ('Teams.exe','Microsoft.SharePoint.exe','ONENOTE.EXE','EPSecurityService.exe','Dropbox.exe','strwinclt.exe') GROUP BY hash.md5;",
      "interval": 300,
      "snapshot": false,
      "description": "List of all running processes"
    }
What I want to achieve with this query is to view the processes on the computers, along with their hash and destination IP, avoiding repetitions and ordering them by hash. I also want to exclude certain paths and specific processes from the query, as well as omit the IP: 127.0.0.1, among other data described in the query. What I have noticed is that sometimes the query fails and returns data with IP: 127.0.0.1. I would appreciate it if you could review my query and suggest improvements to make it more optimal, preventing unnecessary and repeated data.