Ejemplo n.º 1
0
set_name("Server")

try:
    log("Listening on {}.".format(pp_host(HOST_PAIR)))
    conn = None
    listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    listener.settimeout(3)
    listener.bind(HOST_PAIR)
    listener.listen(1)

    password = random.choice(PASSWORDS)
    log("Set password to '{}'.".format(password))

    while True:
        conn, sender = listener.accept()
        set_conn(conn)
        log("Got a connection from {}.".format(pp_host(sender)))
        send("PASSWORDPLS")
        data = receive()
        if data == password:
            send("OK")
            data = receive()
            if data == "FLAGPLS":
                send("<3><")
        else:
            send("BAD PASSWORD")
        close_conn()
except socket.error, e:
    log("-!- {}".format(str(e)))
except KeyboardInterrupt:
    log("Killed.")
Ejemplo n.º 2
0
from tcp_tools import set_name, set_conn, log, pp_host, send, receive

HOST_PAIR = ("127.0.0.1", 2001)

set_name("Server")

try:
    log("Listening on {}.".format(pp_host(HOST_PAIR)))
    conn = None
    listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    listener.settimeout(3)
    listener.bind(HOST_PAIR)
    listener.listen(1)

    conn, sender = listener.accept()
    set_conn(conn)
    log("Got a connection from {}.".format(pp_host(sender)))
    data = True
    while data and data != "FLAGPLS":
        data = receive()
        if data and data != "FLAGPLS":
            log("Ignoring.")
    if data:
        send("><3>")
        log("Sent the flag.")
    else:
        log("Lost client.")
except socket.error, e:
    log("-!- {}".format(str(e)))
except KeyboardInterrupt:
    log("Killed.")
Ejemplo n.º 3
0
#!/usr/bin/python

import socket

from tcp_tools import set_name, set_conn, close_conn, log, pp_host, send, receive

HOST_PAIR = ("127.0.0.1", 2001)

set_name("Client")

try:
    log("Connecting on {}.".format(pp_host(HOST_PAIR)))
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    set_conn(sock)
    sock.connect(HOST_PAIR)
    data = receive()
    if data.startswith("CHALLENGE"):
        operands = [None, None]
        challenge, operands[0], operator, operands[1] = data.split()
        operands = map(int, operands)
        if operator == '+':
            answer = operands[0] + operands[1]
        elif operator == '-':
            answer = operands[0] - operands[1]
        elif operator == '*':
            answer = operands[0] * operands[1]
        else:
            answer = operands[0] / operands[1]
        send(answer)
        data = receive()
        if data == "OK":
Ejemplo n.º 4
0
#!/usr/bin/python

import socket

from tcp_tools import set_name, set_conn, close_conn, log, pp_host, send, receive

HOST_PAIR = ("127.0.0.1", 2001)

set_name("Client")

try:
    log("Connecting on {}.".format(pp_host(HOST_PAIR)))
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    set_conn(sock)
    sock.connect(HOST_PAIR)
    data = receive()
    if data.startswith("CHALLENGE"):
        operands = [None, None]
        challenge, operands[0], operator, operands[1] = data.split()
        operands = map(int, operands)
        if operator == "+":
            answer = operands[0] + operands[1]
        elif operator == "-":
            answer = operands[0] - operands[1]
        elif operator == "*":
            answer = operands[0] * operands[1]
        else:
            answer = operands[0] / operands[1]
        send(answer)
        data = receive()
        if data == "OK":