| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import subprocess
- # Set the domain name and administrator credentials
- domain_name = "example.com"
- admin_username = "administrator"
- admin_password = "password"
- # Set Hostname
- def set_hostname():
- hostname = subprocess.run(["hostname"], stdout=subprocess.PIPE, check=True).stdout.decode().strip()
- hostname = hostname.split(".")[0]
- subprocess.run(["sudo", "hostnamectl", "set-hostname", hostname], check=True)
- # Install the necessary packages
- def install_packages():
- packages = ["realmd", "libnss-sss", "libpam-sss", "sssd", "sssd-tools", "adcli", "samba-common-bin", "oddjob", "oddjob-mkhomedir", "packagekit", "python-ldap", "net-tools", "network-manager", "policycoreutils"]
- subprocess.run(["sudo", "apt-get", "install", "-y", *packages], check=True)
- # Copy the files from the remote server
- def copy_files(file_name):
- subprocess.run(["scp", "anonymous@ptiwa001:"+file_name, "~/"], check=True)
- # Join the domain using realm
- def join_domain():
- subprocess.run(["sudo", "realm", "join", "--user", f"{admin_username}%'{admin_password}'", domain_name], 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. Error: ",result.stderr.decode())
- # Activate creation of homedir
- def activate_mkhomedir():
- 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", "~/falcon-sensor_6.46.0-14306.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("falcon-sensor service is not running. Error: ", result.stderr.decode())
- # Install Ninja.deb file
- subprocess.run(["sudo", "dpkg", "-i", "~/ninja-agent.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. Error: ", result.stderr.decode())
-
- # Permit domain groups
- hostname = subprocess.run(["hostname"], stdout=subprocess.PIPE, check=True).stdout.decode().strip()
- group_name = f"Access - Admin - {hostname}"
- subprocess.run(["sudo", "realm", "deny", "--all"], check=True)
- subprocess.run(["sudo", "realm", "permit", "-g", "Domain Admins"], check=True)
- subprocess.run(["sudo", "realm", "permit", "-g", "Access - Admin - All Servers"], check=True)
- subprocess.run(["sudo", "realm", "permit", "-g", group_name], check=True)
- # Edit the sudoers file
- subprocess.run(["sudo", "visudo", "-f", "/etc/sudoers.d/LocalAdmins"], check=True)
- subprocess.run(["sudo", "bash", "-c", f"echo '%Domain\ Admins ALL=(ALL:ALL) ALL' >> /etc/sudoers.d/LocalAdmins"], check=True)
- subprocess.run(["sudo", "bash", "-c", f"echo '%Access\ -\ Admin\ -\ All\ Servers ALL=(ALL) ALL' >> /etc/sudoers.d/LocalAdmins"], check=True)
- subprocess.run(["sudo", "bash", "-c", f"echo '%{group_name} ALL=(ALL) ALL' >> /etc/sudoers.d/LocalAdmins"], check=True)
|