Advertisement
foryou97

NeverEnCode

Nov 27th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. from pwn import *
  2.  
  3. ## The in order list of chars being used for the encryption cipher
  4. algorithmns_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !\"#$%&'()*+,-./0123456789:;<=>?@"
  5.  
  6.  
  7. ## Pass in the offset (shift) the program is using this run through and the encrypted text
  8. ## decrypt it
  9. def decrypt(encrypted, index):
  10.     global algorithmns_list
  11.     solved = ''
  12.     for c in encrypted:
  13.         plain_char_posn = (algorithmns_list.index(c) - offset) % len(algorithmns_list)
  14.         solved += algorithmns_list[plain_char_posn]
  15.  
  16.     return solved
  17.  
  18.  
  19. ## Find the offset (shift) being used for this run through
  20. def find_offset(result):
  21.     global algorithmns_list
  22.     index = algorithmns_list.index(result)
  23.     return index
  24.  
  25.  
  26. ## connect and receive banner
  27. conn = remote('neverending.tuctf.com', 12345)
  28.  
  29.  
  30.  
  31. ## solve over and over until we reach 50 solves
  32. count = 1
  33. while True:
  34.  
  35.     banner = conn.recvuntil('text:')
  36.  
  37.     ## send an A and receive what A encrypts to
  38.     conn.send('A\r\n')
  39.     result = conn.recvline()
  40.     #strip away everything but the encrypted result
  41.     result = result[-3]
  42.  
  43.     ##find the offset for this current attempt
  44.     offset = find_offset(result)
  45.  
  46.     ## receive the encrypted text to solve
  47.     solve = conn.recvline()
  48.     conn.recvuntil(':')
  49.  
  50.     ## cut out the superfluous crap  received along with the solve string
  51.     solve = solve[8:-12]
  52.  
  53.     ## attempt to decrypt the string
  54.     solution = decrypt(solve, offset)
  55.  
  56.  
  57.     ## send solution and check if its right
  58.     print 'Sending solution: %s' %(solution)
  59.     conn.sendline(solution)
  60.    
  61.  
  62.     ## Once we reach 50 solves, print stop and receive all text back from the server to get the flag
  63.     if count == 50:
  64.         result = conn.recvall()
  65.         print result
  66.         break
  67.  
  68.     else:
  69.         conn.recvline()
  70.  
  71.     count += 1     
  72.  
  73. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement