Python 침투 테스트: 다중 옵션 도구 빌드

Mar 10 2023
R. Eric Kiser 침투 테스트 중에 가볍고 조용한 도구를 개발해야 하는 경우가 있을 수 있습니다.

R. 에릭 키저

침투 테스트 중에 가볍고 조용한 도구를 개발해야 하는 경우가 있을 수 있습니다. 시스템 정찰을 수행한 후 네트워크 시스템이 어떻게 구성되어 있는지 더 명확하게 이해할 수 있습니다. 이 지식으로 무장하면 영향이 적은 여러 작업을 수행하는 도구를 만들 수 있습니다. 이 기사에서는 Ansible을 사용하여 Linux 시스템을 관리하는 명령줄 유틸리티를 통합하는 Python 스크립트를 구성하는 방법을 보여줍니다.

운영 체제와 상호 작용하고 명령을 실행하려면 os및 모듈을 가져와야 합니다 .subprocess

import os
import subprocess

subprocess.run첫 번째 기능은 필요한 명령을 실행하는 기능을 사용하여 시스템에 Ansible을 설치하는 옵션을 제공합니다 .

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()

당신은 그것을 가지고 있습니다. 이제 원하는 도구를 만들 수 있습니다! 이 글이 마음에 드셨다면 박수 치고, 팔로우하고, 공유해 주세요. 즐거운 사냥 되세요!