EvilZone

Programming and Scripting => Scripting Languages => : frog June 11, 2014, 11:55:39 AM

: [Python] nc-lp.py - Netcat-like listener
: frog June 11, 2014, 11:55:39 AM
: (python)
#!/usr/bin/env python
##
### nc-lp.py - listen for a tcp connection on a certain port
##
#
import sys,socket,re

def usage():
    print("""\n    nc-lp.py - listen for incoming TCP connection
           usage: python nc-lp.py <port>""")

def listen(lport):
    lsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    lsocket.bind(("", int(lport)))
    lsocket.listen(1)
    print("[+] Listening on port " + lport)
    connection, address = lsocket.accept()
    print("[*] Connection from " + str(address[0]))

    while True:
        try:
            incoming = connection.recv(2048)
            print(str(incoming))
            outgoing = raw_input("@" + str(address[0]) + ">")

            while outgoing == "":
                outgoing = raw_input("@" + str(address[0]) + ">")

            if outgoing == "exit":
                print("[!] Exiting..")
                exit()

            connection.send(outgoing)
        except socket.error:
            print("[!] Error: Connection lost")
            exit()
        except socket.timeout:
            print("[!] Error: Connection timed out")
            exit()

def main():
    if len(sys.argv) < 2:
        usage()
        exit()

    search = re.compile("([0-9]{1,5})")
    lport = sys.argv[1]

    if search.match(lport):
        try:
            listen(lport)
        except OverflowError:
            print("[!] Error: port must be between 1-65535")
    else:
        print("[!] Error: port must be between 1-65535")

if __name__ == "__main__":
    main()
: Re: [Python] nc-lp.py - Netcat-like listener
: lucid June 12, 2014, 04:01:49 AM
Nice. I'm actually about to get started on a Ruby script that is telnet-like, so this is interesting. Even if it is in a different language then the one I had planned on using.
: Re: [Python] nc-lp.py - Netcat-like listener
: DeXtreme June 12, 2014, 05:03:04 AM
Cool.I was also gonna write something similar also in python but to execute shell commands on remote systems.
: Re: [Python] nc-lp.py - Netcat-like listener
: frog June 12, 2014, 06:21:35 AM
@lucid, Ruby is a cool looking language but it's like perl/python combined with a goofy-ass syntax. Your post reminds me of an article from 2010 in a hakin9 magazine. I was able to find it. The code in there is very comprehensive. Check it out. http://www.slideshare.net/keith55/manipulating-the-network-with-packet-fu

@DeXtreme, I was thinking the same thing(using python for a remote shell of some sort). The only real application I could think of for such a thing would be for the Apple computers on display at Best Buy. You could make the mac 'say (http://"https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/say.1.html")' things when people walk by.

This is really just so I can test a reverse shell being dropped from a Teensy. I'm going to encode the reverse-shell binary(hex or base64) and store it in the Teensy's flashmem during runtime. I will make a separate thread with the details.

https://evilzone.org/projects-and-discussion/teensy-dropper-project-details-and-progress/msg84126/#msg84126
: Re: [Python] nc-lp.py - Netcat-like listener
: DeXtreme June 12, 2014, 06:08:40 PM
@lucid, Ruby is a cool looking language but it's like perl/python combined with a goofy-ass syntax. Your post reminds me of an article from 2010 in a hakin9 magazine. I was able to find it. The code in there is very comprehensive. Check it out. http://www.slideshare.net/keith55/manipulating-the-network-with-packet-fu

@DeXtreme, I was thinking the same thing(using python for a remote shell of some sort). The only real application I could think of for such a thing would be for the Apple computers on display at Best Buy. You could make the mac 'say (http://"https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/say.1.html")' things when people walk by.

This is really just so I can test a reverse shell being dropped from a Teensy. I'm going to encode the reverse-shell binary(hex or base64) and store it in the Teensy's flashmem during runtime. I will make a separate thread with the details.

https://evilzone.org/projects-and-discussion/teensy-dropper-project-details-and-progress/msg84126/#msg84126


Sounds great. Heading over there now ;)