Upload Keylogger python code.py
Browse files- Keylogger python code.py +70 -0
Keylogger python code.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import psutil
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
SUSPICIOUS_KEYWORDS = [
|
| 5 |
+
"keylogger",
|
| 6 |
+
"pynput",
|
| 7 |
+
"keyboard",
|
| 8 |
+
"keystroke",
|
| 9 |
+
"hook"
|
| 10 |
+
]
|
| 11 |
+
|
| 12 |
+
SUSPICIOUS_FILES = [
|
| 13 |
+
"keylogger.py",
|
| 14 |
+
"logs.json",
|
| 15 |
+
"keylog.txt"
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
def check_running_processes():
|
| 19 |
+
print("\n[+] Scanning running processes...\n")
|
| 20 |
+
found = False
|
| 21 |
+
|
| 22 |
+
for process in psutil.process_iter(['pid', 'name', 'cmdline']):
|
| 23 |
+
try:
|
| 24 |
+
cmdline = " ".join(process.info['cmdline']) if process.info['cmdline'] else ""
|
| 25 |
+
for keyword in SUSPICIOUS_KEYWORDS:
|
| 26 |
+
if keyword.lower() in cmdline.lower():
|
| 27 |
+
print(f"[!] Suspicious Process Found")
|
| 28 |
+
print(f" PID : {process.info['pid']}")
|
| 29 |
+
print(f" Name: {process.info['name']}")
|
| 30 |
+
print(f" Cmd : {cmdline}\n")
|
| 31 |
+
found = True
|
| 32 |
+
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
| 33 |
+
pass
|
| 34 |
+
|
| 35 |
+
if not found:
|
| 36 |
+
print("[✓] No suspicious running processes detected.\n")
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def check_suspicious_files():
|
| 40 |
+
print("[+] Scanning common folders for keylogger files...\n")
|
| 41 |
+
found = False
|
| 42 |
+
|
| 43 |
+
common_paths = [
|
| 44 |
+
os.path.expanduser("~"),
|
| 45 |
+
os.getcwd()
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
for path in common_paths:
|
| 49 |
+
for root, dirs, files in os.walk(path):
|
| 50 |
+
for file in files:
|
| 51 |
+
if file.lower() in SUSPICIOUS_FILES:
|
| 52 |
+
print(f"[!] Suspicious File Found: {os.path.join(root, file)}")
|
| 53 |
+
found = True
|
| 54 |
+
|
| 55 |
+
if not found:
|
| 56 |
+
print("[✓] No suspicious files found.\n")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def risk_level():
|
| 60 |
+
print("\n--- Risk Assessment ---")
|
| 61 |
+
print("LOW : No suspicious activity")
|
| 62 |
+
print("MEDIUM : Python background scripts found")
|
| 63 |
+
print("HIGH : pynput / keyboard detected\n")
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
if __name__ == "__main__":
|
| 67 |
+
print("\n=== Python Keylogger Detection Tool ===")
|
| 68 |
+
check_running_processes()
|
| 69 |
+
check_suspicious_files()
|
| 70 |
+
risk_level()
|