-1

can someone please help me understand this code

clientsock.send("Welcome to Maths_Server 1.0\n")

try:
    clientsock.send("Enter the first number, so I can EVALuate it:\n")
    firstNum = eval(clientsock.recv(1024))
    firstNum = firstNum + firstNum + ord(flag[4]) + ord(flag[8]) + ord(flag[5])
    clientsock.send("Enter the second number, so I can EVALuate it:\n")
    secondNum = eval(clientsock.recv(1024))
    if secondNum == firstNum:
        clientsock.send("The flag is: " + flag + "\n")
        firstNum = 0
        secondNum = 0
except:
    pass

clientsock.close()

i want to know what does recv() does and how can i make the if statement true

AdoobII
  • 249
  • 3
  • 11
  • this code is full of errors and security flaws. DON'T USE IT. – Daniel Feb 11 '16 at 17:26
  • i am not using it, actually my mission is to know how to crack it (homework) but i don't understand what does recv do – AdoobII Feb 11 '16 at 17:37
  • `clientsock` is obviously a socket object. So https://docs.python.org/2/library/socket.html#socket.socket.recv. Note, Googling `python recv` leads you to this exact page. – kindall Feb 11 '16 at 17:47
  • ok how can i know make the if statement true without knowing the value of firstnum – AdoobII Feb 11 '16 at 17:53
  • You don't have to crack anything, simple do `server.sendall('clientsock.sendall("Flag: %s" % flag)')` and read the result. – Daniel Feb 11 '16 at 18:00
  • i can't change the code, it's a webserver and i am accessing it from netcat – AdoobII Feb 11 '16 at 18:02
  • they have provided me with a piece of the source code of the webserver – AdoobII Feb 11 '16 at 18:03

2 Answers2

0

Well, you can't determine the firstNum value because it's inputted by the user, so you input a random number into the firstNum, then for the secondNum you enter firstNum, so what this does is the eval() takes the firstNum value and convert it into string for the secondNum which will make the if-statement true. Hope this works out.

adib
  • 28
  • 6
-2

The answer to this riddle is this is actually the server code, but you need to make a client which will connect to that server, and produce equal results to get the flag.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Guy
  • 1