#!/usr/bin/env python

import hlextend
import pwn
import re

#init the tool
sha = hlextend.new('sha1')
host = "bogged.wpictf.xyz"
port = 31337

#connect to remote host
s = pwn.remote(host, port)

result = s.recv()

#loop over the length of the secret
for i in range(1,200):
	print("Testing Secret Length: "+str(i))
	sha = hlextend.new('sha1')
	#get the extended command
	cmd = sha.extend(';withdraw cryptowojak123;deposit not_b0gdan0ff', 'withdraw cryptowojak123;deposit xXwaltonchaingangXx', i, 'e429ffbfe7cabd62bda3589576d8717aaf3f663f',raw=True)+'\n'
	s.send(cmd)	
	result = s.recv()
	#search for flag in the output
	flag = re.search(r'WPI[\S]*',result)
	#if flag is found, print it, and leave the loop
	if(flag):
		print(flag.group())
		break
	#get the new hash value with the length-extension attack tool
	cmd = sha.hexdigest()+'\n'
	s.send(cmd)
	result = s.recv().strip()
