Projects STRLCPY linuxprivchecker Commits 5368ecaf
🤬
  • changed to a pool of workers to take care of the searching

  • Loading...
  • linted committed 6 years ago
    5368ecaf
    1 parent 20fff39a
  • ■ ■ ■ ■ ■ ■
    privcheckerserver.py
    skipped 7 lines
    8 8   import re
    9 9   import subprocess
    10 10   import json
     11 + import multiprocessing
    11 12  except Exception as e:
    12 13   print("Caught exception: {}\nAre you running with python3?".format(e))
    13 14   exit(1)
    skipped 7 lines
    21 22   def handle(self):
    22 23   try:
    23 24   print('[+] Connection from '+ self.client_address[0])
    24  - output = []
    25  - for data in iter(self.rfile.readline, ''):
    26  - term = data.decode().strip().split(" ")
    27  - term[-1] = term[-1][:3] #cut down on the last item which should be the version number
    28  - for splitTerms in term:
    29  - if not re.search("^[\w\s:\-\+\.~_]+$", splitTerms):
    30  - print("[-] recieved search term with invalid characters: {}".format(splitTerms))
    31  - break #bad term break so we don't search it
     25 + p = multiprocessing.Pool(5)
     26 + for output in p.imap_unordered(self.search, iter(self.rfile.readline, b'\n')):
     27 + if not output[0]:
     28 + #error'd out. print the results, but don't send them on?
     29 + print(output[1])
     30 + continue
     31 + if json.loads(output[1]).get("results", False):
     32 + print('[+] Found results for: {}'.format(' '.join(term)))
     33 + self.wfile.write(output.encode())
    32 34   else:
    33  - print('[ ] Searching for: {}'.format(' '.join(term)))
    34  - proc = subprocess.Popen([_searchsploit, '-j', *term], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    35  - output = proc.stdout.read()
    36  - if json.loads(output).get("results", False):
    37  - self.wfile.write(output.encode())
     35 + print('[-] No results for: {}'.format(' '.join(term)))
    38 36   
    39 37   print('[$] Closing connection from {}\n'.format(self.client_address[0]))
    40  - except Exception as e:
    41  - print("[-] Caught exception {}. Closing this connection.".format(e))
    42  - self.wfile.write("[-] Server caught {}. Closing Connection\n".format(e).encode())
    43 38   
     39 + def search(data):
     40 + try:
     41 + term = data.decode().strip().split(" ")
     42 + term[-1] = term[-1][:3] #cut down on the last item which should be the version number
     43 + for splitTerms in term:
     44 + if not re.search("^[\w:\-\+\.~_]+$", splitTerms):
     45 + return [False, "[-] recieved search term with invalid characters: {}".format(data.decode().strip())] #bad term return so we don't search it
     46 + else:
     47 + proc = subprocess.Popen([_searchsploit, '-j', *term], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     48 + output = proc.stdout.read()
     49 + return [True, output]
     50 +
     51 + except Exception as e:
     52 + return [False, "[-] ".format(e)]
    44 53   
    45 54   
    46 55  class ExploitServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
    skipped 32 lines
Please wait...
Page is in error, reload to recover