Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import socket
- import string
- import random
- import hashlib
- import time
- import sys
- 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(identifier, session):
- table = [83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
- 99, 100, 101, 102, 103, 104, 105, 106, 107, 108,
- 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
- 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
- 147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
- 163, 164, 165, 166, 167, 168, 169, 170, 171, 172,
- 179, 180, 181, 182, 183, 184, 185, 186, 187, 188,
- 195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
- 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
- 227, 228, 229, 230, 231, 232, 233, 234, 235, 236 ]
- str_enc = chr(154) # 0x9A
- temp = str(identifier[0])+str(identifier[1])
- str_enc += str(chr(table[int(temp)])); # example --> 0xA6
- temp = str(identifier[2])+str(identifier[3])
- str_enc += str(chr(table[int(temp)]));# example --> 0x84
- switcher = {
- 0 :chr(80),
- 1 :chr(96),
- 2 :chr(112),
- 3 :chr(128),
- 4 :chr(144),
- 5 :chr(160),
- 6 :chr(176),
- 7 :chr(192),
- 8 :chr(208),
- 9 :chr(224)
- }
- str_enc+=str(switcher.get(int(identifier[4]), ""))
- temp = str(session[0])+str(session[1])
- str_enc += str(chr(table[int(temp)])); # example --> 0x64
- temp = str(session[2])+str(session[3])
- str_enc += str(chr(table[int(temp)]));# example --> 0x86
- switcher = {
- 0 :chr(79),
- 1 :chr(95),
- 2 :chr(111),
- 3 :chr(127),
- 4 :chr(143),
- 5 :chr(159),
- 6 :chr(175),
- 7 :chr(191),
- 8 :chr(207),
- 9 :chr(223)
- }
- str_enc+=str(switcher.get(int(session[4]), ""))
- str_enc+=str(chr(14))
- res = bytearray(str_enc)
- return res
- 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
- def send(nb,s,session,user,passwd):
- packet = oldencrypt(str(session),int(session),True)
- s.send(packet)
- ''' packet = oldencrypt(user,int(session),False)
- s.send(packet)
- packet =oldencrypt(passwd,int(session),False)
- s.send(packet)'''
- time.sleep(0.1)
- def oldencrypt(buf, session, is_session_packet):
- packet_length = len(buf)
- packet_mask = "11111" #transform(buf)
- print(packet_mask)
- 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 = int(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:
- print( "before: " + str(current_byte))
- current_byte-= 0x2C
- print("after: " + str(current_byte))
- if(current_byte != 0x00):
- if(i % 2 == 0):
- output.append(current_byte << 4)
- #print("Modulo" + str(current_byte << 4))
- else:
- output[len(output)-1] = output[len(output)-1] | current_byte
- #output.back() |= current_byte;
- last_position +=1
- output.append(0xff)
- print("Before :" + str(list(output)))
- completeGamePacketEncrypt(output,session,is_session_packet)
- output = [x % 256 for x in output]
- print("After :" + str(list(output)))
- return bytearray(output)
- 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))
- b = encryptLoginPacket(fpacket)
- #print(list(b))
- s.send(encryptLoginPacket(fpacket))
- data = s.recv(BUFFER_SIZE)
- s.close()
- login = decryptLoginPacket(data)
- #print("\nReceived Data: %s" % login)
- server3info =login.split(' ')[6] #failc4 = deja loggé
- debug = int(sys.argv[1])
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- if debug == 0:
- ip3=server3info.split(':')[0]
- session = login.split(' ')[2]
- port3=server3info.split(':')[1]
- print("IP: " + ip3 +"\n" + "PORT : " + port3 + "\nSession ID: " + str(session))
- s.connect((ip3, int(port3)))
- send(1,s,session,USERNAME,PASSWORD)
- print(s.recv(1024))
- s.close()
- elif debug == 1:
- ip3="192.168.1.27"
- port3=4033
- session = 33247
- print("IP: " + ip3 +"\n" + "PORT : " + str(port3) + "\nSession ID: " + str(session))
- s.connect((ip3, int(port3)))
- send(1,s,session,USERNAME,PASSWORD)
- print(s.recv(1024))
- s.close()
- """
- print("IP: " + ip3 +"\n" + "PORT : " + str(port3) + "\nSession ID: " + str(session))
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((ip3, int(port3)))
- send(1,s,session,USERNAME,PASSWORD)
- print ("TEST : " + s.recv(1024))"""
- #data = s.recv() AFTER...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement