addition.py (843B)
1 # A CTF exploit by FIGBERT 2 # for UC Davis class ECS189M 3 # twinpeaks.cs.ucdavis.net:30001 4 # Category: Linux and miscellaneous 5 # Challenge: addition 6 # 04/01/2020 7 from pwn import * 8 9 # Connecting to the server 10 connection = remote("twinpeaks.cs.ucdavis.edu", 30001) 11 for i in range(0,50): 12 # Recieving the equation 13 equation = connection.recvline_contains("Question") 14 # Splitting the equation into the two numbers to add 15 numbers = [int(item.strip()) for item in ((equation.split(b":")[1]).strip()).split(b"+")] 16 num_one = numbers[0] 17 num_two = numbers[1] 18 # Adding the two numbers 19 num_sum = sum(numbers) 20 print("Equation %d: %d + %d = %d"%(i+1, num_one, num_two, num_sum)) 21 connection.recv() 22 # Sending the password 23 connection.sendline(bytes("%d"%num_sum, "utf-8")) 24 connection.recv() 25 connection.interactive()