Valhalla Legends Forums Archive | Battle.net Bot Development | Re: Help 0x51 SID_AUTH_CHECK

AuthorMessageTime
iNsaNe
I have searched other topics on 0x51 but I can't get my head around it. I have added MBNCSUtil and I have read https://davnit.net/bnet/vL/index.php?topic=15325.0, but I decided not to add anything because that topic was started in July of last year. This is what I have:
[code]    Public Sub SEND_SIDAUTHCHECK()

        'C -> S 0x51 (SID_AUTH_CHECK)

        AddChat(Color.Yellow, "-> Sending 0x51...")

        If strProduct = "Warcraft III RoC" Then

            '                                (DWORD)        Client Token
            '                                (DWORD) EXE Version
            '                                (DWORD) EXE Hash
            InsertDWORD(&H1)                '(DWORD) Number of keys in this packet
            InsertDWORD(&H0)                '(BOOLEAN)     Using Spawn (32-bit)
            '
            'For Each Key:
            InsertDWORD(Len(strCDKey))      '(DWORD) Key Length
            '                                (DWORD) CD key's product value
            '                                (DWORD) CD key's public value
            InsertDWORD(&H0)                '(DWORD) Unknown (0)
            '                                (DWORD[5])     Hashed Key Data
            '
            '                                (STRING)     Exe Information
            InsertNonNTString(strUsername)  '(STRING)     CD Key owner name

            SendPacket(&H51)

        End If

    End Sub[/code]

Btw, I have already attempted the code in that forum and it didn't work.
March 14, 2007, 12:56 AM
BreW
Well ofcourse it wouldn't work, you're missing half the information of the packet. You might want to add:
The client token.
The EXEVersion.
The Checksum.
Private & Public value of cdkey
CDkey hash.
EXEInfo

Maybe if you add those it might work :)
All those, minus the client token, requires MBNCSUtil to retrieve values for.
I'm unfamiliar with MBNCSUtil, but for the values in 0x51, it would be something like this (the code is all in vb6):

EDIT***** Oops, heh I didn't read your post too well and I didnt realize you were talking about the code in that link. Anymore, battle.net requires a valid value for the EXEInfo string. (which fapiko's bot doesn't give) among other things.

[code]
EXEVersion = getExeInfo(App.Path & File(0), EXEInfo) 'For the exeversion and exeinfo....

Also you can use this to get the checksum value which is passed by refrence..

If Not checkRevision(ChecksumFormula, App.Path & File(0), App.Path & File(1), App.Path & File(2), mpqNumber, Checksum) Then
            AddChat vbRed, "Missing " & Client & " hashes."
            Disconnect
        Exit Sub
End If

Same with the private value, public value, and keyhash:

    If kd_quick(CDKey, ClientToken, ServerToken, PublicValue, ProductValue, Keyhash, 20) = 0 Then
        AddChat vbRed, "Invalid hashed CDKey."
        Disconnect
        Exit Sub
    End If


Public Declare Function checkRevision_Raw Lib "bncsutil.dll" Alias "checkRevisionFlat" (ByVal ValueString
As String, ByVal File1 As String, ByVal File2 As String, ByVal file3 As String, ByVal mpqNumber As Long,
ByRef Checksum As Long) As Long
Public Declare Function getExeInfo_Raw Lib "bncsutil.dll" Alias "getExeInfo" (ByVal Filename As String,
ByVal exeInfoString As String, ByVal infoBufferSize As Long, Version As Long, ByVal Platform As Long) As
Long

Public Function getExeInfo(EXEFile As String, InfoString As String, Optional ByVal Platform As Long = 1) As Long
Dim Version As Long, InfoSize As Long, Result As Long
Dim i&
  InfoSize = 256
  InfoString = String$(256, vbNullChar)
  Result = getExeInfo_Raw(EXEFile, InfoString, InfoSize, Version, Platform)
  If Result = 0 Then
    getExeInfo = 0
    Exit Function
  End If
  While Result > InfoSize
    If InfoSize > 1024 Then
      getExeInfo = 0
      Exit Function
    End If
    InfoSize = InfoSize + 256
    InfoString = String$(InfoSize, vbNullChar)
    Result = getExeInfo_Raw(EXEFile, InfoString, InfoSize, Version, Platform)
  Wend
  getExeInfo = Version
  i = InStr(InfoString, vbNullChar)
  If i = 0 Then Exit Function
  InfoString = Left$(InfoString, i - 1)
End Function

Public Function checkRevision(ValueString As String, File1 As String, File2 As String, file3 As String,
mpqNumber As Long, Checksum As Long) As Boolean
  checkRevision = (checkRevision_Raw(ValueString, File1, File2, file3, mpqNumber, Checksum) > 0)
End Function
[/code]

[Edit: broke up some long lines.]
March 14, 2007, 1:17 AM
iNsaNe
edit: nvm, lemme go mess around a bit more.

For Warcraft III would the files be game.dll, storm.dll, and war3.exe?
March 14, 2007, 1:55 AM
bethra
Next time post all of your code.  It's really hard go by just the code you've given and make assumptions as to exactly what code from the link you've incorporated.
March 14, 2007, 1:59 AM
iNsaNe
Can someone explain to me what the HashCommand and ServerToken are?
March 14, 2007, 2:18 AM
bethra
In the case of that person's code, it's the value string which the server sends you in 0x50.

[quote]
Calculates the revision check for the specified files.

public static int DoCheckRevision(
  string valueString,
  string[] files,
  int mpqNumber
);

Parameters

valueString
    The value string for the check revision function specified by Battle.net's SID_AUTH_INFO message.
files
    The list of files for the given game client. This parameter must be exactly three files long.
mpqNumber
    The number of the MPQ file. To extract this number, see the ExtractMPQNumber method.

Return Value

The checksum value.
[/quote]

The server token is what the server sends you in 0x50 as well.

[quote]
Computes the 20-byte hash value of the CD key.

public byte[] GetHash(
  int clientToken,
  int serverToken
);

Parameters
clientToken
A randomly-generated token value that is determined by session at the client.
serverToken
A randomly-generated token value that is determined by session at the server.
Return Value
A 20-byte array containing the hash value of the specified key.
[/quote]

EDIT:  Found by using the MBNCSutil documentation @ http://www.jinxbot.net/mbncsutil/

Note, in Firefox the left navigation frame is kinda messed up.

EDIT2: Since BnetDocs is down you can always use http://www.valhallalegends.com/yoni/BNLSProtocolSpec.txt as a reference too.
March 14, 2007, 2:22 AM
iNsaNe
[code]0030                    ff 50 e6 00 02 00 00 00 e9 e6  .P........
0040  bb 68 1c 57 1a 00 00 20 58 7d 99 cb c6 01 76 65  .h.W... X}....ve
0050  72 2d 49 58 38 36 2d 31 2e 6d 70 71 00 43 3d 31  r-IX86-1.mpq.C=1
0060  33 33 33 36 35 30 35 32 35 20 42 3d 37 35 32 37  333650525 B=7527
0070  37 34 37 38 34 20 41 3d 36 36 34 31 38 35 33 39  74784 A=66418539
0080  31 20 34 20 41 3d 41 5e 53 20 42 3d 42 2b 43 20  1 4 A=A^S B=B+C
0090  43 3d 43 2b 41 20 41 3d 41 2d 42 00 86 18 96 a1  C=C+A A=A-B.....
00a0  d9 33 80 73 30 92 89 fe d8 34 2d 0d 3e f1 22 8a  .3.s0....4-.>.".
00b0  ef 91 2f 19 27 5b 78 e5 9f 0a cd b9 29 1a fd 84  ../.'[x.....)...
00c0  c9 f2 7b f0 81 3e 4a c3 c5 a9 1b 27 8d 8c 05 d4  ..{..>J....'....
00d0  c8 d0 2a 6b 2b d1 9f e9 7b b2 e5 fe 6c 62 5d 81  ..*k+...{...lb].
00e0  29 bb f1 a4 90 f6 62 41 40 71 1e 67 52 25 42 25  ).....bA@q.gR%B%
00f0  3e ec 3e 0e d2 7e 70 76 45 78 19 b7 19 61 d3 5a  >.>..~pvEx...a.Z
0100  ab c7 48 fb 37 65 96 36 7e 4f 37 9e c8 2c 0f 1b  ..H.7e.6~O7..,..
0110  9b d6 b4 c8 a3 00 8d 90 1b e0 89 8d              ............[/code]

if you can point out which is the Server Token and Value String i would appreciate it thought im guessing C=1333650525 B=752774784 A=664185391 4 A=A^S B=B+C C=C+A A=A-B is the value string?
March 14, 2007, 2:59 AM
Ersan
e9 e6 bb 68 is the server token in that example and yes that is the value string.

http://ersan.us/src/bnetdocs/content2148.html
March 14, 2007, 3:24 AM
iNsaNe
Confused... the value string is the entire data after the ix86ver filename? or just the numbers i posted above?
March 14, 2007, 3:48 AM
HdxBmx27
Just the string you posted is the 'ValueString'
Everything after the 0x00 is the server signature. http://www.javaop.com/~iago/documents/ServerSig.html
Once you start useing a good buffer class. It will be alot easier. Just remove EVERYTHING exactly as described on BnetDocs and you'll be good.
~Hdx
March 14, 2007, 3:54 AM
bethra
I'm assuming he's now using the buffer classes in MBNCSutil, at least he might as well.
March 14, 2007, 4:05 AM
iNsaNe
I'm still having troubles. This is my code so far:
[code]    Private Sub winSock_DataArrival(ByVal sender As System.Object, ByVal e As
AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles winSock.DataArrival

        Dim Data As String
        winSock.GetData(Data, vbString, e.bytesTotal)

        If InStr(Data, HexToStr("FF50")) Then

            AddChat(Color.SpringGreen, "<- Received: 0x50!")

            Get_SIDAUTHINFO = Data

            Get_SIDAUTHINFO_ValueString = Split(Get_SIDAUTHINFO, ".mpq" & Chr(0))(1)
            Get_SIDAUTHINFO_ValueString = Split(Get_SIDAUTHINFO_ValueString, Chr(0))(0)

            Get_SIDAUTHINFO_MPQ = Split(Get_SIDAUTHINFO, "ver")(1)
            Get_SIDAUTHINFO_MPQ = Split(Get_SIDAUTHINFO_MPQ, Chr(0))(0)
            Get_SIDAUTHINFO_MPQ = "ver" & Get_SIDAUTHINFO_MPQ

            PBuff.Get_SERVERTOKEN()
            PBuff.SEND_SIDAUTHCHECK()
            'Send SID_AUTH_CHECK
        End If

End Sub[/code]
And my PacketBuffer class:
[code]Public Sub Get_SERVERTOKEN()

        ServerToken = Left(Get_SIDAUTHINFO, 12)
        ServerToken = Right(ServerToken, 4)

    End Sub

Public Sub SEND_SIDAUTHCHECK()

        'C -> S 0x51 (SID_AUTH_CHECK)

        Dim ClientToken As UInteger
        Dim CheckRevision As Long

        Dim MPQNumber As Byte

        Dim KeyHash As String
        Dim HashLength() As Byte

        Dim EXEInfo As String
        Dim EXEVersion As Integer

        Dim Files(2) As String
        Dim CDKeyDecoded As MBNCSUtil.CdKey

        AddChat(Color.Yellow, "-> Sending 0x51...")
        ClientToken = Right(GetTickCount, 5)

        If strProduct = "Warcraft III RoC" Then

            Files(0) = "C:\Program Files\Warcraft III\war3.exe"
            Files(1) = "C:\Program Files\Warcraft III\game.dll"
            Files(2) = "C:\Program Files\Warcraft III\Storm.dll"

            CDKeyDecoded = MBNCSUtil.CdKey.CreateDecoder(strCDKey)

            HashLength = CDKeyDecoded.GetHash(ClientToken, CUInt(ServerToken))
            EXEVersion = MBNCSUtil.CheckRevision.GetExeInfo(Files(0), EXEInfo)

            MPQNumber = MBNCSUtil.CheckRevision.ExtractMPQNumber(Get_SIDAUTHINFO_MPQ)
            CheckRevision = MBNCSUtil.CheckRevision.DoCheckRevision(Get_SIDAUTHINFO_ValueString, Files, MPQNumber)
            KeyHash = CDKeyDecoded.GetHashCode

            InsertDWORD(ClientToken)
            InsertDWORD(EXEVersion)
            InsertDWORD(CheckRevision)
            InsertDWORD(&H1)
            InsertDWORD(&H0)

            InsertDWORD(Len(strCDKey))
            InsertDWORD(CDKeyDecoded.Product)
            InsertDWORD(CDKeyDecoded.Value1)
            InsertDWORD(&H0)

            InsertNonNTString(ASCII.GetString(HashLength))
            InsertNTString(EXEInfo)
            InsertNonNTString(strUsername)
            'This isnt nulled because the packet is automatically nulled at the end anyways

            SendPacket(&H51)

        End If

    End Sub
[/code]

Please don't get on my case about how bad my coding is. I am just trying to make a bot log in for the first time. My ServerToken is initially a string, but converted to a UInt. That's not the source of my problems but the packet isnt even being sent. Code stops at "CDKeyDecoded = MBNCSUtil.CdKey.CreateDecoder(strCDKey)". I am using MBNCSUtil 2.0

[Edit: broke up a long line.]
March 14, 2007, 11:09 PM
BreW
When you say "it stops" do you mean stops executing, or freezes up and crashes vb? that would be most likely because of a type mismatch in your arguments. other then that ionno what to tell you.
March 15, 2007, 1:26 AM
iNsaNe
Stops executing
March 15, 2007, 1:38 AM
rabbit
[quote author=brew link=topic=16487.msg166775#msg166775 date=1173921971]
When you say "it stops" do you mean stops executing, or freezes up and crashes vb? that would be most likely because of a type mismatch in your arguments. other then that ionno what to tell you.
[/quote]You need to stop trying to sound like you know what you're talking about, because you really have no idea what you're talking about.  Really.  Just stop.

Just from the way you explained it, I can say that you're trying to implement CreateDecoder() incorrectly.  I don't know the specifics of MBNCSUtil, so that's as much help as I can give.
March 15, 2007, 3:11 AM
iNsaNe
the parameters say:
[code]CreateDecoder(key As String) as MBNCSUtil.CdKey
key:
The CD key to initialize processing for.[/code]
and strCDKey is the string variable of my CD Key from the text box from my bot options.
March 15, 2007, 3:58 AM
MysT_DooM
not familar with MBNCUtil , but are you positive strcdkey is storing the cdkey
which you provided from ur textbox in ur options?  I reckon it shud error if blank
but im not familar with the dll ur using.  if not sure before doing the decoding of key do
[code]
if strcdkey = "" then
Msgbox "ur key is nothing"
else
msgbox "ur key is " & strcdkey
end if
[/code]

March 15, 2007, 3:23 PM
iNsaNe
Yes, ive already used msgbox to show my cdkey, which worked.
Just MBNCSUtil isnt storing my cd key
March 15, 2007, 7:05 PM
MysT_DooM
well the code ur using looks just like this one
https://davnit.net/bnet/vL/index.php?topic=15325.0
and he didn't have much problems with it stopping at that spot so
try instead of
[code]
CDKeyDecoded = MBNCSUtil.CdKey.CreateDecoder(strCDKey)
[/code]
try putting the direct path to the cdkey
[code]
CDKeyDecoded = MBNCSUtil.CdKey.CreateDecoder(form1.text1.text)
[/code]
March 15, 2007, 8:50 PM
BreW
I believe MBNCSUtil is open source, you *should* take a look at how it stores your cdkey and what possibly be the problem. And become more familiar with it so you won't have any other problems later on.
March 15, 2007, 9:21 PM
bethra
Are you making sure you pass the CD-key without dashes?

The key will need to be 13, 16, or 26 (depends on the product) in length without dashes.
March 15, 2007, 10:19 PM
iNsaNe
Ok my CDKeyDecoded works now, now I have a problem with settings the ServerToken.
[code]    Private Sub winSock_DataArrival(ByVal sender As System.Object, ByVal e As
AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles winSock.DataArrival

        Dim Data As String
        winSock.GetData(Data, vbString, e.bytesTotal)

        If InStr(Data, HexToStr("FF50")) Then

            AddChat(Color.SpringGreen, "<- Received: 0x50!")

            Get_SIDAUTHINFO = Data

            Get_SIDAUTHINFO_ValueString = Mid$(Get_SIDAUTHINFO, 40, 102)
            Get_SIDAUTHINFO_MPQ = Mid$(Get_SIDAUTHINFO, 25, 14)
            ServerToken = Val("&H" & StrToHex(StrReverse(Mid(Get_SIDAUTHINFO, 9, 4)))) 'Is this the problem?

            PBuff.SEND_SIDAUTHCHECK()

        End If

...

...

...

End Sub[/code]

ServerToken is initially set as Long but then converted to an unsigned integer in my SEND_SIDAUTHCHECK command. I think its wrong.
[code]...

HashLength = CDKeyDecoded.GetHash(ClientToken, CUInt(ServerToken))

...[/code]
Im trying to set it to the server token sent by bnet without it being a string because MBNCSUtil requires it to be an unsigned integer. Can someone help me setting the ServerToken (for Warcraft III if the game matters) properly?

[Edit: broke up a long line.]
March 16, 2007, 1:47 AM
bethra
Why don't you use the BncsReader Class included in MBNCSutil to parse packets?!

Need to make it a byte array instead of treating the packet data as a string...
[code]
winSock.GetData(Data, vbByte, e.bytesTotal)
[/code]

[code]
Dim pck0x50 As New BncsReader(Data)

Dim ServerToken As UInteger
Dim MpqFiletime As Long
Dim MpqFilename As String
Dim ValueString As String
Dim ServerSig() As Byte

pck0x50.Seek(8)
ServerToken = pck0x50.ReadUInt32()
pck0x50.Seek(4)
MpqFiletime = pck0x50.ReadInt64()
MpqFilename = pck0x50.ReadCString()
ValueString = pck0x50.ReadCString()
ServerSig = pck0x50.ReadByteArray(128)
[/code]

Something like that should work.


Bah, I'm still debating whether or not Insane even wrote the VB6 code he's posting.  If he did he wouldn't be trying to rewrite the whole bot over again in .NET which is basically what he's doing right now/will end up having to do... then again if he leeched it why the hell would he want to leech this god awful VB6 sourcecode b/c I'm sure there are better coded open source VB6 bots (I can't match the code of VB6 bots to the original authors like some people on this forum can :P).

I think it's time for me to stop helping him either way.
March 16, 2007, 2:42 AM
iNsaNe
It's nice of you to assume such, but I wrote it all. Get off the forums if you dont feel like helping. This is my first bot, Im sure you had just as many questions.
March 16, 2007, 4:20 AM
BreW
I had many problems like that when I wrote my first bot too. .NET is challenging, and for a beginner, I would probably get confused on the same things too. Please, just stop trying to put people down Polgara. iNsaNe: What I would do, is extract the long value out of the acual text which coresponds to the server token
[code]
sample:
ServerToken = GetDWORDVal(Mid(Data, 9, 4))
'(assuming GetDWORDVal is a function that returns the long value of the string, try using the bit converter class for this)
[/code]
Or w/e the .NET equivalent to Mid() is.
You really should use your packet debuffer class you're using with this project (if you're using one at all) but in the case you're not, just go with that code and nothing will go wrong.
I can see where sorc.polgara is getting this conclusion from, but any piece of code, even as simple as getting the server token, could become very challenging to someone with little expierence.
Edit* Yeah for the cdkey you really should do CDKey = Replace(CDKey, "-", vbNullString) or something before hashing in your logon code, to make it easier to configure among other things. Don't be afraid to do checks, for example "If Len(CDKey) <> 13 Or Len(CDKey) <> 16 Or Len(CDKey) <> 26 Then MsgBox "you entered the cdkey wrong"". small error catchers like that can prevent huge errors later on.
March 16, 2007, 6:10 PM
bethra
Maybe if he LISTENED and LEARNED to stopped treating packets as strings, which he's been told 1000 times already then he wouldn't be running into these problems.
March 16, 2007, 7:06 PM
MyStiCaL
[quote author=iNsaNe link=topic=16487.msg166769#msg166769 date=1173913794]
I'm still having troubles. This is my code so far:
[code] InsertNonNTString(ASCII.GetString(HashLength))[/code]
[/quote]

[quote author=MyndFyre[vL] link=topic=15325.msg155286#msg155286 date=1151967957]

you shouldn't use Encoding.ASCII.GetString(hash) to insert the string.  It's a byte array and should stay as such.  With Encoding.ASCII you risk losing values greater than 0x7f

I suppose you could convert each to a character then a byte:
[code]
For i = 0 To HashLength.Length
    .InsertByte(CByte(HashLength(i) And &Hff))
Next
[/code]

Are you aware that MBNCSUtil also includes a packet buffer designed for Battle.net?
[/quote]
March 16, 2007, 7:39 PM
DDA-TriCk-E
Try...

            Dim CDKeyDecoded As New MBNCSUtil.CdKey.CreateDecoder(strCDKey)
March 18, 2007, 4:41 AM

Search