¡Hola a todos!
Hace poco comenté que Kraken, un bitcoin exchange, ofrecía un Bug Bounty. En la búsqueda de fallos, me encontré que el API de Kraken tiene un medio de identificación bastante poco estándar.
Está descrito acá, pero les dejo un poco de código, en python y usando mitmproxy, que sirve para manejar eso de manera automática. Para hacer funcionar esto, ejecutar este script (potencialmente cambinado el puerto para evitar conflictos), y luego configurar ZAP o Burp para que utilizen el proxy como “parent proxy”.
También, importante instalar mitmproxy (pip install mitmproxy).
#!/usr/bin/env python """ This MITM proxy example grabs a request that comes through and analyzes the data, creates a valid HMAC-SHA512 signature and puts those into the headers, as required by kraken, the bitcoin exchange in it's API. Be sure to change the contents of key and secret. """ from libmproxy import controller, proxy import os import re import time import hashlib import hmac import base64 key = "" secret = "" class StickyMaster(controller.Master): def __init__(self, server): controller.Master.__init__(self, server) self.stickyhosts = {} def run(self): try: return controller.Master.run(self) except KeyboardInterrupt: self.shutdown() def handle_request(self, msg): # strip nonce new_content = re.sub("nonce=.*?&", "", msg.content) nonce = int(1000*time.time()) new_content += "&nonce=" + str(nonce) msg.content = new_content new_headers = self.headers_signature(msg.path, new_content, nonce) msg.headers["API-Key"] = [new_headers["API-Key"]] msg.headers["API-Sign"] = [new_headers["API-Sign"]] print msg.headers msg.reply() def headers_signature(self, request_path, postdata, nonce): headers = {} message = request_path + hashlib.sha256(str(nonce) + postdata).digest() signature = hmac.new(base64.b64decode(secret), message, hashlib.sha512) headers['API-Key'] = key headers['API-Sign'] = base64.b64encode(signature.digest()) return headers config = proxy.ProxyConfig( cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem") ) server = proxy.ProxyServer(config, 8080) m = StickyMaster(server) m.run()