Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. from socket import socket, AF_INET, SOCK_STREAM
  2. from sys import stderr, exit
  3. from threading import Thread
  4. from struct import pack, unpack, unpack_from, calcsize
  5. from reciver import *
  6. import random
  7.  
  8. # Settings
  9. host = "127.0.0.1"
  10. port = 25566
  11. debug = False
  12.  
  13. handshake = '\x0f\x00\x04\t127.0.0.1\xde\x02'.encode("utf-8")
  14. user = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
  15.  
  16. def getRandomChar():
  17. return str(user[random.randint(0, len(user)-1)])
  18.  
  19. def getRandomUsername():
  20. username = ''
  21. for x in range(0,9):
  22. username = username + getRandomChar()
  23. return username
  24.  
  25. sock = socket(AF_INET, SOCK_STREAM)
  26. try:
  27. sock.connect((host, port))
  28. except ConnectionRefusedError:
  29. print("Server is not online", file=stderr)
  30. exit(1)
  31.  
  32. def varint_pack(d):
  33. o = b''
  34. while True:
  35. b = d & 0x7F
  36. d >>= 7
  37. o += pack("B", b | (0x80 if d > 0 else 0))
  38. if d == 0:
  39. break
  40. return o
  41. def varint_unpack(s):
  42. d, l = 0, 0
  43. length = len(s)
  44. if length > 5:
  45. length = 5
  46. for i in range(length):
  47. l += 1
  48. b = s[i]
  49. d |= (b & 0x7F) << 7 * i
  50. if not b & 0x80:
  51. break
  52. return (d, s[l:])
  53.  
  54. def data_pack(data):
  55. return varint_pack(len(data)) + data
  56. def data_unpack(bytes):
  57. length, bytes = varint_unpack(bytes)
  58. return bytes[:length], bytes[length:]
  59.  
  60. def string_pack(string):
  61. return data_pack(string.encode())
  62. def string_unpack(bytes):
  63. string, rest = data_unpack(bytes)
  64. return string.decode(), rest
  65.  
  66. def struct_unpack(format, struct):
  67. data = unpack_from(format, struct)
  68. rest = struct[calcsize(format):]
  69. return data, rest
  70.  
  71. def send(id, packet):
  72. packid = varint_pack(int(id, 16))
  73. data = packet
  74. sock.sendall(data_pack(packid + data))
  75.  
  76.  
  77. def handshake(v, ip, port, next):
  78. version = varint_pack(v)
  79. host = string_pack(ip)
  80. port = pack('!H', port)
  81. next = varint_pack(next)
  82. return version + host + port + next
  83.  
  84. def login(nick):
  85. nick = string_pack(nick)
  86. return nick
  87.  
  88. send("0x00", handshake(47, "127.0.0.1", 25566, 2))
  89.  
  90.  
  91. send("0x00", login(getRandomUsername()))
  92. packet_listener.run(sock)
  93.  
  94.  
  95. reciver:
  96. import threading
  97. from leave import *
  98. class packet_listener(threading.Thread):
  99.  
  100. def __init__(self,connection):
  101. threading.Thread.__init__(self)
  102. self.packet_functions = {
  103. 0xff: xd()
  104. }
  105. self.connection=connection
  106. def run(self):
  107. packet_functions=self.packet_functions
  108. connection=self.connection
  109. while True:
  110. fileobj = connection.makefile()
  111. packet_id = ord(fileobj.read(1))
  112. if packet_id in packet_functions:
  113. print(packet_functions[packet_id](fileobj, connection))
  114.  
  115. leave:
  116. def xd():
  117. print("Kicked")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement