Advertisement
Madmouse

a cute little terminal spy

Aug 29th, 2016
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. #////////////////////////////////////////////////////////////////////////////////
  4. #// THE SCOTCH-WARE LICENSE (Revision 0):
  5. #//  wrote this file. As long as you retain this notice you
  6. #// can do whatever you want with this stuff. If we meet some day, and you think
  7. #// this stuff is worth it, you can buy me a shot of scotch in return
  8. #////////////////////////////////////////////////////////////////////////////////
  9. #
  10. # A gift for Aaron lol
  11.  
  12. import sys, subprocess
  13.  
  14. ps = None
  15. if len(sys.argv) != 3:
  16.     if len(sys.argv) == 2:
  17.         ps = 'bash'
  18.     else:
  19.         print(sys.argv[0]+' <PTS/TTY> <PROCESS NAME (default: bash)>')
  20.         exit(1)
  21. else:
  22.     ps = sys.argv[2]
  23.  
  24. c = [
  25.     'stdbuf', '-oL',
  26.     'bash', '-c',
  27.     'strace -e trace=write -s1000 -fp '
  28.     '$(ps -t %s | grep -oP \'\\K^[0-9]+(?= .* %s)\') 2>&1 '
  29.     '| grep -oP \'(?<=write\\([0-9]{1}, \").*(?=\", [0-9]*\\))\' ' % (sys.argv[1], ps)
  30. ]
  31.  
  32. p = subprocess.Popen(c, stdout=subprocess.PIPE,
  33.     stderr=subprocess.STDOUT,
  34.     stdin=subprocess.PIPE,
  35.     shell=False,
  36.     bufsize=1,
  37.     universal_newlines=True)
  38.  
  39. print('Watching %s on %s\n' % (ps, sys.argv[1]))
  40. while p.poll() == None:
  41.     out = p.stdout.readline().rstrip('\n')
  42.     out = out.decode('string_escape')
  43.     sys.stdout.write(out)
  44.     sys.stdout.flush()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement