|
@@ -0,0 +1,84 @@
|
|
|
|
|
+import subprocess
|
|
|
|
|
+
|
|
|
|
|
+# Set the domain name and administrator credentials
|
|
|
|
|
+domain_name = "example.com"
|
|
|
|
|
+admin_username = "administrator"
|
|
|
|
|
+admin_password = "password"
|
|
|
|
|
+
|
|
|
|
|
+# Set Hostname
|
|
|
|
|
+subprocess.run(["sudo", "hostnamectl", "set-hostname", "newhostname.peo.local"], check=True)
|
|
|
|
|
+
|
|
|
|
|
+# Install the necessary packages
|
|
|
|
|
+subprocess.run(["sudo", "apt-get", "install", "-y", "realmd", "libnss-sss", "libpam-sss", "sssd", "sssd-tools", "adcli", "samba-common-bin", "oddjob", "oddjob-mkhomedir", "packagekit", "python-ldap", "net-tools", "network-manager", "policycoreutils"], check=True)
|
|
|
|
|
+
|
|
|
|
|
+# Join the domain using realm
|
|
|
|
|
+subprocess.run(["sudo", "realm", "join", "--user", f"{admin_username}%'{admin_password}'", domain_name], check=True)
|
|
|
|
|
+
|
|
|
|
|
+# Copy the Falcon_senson.deb file from the remote server to the home directory
|
|
|
|
|
+subprocess.run(["scp", "anonymous@ptiwa001:falcon-sensor_6.46.0-14306.deb", "~/"], check=True)
|
|
|
|
|
+
|
|
|
|
|
+# Copy the ninja.deb file from the remote server to the home directory
|
|
|
|
|
+subprocess.run(["scp", "anonymous@ptiwa001:ninja-agent.deb", "~/"], check=True)
|
|
|
|
|
+
|
|
|
|
|
+# Verify that the join was successful
|
|
|
|
|
+result = subprocess.run(["sudo", "net", "ads", "testjoin"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
+if result.returncode == 0:
|
|
|
|
|
+ print("Successfully joined the domain")
|
|
|
|
|
+else:
|
|
|
|
|
+ print("Failed to join the domain.")
|
|
|
|
|
+ # Activate creation of homedir
|
|
|
|
|
+ subprocess.run(["sudo", "bash", "-c", "cat > /usr/share/pam-configs/mkhomedir <<EOF\nName: activate mkhomedir\nDefault: yes\nPriority: 900\nSession-Type: Additional\nSession:\n\tRequired\tpam_mkhomedir.so umask=0022 skel=/etc/skel\nEOF"], check=True)
|
|
|
|
|
+ subprocess.run(["sudo", "pam-auth-update", "--package", "--enable", "mkhomedir"], check=True)
|
|
|
|
|
+
|
|
|
|
|
+ # Set fully qualified domain names to false
|
|
|
|
|
+ subprocess.run(["sudo", "sed", "-i", "s/use_fully_qualified_names = True/use_fully_qualified_names = False/g", "/etc/sssd/sssd.conf"], check=True)
|
|
|
|
|
+ subprocess.run(["sudo", "systemctl", "restart", "sssd.service"], check=True)
|
|
|
|
|
+
|
|
|
|
|
+ # Install Falcon_sensor.deb file
|
|
|
|
|
+ subprocess.run(["sudo", "dpkg", "-i", "~/file.deb"], check=True)
|
|
|
|
|
+
|
|
|
|
|
+ # Run additional Crowdstrike commands
|
|
|
|
|
+ subprocess.run(["sudo", "/opt/CrowdStrike/falconctl", "-s", "--cid=D0511099B3FF494D8B87F48C4AB90201-56"], check=True)
|
|
|
|
|
+ subprocess.run(["sudo", "systemctl", "start", "falcon-sensor"], check=True)
|
|
|
|
|
+ result = subprocess.run(["sudo", "systemctl", "status", "falcon-sensor"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
+if result.returncode == 0:
|
|
|
|
|
+ print("falcon-sensor service is running.")
|
|
|
|
|
+else:
|
|
|
|
|
+ print("Failed to join the domain.")
|
|
|
|
|
+
|
|
|
|
|
+ # Install Ninja.deb file
|
|
|
|
|
+ subprocess.run(["sudo", "dpkg", "-i", "~/file.deb"], check=True)
|
|
|
|
|
+
|
|
|
|
|
+ # Run additional Ninja commands
|
|
|
|
|
+ subprocess.run(["sudo", "systemctl", "start", "ninjarmm-agent.service"], check=True)
|
|
|
|
|
+ result = subprocess.run(["sudo", "systemctl", "status", "ninjarmm-agent.service"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
+if result.returncode == 0:
|
|
|
|
|
+ print("ninjarmm-agent service is running.")
|
|
|
|
|
+else:
|
|
|
|
|
+ print("ninjarmm-agent service is not running.")
|
|
|
|
|
+
|
|
|
|
|
+#Deny all permissions
|
|
|
|
|
+subprocess.run(["sudo", "realm", "deny", "--all"], check=True)
|
|
|
|
|
+
|
|
|
|
|
+#Permit access for Domain Admins group
|
|
|
|
|
+subprocess.run(["sudo", "realm", "permit", "-g", "Domain Admins"], check=True)
|
|
|
|
|
+
|
|
|
|
|
+#Permit access for Access - Admin - All Servers group
|
|
|
|
|
+subprocess.run(["sudo", "realm", "permit", "-g", "Access - Admin - All Servers"], check=True)
|
|
|
|
|
+
|
|
|
|
|
+#get hostname
|
|
|
|
|
+hostname = subprocess.run(["hostname"], stdout=subprocess.PIPE, check=True).stdout.decode().strip()
|
|
|
|
|
+
|
|
|
|
|
+#Permit access for Access - Admin - hostname group
|
|
|
|
|
+subprocess.run(["sudo", "realm", "permit", "-g", f"Access - Admin - {hostname}"], check=True)
|
|
|
|
|
+
|
|
|
|
|
+#get hostname
|
|
|
|
|
+hostname = subprocess.run(["hostname"], stdout=subprocess.PIPE, check=True).stdout.decode().strip()
|
|
|
|
|
+
|
|
|
|
|
+#Edit the file using visudo
|
|
|
|
|
+subprocess.run(["sudo", "sh", "-c", "echo '%Domain\\ Admins ALL=(ALL:ALL) ALL' >> /etc/sudoers.d/LocalAdmins"], check=True)
|
|
|
|
|
+subprocess.run(["sudo", "sh", "-c", "echo '%Access\\ -\\ Admin\\ -\\ All\\ Servers ALL=(ALL) ALL' >> /etc/sudoers.d/LocalAdmins"], check=True)
|
|
|
|
|
+subprocess.run(["sudo", "sh", "-c", f"echo '%Access\\ -\\ Admin\\ -\\ {hostname} ALL=(ALL) ALL' >> /etc/sudoers.d/LocalAdmins"], check=True)
|
|
|
|
|
+
|
|
|
|
|
+print("Join to Domain, installation of Falson Sensor and Ninja Agent are complete")
|
|
|
|
|
+print(result.stderr.decode())
|