Write a file in Python 2.7 without getting blocked by Windows?
Question: I'm writing a simple fuzzer for use on Windows applications based on the
Charlie Miller code from the babysitting an army of monkeys talk. However I
keep receiving the error

    
    
      Traceback (most recent call last):
      File "D:/Python27/fuzzer.py", line 29, in <module>
        process=subprocess.Popen([app_choice,fuzz_output])
      File "D:\Python27\lib\subprocess.py", line 679, in __init__
        errread, errwrite)
      File "D:\Python27\lib\subprocess.py", line 896, in _execute_child
       startupinfo)
    WindowsError: [Error 5] Access is denied
    

Does anyone know how to bypass this? I'm really stumped because I'm not all
too familiar with Windows 7 permissions or Python 2.7 to be honest. Full code
below

    
    
    #List of file names (all located in the python folder)
    fuzz_files=[ "slides_algo-guiding.pdf", "slides_algo-intro-annotated-   final.pdf","slides_algo-merge1.pdf"]
    apps=["C:\Program Files (x86)\Adobe\Reader 9.0\Reader"
      ]
    #Creates an output file in the Python folder
    fuzz_output="fuzz.pdf"
    FuzzFactor=50
    num_tests=1000
    import math
    import string
    import random
    import subprocess
    import time
    
    for i in range(num_tests):
        file_choice=random.choice(fuzz_files)
        app_choice=random.choice(apps)
        buf=bytearray(open(file_choice,'rb').read())
        #Charlie Miller code
    
        numwrites=random.randrange(math.ceil((float(len(buf))/FuzzFactor)))+1
        for j in range(numwrites):
            rbyte=random.randrange(256)
            rn=random.randrange(len(buf))
            buf[rn]="%c"%(rbyte)
         #End Charlie miller code
    
         #Write code
         open(fuzz_output,'wb').write(buf)
         process=subprocess.Popen([app_choice,fuzz_output])
    
         time.sleep(1)
         crashed=process.poll()
        if not crashed:
           process.terminate()
    


Answer: I believe that `C:\Program Files (x86)\Adobe\Reader 9.0\Reader` is the path of
a _folder_ , not an executable. Therefore trying to run it with `Popen` makes
no sense.

Also, you should be using raw strings when writing Windows paths `r"C:\Program
Files (x86)\Adobe\Reader 9.0\Reader\AcroRd32.exe"` or using slashes instead
`"C:/Program Files (x86)/Adobe/Reader 9.0/Reader/AcroRd32.exe"`. You were just
lucky that there weren't any valid escape sequences in the paths.

