def do_tls_mutual_auth(host):
    with open(os.path.join(basedir, "tests/integration/keys/scapy-tls-client.crt.der"), "rb") as f:
        client_cert = f.read()
    certificate = TLSCertificate(data=client_cert)

    tls_version = TLSVersion.TLS_1_2

    socket_ = socket.socket()
    tls_socket = TLSSocket(socket_, client=True)
    tls_socket.connect(host)
    tls_socket.tls_ctx.rsa_load_keys_from_file(os.path.join(basedir,
                                                            "tests/integration/keys/scapy-tls-client.key.pem"),
                                                            client=True)

    client_hello = TLSRecord(version=tls_version) / TLSHandshake() /\
                   TLSClientHello(version=tls_version, compression_methods=[TLSCompressionMethod.NULL, ],
                                  cipher_suites=[TLSCipherSuite.ECDHE_RSA_WITH_AES_128_CBC_SHA256, ])
    tls_socket.sendall(client_hello)
    server_hello = tls_socket.recvall()
    server_hello.show()

    client_cert = TLSRecord(version=tls_version) / TLSHandshake() / TLSCertificateList(certificates=certificate)
    client_key_exchange = TLSRecord(version=tls_version) / TLSHandshake() / tls_socket.tls_ctx.get_client_kex_data()
    p = TLS.from_records([client_cert, client_key_exchange])
    tls_socket.sendall(p)

    sig_hash_alg = TLSSignatureHashAlgorithm(hash_alg=TLSHashAlgorithm.SHA256, sig_alg=TLSSignatureAlgorithm.RSA)
    sig = tls_socket.tls_ctx.get_client_signed_handshake_hash(SHA256.new())
    # sig = sig[:128] + chr(ord(sig[128]) ^ 0xff) + sig[129:]
    client_cert_verify = TLSRecord(version=tls_version) / TLSHandshake() / \
                         TLSCertificateVerify(alg=sig_hash_alg,
                                              sig=sig)
    tls_socket.sendall(client_cert_verify)

    client_ccs = TLSRecord(version=tls_version) / TLSChangeCipherSpec()
    tls_socket.sendall(client_ccs)
    tls_socket.sendall(to_raw(TLSFinished(), tls_socket.tls_ctx))
    server_finished = tls_socket.recvall()
    server_finished.show()

    tls_socket.sendall(to_raw(TLSPlaintext(data="GET / HTTP/1.1\r\nHOST: localhost\r\n\r\n"), tls_socket.tls_ctx))
    resp = tls_socket.recvall()
    print (("Got response from server"))
    resp.show()
    print ((tls_socket.tls_ctx))
Beispiel #2
0
def tls_client(ip, priv_key=None):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        sock.connect(ip)
        sock = TLSSocket(sock, client=True)
        print (("Connected to server: %s" % (ip,)))
    except socket.timeout as te:
        print (("Failed to open connection to server: %s" % (ip,), file=sys.stderr))
    else:
        tls_hello(sock)
        tls_client_key_exchange(sock)
        print (("Finished handshake. Sending application data (GET request)"))
        sock.sendall(to_raw(TLSPlaintext(data="GET / HTTP/1.1\r\nHOST: localhost\r\n\r\n"), sock.tls_ctx))
        resp = sock.recvall()
        print (("Got response from server"))
        resp.show()
        print ((sock.tls_ctx))
    finally:
        sock.close()
Beispiel #3
0
def warn(msg, explanation='', state='Warning'):
    print('[{}]'.format(colored(state, 'yellow')))
    print('{}{}'.format(colored(msg, 'yellow'), explanation))
Beispiel #4
0
def error(msg, explanation='', state='Error'):
    print('[{}]'.format(colored(state, 'red')))
    print('{}{}'.format(colored(msg, 'red'), explanation))
Beispiel #5
0
def task(msg):
    print('{}...'.format(msg), end='')
#! /usr/bin/python
"""
     Program: ch08_03_file_read.py
    Function: An exploration of simple conversion
"""
import os

from __future__ import print

file_working = open("output.txt", "r")

# using file_working.readline() read a line into the variable
# integer_string
# remove the newline from the end of the string
# HINT: [:-1]
# convert the string to an integer variable
print("integer:", integer_variable)

# repeat for the float which is the next line
print("  float:", float_variable)

string_variable = file_working.readline()
print(" string:", string_variable, end="")

file_working.close()

print("That's all folks!")
    except socket.error:
        error_msg += "Connection reset by peer"
    return error_msg


if __name__ == "__main__":
    if len(sys.argv) > 2:
        server = (sys.argv[1], int(sys.argv[2]))
    else:
        server = ("127.0.0.1", 8443)
    cipher_suite = TLSCipherSuite.RSA_WITH_AES_128_CBC_SHA

    request = "GET / HTTP/1.1\r\nHOST: %s\r\n\r\n" % server[0]
    block_aligned_request = align_data_on_block_bounday(request, cipher_suite)

    print (("Testing all padding bytes"))
    # Perform poodle 2 check
    for _ in range(0, TLSSecurityParameters.crypto_params[cipher_suite]["cipher"]["type"].block_size - 1):
        print (("Modifying padding byte %d" % index))
        print ((test_all_field_bytes(server, cipher_suite, block_aligned_request, modify_padding)))
        index += 1

    print (("Testing all mac bytes"))
    index = 0
    # Perform mac check
    for _ in range(0, TLSSecurityParameters.crypto_params[cipher_suite]["hash"]["type"].digest_size - 1):
        print (("Modifying mac byte %d" % index))
        print ((test_all_field_bytes(server, cipher_suite, block_aligned_request, modify_mac)))
        index += 1

    print (("Test complete"))
def _help():
    print()
    args = parser.parse_args()

    return args


def _help():
    print()


if __name__ == '__main__':
    args = get_args()

    # output directory
    outdir = args.output_dir
    if not isdir(outdir):
        print('Output dir {} does not exists!'.format(outdir))
        exit()

    # difficulty level
    levellist = ['Easy', 'Hard']
    if args.only_easy:
        levellist = ['Easy']
    if args.only_hard:
        levellist = ['Hard']
    if args.only_easy and args.only_hard:
        print(
            '--only-eazy and --only-hard tags can not be set at the same time!'
        )
        exit()

    # filetype
Beispiel #10
0
from __future__ import print

print("hello, this is test for github in python!")
def python2():
    print('before future import')
    print(1, 2, 3, 4)
def python3():
    from __future__ import print
    print('after future import')
    print(1, 2, 3, 4, sep='\t')
if sys.version_info.major >= 3:
    print('please use this script with version 2')
    return

import sys


def python2():
    print('before future import')
    print(1, 2, 3, 4)


def python3():
    from __future__ import print
    print('after future import')
    print(1, 2, 3, 4, sep='\t')


def main():
    python2()
    python3()


main()