# -*- coding:UTF-8 -*-fromweb3importWeb3,HTTPProviderimportosimporttimeimportbinasciiimportbase64importsmtplibfromemail.mime.textimportMIMETextfromemail.headerimportHeadercontract_address="0xF8dCbDcbc61752E95d9AB23b38fB79674c9A8FB6"# 你的合约地址 Your contract addresscontract_topic0="0x90c04e3c5f60e054d780a4cf893b5797e089c3da43565f81a1146044d51e8a11"# 事件日志中的topic0,针对同一合约的所有事件日志的topic0都是相同的 topic0 in event log .Every events of one contract has same topic0 rpc="https://ropsten.infura.io/v3/da.....2d7"# 你注册的Infura中的ENDPOINT。 your infura ENDPOINT url flag="flag{a_smart_contract_test}"email={"host":"smtp.163.com","port":25,"user":"[email protected]",# 用来发送flag的邮箱 email used to send flag"code":"aaaaa"# 邮箱的客户端授权码 email verification code}# initialw3=Web3(Web3.HTTPProvider(rpc))sender=smtplib.SMTP(host=email["host"],port=email["port"])sender.ehlo()sender.starttls()sender.login(email["user"],email["code"])# email contentmessage=MIMEText("收下你的flag:"+flag,'plain','utf-8')message["From"]=email["user"]message["Subject"]=Header("ctf flag","utf-8")# 发送flag的函数 send flagdefsendflag(toEmail):message["To"]=toEmailsender.sendmail(email["user"],toEmail,message.as_string())# logos.system("echo "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+": Get flag -- "+toEmail+" >> /tmp/variant_of_cat.log")print("send success")# 监听合约事件的函数 listening to event logdefevent():# 从网络中的事件日志中抓取符合这一合约的日志信息 get event log from blockhain filtered by address and topic0flag_logs=w3.eth.getLogs({"address":contract_address,"topic0":contract_topic0})ifflag_logsisnot[]:forflag_loginflag_logs:data=flag_log["data"][2:]length=int(data[64*2:64*3].replace('00',''),16)data=data[64*3:][:length*2]b64email=binascii.unhexlify(data).decode('utf-8')try:#print(dict.get(b64email))ifdict.get(b64email)==None:# 防止重复发送 Prevent duplicate sendingprint(b64email)sendflag(b64email)dict[b64email]=1exceptExceptionase:errmsg=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+":decode or send to b64 - {} fail".format(b64email)os.system("echo "+errmsg+str(e)+">> /tmp/variant_of_cat_error.log")print(errmsg+str(e))# 循环运行 dict={}while(True):event()
说些什么吧!