예제 #1
0
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.")
finally:
    close_conn()
예제 #2
0
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.")
finally:
    log("Closing socket.")
    if conn:
        conn.shutdown(socket.SHUT_RDWR)
        conn.close()
예제 #3
0
    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":
            send("FLAGPLS")
            data = receive()
            if data:
                log("Got the flag!")
    close_conn()
except socket.error, e:
    log("-!- {}".format(str(e)))
except KeyboardInterrupt:
    log("Killed.")
finally:
    close_conn()
예제 #4
0
    operator = random.choice(['+', '-', '*', '/'])
    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]
    challenge = "{} {} {}".format(operands[0], operator, operands[1])
    log("Set challenge to '{}' (answer is {}).".format(challenge, answer))

    conn, sender = listener.accept()
    set_conn(conn)
    log("Got a connection from {}.".format(pp_host(sender)))
    send("CHALLENGE {}".format(challenge))
    data = receive()
    if int(data) == answer:
        send("OK")
        data = receive()
        if data == "FLAGPLS":
            send("<3><")
    else:
        send("NO")
except socket.error, e:
    log("-!- {}".format(str(e)))
except KeyboardInterrupt:
    log("Killed.")
finally:
    close_conn()
예제 #5
0
    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":
            send("FLAGPLS")
            data = receive()
            if data:
                log("Got the flag!")
    close_conn()
except socket.error, e:
    log("-!- {}".format(str(e)))
except KeyboardInterrupt:
    log("Killed.")
finally:
    close_conn()
예제 #6
0
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.")
finally:
    close_conn()
예제 #7
0
#!/usr/bin/python

import socket

from tcp_tools import set_name, set_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)
    sock.settimeout(3)
    set_conn(sock)
    sock.connect(HOST_PAIR)
    send("Hi!")
    data = receive()
    send("FLAGPLS")
    data = receive()
    if data:
        log("Got the flag!")
except socket.error, e:
    log("-!- {}".format(str(e)))
except KeyboardInterrupt:
    log("Killed.")
finally:
    log("Closing socket.")
    sock.shutdown(socket.SHUT_RDWR)
    sock.close()
예제 #8
0
HOST_PAIR = ("127.0.0.1", 2005)
PASSWORDS = ["red", "blue", "gray", "purple", "elephant", "monkey", "lion",
             "tiger", "bear", "password", "hunter", "dog", "cat", "swordfish"]

set_name("Client")

try:
    for password in PASSWORDS:
        log("Connecting on {}.".format(pp_host(HOST_PAIR)))
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(3)
        set_conn(sock)
        sock.connect(HOST_PAIR)
        data = receive()
        if data == "PASSWORDPLS":
            send(password)
            data = receive()
            if data == "OK":
                send("FLAGPLS")
                data = receive()
                if data:
                    log("Got the flag!")
                    break
        close_conn()
except socket.error, e:
    log("-!- {}".format(str(e)))
except KeyboardInterrupt:
    log("Killed.")
finally:
    close_conn()