Advertisement
Python253

demo_pml

Apr 13th, 2024 (edited)
884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.71 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: demo_pml.py
  4. # Version: 1.0.2
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. This script generates a demo Process Monitor Log (PML) file (.pml) containing sample process monitoring data.
  9. The generated .pml file simulates process events such as process name, operation, path, result, and detail.
  10. It serves as a convenient tool for generating sample input data for testing the pml2csv.py script.
  11.  
  12. Requirements:
  13. - Python 3.x
  14.  
  15. Usage:
  16. 1. Ensure Python 3.x is installed on your system.
  17. 2. Save the demo_pml.py script to a directory of your choice.
  18. 3. Open a terminal or command prompt.
  19. 4. Navigate to the directory where the demo_pml.py script is saved.
  20. 5. Run the script using the following command:  'python demo_pml.py'
  21. 6. After successful execution, a demo .pml file named "demo.pml" will be created in the same directory.
  22.  
  23. Additional Notes:
  24. - The generated .pml file contains sample process monitoring data in tab-separated format.
  25. - This script is intended for demonstration purposes and generates static demo data.
  26. - Users can customize the script to adjust the generated data according to their testing needs.
  27.  
  28. Demo Output:
  29. Time    Process Name    PID    Operation    Path    Result    Detail
  30. 2024-04-14 10:05:39    svchost.exe    2278    Open    C:\Users\user\Documents\document.docx    ERROR    File opened
  31. 2024-04-14 10:20:33    cmd.exe    1790    Close    C:\Users\user\Downloads\data.csv    ERROR    File deleted
  32. 2024-04-14 10:27:54    svchost.exe    8502    Delete    C:\Users\user\Downloads\data.csv    SUCCESS    File opened
  33. 2024-04-14 10:49:44    explorer.exe    9543    Close    C:\Users\user\Downloads\data.csv    ERROR    File created
  34. 2024-04-14 10:50:43    svchost.exe    2515    Read    C:\Users\user\Downloads\data.csv    ERROR    Data written
  35. 2024-04-14 10:29:51    chrome.exe    4401    Delete    C:\Users\user\Desktop\file.txt    SUCCESS    File deleted
  36. 2024-04-14 10:02:40    notepad.exe    9053    Open    C:\Users\user\Downloads\data.csv    ERROR    File opened
  37. 2024-04-14 10:44:16    cmd.exe    9617    Delete    C:\Users\user\Desktop\file.txt    SUCCESS    File deleted
  38. 2024-04-14 10:32:35    explorer.exe    8641    Write    C:\Users\user\Desktop\file.txt    ERROR    File deleted
  39. 2024-04-14 10:23:53    explorer.exe    3626    Close    C:\Users\user\Desktop\file.txt    ERROR    Data written
  40. 2024-04-14 10:22:16    explorer.exe    8256    Open    C:\Users\user\Documents\document.docx    SUCCESS    Access denied
  41. 2024-04-14 10:37:15    cmd.exe    9703    Open    C:\Users\user\Downloads\data.csv    SUCCESS    File created
  42. 2024-04-14 10:34:29    cmd.exe    4558    Read    C:\Users\user\Desktop\file.txt    SUCCESS    File opened
  43. 2024-04-14 10:39:57    svchost.exe    5124    Read    C:\Users\user\Desktop\file.txt    ERROR    File opened
  44. 2024-04-14 10:35:53    chrome.exe    6575    Write    C:\Users\user\Documents\document.docx    ERROR    Access denied
  45. 2024-04-14 10:19:27    svchost.exe    8720    Read    C:\Users\user\Downloads\data.csv    ERROR    File created
  46. 2024-04-14 10:53:14    notepad.exe    2171    Create    C:\Users\user\Downloads\data.csv    ERROR    File created
  47. 2024-04-14 10:41:20    chrome.exe    4867    Write    C:\Users\user\Downloads\data.csv    ERROR    Data written
  48. 2024-04-14 10:15:16    svchost.exe    6153    Create    C:\Users\user\Documents\document.docx    ERROR    File opened
  49. 2024-04-14 10:46:36    chrome.exe    2582    Create    C:\Users\user\Downloads\data.csv    ERROR    Access denied
  50.  
  51.  
  52. """
  53.  
  54. import random
  55.  
  56. def generate_demo_pml(filename):
  57.     with open(filename, 'w') as f:
  58.         # Write header
  59.         f.write("Time\tProcess Name\tPID\tOperation\tPath\tResult\tDetail\n")
  60.         # Generate sample process events
  61.         processes = ["explorer.exe", "notepad.exe", "chrome.exe", "svchost.exe", "cmd.exe"]
  62.         operations = ["Create", "Read", "Write", "Delete", "Open", "Close"]
  63.         paths = ["C:\\Users\\user\\Desktop\\file.txt", "C:\\Users\\user\\Documents\\document.docx", "C:\\Users\\user\\Downloads\\data.csv"]
  64.         results = ["SUCCESS", "ERROR"]
  65.         details = ["File created", "File opened", "File deleted", "Data written", "Access denied"]
  66.         for i in range(20):  # Generate 20 sample events
  67.             time = f"2024-04-14 10:{random.randint(0, 59):02d}:{random.randint(0, 59):02d}"
  68.             process = random.choice(processes)
  69.             pid = random.randint(1000, 9999)
  70.             operation = random.choice(operations)
  71.             path = random.choice(paths)
  72.             result = random.choice(results)
  73.             detail = random.choice(details)
  74.             f.write(f"{time}\t{process}\t{pid}\t{operation}\t{path}\t{result}\t{detail}\n")
  75.  
  76. if __name__ == "__main__":
  77.     generate_demo_pml("demo.pml")
  78.  
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement