Enumerate root packages (enum_root_pkg_proc) Enumerate Root/superuser packages to target based on process information :param pkgsandprocs: Dictionary with process and package information :param userinfo: Dictionary with the user information commands and results :return: The dr
(pkgsandprocs, userinfo)
| 318 | |
| 319 | |
| 320 | def enum_root_pkg_proc(pkgsandprocs, userinfo): |
| 321 | """ |
| 322 | Enumerate root packages (enum_root_pkg_proc) |
| 323 | Enumerate Root/superuser packages to target based on process information |
| 324 | :param pkgsandprocs: Dictionary with process and package information |
| 325 | :param userinfo: Dictionary with the user information commands and results |
| 326 | |
| 327 | :return: The drive information Dictionary with the commands results included |
| 328 | """ |
| 329 | print "[*] IDENTIFYING PROCESSES AND PACKAGES RUNNING AS ROOT OR OTHER SUPERUSER...\n" |
| 330 | |
| 331 | # find the package information for the processes currently running |
| 332 | # under root or another super user |
| 333 | |
| 334 | procs = pkgsandprocs["PROCS"]["results"] |
| 335 | pkgs = pkgsandprocs["PKGS"]["results"] |
| 336 | supusers = userinfo["SUPUSERS"]["results"] |
| 337 | procdict = {} # dictionary to hold the processes running as super users |
| 338 | |
| 339 | for proc in procs: # loop through each process |
| 340 | relatedpkgs = [] # list to hold the packages related to a process |
| 341 | try: |
| 342 | for user in supusers: # loop through the known super users |
| 343 | if (user != "") and (user in proc): # if the process is being run by a super user |
| 344 | procname = proc.split(" ")[4] # grab the process name |
| 345 | if "/" in procname: |
| 346 | splitname = procname.split("/") |
| 347 | procname = splitname[len(splitname)-1] |
| 348 | for pkg in pkgs: # loop through the packages |
| 349 | if not len(procname) < 3: # name too short to get reliable package results |
| 350 | if procname in pkg: |
| 351 | if procname in procdict: |
| 352 | relatedpkgs = procdict[proc] # if already in the dict, grab its pkg list |
| 353 | if pkg not in relatedpkgs: |
| 354 | relatedpkgs.append(pkg) # add pkg to the list |
| 355 | procdict[proc] = relatedpkgs # add any found related packages to the process dictionary entry |
| 356 | except: |
| 357 | pass |
| 358 | |
| 359 | for key in procdict: |
| 360 | print " " + key # print the process name |
| 361 | try: |
| 362 | if not procdict[key][0] == "": # only print the rest if related packages were found |
| 363 | print " Possible Related Packages: " |
| 364 | for entry in procdict[key]: |
| 365 | print " " + entry # print each related package |
| 366 | except IndexError: |
| 367 | pass |
| 368 | |
| 369 | |
| 370 | def enum_dev_tools(): |