Event collector for Linux (python) and Windows (powershell). I write theses scripts in KOTH (King of the Hill) to detect any intrusion by monitoring only one file.
It's a POC (i write it in less than 2 hours for the KOTH), connection are not secure, there is no authentication, it's not recommended for production (you can use it in incident response if you don't have any other solution but you should consider logs as untrust, because it's very easy for an attacker to send fake/crafted logs, to sniff the network connection, to block it or to modify logs between client and server).
In this KOTH we had only one Windows Server (an Active Directory), a Linux server (with SMB file share and SSH access linked to domain with SSSD), a PfSense and a switch. We had secure access to AD and Linux server by creating new VLAN for servers and monitor all connections between servers and PC with the PfSense. We had some local firewall rules on the AD and the Linux, we had theses script to monitor easily servers activity with only one console and only one SOC analyst (everyone else on the team could compromise the adversaries' systems). On the Linux we had
selinux
policy for the samba share.
- Change IP and port in
FastLogCollectorServer.py
andFastLogCollectorLinuxClient.py
. - Write or copy the
FastLogCollectorServer.py
in/root
directory (as/root/FastLogCollectorServer.py
). - Write or copy the
FastLogCollectorLinuxClient.py
in/root
directory (as/root/FastLogCollectorLinuxClient.py
). - Write or copy the
FastLogCollectorServer.service
in/etc/systemd/system
directory (as/etc/systemd/system/FastLogCollectorServer.service
). - Write or copy the
FastLogCollectorLinuxClient.service
in/etc/systemd/system
directory (as/etc/systemd/system/FastLogCollectorLinuxClient.service
). - Run the script:
InstallAndConfigureAuditAndFirewall.sh
with root privileges (sudo bash InstallAndConfigureAuditAndFirewall.sh
).
- Change IP and port in
FastLogCollectorWindowsClient.ps1
. - Write or copy the
FastLogCollectorWindowsClient.ps1
inC:\Users\Administrator\services
directory (asC:\Users\Administrator\services\FastLogCollectorWindowsClient.ps1
). - Run the script:
SysmonInstallAndConfigure.ps1
as Administrator. - Run the script:
InstallServiceWindows.ps1
as Administrator.
In a KOTH we know that an attack is going to happen but we don't know how, we don't know the precise minute and we don't know the attacker's skills. The use of this project in KOTH is relatively simple since it requires to read a file only continuously, when a process creation log occurs, the attack is successful, when an outgoing connection occurs the attacker tries to establish a means of communication for an easier to use takeover (reverse shell, C&C agent)...
It's possible with this project to monitor all your machines at the same time (manually, a SOC analyst should wait for a new event in the unique console) and when an attack occurs go to the compromised machine before the attacker exploits privileges escalation vulnerability and block the IP address used or the compromised user and fix the exploited vulnerability (sometime the vulnerability should be difficult to found, you should restrict access to the service used to get more time to find the vulnerability).
tail -f /root/received_logs.txt
Licensed under the GPL, version 3.