Пример #1
0
def handle_tcp_https(socket, dstport):
	plaintext_socket = switchtossl(socket)
	if plaintext_socket:
		handle_tcp_http(plaintext_socket, dstport)
	else:
		socket.close()
Пример #2
0
def handle_tcp_hexdump_ssl(socket, dstport):
	socket = switchtossl(socket)
	if socket:
		handle_tcp_hexdump(socket, dstport)
	else:
		print("SSL handshake failed")
Пример #3
0
def handle_tcp_smtp(plaintext_socket, dstport):
    socket = TextChannel(plaintext_socket)
    tls_started = False
    ctr = 0.5

    msg_from = ''
    msg_to = []

    try:
        socket.send("220 localhost ESMTP server ready\n")

        while True:
            cmd = readline(socket)
            cmdupper = cmd.upper() if cmd else None
            time.sleep(ctr)  # Rate limit
            ctr *= 1.1

            if not cmd or not cmd.endswith('\n'):
                raise Exception('Invalid request')
            elif cmdupper.startswith('HELO'):
                socket.send("250 localhost\n")
            elif cmdupper.startswith('EHLO'):
                socket.send(
                    "250-localhost offers TWO extensions:\n250-8BITMIME\n250 STARTTLS\n"
                )
            elif cmdupper.startswith('STARTTLS'):
                if tls_started:
                    socket.send(
                        "454 TLS not available due to temporary reason\n")
                else:
                    tls_started = True
                    socket.send("220 Go ahead\n")
                    socket = TextChannel(switchtossl(plaintext_socket))
            elif cmdupper.startswith('QUIT'):
                socket.send("221 localhost ESMTP server closing connection\n")
                break
            elif cmdupper.startswith('NOOP'):
                socket.send("250 No-op Ok\n")
            elif cmdupper.startswith('RSET'):
                msg_from = ''
                msg_to = []
                socket.send("250 Reset Ok\n")
            elif cmdupper.startswith('DATA'):
                socket.send("354 Ok Send data ending with <CRLF>.<CRLF>\n")
                msg_contents = receive_data(socket)
                msg_id = uuid.uuid4().hex
                store_email(plaintext_socket.getpeername()[0], msg_id,
                            msg_contents, msg_from, msg_to)
                socket.send(
                    "250 Message received: {}@localhost\n".format(msg_id))
            elif cmdupper.startswith('MAIL FROM:') or cmdupper.startswith(
                    'SEND FROM:') or cmdupper.startswith(
                        'SOML FROM:') or cmdupper.startswith('SAML FROM:'):
                msg_from = cmd[len('MAIL FROM:'):].strip()
                socket.send("250 Sender: {} Ok\n".format(msg_from))
            elif cmdupper.startswith('RCPT TO:'):
                recipient = cmd[len('RCPT TO:'):].strip()
                msg_to.append(recipient)
                socket.send("250 Recipient: {} Ok\n".format(recipient))
            else:
                socket.send("502 Command not implemented\n")
    except Exception as err:
        #print(traceback.format_exc())
        pass

    try:
        print("-- SMTP TRANSPORT CLOSED --")
        socket.close()
    except:
        pass
Пример #4
0
def handle_tcp_https(socket, dsthost, dstport, persona):
    plaintext_socket = switchtossl(socket)
    if plaintext_socket:
        handle_tcp_http(plaintext_socket, dsthost, dstport, persona)
    else:
        socket.close()
Пример #5
0
def handle_tcp_hexdump_ssl(socket, dstport):
    socket = switchtossl(socket)
    if socket:
        handle_tcp_hexdump(socket, dstport)
    else:
        print("SSL handshake failed")
Пример #6
0
def handle_tcp_smtp(plaintext_socket, dstport):
	socket = TextChannel(plaintext_socket)
	tls_started = False
	ctr = 0.5

	msg_from = ''
	msg_to = []

	try:
		socket.send("220 localhost ESMTP server ready\n")

		while True:
			cmd = readline(socket)
			cmdupper = cmd.upper() if cmd else None
			time.sleep(ctr) # Rate limit
			ctr *= 1.1

			if not cmd or not cmd.endswith('\n'):
				raise Exception('Invalid request')
			elif cmdupper.startswith('HELO'):
				socket.send("250 localhost\n")
			elif cmdupper.startswith('EHLO'):
				socket.send("250-localhost offers TWO extensions:\n250-8BITMIME\n250 STARTTLS\n")
			elif cmdupper.startswith('STARTTLS'):
				if tls_started:
					socket.send("454 TLS not available due to temporary reason\n")
				else:
					tls_started = True
					socket.send("220 Go ahead\n")
					socket = TextChannel(switchtossl(plaintext_socket))
			elif cmdupper.startswith('QUIT'):
				socket.send("221 localhost ESMTP server closing connection\n")
				break
			elif cmdupper.startswith('NOOP'):
				socket.send("250 No-op Ok\n")
			elif cmdupper.startswith('RSET'):
				msg_from = ''
				msg_to = []
				socket.send("250 Reset Ok\n")
			elif cmdupper.startswith('DATA'):
				socket.send("354 Ok Send data ending with <CRLF>.<CRLF>\n")
				msg_contents = receive_data(socket)
				msg_id = uuid.uuid4().hex
				store_email(plaintext_socket.getpeername()[0], msg_id, msg_contents, msg_from, msg_to)
				socket.send("250 Message received: {}@localhost\n".format(msg_id))
			elif cmdupper.startswith('MAIL FROM:') or cmdupper.startswith('SEND FROM:') or cmdupper.startswith('SOML FROM:') or cmdupper.startswith('SAML FROM:'):
				msg_from = cmd[len('MAIL FROM:'):].strip()
				socket.send("250 Sender: {} Ok\n".format(msg_from))
			elif cmdupper.startswith('RCPT TO:'):
				recipient = cmd[len('RCPT TO:'):].strip()
				msg_to.append(recipient)
				socket.send("250 Recipient: {} Ok\n".format(recipient))
			else:
				socket.send("502 Command not implemented\n")
	except Exception as err:
		#print(traceback.format_exc())
		pass

	try:
		print("-- SMTP TRANSPORT CLOSED --")
		socket.close()
	except:
		pass