Advertisement
cookthebook

Obfuscated Python writeup

Mar 4th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. Obfuscated Python writeup:
  2. solved by AuPhishYellow member cookthebook for sCTF 2015
  3.  
  4. Obfuscated python is actually a simple crypto challenge, not a python exploit. If you connect to the server and send 'a', you will be given a number. Then if you send 'b', you will get the number that is one higher than 'a' was. You should also notice that if you send 'aa', the first number you get does not change. Thus, we can assume the following:
  5.  
  6. 1. Each byte is encrypted separately
  7. 2. The digits you get are hex encodings of ascii
  8.  
  9. Thus, all we have to do is calculate what "flag.txt" would be, since we want that file to be printed. The following script checks each letter one at a time. If I were to rewrite it, I would simply add a given value to the byte I was sending based upon what I got, but I used this script first to solve the challenge, and it works even if it is a bit slower:
  10.  
  11. ---------------------------------------------------------------------
  12. import socket, time
  13.  
  14. total = ''
  15.  
  16. for j in range(len("flag.txt")):
  17. print "flag.txt"[0:j+1]
  18. for i in range(256):
  19. send = hex(i).replace('0x','')
  20. if len(send) == 1:
  21. send = '0' + send
  22. sendme = total + send
  23.  
  24. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  25. s.connect(("python.sctf.io", 25566))
  26. s.recv(1024)
  27. s.send(sendme)
  28. data = s.recv(1024)
  29. print data
  30. if data[-j-2:-1] == "flag.txt"[0:j+1]:
  31. total += send
  32. print total
  33. break
  34. ---------------------------------------------------------------------
  35.  
  36. If you run this, it will slowly go through each value for "i", and eventually print the flag.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement