├── Zen_of_Python ├── Zen_of_Python.py └── Zen_of_Python.png ├── .gitattributes ├── Images └── binance.jpg ├── CONTRIBUTING.md ├── Python_Scripts ├── Binary_Conversion.py ├── Hex_Conversion.py ├── DLL_Injector │ ├── injector_cli.py │ └── injector.py ├── WriteProcessMemory.py ├── ReadProcessMemory.py ├── Memory_Scanner.py └── Code_Injector.py ├── README.md ├── Templates └── Klassenbeispiel.py ├── LICENSE └── CODE_OF_CONDUCT.md /Zen_of_Python/Zen_of_Python.py: -------------------------------------------------------------------------------- 1 | import this 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Images/binance.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IDouble/Python-Scripts/HEAD/Images/binance.jpg -------------------------------------------------------------------------------- /Zen_of_Python/Zen_of_Python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IDouble/Python-Scripts/HEAD/Zen_of_Python/Zen_of_Python.png -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contribute per PR (Pull Request), if you have an Idea or found a bug, open a Issue. 4 | 5 | ## Pull Request Process 6 | 7 | 1. Create a Pull Request and it will be reviewed -------------------------------------------------------------------------------- /Python_Scripts/Binary_Conversion.py: -------------------------------------------------------------------------------- 1 | def binaer(): 2 | try: 3 | x = input("gib Binär ein: ") 4 | print(int(x,2)) 5 | binaer() 6 | except: 7 | print("geht nicht") 8 | binaer() 9 | 10 | binaer() 11 | -------------------------------------------------------------------------------- /Python_Scripts/Hex_Conversion.py: -------------------------------------------------------------------------------- 1 | def heximal(): 2 | try: 3 | x = input("gib Hex ein: ") 4 | print(int(x,16)) 5 | heximal() 6 | except: 7 | print("geht nicht") 8 | heximal() 9 | 10 | heximal() 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🐍 Python Scripts 🐍 2 | 3 | In this Repository, I upload all Python 2.x and 3.x Code Snippets, that I find useful and helpful. 🐍 4 | 5 | **⚠️ Be Warned that some Scripts are not suited for beginners ⚠️** 6 | 7 | ## 📕 Zen of Python 8 | ![Zen of Python](Zen_of_Python/Zen_of_Python.png) 9 | 10 | ![Binance Ready to give crypto a try ? buy bitcoin and other cryptocurrencies on binance](Images/binance.jpg) 11 | -------------------------------------------------------------------------------- /Python_Scripts/DLL_Injector/injector_cli.py: -------------------------------------------------------------------------------- 1 | # Good Example of a DLL Injector 2 | # Developed by -> numaru / https://github.com/numaru 3 | 4 | import sys 5 | 6 | from injector import Injector 7 | 8 | 9 | def main(): 10 | path_exe = str(sys.argv[1]) 11 | path_dll = str(sys.argv[2]) 12 | 13 | injector = Injector() 14 | pid = injector.create_process(path_exe) 15 | injector.load_from_pid(pid) 16 | injector.inject_dll(path_dll) 17 | injector.unload() 18 | 19 | if __name__ == "__main__": 20 | main() -------------------------------------------------------------------------------- /Templates/Klassenbeispiel.py: -------------------------------------------------------------------------------- 1 | #Dies soll ein Beispiel für eine Klasse sein in Python 2 | 3 | class make(): 4 | def __init__ (self,color,length,height): 5 | color = self.color 6 | length = self.length 7 | height = self.height 8 | def car(color,length,height): 9 | print ("""The color is %s,the length is %s,The length is %s""" % (color,length,height)) 10 | 11 | # make.car("red","2.5","3") Beispielausführung des Programms 12 | 13 | class do(make): 14 | pass 15 | 16 | # Beispiel von Klassenverebung in Python 17 | # do.car("red","2.5","3") Die Methode von der Klasse make wird vererbt 18 | 19 | # Alpay Yildirim 06.08.2014 Python 3.4.1 20 | -------------------------------------------------------------------------------- /Python_Scripts/WriteProcessMemory.py: -------------------------------------------------------------------------------- 1 | from ctypes import * 2 | from ctypes.wintypes import * 3 | 4 | PROCESS_ID = 9476 # From TaskManager for Notepad.exe 5 | PROCESS_HEADER_ADDR = 0x7ff7b81e0000 # From SysInternals VMMap utility 6 | 7 | # write to address 8 | newValue = 50 9 | 10 | PROCESS_VM_READ = 0x0010 11 | 12 | k32 = WinDLL('kernel32') 13 | k32.OpenProcess.argtypes = DWORD,BOOL,DWORD 14 | k32.OpenProcess.restype = HANDLE 15 | k32.WriteProcessMemory.argtypes = HANDLE,LPVOID,LPVOID,c_size_t,POINTER(c_size_t) 16 | k32.WriteProcessMemory.restype = BOOL 17 | 18 | process = k32.OpenProcess(PROCESS_VM_READ, 0, PROCESS_ID) 19 | s = c_size_t() 20 | 21 | k32.WriteProcessMemory(process, PROCESS_HEADER_ADDR, newValue, 255, byref(s)) -------------------------------------------------------------------------------- /Python_Scripts/ReadProcessMemory.py: -------------------------------------------------------------------------------- 1 | from ctypes import * 2 | from ctypes.wintypes import * 3 | 4 | PROCESS_ID = 9476 # From TaskManager for Notepad.exe 5 | PROCESS_HEADER_ADDR = 0x7ff7b81e0000 # From SysInternals VMMap utility 6 | 7 | # read from addresses 8 | STRLEN = 255 9 | 10 | PROCESS_VM_READ = 0x0010 11 | 12 | k32 = WinDLL('kernel32') 13 | k32.OpenProcess.argtypes = DWORD,BOOL,DWORD 14 | k32.OpenProcess.restype = HANDLE 15 | k32.ReadProcessMemory.argtypes = HANDLE,LPVOID,LPVOID,c_size_t,POINTER(c_size_t) 16 | k32.ReadProcessMemory.restype = BOOL 17 | 18 | process = k32.OpenProcess(PROCESS_VM_READ, 0, PROCESS_ID) 19 | buf = create_string_buffer(STRLEN) 20 | s = c_size_t() 21 | if k32.ReadProcessMemory(process, PROCESS_HEADER_ADDR, buf, STRLEN, byref(s)): 22 | print(s.value,buf.raw) -------------------------------------------------------------------------------- /Python_Scripts/Memory_Scanner.py: -------------------------------------------------------------------------------- 1 | import ctypes as c 2 | from ctypes import wintypes as w 3 | from struct import * 4 | from time import * 5 | import datetime 6 | import sys 7 | 8 | pid = 1234 9 | 10 | k32 = c.windll.kernel32 11 | 12 | OpenProcess = k32.OpenProcess 13 | OpenProcess.argtypes = [w.DWORD,w.BOOL,w.DWORD] 14 | OpenProcess.restype = w.HANDLE 15 | 16 | ReadProcessMemory = k32.ReadProcessMemory 17 | ReadProcessMemory.argtypes = [w.HANDLE,w.LPCVOID,w.LPVOID,c.c_size_t,c.POINTER(c.c_size_t)] 18 | ReadProcessMemory.restype = w.BOOL 19 | PAA = 0x1F0FFF 20 | address = 0x4000000 21 | ph = OpenProcess(PAA,False,int(pid)) #program handle 22 | 23 | buff = c.create_string_buffer(4) 24 | bufferSize = (c.sizeof(buff)) 25 | bytesRead = c.c_ulonglong(0) 26 | 27 | addresses_list = xrange(address,0x9000000,0x4) 28 | log=open(r'out.txt.','wb',0) 29 | for i in addresses_list: 30 | ReadProcessMemory(ph, c.c_void_p(i), buff, bufferSize, c.byref(bytesRead)) 31 | value = unpack('I',buff)[0] 32 | if value == int(sys.argv[1]): 33 | log.write('%x\r\n' % (i, )) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 AYIDouble 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Python_Scripts/Code_Injector.py: -------------------------------------------------------------------------------- 1 | # Good Example of a simple Code Injector 2 | # Developed by -> Andrea Fortuna / https://github.com/andreafortuna 3 | 4 | import sys 5 | from ctypes import * 6 | from win32com.client import GetObject 7 | 8 | if len(sys.argv) < 2: 9 | print "Python code injector: ./" + sys.argv[0] + " " 10 | sys.exit(0) 11 | 12 | proc = sys.argv[1] 13 | WMI = GetObject('winmgmts:') 14 | p = WMI.ExecQuery('select * from Win32_Process where Name="%s"' %(proc)) 15 | if len(p) == 0: 16 | print "Process " + proc + " not found, exiting!" 17 | sys.exit(0) 18 | 19 | process_id = p[0].Properties_('ProcessId').Value 20 | 21 | shellcode = \ 22 | "\xd9\xeb\x9b\xd9\x74\x24\xf4\x31\xd2\xb2\x77\x31\xc9\x64" \ 23 | "\x8b\x71\x30\x8b\x76\x0c\x8b\x76\x1c\x8b\x46\x08\x8b\x7e" \ 24 | "\x20\x8b\x36\x38\x4f\x18\x75\xf3\x59\x01\xd1\xff\xe1\x60" \ 25 | "\x8b\x6c\x24\x24\x8b\x45\x3c\x8b\x54\x28\x78\x01\xea\x8b" \ 26 | "\x4a\x18\x8b\x5a\x20\x01\xeb\xe3\x34\x49\x8b\x34\x8b\x01" \ 27 | "\xee\x31\xff\x31\xc0\xfc\xac\x84\xc0\x74\x07\xc1\xcf\x0d" \ 28 | "\x01\xc7\xeb\xf4\x3b\x7c\x24\x28\x75\xe1\x8b\x5a\x24\x01" \ 29 | "\xeb\x66\x8b\x0c\x4b\x8b\x5a\x1c\x01\xeb\x8b\x04\x8b\x01" \ 30 | "\xe8\x89\x44\x24\x1c\x61\xc3\xb2\x08\x29\xd4\x89\xe5\x89" \ 31 | "\xc2\x68\x8e\x4e\x0e\xec\x52\xe8\x9f\xff\xff\xff\x89\x45" \ 32 | "\x04\xbb\x7e\xd8\xe2\x73\x87\x1c\x24\x52\xe8\x8e\xff\xff" \ 33 | "\xff\x89\x45\x08\x68\x6c\x6c\x20\x41\x68\x33\x32\x2e\x64" \ 34 | "\x68\x75\x73\x65\x72\x30\xdb\x88\x5c\x24\x0a\x89\xe6\x56" \ 35 | "\xff\x55\x04\x89\xc2\x50\xbb\xa8\xa2\x4d\xbc\x87\x1c\x24" \ 36 | "\x52\xe8\x5f\xff\xff\xff\x68\x58\x20\x20\x20\x68\x20\x50" \ 37 | "\x4f\x43\x68\x63\x74\x6f\x72\x68\x49\x6e\x6a\x65\x68\x6f" \ 38 | "\x64\x65\x20\x68\x6f\x6e\x20\x43\x68\x50\x79\x74\x68\x31" \ 39 | "\xdb\x88\x5c\x24\x18\x89\xe3\x68\x72\x67\x58\x20\x68\x6e" \ 40 | "\x61\x2e\x6f\x68\x6f\x72\x74\x75\x68\x72\x65\x61\x66\x68" \ 41 | "\x2e\x61\x6e\x64\x68\x2f\x77\x77\x77\x68\x70\x73\x3a\x2f" \ 42 | "\x68\x20\x68\x74\x74\x68\x72\x67\x20\x2d\x68\x6e\x61\x2e" \ 43 | "\x6f\x68\x6f\x72\x74\x75\x68\x72\x65\x61\x66\x68\x40\x61" \ 44 | "\x6e\x64\x68\x64\x72\x65\x61\x68\x2d\x20\x61\x6e\x68\x75" \ 45 | "\x6e\x61\x20\x68\x46\x6f\x72\x74\x68\x72\x65\x61\x20\x68" \ 46 | "\x20\x41\x6e\x64\x68\x64\x20\x62\x79\x68\x6c\x6f\x70\x65" \ 47 | "\x68\x64\x65\x76\x65\x68\x64\x6c\x79\x20\x68\x50\x72\x6f" \ 48 | "\x75\x31\xc9\x88\x4c\x24\x5e\x89\xe1\x31\xd2\x52\x53\x51" \ 49 | "\x52\xff\xd0\x31\xc0\x50\xff\x55\x08" 50 | 51 | 52 | process_handle = windll.kernel32.OpenProcess(0x1F0FFF, False, process_id) 53 | 54 | if not process_handle: 55 | print "Couldn't acquire a handle to PID: %s" % process_id 56 | sys.exit(0) 57 | 58 | memory_allocation_variable = windll.kernel32.VirtualAllocEx(process_handle, 0, len(shellcode), 0x00001000, 0x40) 59 | windll.kernel32.WriteProcessMemory(process_handle, memory_allocation_variable, shellcode, len(shellcode), 0) 60 | 61 | if not windll.kernel32.CreateRemoteThread(process_handle, None, 0, memory_allocation_variable, 0, 0, 0): 62 | print "Failed to inject shellcode. Exiting." 63 | sys.exit(0) 64 | 65 | print "Remote thread created!" -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at GitHub. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /Python_Scripts/DLL_Injector/injector.py: -------------------------------------------------------------------------------- 1 | # Good Example of a DLL Injector 2 | # Developed by -> numaru / https://github.com/numaru 3 | 4 | import subprocess 5 | from ctypes import (WinError, byref, c_int, c_long, c_ulong, 6 | create_string_buffer, windll) 7 | 8 | 9 | class Injector: 10 | PROC_ALL_ACCESS = (0x000F0000 | 0x00100000 | 0x00000FFF) 11 | MEM_CREATE = 0x00001000 | 0x00002000 12 | MEM_RELEASE = 0x8000 13 | PAGE_EXECUTE_READWRITE = 0x40 14 | 15 | def __init__(self): 16 | self.kernel32 = windll.kernel32 17 | self.user32 = windll.user32 18 | self.pid = c_ulong() 19 | self.handle = None 20 | 21 | def create_process(self, path): 22 | return subprocess.Popen([path]).pid 23 | 24 | def load_from_pid(self, pid): 25 | self.unload() 26 | self.pid = c_ulong(pid) 27 | self.handle = self.kernel32.OpenProcess(self.PROC_ALL_ACCESS, 0, pid) 28 | if not self.handle: 29 | raise WinError() 30 | 31 | def unload(self): 32 | if self.handle: 33 | self.kernel32.CloseHandle(self.handle) 34 | if not self.handle: 35 | raise WinError() 36 | self.handle = None 37 | 38 | def alloc_remote(self, buffer, size): 39 | alloc = self.kernel32.VirtualAllocEx(self.handle, None, c_int(size), 40 | self.MEM_CREATE, self.PAGE_EXECUTE_READWRITE) 41 | if not alloc: 42 | raise WinError() 43 | self.write_memory(alloc, buffer) 44 | return alloc 45 | 46 | def free_remote(self, addr, size): 47 | if not self.kernel32.VirtualFreeEx(self.handle, addr, c_int(0), self.MEM_RELEASE): 48 | raise WinError() 49 | 50 | def get_address_from_module(self, module, function): 51 | module_addr = self.kernel32.GetModuleHandleA(module.encode("ascii")) 52 | if not module_addr: 53 | raise WinError() 54 | function_addr = self.kernel32.GetProcAddress(module_addr, function.encode("ascii")) 55 | if not module_addr: 56 | raise WinError() 57 | return function_addr 58 | 59 | def create_remote_thread(self, function_addr, args): 60 | dll_addr = c_long(0) 61 | args_addr = self.alloc_remote(args, len(args)) 62 | thread = self.kernel32.CreateRemoteThread(self.handle, None, None, c_long(function_addr), 63 | c_long(args_addr), None, None) 64 | if not thread: 65 | raise WinError() 66 | if self.kernel32.WaitForSingleObject(thread, 0xFFFFFFFF) == 0xFFFFFFFF: 67 | raise WinError() 68 | if not self.kernel32.GetExitCodeThread(thread, byref(dll_addr)): 69 | raise WinError() 70 | self.free_remote(args_addr, len(args)) 71 | return dll_addr.value 72 | 73 | def read_memory(self, addr, size): 74 | buffer = create_string_buffer(size) 75 | if not self.kernel32.ReadProcessMemory(self.handle, c_long(addr), buffer, size, None): 76 | raise WinError() 77 | return buffer 78 | 79 | def write_memory(self, addr, string): 80 | size = len(string) 81 | if not self.kernel32.WriteProcessMemory(self.handle, addr, string, size, None): 82 | raise WinError() 83 | 84 | def load_library(self, buffer): 85 | function_addr = self.get_address_from_module("kernel32.dll", "LoadLibraryA") 86 | dll_addr = self.create_remote_thread(function_addr, buffer) 87 | return dll_addr 88 | 89 | def inject_dll(self, path): 90 | return self.load_library(path.encode("ascii")) 91 | 92 | def call_from_injected(self, path, dll_addr, function, args): 93 | function_offset = self.get_offset_of_exported_function(path.encode("ascii"), function) 94 | self.create_remote_thread(dll_addr + function_offset, args) 95 | 96 | def get_offset_of_exported_function(self, module, function): 97 | base_addr = self.kernel32.LoadLibraryA(module) 98 | if not base_addr: 99 | raise WinError() 100 | function_addr = self.kernel32.GetProcAddress(base_addr, function.encode("ascii")) 101 | if not function_addr: 102 | raise WinError() 103 | if not self.kernel32.FreeLibrary(base_addr): 104 | raise WinError() 105 | return function_addr - base_addr --------------------------------------------------------------------------------