Advertisement
Guest User

artifact_check.py

a guest
Jul 23rd, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.57 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. #This Python script checks for operating system artifacts
  4.  
  5. #By Enigma
  6.  
  7. import os
  8.  
  9. # Color Codes:
  10. # Green (Success) = \033[92m
  11. # Red (Error) = \033[93m
  12.  
  13. ## Setting global print variables
  14.  
  15. openrc = ("\n\033[92m rc-status: \033[0m")
  16. sysd = ("\n\033[92m systemctl-status: \033[0m")
  17. runit = ("\n\033[92m /var/service: \033[0m")
  18. init_ = ("\n\033[93m no init status available \033[0m")
  19. mounts = ("\n\033[92m /proc/mounts: \033[0m")
  20. mounts_ = ("\n\033[93m /proc/mounts does not exist \033[0m")
  21. hosts = ("\n\033[92m Trusted host relationship: \033[0m")
  22. hosts_ = ("\n\033[93m /etc/hosts.allow does not exist \033[0m")
  23. passwd = ("\n\033[92m Account creation order: \033[0m")
  24. passwd_ = ("\n\033[93m /etc/passwd does not exist \033[0m")
  25. UUID_0 = ("\n\033[92m UUID 0: \033[0m")
  26. crontab = ("\n\033[92m /etc/crontab: \033[0m")
  27. crontab_ = ("\n\033[93m /etc/crontab does not exist \033[0m")
  28. cron_allow = ("\n\033[92m /etc/cron.allow: \033[0m")
  29. cron_allow_ = ("\n\033[93m /etc/cron.allow does not exist \033[0m")
  30. cron_deny = ("\n\033[92m /etc/cron.deny: \033[0m")
  31. cron_deny_ = ("\n\033[93m /etc/cron.deny does not exist \033[0m")
  32. cron_hourly = ("\n\033[92m /etc/cron.hourly/: \033[0m")
  33. cron_hourly_ = ("\n\033[93m /etc/cron.hourly/ does not exist \033[0m")
  34. cron_daily = ("\n\033[92m /etc/cron.daily/: \033[0m")
  35. cron_daily_ = ("\n\033[93m /etc/cron.daily/ does not exist \033[0m")
  36. cron_weekly = ("\n\033[92m /etc/cron.weekly/: \033[0m")
  37. cron_weekly_ = ("\n\033[93m /etc/cron.weekly/ does not exist \033[0m")
  38. cron_monthly = ("\n\033[92m /etc/cron.monthly/: \033[0m")
  39. cron_monthly_ = ("\n\033[93m /etc/cron.monthly/ does not exist \033[0m")
  40. log = ("\n\033[92m /var/log: \033[0m")
  41. log_ = ("\n\033[93m /var/log/ does not exist \033[0m")
  42.  
  43. # Defining functions
  44.  
  45. def _init():
  46.     if os.path.exists('/etc/rc.conf') == True:
  47.         print (openrc)
  48.         os.system('rc-status')
  49.     elif os.path.exists('/etc/systemd') == True:
  50.         print (sysd)
  51.         os.system('systemctl-status')
  52.     elif os.path.exists('/var/service') == True:
  53.         print (runit)
  54.         os.system('cat /var/service')
  55.     else:
  56.         print (init_)
  57.  
  58. def _mounts():
  59.     if os.path.exists('/proc/mounts') == True:
  60.         print (mounts)
  61.         os.system('cat /proc/mounts')
  62.     else:
  63.         print (mounts_)
  64.  
  65. def _hosts():
  66.     if os.path.exists('/etc/hosts.allow') == True:
  67.         print (hosts)
  68.         os.system('cat /etc/hosts.allow')
  69.     else:
  70.         print (hosts_)
  71.  
  72. def _passwd():
  73.     if os.path.exists('/etc/passwd') == True:
  74.         print (passwd)
  75.         os.system('cat /etc/passwd | sort -nk3 -t:')
  76.         print (UUID_0)
  77.         os.system('cat /etc/passwd | grep x:0: | cut -d ":" -f 1')
  78.     else:
  79.         print (passwd_)
  80.  
  81. def _crontab():
  82.     if os.path.exists('/etc/crontab') == True:
  83.         print (crontab)
  84.         os.system('cat /etc/crontab')
  85.     else:
  86.         print (crontab_)
  87.  
  88. def _cron_allow():
  89.     if os.path.exists('/etc/cron.allow') == True:
  90.         print (cron_allow)
  91.         os.system('cat /etc/cron.allow')
  92.     else:
  93.         print (cron_allow_)
  94.  
  95. def _cron_deny():
  96.     if os.path.exists('/etc/cron.deny') == True:
  97.         print (cron_deny)
  98.         os.system('cat /etc/cron.deny')
  99.     else:
  100.         print (cron_deny_)
  101.  
  102. def _cron_hourly():
  103.     if os.path.isdir('/etc/cron.hourly/') == True:
  104.         print (cron_hourly)
  105.         for file in os.listdir('/etc/cron.hourly/'):
  106.             print(file)
  107.     else:
  108.         print (cron_hourly_)
  109.  
  110. def _cron_daily():
  111.     if os.path.isdir('/etc/cron.daily/') == True:
  112.         print (cron_daily)
  113.         for file in os.listdir('/etc/cron.daily/'):
  114.             print(file)
  115.     else:
  116.         print (cron_daily_)
  117.  
  118. def _cron_weekly():
  119.     if os.path.isdir('/etc/cron.weekly/') == True:
  120.         print (cron_weekly)
  121.         for file in os.listdir('/etc/cron.weekly/'):
  122.             print(file)
  123.     else:
  124.         print (cron_weekly_)
  125.  
  126. def _cron_monthly():
  127.     if os.path.isdir('/etc/cron.monthly/') == True:
  128.         print (cron_monthly)
  129.         for file in os.listdir('/etc/cron.monthly/'):
  130.             print(file)
  131.     else:
  132.         print (cron_monthly_)
  133.  
  134. def _log():
  135.     if os.path.isdir('/var/log/') == True:
  136.         print (log)
  137.         for file in os.listdir('/var/log/'):
  138.             print(file)
  139.     else:
  140.         print (log_)
  141.  
  142. ## Defining the main function to call each other function
  143.  
  144. def main():
  145.     _init()
  146.     _mounts()
  147.     _hosts()
  148.     _passwd()
  149.     _cron_allow()
  150.     _cron_deny()
  151.     _crontab()
  152.     _cron_hourly()
  153.     _cron_daily()
  154.     _cron_weekly()
  155.     _cron_monthly()
  156.     _log()
  157. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement