tcpClient a prihlasenie na server

C,C++,C#

Moderátori: psichac, Moderátori

skorec1
Okoloidúci
Okoloidúci
Príspevky: 6
Dátum registrácie: 10 Mar 2011, 00:00
Vek: 44
Kontaktovať používateľa:

tcpClient a prihlasenie na server

Príspevok od používateľa skorec1 » 27 Jún 2011, 23:39

ahoj, vedel by mi niekto poradit? mam aplikaciu s ktorou sa pripojim na server a neviem ako sa mam prihlasit na server a v spravnom "tvare" odosielat data

Princip prihlasenia na server je tu v PERL, ale to nemam ani sajnu
http://outflux.net/software/bf1942-console

Kód: Vybrať všetko

# Post-authentication Client/Server communication is done via blocks of
# data. Each data block starts with the number of strings contained in
# the block, then each string, null terminated, with a 4-byte size sent
# before the string. Each 4-byte "length" is sent in unsigned long
# little-endian order.
#
# Bytes Meaning
# 1 2 3 4 Number of strings in this block
# 5 6 7 8 Size of string #1
# 9 ... String #1, with trailing NULL
# ... Size of string #2
# ... String #2, with trailing NULL
#

# Initial authentication is done via simple XOR'ing. The server sends 10
# bytes, and the client XORs the authentication information against those
# 10 bytes (and re-uses them again for each of the 10 bytes it sends to
# the server).
#
# Server->Client: 10 bytes: XOR pattern to use
# Client->Server: 4 bytes: length of user name (including the trailing NULL)
# Client->Server: X bytes: user (index-XOR'd, with trailing NULL)
# for example, if the user name was 15 "0x10" values,
# and the XOR pattern was the byte values from
# 0x00-0x09, the resulting "encrypted" user name
# would be in hex:
# 10,11,12,13,14,15,16,17,18,19,10,11,12,13,14,0
# Client->Server: 4 bytes: length of password (including the trailing NULL)
# Client->Server: X bytes: password, XOR'd like the username, with final NULL
# Server->Client: 1 byte. (value of "1" means authenticated)
#
# To start console communication, the client seems to send something that
# almost matches the description of "Post-Authentication" communication,
# but the count of strings is wrong. Where "OFFSET" is the server instance
# to talk to (0 being first, 1 for the next server on the same IP, etc) it
# sends:
#
# 4 byte block length: 2
# NULL-terminated string: ConsoleRun OFFSET
# 4 byte block length: 2
# empty NULL-terminated string
# empty NULL-terminated string
#
# and then it reads back a regular block from the server, and then "normal"
# block-at-a-time communication starts up.
0

skorec1
Okoloidúci
Okoloidúci
Príspevky: 6
Dátum registrácie: 10 Mar 2011, 00:00
Vek: 44
Kontaktovať používateľa:

Príspevok od používateľa skorec1 » 01 Júl 2011, 11:00

http://msdn.microsoft.com/en-us/library ... erter.aspx
toto mi pomohlo to pochopit, aspon si myslim :-)

Pripojim sa na server a ten mi posle 10Bytes kluc

prihlasovacie meno pouzijem string "meno"
dlzka pri. mena 4 a premenim to na byte
04-00-00-00
premenim to na little-endian
00-00-00-04
pridam na konic nulty bytes
00-00-00-04-00
v takom to tvare odoslem na server

prihlasovacie meno premenim na byte
ale teraz neviem ako mam pouzit XOR na kazdy byte prih. mena s klucom ktory mi poslal server
nacitam byte kluc

Kód: Vybrať všetko

     
byte[] dataRead = new Byte[10];
Int32 bytes = stream.Read(dataRead, 0, dataRead.Length);
a chem pouzit XOR ale takto sa neda pouzit na kazdy byte

Kód: Vybrať všetko

// prihlasovacie meno na byte
data1 = System.Text.Encoding.ASCII.GetBytes(txtMsg.Text);
for (int i = 0; i < data1.Length; i++)
        {
          data1[i] ^= dataRead;
        }
0

skorec1
Okoloidúci
Okoloidúci
Príspevky: 6
Dátum registrácie: 10 Mar 2011, 00:00
Vek: 44
Kontaktovať používateľa:

Príspevok od používateľa skorec1 » 05 Júl 2011, 01:07

diky za pomoc, skusam vsetko mozne ale neviem kde robim chybu, data odoslem ale nepride ziadna odpoved, asi XOR nemam spravne spraveny...

takze este raz co mam

Prihlasim sa na server a server posle 10Bytes key

Server->Client : 8F-7F-94-56-51-EF-59-55-51-3A - 10Bytes KEY

Login name ="meno" lenght + 1(null) ="5"

Bytes : 05-00-00-00-00

a odoslem velkost mena na server

Login name bytes : 6D-65-6E-6F
Login name bytes XOR + add NULL byte: 86-8E-85-84-00
a odoslem XOR meno na server

Login name ="heslo" lenght + 1(null) ="6"

Bytes : 06-00-00-00-00

a odoslem velkost hesla na server

Login pass bytes : 68-65-73-6C-6F

Login pass bytes XOR + add NULL byte : 83-8E-98-87-84-00

a odoslem XOR heslo na server


a server nevrati nic...

Moj pouzity XOR, to znamena ze kazdy jeden Byte prihlasovacieho mena a hesla XORujem s kazdy jednym Byte kluca


for (int i = 0; i < loginNameBytes.Length; i++)
{
for (int j = 0; j < serverKey.Length; j++)
{
loginNameBytes ^= serverKey[j];
}
}
0

Napísať odpoveď
  • Podobné témy
    Odpovedí
    Zobrazení
    Posledný príspevok