Python Sızma Testi: Çok Seçenekli Araçlar Oluşturma

Mar 10 2023
R. Eric Kiser Bir sızma testi sırasında, hafif ve sessiz bir araç geliştirmeniz gereken durumlar olabilir.

Eric Kiser

Sızma testi sırasında, hafif ve sessiz bir araç geliştirmeniz gereken durumlar olabilir. Sistem üzerinde keşif yaptıktan sonra, ağ sistemlerinin nasıl yapılandırıldığına dair daha net bir anlayış elde edebilirsiniz. Bu bilgiyle donanmış olarak, çok sayıda düşük etkili görevi gerçekleştiren bir araç oluşturabilirsiniz. Bu makalede, Linux sistemlerini Ansible kullanarak yöneten bir komut satırı yardımcı programını içeren bir Python betiğinin nasıl oluşturulacağını göstereceğim.

İşletim sistemiyle etkileşim kurmak ve komutları yürütmek için osve modüllerini içe aktarmamız gerekecek .subprocess

import os
import subprocess

subprocess.runİlk işlev, gerekli komutları yürütmek için işlevi kullanarak Ansible'ı sisteme yükleme seçeneği sunar .

def install_ansible():
    subprocess.run(["sudo", "apt", "update"])
    subprocess.run(["sudo", "apt", "install", "software-properties-common"])
    subprocess.run(["sudo", "apt-add-repository", "--yes", "--update", "ppa:ansible/ansible"])
    subprocess.run(["sudo", "apt", "install", "ansible"])

def add_ssh_key():
    ip = input("Enter the IP address of the remote server: ")
    username = input("Enter the username on the remote server: ")
    ssh_key_path = input("Enter the path to the SSH key: ")
    subprocess.run(["ssh-copy-id", f"{username}@{ip}", "-i", ssh_key_path])

def download_files():
    ips = input("Enter the IP addresses of the systems to download files from (comma-separated): ")
    files = input("Enter the files to download (comma-separated): ")
    dest = input("Enter the destination folder to save the files: ")
    for ip in ips.split(","):
        for file in files.split(","):
            subprocess.run(["ansible", f"{ip}", "-m", "fetch", "-a", f"src={file} dest={os.path.join(dest, ip)}"])

def download_files():
    ips = input("Enter the IP addresses of the systems to download files from (comma-separated): ")
    files = input("Enter the files to download (comma-separated): ")
    dest = input("Enter the destination folder to save the files: ")
    for ip in ips.split(","):
        for file in files.split(","):
            subprocess.run(["ansible", f"{ip}", "-m", "fetch", "-a", f"src={file} dest={os.path.join(dest, ip)}"])

def transfer_files():
    source_ip = input("Enter the IP address of the source server: ")
    dest_ip = input("Enter the IP address of the destination server: ")
    files = input("Enter the files to transfer (comma-separated): ")
    for file in files.split(","):
        subprocess.run(["ansible", f"{source_ip}", "-m", "copy", "-a", f"src={file} dest={dest_ip}:"])

choice = input("Enter your choice: ")
        if choice == "1":
            install_ansible()
        elif choice == "2":
            add_ssh_key()
        elif choice == "3":
            scan_files()
        elif choice == "4":
            download_files()
        elif choice == "5":
            transfer_files()
        elif choice == "0":
            break
        else:
            print("Invalid choice")

if __name__ == "__main__":
    main()

İşte aldın. Artık istediğiniz herhangi bir aracı inşa etme yeteneğine sahipsiniz! Alkışlayın, takip edin ve bu makaleyi beğendiyseniz paylaşın ve Mutlu Avlar!