美文网首页
CTF EIS2018 checkin

CTF EIS2018 checkin

作者: 云zeeo | 来源:发表于2018-11-16 19:53 被阅读0次

    python识别脚本

    通过socket连接启动nc服务器

    
    import json
    
    import os,socket,subprocess
    
    import time
    
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
    s.connect(('210.32.4.14',13373))
    
    temp=s.recv(100)
    
    print(temp)
    
    last=''
    
    def get():
    
        obj=s.recv(4520)
    
        if len(str(obj,encoding="ASCII"))<100:
    
            obj=s.recv(4520)
    
        return str(obj,encoding="ASCII").split('\n')
    
    def commit(resu):
    
        s.sendall(bytes(resu+'\n',encoding="utf-8"))
    
        #print(s.recv(100))
    
    keys={'a':[],'b':[],'c':[],'d':[],'e':[],'f':[],'g':[],'h':[],'i':[],'j':[],'k':[],'l':[],'m':[],'n':[],'o':[],'p':[],'q':[],'r':[],'s':[],'t':[],'u':[],'v':[],'w':[],'x':[],'y':[],'z':[],'0':[],'1':[],'2':[],'3':[],'4':[],'5':[],'6':[],'7':[],'8':[],'9':[]}
    
    def cut(pig):
    
        lenth=len(pig[0])
    
        num=lenth//18
    
        result=[]
    
        for i in range(num):
    
            temp = [([]) for i in range(10)]
    
            for ii in range(10):
    
                temp[ii]=pig[ii][i*18:i*18+18]
    
            result.append(temp)
    
        return result
    
    def learn(item):
    
        global keys
    
        f=open('lea.txt','a+',encoding='utf-8')
    
        for i in range(10):
    
            print(item[i])
    
        iii=input('当前?:')
    
        if keys[iii]==[]:
    
            keys[iii]=item
    
            f.write(iii+json.dumps(item)+'\n')
    
        else:
    
            print("存在:")
    
            for i in range(10):
    
                print(item[i])
    
        f.close()
    
    
    
    def read():
    
        global keys
    
        f=open('lea.txt','r',encoding='utf-8')
    
        while True:
    
            line=f.readline()
    
            if line=='':
    
                break
    
            if keys[line[0]]==[]:
    
                keys[line[0]]=json.loads(line[1:-1])
    
        f.close()
    
    def ana(res):
    
        result=''
    
        all_none=True
    
        global keys
    
        for item in res:
    
            all_none=True
    
            for i in keys:
    
                if keys[i]==item:
    
                    all_none=False
    
                    result+=i
    
                    break
    
            if all_none==True:
    
                learn(item)
    
                for i in keys:
    
                    if keys[i]==item:
    
                        all_none=False
    
                        result+=i
    
                        break
    
                if all_none==True:
    
                    input("error")
    
        return result
    
    #f=open('a.txt','r',encoding='utf-8')
    
    #pig = []
    
    read()
    
    while True:
    
        pig=get()
    
        print("--------------------------------------------")
    
        for i in pig:
    
            print(i)
    
        print("--------------------------------------------")
    
        if str(pig).find('bad')!=-1:
    
            input("error")
    
        if len(pig)>11:
    
            pig.remove('')
    
        #print(pig)
    
        last=pig
    
        c=cut(pig)
    
        aa=ana(c)
    
        if aa=='':
    
            aa=input()
    
        print("result="+aa)
    
        #time.sleep(0)
    
        commit(aa)
    
    #learn(c)
    

    相关文章

      网友评论

          本文标题:CTF EIS2018 checkin

          本文链接:https://www.haomeiwen.com/subject/vskvfqtx.html