Projects STRLCPY linuxprivchecker Commits 02cd1af1
🤬
  • changed to a slightly easier to maintain versioning of the two. now it's only a single line difference

  • Loading...
  • linted committed 6 years ago
    02cd1af1
    1 parent 3adb8915
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    linuxprivchecker.py
    skipped 22 lines
    23 23  if version_info >= (3,5):
    24 24   #import subprocess as sub
    25 25   from subprocess import run, PIPE
    26  - # loop through dictionary, execute the commands, store the results, return updated dict
    27  - def execCmd(cmdDict):
    28  - ''' for versions >= 3.5 '''
    29  - for item in cmdDict:
    30  - cmd = cmdDict[item]["cmd"]
    31  - try:
    32  - process = run(cmd, stdout=PIPE, stderr=PIPE, shell=True)
    33  - results = process.stdout.decode().split('\n')
    34  - except Exception as e:
    35  - results = ['[-] failed: {}'.format(e)]
    36  - cmdDict[item]["results"]=results
    37  - return cmdDict
    38  - 
     26 + def do_cmd(cmd):
     27 + return run(cmd, stdout=PIPE, stderr=PIPE, shell=True).stdout
    39 28  elif version_info >= (3,):
    40 29   #import os # older version of python, need to use ### instead
    41  - from subprocess import check_output, PIPE
    42  - # loop through dictionary, execute the commands, store the results, return updated dict
    43  - def execCmd(cmdDict):
    44  - ''' for version < 3.5 '''
    45  - for item in cmdDict:
    46  - cmd = cmdDict[item]["cmd"]
    47  - try:
    48  - echo_stdout = check_output(cmd, shell=True)
    49  - results = echo_stdout.decode().split('\n')
    50  - except Exception as e:
    51  - results = ['[-] failed: {}'.format(e)]
    52  - cmdDict[item]["results"]=results
    53  - return cmdDict
     30 + from subprocess import check_output, STDOUT
     31 + def do_cmd(cmd):
     32 + return check_output(cmd, shell=True, stderr=STDOUT)
    54 33  else:
    55 34   print("Error: please run in python3 only.")
    56 35   exit(1)
    skipped 10 lines
    67 46   print(bigline)
    68 47   print("")
    69 48   
     49 +# loop through dictionary, execute the commands, store the results, return updated dict
     50 +def execCmd(cmdDict):
     51 + for item in cmdDict:
     52 + cmd = cmdDict[item]["cmd"]
     53 + try:
     54 + stdout = do_cmd(cmd)
     55 + results = stdout.decode().split('\n')
     56 + except Exception as e:
     57 + results = ['[-] failed: {}'.format(e)]
     58 + cmdDict[item]["results"]=results
    70 59  
     60 + return cmdDict
    71 61   
    72 62  # print results for each previously executed command, no return value
    73 63  def printResults(cmdDict):
    skipped 196 lines
Please wait...
Page is in error, reload to recover