Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. import subprocess
  2. from telnetlib import *
  3. from base64 import *
  4.  
  5. host,port = 'meepwn.team', 54321
  6.  
  7. r = Telnet(host,port)
  8. def reg(uname,passwd):
  9. #r = Telnet(host,port)
  10. a = r.read_until('>>> ')
  11. #print a
  12. r.write('1\n')
  13. a = r.read_until('Username: ')
  14. #print a
  15. r.write(uname+'\n')
  16. a = r.read_until('Password: ')
  17. #print a
  18. r.write(passwd+'\n')
  19. a = r.read_until('login: ')
  20. cipher = r.read_until('\n').strip()
  21. return cipher
  22.  
  23. def login(cre):
  24. #r = Telnet(host,port)
  25. a = r.read_until('>>> ')
  26. #print a
  27. r.write('2\n')
  28. a = r.read_until('Enter your creds: ')
  29. #print a
  30. r.write(cre+'\n')
  31. r.interact()
  32.  
  33. def parse(cipher):
  34. cipher = b64decode(cipher)
  35. sign = cipher[-40:]
  36. data = cipher[:-46]
  37. return sign,data
  38.  
  39.  
  40. def hash_length_ex(data,len_secret,append,sign,_format):
  41. res_sign = ''
  42. res_string = ''
  43. command = './hash_extender/hash_extender -d "' + data + '" -l ' + str(len_secret) + ' -a "' + append + '" -s "' + sign + '" -f "' + _format + '"'
  44.  
  45. p = subprocess.Popen(command, shell = True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  46.  
  47. for line in p.stdout.readlines():
  48. if line.startswith('New signature:'):
  49. res_sign = line.split(' ')[2].strip()
  50.  
  51. if line.startswith('New string:'):
  52. res_string = line.split(' ')[2].strip()
  53.  
  54. retval = p.wait()
  55.  
  56. return res_sign,res_string
  57.  
  58. # run every part to find full flag
  59.  
  60.  
  61. # part1
  62. cipher = reg('admin','abc')
  63. print 'Cres: ' + cipher
  64. sign,data = parse(cipher)
  65. new_sign,new_string = hash_length_ex(data,16,'&ROLE=1',sign,'sha1')
  66. new_cre = b64encode(new_string.decode('hex') + '&sign=' + new_sign)
  67. print 'New cres: ' + new_cre
  68. login(new_cre)
  69.  
  70. '''
  71. # part2
  72. key1 = '01FE01FE01FE01FE'.decode('hex')
  73. key2 = 'FE01FE01FE01FE01' # input key2 when interact with server
  74.  
  75. cipher = reg('iamgroot',key1)
  76. print 'Cres: ' + cipher
  77. sign,data = parse(cipher)
  78. new_sign,new_string = hash_length_ex(data,16,'&ROLE=2',sign,'sha1')
  79. new_cre = b64encode(new_string.decode('hex') + '&sign=' + new_sign)
  80. print 'New cres: ' + new_cre
  81. login(new_cre)
  82. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement