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,7 +15,6 @@ rand_chars = ([chr(x) for x in range(ord('a'), ord('z'))] +
[chr(x) for x in range(ord('0'), ord('9'))] + [chr(x) for x in range(ord('0'), ord('9'))] +
['+', '-', '/']) ['+', '-', '/'])
char_map = {'0': '0000', char_map = {'0': '0000',
'1': '0001', '1': '0001',
'2': '0010', '2': '0010',
@ -33,7 +32,6 @@ char_map = {'0' : '0000',
'e': '1110', 'e': '1110',
'f': '1111'} 'f': '1111'}
rc_len = len(rand_chars) rc_len = len(rand_chars)
min_bits = 0 min_bits = 0
@ -41,9 +39,11 @@ min_bits = 0
max_bits = 160 max_bits = 160
default_bits = 15 default_bits = 15
def is_valid(stamp: str) -> bool: def is_valid(stamp: str) -> bool:
return validate(int(stamp.split(':')[1]), stamp) 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: if nbits < min_bits or nbits > max_bits:
raise ValueError("Param 'nbits' must be in range [0, 160), but is {}".format(nbits)) raise ValueError("Param 'nbits' must be in range [0, 160), but is {}".format(nbits))
@ -63,6 +63,7 @@ def validate(nbits : int, stamp : str, encoding : str ='utf-8') -> bool:
return total == 0 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:bits:date:resource:[ext]:rand:counter
ver = 1 ver = 1
@ -74,7 +75,6 @@ def generate(nbits : int, resource : str, encoding : str ='utf-8') -> str:
result = None result = None
while result is 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): if validate(nbits, stamp, encoding=encoding):
@ -84,22 +84,3 @@ def generate(nbits : int, resource : str, encoding : str ='utf-8') -> str:
counter += 1 counter += 1
return result 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 hashlib
import requests import requests
import sympy import sympy
import hashcash
""" """
requirements: requirements:
sympy sympy
@ -54,6 +55,11 @@ def sha1_magic(s, last_solution):
print(digest) print(digest)
s.send(digest.encode()) s.send(digest.encode())
print(s.recv(1024).decode()) 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(): def http_comm():
@ -69,7 +75,7 @@ def http_comm():
def https_comm(): def https_comm():
sess = requests.Session() sess = requests.Session()
url = "https://152.66.249.144/" 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) print(flag.content)
@ -99,4 +105,6 @@ if __name__ == '__main__':
knock() knock()
server_communicate() server_communicate()
http_comm() http_comm()
#https_comm() https_comm()
# FLAG: YouCanHandleNetworking-Y8O353-1d66de