Projects STRLCPY linuxprivchecker Commits ecc21789
🤬
  • ■ ■ ■ ■ ■ ■
    linuxprivchecker.py
    skipped 18 lines
    19 19  ###############################################################################################################
    20 20   
    21 21  # conditional import for older versions of python not compatible with subprocess
    22  -try:
     22 +from sys import version_info
     23 +if version_info >= (3,5):
    23 24   #import subprocess as sub
    24 25   from subprocess import run, PIPE
    25  - compatmode = 0 # newer version of python, no need for compatibility mode
    26  -except ImportError:
     26 + def do_cmd(cmd):
     27 + return run(cmd, stdout=PIPE, stderr=PIPE, shell=True).stdout
     28 +elif version_info >= (3,):
    27 29   #import os # older version of python, need to use ### instead
    28  - from subprocess import check_output, PIPE
    29  - compatmode = 1
     30 + from subprocess import check_output, STDOUT
     31 + def do_cmd(cmd):
     32 + return check_output(cmd, shell=True, stderr=STDOUT)
     33 +else:
     34 + print("Error: please run in python3 only.")
     35 + exit(1)
    30 36   
    31 37  # title / formatting
    32 38  bigline = "=" * 80
    skipped 12 lines
    45 51   for item in cmdDict:
    46 52   cmd = cmdDict[item]["cmd"]
    47 53   try:
    48  - if compatmode == 0: # newer version of python, use preferred subprocess
    49  - process = run(cmd, stdout=PIPE, stderr=PIPE, shell=True)
    50  - results = process.stdout.decode().split('\n')
    51  - else: # older version of python, use os.popen
    52  - echo_stdout = check_output(cmd, shell=True)
    53  - results = stdout.decode().split('\n')
     54 + stdout = do_cmd(cmd)
     55 + results = stdout.decode().split('\n')
    54 56   except Exception as e:
    55 57   results = ['[-] failed: {}'.format(e)]
    56 58   cmdDict[item]["results"]=results
    skipped 201 lines
Please wait...
Page is in error, reload to recover