'Python' 카테고리의 다른 글
python technical issues (0) | 2015.12.09 |
---|---|
python for infosec (0) | 2015.12.09 |
simple MessageBox pop-up using Python in windows (0) | 2015.09.24 |
dll injection in python2 (0) | 2015.09.24 |
fileUpload.py (0) | 2015.04.13 |
python technical issues (0) | 2015.12.09 |
---|---|
python for infosec (0) | 2015.12.09 |
simple MessageBox pop-up using Python in windows (0) | 2015.09.24 |
dll injection in python2 (0) | 2015.09.24 |
fileUpload.py (0) | 2015.04.13 |
python basic (0) | 2015.12.09 |
---|---|
python for infosec (0) | 2015.12.09 |
simple MessageBox pop-up using Python in windows (0) | 2015.09.24 |
dll injection in python2 (0) | 2015.09.24 |
fileUpload.py (0) | 2015.04.13 |
python basic (0) | 2015.12.09 |
---|---|
python technical issues (0) | 2015.12.09 |
simple MessageBox pop-up using Python in windows (0) | 2015.09.24 |
dll injection in python2 (0) | 2015.09.24 |
fileUpload.py (0) | 2015.04.13 |
import ctypes
import time
SendInput = ctypes.windll.user32.SendInput
PUL = ctypes.POINTER(ctypes.c_ulong)
class KeyBdInput(ctypes.Structure):
_fields_ = [("wVk", ctypes.c_ushort),
("wScan", ctypes.c_ushort),
("dwFlags", ctypes.c_ulong),
("time", ctypes.c_ulong),
("dwExtraInfo", PUL)]
class HardwareInput(ctypes.Structure):
_fields_ = [("uMsg", ctypes.c_ulong),
("wParamL", ctypes.c_short),
("wParamH", ctypes.c_ushort)]
class MouseInput(ctypes.Structure):
_fields_ = [("dx", ctypes.c_long),
("dy", ctypes.c_long),
("mouseData", ctypes.c_ulong),
("dwFlags", ctypes.c_ulong),
("time",ctypes.c_ulong),
("dwExtraInfo", PUL)]
class Input_I(ctypes.Union):
_fields_ = [("ki", KeyBdInput),
("mi", MouseInput),
("hi", HardwareInput)]
class Input(ctypes.Structure):
_fields_ = [("type", ctypes.c_ulong),
("ii", Input_I)]
def PressKey(hexKeyCode):
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.ki = KeyBdInput( hexKeyCode, 0x48, 0, 0, ctypes.pointer(extra) )
x = Input( ctypes.c_ulong(1), ii_ )
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
def ReleaseKey(hexKeyCode):
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.ki = KeyBdInput( hexKeyCode, 0x48, 0x0002, 0, ctypes.pointer(extra) )
x = Input( ctypes.c_ulong(1), ii_ )
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
def PressAltTab():
PressKey(0x012) #Alt
PressKey(0x09) #Tab
time.sleep(2) #optional : if you want to see the atl-tab overlay
ReleaseKey(0x09) #~Tab
ReleaseKey(0x012) #~Alt
if __name__ =="__main__":
PressAltTab()
while automating, python selenium Chrome filenotfound exception occures (0) | 2015.09.23 |
---|---|
converting .py to .exe (0) | 2015.09.23 |
How do I execute a program from python? os.system fails due to spaces in path (0) | 2015.09.23 |
timer_with_Lock.py (0) | 2015.05.08 |
asyncWrite.py (0) | 2015.05.08 |
You can use the ctypes library, which comes installed with Python:
import ctypes
MessageBox = ctypes.windll.user32.MessageBoxW
MessageBox(None, 'Hello', 'Window title', 0)
Above code is for Python 2.x. For Python 3.x, use MessageBoxW instead of MessageBoxA: This is the version that accepts unicode strings, which Python 3 uses by default.
---------
or
import win32ui
win32ui.MessageBox("Message", "Title")
python technical issues (0) | 2015.12.09 |
---|---|
python for infosec (0) | 2015.12.09 |
dll injection in python2 (0) | 2015.09.24 |
fileUpload.py (0) | 2015.04.13 |
randomGenerator.py (0) | 2015.04.02 |
print "[+] Universal DLL Injector by Y"
print "[+] contact : If you know me then give me a shout"
print "[+] usage: ./dll_injector.py <PID> <DLLPATH>"
print "\n"
from ctypes import *
import sys,ctypes
# Define constants we use
PAGE_RW_PRIV = 0x04
PROCESS_ALL_ACCESS = 0x1F0FFF
VIRTUAL_MEM = 0x3000
#CTYPES handler
kernel32 = windll.kernel32
def dll_inject(PID,DLL_PATH):
print "[+] Starting DLL Injector"
LEN_DLL = len(DLL_PATH)# get the length of the DLL PATH
print "\t[+] Getting process handle for PID:%d " % PID
hProcess = kernel32.OpenProcess(PROCESS_ALL_ACCESS,False,PID)
if hProcess == None:
print "\t[+] Unable to get process handle"
sys.exit(0)
print "\t[+] Allocating space for DLL PATH"
DLL_PATH_ADDR = kernel32.VirtualAllocEx(hProcess,
0,
LEN_DLL,
VIRTUAL_MEM,
PAGE_RW_PRIV)
bool_Written = c_int(0)
print "\t[+] Writing DLL PATH to current process space"
kernel32.WriteProcessMemory(hProcess,
DLL_PATH_ADDR,
DLL_PATH,
LEN_DLL,
byref(bool_Written))
print "\t[+] Resolving Call Specific functions & libraries"
kernel32DllHandler_addr = kernel32.GetModuleHandleA("kernel32")
print "\t\t[+] Resolved kernel32 library at 0x%08x" % kernel32DllHandler_addr
LoadLibraryA_func_addr = kernel32.GetProcAddress(kernel32DllHandler_addr,"LoadLibraryA")
print "\t\t[+] Resolve LoadLibraryA function at 0x%08x" %LoadLibraryA_func_addr
thread_id = c_ulong(0) # for our thread id
print "\t[+] Creating Remote Thread to load our DLL"
if not kernel32.CreateRemoteThread(hProcess,
None,
0,
LoadLibraryA_func_addr,
DLL_PATH_ADDR,
0,
byref(thread_id)):
print "Injection Failed, exiting"
sys.exit(0)
else:
print "Remote Thread 0x%08x created, DLL code injected" % thread_id.value
PID = int(sys.argv[1])
DLL_PATH = str(sys.argv[2])
dll_inject(PID, DLL_PATH)
python for infosec (0) | 2015.12.09 |
---|---|
simple MessageBox pop-up using Python in windows (0) | 2015.09.24 |
fileUpload.py (0) | 2015.04.13 |
randomGenerator.py (0) | 2015.04.02 |
threadingQueue.py (0) | 2015.03.06 |
import os, time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import ctypes
import time
bstack="C:\\Program Files (x86)\\BlueStacks\\HD-StartLauncher.exe"
# chromedriver 다운로드 후 경로 지정 https://sites.google.com/a/chromium.org/chromedriver/downloads
chromedirver="C:\\Users\\bitec101\\Downloads\\chromedriver_win32\\chromedriver"
os.environ["webdriver.chrome.driver"]=chromedirver
chrome_options=webdriver.ChromeOptions()
chrome_options.add_argument('--incognito --start-maximized') # private mode, 전체화면 옵션 적용
driver=webdriver.Chrome(chromedirver,chrome_options=chrome_options)
pyRefPath="file:///C:/Users/bitec101/Downloads/python-3.4.3-docs-html/python-3.4.3-docs-html/library/index.html"
SendInput = ctypes.windll.user32.SendInput
PUL = ctypes.POINTER(ctypes.c_ulong)
class KeyBdInput(ctypes.Structure):
_fields_ = [("wVk", ctypes.c_ushort),
("wScan", ctypes.c_ushort),
("dwFlags", ctypes.c_ulong),
("time", ctypes.c_ulong),
("dwExtraInfo", PUL)]
class HardwareInput(ctypes.Structure):
_fields_ = [("uMsg", ctypes.c_ulong),
("wParamL", ctypes.c_short),
("wParamH", ctypes.c_ushort)]
class MouseInput(ctypes.Structure):
_fields_ = [("dx", ctypes.c_long),
("dy", ctypes.c_long),
("mouseData", ctypes.c_ulong),
("dwFlags", ctypes.c_ulong),
("time",ctypes.c_ulong),
("dwExtraInfo", PUL)]
class Input_I(ctypes.Union):
_fields_ = [("ki", KeyBdInput),
("mi", MouseInput),
("hi", HardwareInput)]
class Input(ctypes.Structure):
_fields_ = [("type", ctypes.c_ulong),
("ii", Input_I)]
def PressKey(hexKeyCode):
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.ki = KeyBdInput( hexKeyCode, 0x48, 0, 0, ctypes.pointer(extra) )
x = Input( ctypes.c_ulong(1), ii_ )
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
def ReleaseKey(hexKeyCode):
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.ki = KeyBdInput( hexKeyCode, 0x48, 0x0002, 0, ctypes.pointer(extra) )
x = Input( ctypes.c_ulong(1), ii_ )
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
def PressAltTab():
PressKey(0x012) #Alt
PressKey(0x09) #Tab
time.sleep(1) #optional : if you want to see the atl-tab overlay
ReleaseKey(0x09) #~Tab
ReleaseKey(0x012) #~Alt
def new_tab(tab_num):
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
driver.switch_to_window(driver.window_handles[-1])
tab_num=driver.current_window_handle
driver.switch_to_window(tab_num)
def main():
driver.get('http://tweetdeck.twitter.com')
tab1=driver.current_window_handle
new_tab("tab2")
driver.get('http://twitter.com')
new_tab("tab3")
driver.get('http://tistory.com')
new_tab("tab4")
driver.get(pyRefPath)
os.startfile(bstack)
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB)
time.sleep(1)
PressAltTab()
if __name__=="__main__":
main()
pressing ALT+TAB in windows (0) | 2015.09.25 |
---|---|
converting .py to .exe (0) | 2015.09.23 |
How do I execute a program from python? os.system fails due to spaces in path (0) | 2015.09.23 |
timer_with_Lock.py (0) | 2015.05.08 |
asyncWrite.py (0) | 2015.05.08 |
pip3 install py2exe
start.py 구성 후
make.py-------------------------
from distutils.core import setup
import py2exe
setup(console=['test.py'])
-------인코딩 에러시 옵션 추가-------
from distutils.core import setup
import py2exe
setup(
zipfile=None,
options={'py2exe':{'packages':['encodings'],'bundle_files':1}}, # 인코딩 및 단일 파일 추출 옵션 적용
console=['start.py'], # 콘솔창 없이 하려면 windows 옵션 적용
)
-------------------------------
python make.py py2exe
cd dist
참고로 , 윈도우 api가 가미된 것을 만들고자 한다면, wxPython을 설치해야 한다 들었음.
pressing ALT+TAB in windows (0) | 2015.09.25 |
---|---|
while automating, python selenium Chrome filenotfound exception occures (0) | 2015.09.23 |
How do I execute a program from python? os.system fails due to spaces in path (0) | 2015.09.23 |
timer_with_Lock.py (0) | 2015.05.08 |
asyncWrite.py (0) | 2015.05.08 |
import os;
os.system('"C:\\Temp\\a b c\\Notepad.exe"');
=============
subprocess.call will avoid problems with having to deal with quoting conventions of various shells. It accepts a list, rather than a string, so arguments are more easily delimited. i.e.
import subprocess
subprocess.call(['C:\\Temp\\a b c\\Notepad.exe', 'C:\\test.txt'])
=============
Here's a different way of doing it.
If you're using windows the following acts like double-clicking the file in Explorer, or giving the file name as an argument to the DOS "start" command: the file is opened with whatever application (if any) its extension is associated.
filepath = 'textfile.txt'
import os
os.startfile(filepath)
Example:
import os
os.startfile('textfile.txt')
This will open textfile.txt with notepad if notepad is associted with .txt files.
=============
The outermost quotes are consumed by Python itself, and the Windows shell doesn't see it. As mentioned above, Windows only understands double-quotes. Python will convert forward-slashed to backslashes on Windows, so you can use
os.system('"C://Temp/a b c/Notepad.exe"')
The ' is consumed by Python, which then passes "C://Temp/a b c/Notepad.exe" (as a Windows path, no double-backslashes needed) to CMD.EXE
=============
At least in Windows 7 and Python 3.1, os.system in Windows wants the command line double-quoted if there are spaces in path to the command. For example:
TheCommand = '\"\"C:\\Temp\\a b c\\Notepad.exe\"\"'
os.system(TheCommand)
A real-world example that was stumping me was cloning a drive in Virtual box. The subprocess.call solution above didn't work because of some access rights issue, but when I double-quoted the command, os.system became happy:
TheCommand = '\"\"C:\\Program Files\\Sun\\VirtualBox\\VBoxManage.exe\" ' \
+ ' clonehd \"' + OrigFile + '\" \"' + NewFile + '\"\"'
os.system(TheCommand)
=============
pip3 install pypiwin32
import win32api
try: win32api.WinExec('NOTEPAD.exe') # Works seamlessly
except: pass
while automating, python selenium Chrome filenotfound exception occures (0) | 2015.09.23 |
---|---|
converting .py to .exe (0) | 2015.09.23 |
timer_with_Lock.py (0) | 2015.05.08 |
asyncWrite.py (0) | 2015.05.08 |
threading (0) | 2015.05.08 |