Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import socket
- import string
- import random
- import hashlib
- def completeGamePacketEncrypt(buf,session,is_session_packet):
- session_number = (((session >> 6) & 0xFF) & 0x80000003)
- if(session_number < 0):
- session_number = (((session_number - 1) | 0xFFFFFFFC) + 1)
- session_key = (session & 0xFF)
- if(is_session_packet):
- session_number = -1
- if (session_number == 0):
- for i in range(len(buf)):
- buf[i] = (buf[i] + (session_key + 0x40))
- elif(session_number == 1):
- for i in range(len(buf)):
- buf[i] = (buf[i] - (session_key + 0x40))
- elif(session_number == 2):
- for i in range(len(buf)):
- buf[i] = (buf[i] ^ 0xC3) + (session_key + 0x40)
- elif(session_number == 3):
- for i in range(len(buf)):
- buf[i] = (buf[i] ^ 0xC3) - (session_key + 0x40)
- else:
- for i in range(len(buf)):
- buf[i] = buf[i] + 0x0F
- def transform(chaine):
- final = ""
- for i in range (len(chaine)):
- c = chaine[i]
- if (c == '#'):
- final += '0'
- else:
- n = ord(c)
- #!(n-= 0x20)
- if(not(n - 0x20) or (n + 0xF1) < 0 or (n - 0xB) < 0 or not(n - 0xC5)):
- final += '1'
- else:
- final += '0'
- return final
- def encryptworld(buf, session, is_session_packet):
- packet_length = len(buf)
- packet_mask = transform(buf)
- output = []
- sequences = 0
- sequence_counter = 0
- last_position = 0
- current_position = 0
- length = 0
- current_byte = 0
- while current_position <= packet_length:
- last_position = current_position
- while (current_position < packet_length) and (packet_mask[current_position] == '0'):
- current_position += 1
- if (current_position):
- length = (current_position - last_position)
- sequences = (length / 0x7E)
- for i in range (length):
- if (i == (sequence_counter * 0x7E)) :
- if not(sequences):
- output.append(length - i)
- else:
- output.append(0x7E)
- sequences-=1
- sequence_counter+=1
- output.append(ord(buf[last_position]) ^ 0xFF)
- last_position =+ 1
- if(current_position >= packet_length):
- break
- last_position = current_position
- while(current_position < packet_length) and (packet_mask[current_position] == '1'):
- current_position+=1
- if(current_position):
- length = (current_position - last_position)
- sequences = (length / 0x7E)
- for i in range(length):
- if(i == (sequence_counter * 0x7E)):
- if(not(sequences)):
- output.append((length - i) | 0x80)
- else:
- output.append(0x7E | 0x80)
- sequences-=1
- sequence_counter+=1
- current_byte = buf[last_position]
- if (current_byte == 0x20):
- current_byte=1
- elif (current_byte == 0x2D):
- current_byte = 2
- elif (current_byte== 0x2E):
- current_byte = 3
- elif (current_byte== 0xFF):
- current_byte = 0xE
- else:
- current_byte-= 0x2C
- if(current_byte != 0x00):
- if(i % 2 == 0):
- output.append(current_byte << 4)
- print(current_byte)
- else:
- output[len(output)-1] = output[len(output)-1] | current_byte
- #output.back() |= current_byte;
- last_position +=1
- output.append(0xff)
- print( "Before :complete -> " + str(output))
- completeGamePacketEncrypt(output,session,is_session_packet)
- print("After : complete -> " + str(output))
- output = [x % 256 for x in output]
- return bytearray(output)
- def decryptLoginPacket(buf):
- tmp = ""
- for i in range(len(buf)):
- tmp += chr(ord(buf[i]) - 0xF)
- return tmp[:-1]
- def encryptLoginPacket(buf):
- return bytearray([((ord(x) ^ 0xC3) + 0xF) % 256 for x in buf + '\n'])
- def genLoginPacket(username, password, game_version, game_hash):
- res = 'NoS0575 '
- res += str(random.randrange(10000, 8888888))
- res += ' '
- res += username
- res += ' '
- res += hashlib.sha512(password.encode('utf-8')).hexdigest().upper()
- res += ' 000'
- res += '027AF'
- res += '\x0b'
- res += game_version
- res += ' 0 '
- res += hashlib.md5((game_hash+username).encode('utf-8')).hexdigest().upper()
- return res
- #NoS0575 665638 ssss 092BCBA17FDEE6FF9C3CE4262CD48BB3D9BFB042D8D14E2DC7B35A0EE3F92D0C040EA49A1820D6EA3F86EA159B8C2D3590ED7DF4FB4AC20BB0CE35BE6D80E1AB 009027AF0.9.3.3088 0 5E242D4D5C6EBFB9176C887078084537
- TCP_IP = 'login.nostale.gfsrv.net'
- TCP_PORT = 4002
- BUFFER_SIZE = 4096
- USERNAME = 'socket1'
- PASSWORD = 'socket'
- GAME_VERSION = '0.9.3.3088'
- GAME_HASH = 'CDB86A1430332375FB8B05B1A5C45755F807636A5832DDF13143AF01CCCB1695' # md5(NostaleClientX.exe)+(NostaleClient.exe) : http://onlinemd5.com/
- fpacket = genLoginPacket(USERNAME, PASSWORD, GAME_VERSION, GAME_HASH)
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((TCP_IP, TCP_PORT))
- s.send(encryptLoginPacket(fpacket))
- data = s.recv(BUFFER_SIZE)
- s.close()
- #print("\nReceived Data: %s" % data)
- login = decryptLoginPacket(data)
- server3info =login.split(' ')[6]
- ip3=server3info.split(':')[0]
- port3=server3info.split(':')[1]
- session = 54284 #int(login.split(' ')[2])
- print("IP: " + ip3 +"\n" + "PORT : " + port3 + "\nSession ID: " + str(session))
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((ip3, int(port3)))
- s.send(encryptworld(str(session),session,True))
- s.send(encryptworld(USERNAME,session,False))
- s.send(encryptworld(PASSWORD,session,False))
- print (s.recv(1024))
- #data = s.recv() AFTER...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement