socketserver交互

class Task(socketserver.BaseRequestHandler):
def __init__(self, *args, **kargs):
super().__init__(*args, **kargs)
#super用来调用父类的构造函数,并将相应的参数传递给父类

工作认证

def proof_of_work(self):
random.seed(urandom(9))
proof = ''.join([random.choice(string.ascii_letters + string.digits) for _ in range(16)])
digest = sha256(proof.encode()).hexdigest()
self.dosend('sha256(XXXX + {}) == {}'.format(proof[4:], digest) + "\n" + '@ XXXX=')
x = self.request.recv(10)
x = (x.strip()).decode('utf-8')
if len(x) != 4 or sha256((x + proof[4:]).encode()).hexdigest() != digest:
return False
return True
exp
def desha(end,hash):
form=string.ascii_letters+string.digits
for a in form:
for b in form:
for c in form:
for d in form:
str=a+b+c+d+end
if sha256(str.encode()).hexdigest()==hash:
print(a+b+c+d)
return a+b+c+d

pwn交互

from pwn import *

#调试
context.log_level='debug'

r=remote('ip',port)
#接收直至...
r.recvuntil(b' ',drop=True)
#接收一行
r.recvline(keepends=false)#是否保留结尾\n
#接收结果并赋值
n=int(r.recvline()[:-1])

payload=''

#发送数据
r.send(payload)
#发送一行,结尾加\n
r.sendline(payload)