Advertisement
patmccabe5

scripts

Feb 22nd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. import os
  2. import time
  3. def f_s(l):
  4.     a = l[l.rfind(' ')+1:-1]
  5.     return a[a.rfind('/')+1:]
  6. def l_s(l, i):
  7.     return l.split()[i]
  8. r_r = {}
  9. p_s = [f_s(l)[f_s(l).rfind('/')+1:] for l in os.popen('sudo cat /etc/shells').readlines()[1:] if "/" in l]
  10. b_s = [l_s(l, 1) for l in os.popen('sudo ps -aux').readlines()[1:] if f_s(l) in p_s]
  11. o_l = os.popen('sudo systemctl -a --plain').readlines()
  12. c_s = dict((l_s(l, 0), l_s(l, 2)) for l in o_l[:o_l.index("\n")])
  13. i_p = [l for l in os.popen('sudo cat /etc/passwd').readlines()]
  14. i_s = [l for l in os.popen('sudo cat /etc/shadow').readlines()]
  15. while True:
  16.     time.sleep(0.1)
  17.     o_l = os.popen('sudo ps -aux').readlines()[1:]
  18.     r_r = dict.fromkeys(r_r, False)
  19.     for l in (l for l in o_l if f_s(l) in p_s and l_s(l, 1) not in b_s):
  20.         if l_s(l, 1) not in r_r.keys():
  21.             print("NEW SHL: shell=" + f_s(l) + ", pid=" + l_s(l, 1) + "|" + l[:-1])
  22.         r_r[l_s(l, 1)] = True
  23.     r_r.pop((x for x in r_r.keys() if r_r[x] == False), None)
  24.     o_l = os.popen('sudo systemctl -a --plain').readlines()
  25.     o_l = o_l[:o_l.index("\n")]
  26.     for l in (l for l in o_l if l_s(l, 0) not in c_s.keys() or c_s[l_s(l, 0)] != l_s(l, 2)):
  27.         print(("SRV ADD -> " if l_s(l, 0) not in c_s.keys() else "SRV CHN -> ") + l_s(l, 0) + ":" + l_s(l, 2))
  28.         c_s[l_s(l, 0)] = l_s(l, 2)
  29.     for p in [l for l in c_s.keys() if l not in [l_s(k, 0) for k in o_l]]:
  30.         print("SRV DEL -> " + p + 0*c_s.pop(p, None))
  31.     o_l = os.popen('sudo cat /etc/passwd').readlines()
  32.     for l in (l for l in i_p if l not in o_l):
  33.         print('PSW DEL: ' + i_p.pop(i_p.index(l))[:-1])
  34.     for l in (l for l in o_l if l not in i_p):
  35.         print('PSW ADD: ' + (l[:-1] + str(i_p.append(l) is None) * 0))
  36.     o_l = os.popen('sudo cat /etc/shadow').readlines()
  37.     for l in (l for l in i_s if l not in o_l):
  38.         print('SHD DEL: ' + i_s.pop(i_s.index(l))[:-1])
  39.     for l in (l for l in o_l if l not in i_s):
  40.         print('SHD ADD: ' + (l[:-1] + str(i_s.append(l) is None) * 0))
  41. # f_s - Find Shell in ps Line
  42. # g_p - Get pid from line
  43. # l_v - Get Service from Line
  44. # l_t - Get Status from Line
  45. # o_l - Output Lines
  46. # p_s - Possible Shells
  47. # b_s - Beginning Shells
  48. # r_r - Reported and Running
  49. # c_s - Current Status
  50. # i_p - Initial Passwd
  51. # i_s - Initial Shadow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement