got the flag

This commit is contained in:
Torma Kristóf 2020-05-01 20:56:02 +02:00
parent 49f38d0429
commit 914fd08d3b
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
3 changed files with 36 additions and 47 deletions

Binary file not shown.

View File

@ -15,24 +15,22 @@ rand_chars = ([chr(x) for x in range(ord('a'), ord('z'))] +
[chr(x) for x in range(ord('0'), ord('9'))] +
['+', '-', '/'])
char_map = {'0' : '0000',
'1' : '0001',
'2' : '0010',
'3' : '0011',
'4' : '0100',
'5' : '0101',
'6' : '0110',
'7' : '0111',
'8' : '1000',
'9' : '1001',
'a' : '1010',
'b' : '1011',
'c' : '1100',
'd' : '1101',
'e' : '1110',
'f' : '1111'}
char_map = {'0': '0000',
'1': '0001',
'2': '0010',
'3': '0011',
'4': '0100',
'5': '0101',
'6': '0110',
'7': '0111',
'8': '1000',
'9': '1001',
'a': '1010',
'b': '1011',
'c': '1100',
'd': '1101',
'e': '1110',
'f': '1111'}
rc_len = len(rand_chars)
@ -41,16 +39,18 @@ min_bits = 0
max_bits = 160
default_bits = 15
def is_valid(stamp : str) -> bool:
def is_valid(stamp: str) -> bool:
return validate(int(stamp.split(':')[1]), stamp)
def validate(nbits : int, stamp : str, encoding : str ='utf-8') -> bool:
def validate(nbits: int, stamp: str, encoding: str = 'utf-8') -> bool:
if nbits < min_bits or nbits > max_bits:
raise ValueError("Param 'nbits' must be in range [0, 160), but is {}".format(nbits))
i = 0
total = 0
N = int(nbits/8)
N = int(nbits / 8)
hashed = sha1(stamp.encode(encoding)).digest()
while i < N:
@ -63,19 +63,19 @@ def validate(nbits : int, stamp : str, encoding : str ='utf-8') -> bool:
return total == 0
def generate(nbits : int, resource : str, encoding : str ='utf-8') -> str:
def generate(nbits: int, resource: str, encoding: str = 'utf-8') -> str:
# ver:bits:date:resource:[ext]:rand:counter
ver = 1
bits = nbits
date_str = datetime.utcnow().strftime("%Y%m%d%H%M%S")
ext = ''
rand = ''.join(rand_chars[randint(0, rc_len-1)] for x in range(0, 10))
rand = ''.join(rand_chars[randint(0, rc_len - 1)] for x in range(0, 10))
counter = 0
result = None
while result is None:
#stamp = ":".join(str(elem) for elem in [ver, bits, date_str, resource, ext, rand, counter])
stamp = "{}{}".format(resource,counter)
stamp = "{}{}".format(resource, counter)
if validate(nbits, stamp, encoding=encoding):
result = stamp
@ -84,22 +84,3 @@ def generate(nbits : int, resource : str, encoding : str ='utf-8') -> str:
counter += 1
return result
if __name__ == "__main__":
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("NBITS", type=int, default=default_bits, help="Number of leading zeroes in a stamp", choices=range(max_bits+1))
parser.add_argument("RESOURCE", help="The resource string to use in the stamp. Ex: email address, ip address, etc")
parser.add_argument('-v', '--validate', action='store_true', help="Validate RESOURCE as a HashCash stamp")
args = parser.parse_args()
func = generate
if args.validate:
func = validate
print(func(args.NBITS, args.RESOURCE))

View File

@ -6,6 +6,7 @@ import socket
import hashlib
import requests
import sympy
import hashcash
"""
requirements:
sympy
@ -54,6 +55,11 @@ def sha1_magic(s, last_solution):
print(digest)
s.send(digest.encode())
print(s.recv(1024).decode())
newstring = hashcash.generate(16, 'Y8O353{}'.format(last_solution))
print(s.recv(1024).decode())
print(newstring)
s.send(newstring.encode())
print(s.recv(1024).decode())
def http_comm():
@ -69,7 +75,7 @@ def http_comm():
def https_comm():
sess = requests.Session()
url = "https://152.66.249.144/"
flag = sess.get(url, cert=("/tmp/clientcert.pem", "/tmp/clientkey.pem"), verify=False)
flag = sess.get(url, cert=("/tmp/clientcert.pem", "/tmp/clientkey.pem"), verify=False, headers={'User-Agent': 'CrySyS'})
print(flag.content)
@ -90,7 +96,7 @@ def numbre_crunch(s):
solution = sympy.sympify(problem_statement_for.split('.')[1].split('=')[0])
print(solution)
s.send(str(solution).encode())
last_solution=solution
last_solution = solution
return last_solution
@ -99,4 +105,6 @@ if __name__ == '__main__':
knock()
server_communicate()
http_comm()
#https_comm()
https_comm()
# FLAG: YouCanHandleNetworking-Y8O353-1d66de