本文整理汇总了Python中tlsfuzzer.runner.Runner类的典型用法代码示例。如果您正苦于以下问题:Python Runner类的具体用法?Python Runner怎么用?Python Runner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Runner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
fingerprint = Scanner().scan(ip="127.0.0.1", port=4433)
generator = Generator(fingerprint)
good = 0
bad = 0
for conversation in generator:
fuzzer = Fuzzer(conversation, fingerprint)
for fuzzed in fuzzer:
runner = Runner(fuzzed)
try:
res = runner.run()
except:
print(traceback.format_exc())
res = False
if res:
good+=1
else:
bad+=1
print("Test end")
print("successful: {0}".format(good))
print("failed: {0}".format(bad))
if bad > 0:
sys.exit(1)
示例2: main
def main():
if len(sys.argv) < 3:
print(usage())
return -1
conversations = {}
# 16 chars: POLY1305 tag 128 bit
# Tampering one bit suffices to damage the mac
# The payload has to be long enough to trigger heap overflow
n = 15000
fuzzes = [(-1, 1)]
for pos, val in fuzzes:
conversation = Connect(sys.argv[1], int(sys.argv[2]))
node = conversation
ciphers = [CipherSuite.TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256]
node = node.add_child(ClientHelloGenerator(ciphers))
node = node.add_child(ExpectServerHello())
node = node.add_child(ExpectCertificate())
node = node.add_child(ExpectServerKeyExchange())
node = node.add_child(ExpectServerHelloDone())
node = node.add_child(ClientKeyExchangeGenerator())
node = node.add_child(ChangeCipherSpecGenerator())
node = node.add_child(FinishedGenerator())
node = node.add_child(ExpectChangeCipherSpec())
node = node.add_child(ExpectFinished())
node = node.add_child(fuzz_encrypted_message(
ApplicationDataGenerator(b"GET / HTTP/1.0\n" + n * b"A" + b"\n\n"), xors={pos:val}))
node = node.add_child(ExpectAlert(AlertLevel.fatal,
AlertDescription.bad_record_mac))
node = node.add_child(ExpectClose())
conversations["XOR position " + str(pos) + " with " + str(hex(val))] = \
conversation
# run the conversation
good = 0
bad = 0
for conversation_name in conversations:
conversation = conversations[conversation_name]
#print(conversation_name + "...")
runner = Runner(conversation)
res = True
try:
runner.run()
except:
print("Error while processing")
print(traceback.format_exc())
res = False
if res:
good+=1
print("OK")
else:
bad+=1
print("Test end")
print("successful: {0}".format(good))
print("failed: {0}".format(bad))
if bad > 0:
sys.exit(1)
示例3: main
def main():
"""Test if server supports the DHE_RSA key exchange"""
conversations = {}
conversation = Connect("localhost", 4433)
node = conversation
ciphers = [CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA]
node = node.add_child(ClientHelloGenerator(ciphers,
extensions={ExtensionType.
renegotiation_info:None}))
node = node.add_child(ExpectServerHello(extensions={ExtensionType.
renegotiation_info:None}))
node = node.add_child(ExpectCertificate())
node = node.add_child(ExpectServerKeyExchange())
node = node.add_child(ExpectServerHelloDone())
node = node.add_child(ClientKeyExchangeGenerator())
node = node.add_child(ChangeCipherSpecGenerator())
node = node.add_child(FinishedGenerator())
node = node.add_child(ExpectChangeCipherSpec())
node = node.add_child(ExpectFinished())
node = node.add_child(ApplicationDataGenerator(
bytearray(b"GET / HTTP/1.0\n\n")))
node = node.add_child(ExpectApplicationData())
node = node.add_child(AlertGenerator(AlertLevel.warning,
AlertDescription.close_notify))
node = node.add_child(ExpectAlert())
node.next_sibling = ExpectClose()
conversations["sanity check DHE_RSA_AES_128"] = conversation
good = 0
bad = 0
for conversation_name, conversation in conversations.items():
print("{0} ...".format(conversation_name))
runner = Runner(conversation)
res = True
try:
runner.run()
except:
print("Error while processing")
print(traceback.format_exc())
print("")
res = False
if res:
good+=1
print("OK\n")
else:
bad+=1
print("Test end")
print("successful: {0}".format(good))
print("failed: {0}".format(bad))
if bad > 0:
sys.exit(1)
示例4: test_run_with_expect_and_closed_socket
def test_run_with_expect_and_closed_socket(self):
node = ExpectClose()
runner = Runner(node)
runner.state.msg_sock = mock.MagicMock()
runner.state.msg_sock.recvMessageBlocking = \
mock.MagicMock(side_effect=TLSAbruptCloseError())
runner.run()
示例5: main
def main():
#
# Test if server aborts connection upon receiving applicaiton data
# before Finished
#
conversations = {}
conversation = Connect("localhost", 4433)
node = conversation
ciphers = [CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA]
node = node.add_child(ClientHelloGenerator(ciphers, extensions=None))
node = node.add_child(ExpectServerHello())
node = node.add_child(Close())
conversations["no extensions"] = conversation
conversation = Connect("localhost", 4433)
node = conversation
ciphers = [CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA]
node = node.add_child(ClientHelloGenerator(ciphers, extensions={}))
node = node.add_child(ExpectServerHello())
node = node.add_child(Close())
conversations["empty extensions"] = conversation
# run the conversation
good = 0
bad = 0
for conversation_name in conversations:
conversation = conversations[conversation_name]
runner = Runner(conversation)
print(str(conversation_name) + "...\n")
res = True
try:
runner.run()
except:
print("Error while processing")
print(traceback.format_exc())
res = False
if res:
good += 1
else:
bad += 1
print("Test end")
print("successful: {0}".format(good))
print("failed: {0}".format(bad))
if bad > 0:
sys.exit(1)
示例6: test_run_with_generate_and_expected_closed_socket
def test_run_with_generate_and_expected_closed_socket(self):
node = ClientHelloGenerator()
node.next_sibling = ExpectClose()
runner = Runner(node)
runner.state.msg_sock = mock.MagicMock()
runner.state.msg_sock.sendMessageBlocking = \
mock.MagicMock(side_effect=socket.error)
# does NOT raise exception
runner.run()
示例7: test_run_with_unknown_type
def test_run_with_unknown_type(self):
node = mock.MagicMock()
node.is_command = mock.Mock(return_value=False)
node.is_expect = mock.Mock(return_value=False)
node.is_generator = mock.Mock(return_value=False)
node.child = None
runner = Runner(node)
with self.assertRaises(AssertionError):
runner.run()
示例8: test_run_with_command_node
def test_run_with_command_node(self):
node = mock.MagicMock()
node.is_command = mock.Mock(return_value=True)
node.is_expect = mock.Mock(return_value=False)
node.is_generator = mock.Mock(return_value=False)
node.child = None
runner = Runner(node)
runner.run()
node.process.assert_called_once_with(runner.state)
示例9: test_run_with_generate_and_unexpected_closed_socket
def test_run_with_generate_and_unexpected_closed_socket(self):
node = mock.MagicMock()
node.is_command = mock.Mock(return_value=False)
node.is_expect = mock.Mock(return_value=False)
node.is_generator = mock.Mock(return_value=True)
node.child = None
runner = Runner(node)
runner.state.msg_sock = mock.MagicMock()
runner.state.msg_sock.sendMessageBlocking = \
mock.MagicMock(side_effect=socket.error)
with self.assertRaises(AssertionError):
runner.run()
示例10: main
def main():
#
# Test if client hello with invalid session ID gets rejected
#
conversations = {}
conversation = Connect("localhost", 4433)
node = conversation
ciphers = [CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA]
node = node.add_child(ClientHelloGenerator(ciphers,
session_id=bytearray(b'\x03'*33)))
node = node.add_child(ExpectAlert())
node.next_sibling = ExpectClose()
conversations['33 byte long session id'] = conversation
# run the conversation
good = 0
bad = 0
for conversation_name in conversations:
conversation = conversations[conversation_name]
print(str(conversation_name) + "...\n")
runner = Runner(conversation)
res = True
try:
runner.run()
except:
print("Error while processing")
print(traceback.format_exc())
res = False
if res:
good+=1
print("OK")
else:
bad+=1
print("Test end")
print("successful: {0}".format(good))
print("failed: {0}".format(bad))
if bad > 0:
sys.exit(1)
示例11: test_run_with_generator_node
def test_run_with_generator_node(self):
node = mock.MagicMock()
node.is_command = mock.Mock(return_value=False)
node.is_expect = mock.Mock(return_value=False)
node.is_generator = mock.Mock(return_value=True)
node.child = None
runner = Runner(node)
runner.state.msg_sock = mock.MagicMock()
runner.run()
node.generate.assert_called_once_with(runner.state)
self.assertTrue(runner.state.msg_sock.sendMessageBlocking.called)
node.post_send.assert_called_once_with(runner.state)
示例12: main
def main():
conversation = Connect("localhost", 4433)
node = conversation
ciphers = [CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA,
CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
node = node.add_child(ClientHelloGenerator(ciphers))
node = node.add_child(ExpectServerHello())
node = node.add_child(ExpectCertificate())
node = node.add_child(ExpectServerHelloDone())
node = node.add_child(ClientKeyExchangeGenerator())
node = node.add_child(ChangeCipherSpecGenerator())
node = node.add_child(FinishedGenerator())
node = node.add_child(ExpectChangeCipherSpec())
node = node.add_child(ExpectFinished())
node = node.add_child(ApplicationDataGenerator(bytearray(b"hello server!\n")))
#node = node.add_child(ExpectApplicationData(bytearray(b"hello client!\n")))
node = node.add_child(AlertGenerator(AlertLevel.warning,
AlertDescription.close_notify))
node = node.add_child(ExpectAlert())
node.next_sibling = ExpectClose()
# run the conversation
good = 0
bad = 0
runner = Runner(conversation)
res = True
try:
runner.run()
except:
print("Error while processing")
print(traceback.format_exc())
res = False
if res:
good+=1
else:
bad+=1
print("Test end")
print("successful: {0}".format(good))
print("failed: {0}".format(bad))
if bad > 0:
sys.exit(1)
示例13: main
def main():
#
# Test if server aborts connection upon receiving a hello request
#
conversations = {}
conversation = Connect("localhost", 4433)
node = conversation
# type - 0, and 3 bytes of length (0)
node = node.add_child(RawMessageGenerator(22, bytearray(b'\x00\x00\x00\x00')))
node = node.add_child(ExpectAlert())
node.next_sibling = ExpectClose()
node = node.add_child(ExpectClose())
conversations["hello request to server"] = conversation
# run the conversation
good = 0
bad = 0
for conversation_name in conversations:
conversation = conversations[conversation_name]
runner = Runner(conversation)
print(str(conversation_name) + "...\n")
res = True
try:
runner.run()
except:
print("Error while processing")
print(traceback.format_exc())
res = False
if res:
good+=1
else:
bad+=1
print("Test end")
print("successful: {0}".format(good))
print("failed: {0}".format(bad))
if bad > 0:
sys.exit(1)
示例14: test_run_with_expect_node_and_unexpected_message
def test_run_with_expect_node_and_unexpected_message(self):
node = mock.MagicMock()
node.is_command = mock.Mock(return_value=False)
node.is_expect = mock.Mock(return_value=True)
node.is_generator = mock.Mock(return_value=False)
node.get_all_siblings = mock.Mock(return_value=[node])
node.is_match = mock.Mock(return_value=False)
node.child = None
runner = Runner(node)
runner.state.msg_sock = mock.MagicMock()
msg = (mock.MagicMock(name="header"), mock.MagicMock(name="parsser"))
runner.state.msg_sock.recvMessageBlocking = \
mock.MagicMock(return_value=msg)
with self.assertRaises(AssertionError):
runner.run()
runner.state.msg_sock.sock.close.called_once_with()
示例15: test_run_with_expect_node
def test_run_with_expect_node(self):
node = mock.MagicMock()
node.is_command = mock.Mock(return_value=False)
node.is_expect = mock.Mock(return_value=True)
node.is_generator = mock.Mock(return_value=False)
node.get_all_siblings = mock.Mock(return_value=[node])
node.is_match = mock.Mock(return_value=True)
node.child = None
runner = Runner(node)
runner.state.msg_sock = mock.MagicMock()
msg = (mock.MagicMock(name="header"), mock.MagicMock(name="parser"))
runner.state.msg_sock.recvMessageBlocking = mock.Mock(return_value=msg)
runner.run()
internal_message = messages.Message(msg[0].type, msg[1].bytes)
node.is_match.called_once_with(internal_message)
node.process.called_once_with(runner.state, internal_message)