VB Packets Help ( Again :D )

08/11/2011 00:32 DeXeee#1
Hi guys

Here i am again with the same question like last time, just the last time that was a project in AutoIt.

I decided to learn VB becouse it look very easy. I have already learned some basic things, thanks to YouTube and the guy called "TeachMeComputer". I watched all 50+ of his tutorials, so for now i just know some basic things.

For now, i make the connection to srProxy


Code:
Imports System.Net.Sockets
Imports System.Text
Public Class Form1

    Dim clientSocket As New System.Net.Sockets.TcpClient()

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        clientSocket.Connect("127.0.0.1", 9000)
        If clientSocket.Connected Then
            Label2.Text = "Connected"
        End If
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
    End Sub
End Class
Now the question is how do I send packets ? :)

Thanks in advance, cheers ! :D
08/11/2011 00:47 sarkoplata#2
Quote:
Originally Posted by lordfeling View Post
Hi, thanks for you responce.

I've captured somes packet :

Code:
Sit-stand up :
[C -> S][704F]
04
Code:
pick gold :
[C -> S][7074]
01                                                
02                                                
01                                                
6E 05 1A 00

I never programmed a tool with packet.
That why I require help for learn how to use Packet.

Thanks.
Ok, First of all we should import our class.
Just write the top of the class :

PHP Code:
Imports System.Net.Sockets 
Now we are able to use system.net.sockets class.

Lets declare our socket :

PHP Code:
    Public Client As Socket = New Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp
Now , we are should connect to our proxy to inject packets.
You can basicly use phConnector for this.
(And you will redirect your ip to 127.0.0.1 : 15778 from loader. )

Lets connect our socket :

PHP Code:
Client.Connect("localhost"xyour phConnector botport 
Now we connected to proxy and we can send packets.
Packets are in raw form at fact , but we convert em to easier structure.

Client.Send("x") will send raw packets.
So we should make our packet raw at first.
Here is my func. to do that. This func. is written by xKraizy.

PHP Code:
Public Sub SendPacket(ByVal OpCode As StringByVal sData As StringByVal Enc As Boolean)
        
Using buffer As New IO.MemoryStream
            Using w 
As New IO.BinaryWriter(buffer)
                
w.Write(CUShort(0))
                
w.Write(CUShort("&H" OpCode))
                If 
Enc True Then
                    w
.Write(CUShort(3))
                Else
                    
w.Write(CUShort(1))
                
End If
                For 
0 To sData.Length 1
                    w
.Write(CByte("&H" sData.Substring(22)))
                
Next

                w
.BaseStream.Position 0
                w
.Write(CUShort(w.BaseStream.Length 6))
                
w.Flush()
                
Client.Send(buffer.ToArray)
            
End Using
        End Using
    End Sub 
You can call this function anywhere you want now.
For example , add client connecting thingy to form_load , and add a button and write this.

PHP Code:
SendPacket("704F","04",False
First parameter is your opcode
Second parameter is your packet data
Third packet is a boolean , if you make it True , you will be able to send encrypted packets.(They are a bit intermediate part.)

And about gold packet ;

I dont really remember but every byte in packet has a meaning.

PHP Code:
[-> S][7074// Opcode
01 // Some Flag                                               
02 // Some Flag                                                      
01 // Some Flag                                                      
6E 05 1A 00  // UniqueID of gold. 
Have fun and ask when you needed !
sarkolata
08/11/2011 00:50 DeXeee#3
Quote:
Originally Posted by sarkoplata View Post
Ok, First of all we should import our class.
Just write the top of the class :

PHP Code:
Imports System.Net.Sockets 
Now we are able to use system.net.sockets class.

Lets declare our socket :

PHP Code:
    Public Client As Socket = New Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp
Now , we are should connect to our proxy to inject packets.
You can basicly use phConnector for this.
(And you will redirect your ip to 127.0.0.1 : 15778 from loader. )

Lets connect our socket :

PHP Code:
Client.Connect("localhost"xyour phConnector botport 
Now we connected to proxy and we can send packets.
Packets are in raw form at fact , but we convert em to easier structure.

Client.Send("x") will send raw packets.
So we should make our packet raw at first.
Here is my func. to do that. This func. is written by xKraizy.

PHP Code:
Public Sub SendPacket(ByVal OpCode As StringByVal sData As StringByVal Enc As Boolean)
        
Using buffer As New IO.MemoryStream
            Using w 
As New IO.BinaryWriter(buffer)
                
w.Write(CUShort(0))
                
w.Write(CUShort("&H" OpCode))
                If 
Enc True Then
                    w
.Write(CUShort(3))
                Else
                    
w.Write(CUShort(1))
                
End If
                For 
0 To sData.Length 1
                    w
.Write(CByte("&H" sData.Substring(22)))
                
Next

                w
.BaseStream.Position 0
                w
.Write(CUShort(w.BaseStream.Length 6))
                
w.Flush()
                
Client.Send(buffer.ToArray)
            
End Using
        End Using
    End Sub 
You can call this function anywhere you want now.
For example , add client connecting thingy to form_load , and add a button and write this.

PHP Code:
SendPacket("704F","04",False
First parameter is your opcode
Second parameter is your packet data
Third packet is a boolean , if you make it True , you will be able to send encrypted packets.(They are a bit intermediate part.)

And about gold packet ;

I dont really remember but every byte in packet has a meaning.

PHP Code:
[-> S][7074// Opcode
01 // Some Flag                                               
02 // Some Flag                                                      
01 // Some Flag                                                      
6E 05 1A 00  // UniqueID of gold. 
Have fun and ask when you needed !
sarkolata
Ty for this, i will take a look at this codes :)

I rly don't understand this part :(

Code:
Public Sub SendPacket(ByVal OpCode As String, ByVal sData As String, ByVal Enc As Boolean)
        Using buffer As New IO.MemoryStream
            Using w As New IO.BinaryWriter(buffer)
                w.Write(CUShort(0))
                w.Write(CUShort("&H" + OpCode))
                If Enc = True Then
                    w.Write(CUShort(3))
                Else
                    w.Write(CUShort(1))
                End If
                For n = 0 To sData.Length / 2 - 1
                    w.Write(CByte("&H" & sData.Substring(n * 2, 2)))
                Next

                w.BaseStream.Position = 0
                w.Write(CUShort(w.BaseStream.Length - 6))
                w.Flush()
                Client.Send(buffer.ToArray)
            End Using
        End Using
    End Sub
Can you explain me a little bit more ? :o
08/11/2011 10:48 lesderid#4
Quote:
Originally Posted by DeXeee View Post
I rly don't understand this part :(

Code:
Public Sub SendPacket(ByVal OpCode As String, ByVal sData As String, ByVal Enc As Boolean)
        Using buffer As New IO.MemoryStream
            Using w As New IO.BinaryWriter(buffer)
                w.Write(CUShort(0)) ' Size is 0 because it 'cannot' be known yet.
                w.Write(CUShort("&H" + OpCode)) ' Converts the string Opcode to a UInt16, reading the Opcode as a hexadecimal representation
                If Enc = True Then
                    w.Write(CUShort(3)) ' Encryption flag phConnector
                Else
                    w.Write(CUShort(1)) ' No-encryption flag phConnector
                End If
                For n = 0 To sData.Length / 2 - 1 ' Each byte is two characters and starting from 0 so decreasing by 1
                    w.Write(CByte("&H" & sData.Substring(n * 2, 2))) ' Writes every byte
                Next

                w.BaseStream.Position = 0 ' Resets the position to write the size
                w.Write(CUShort(w.BaseStream.Length - 6)) ' Writes the size to the '0' placeholder
                w.Flush() ' Makes sure the data is written to the buffer
                Client.Send(buffer.ToArray) ' Sends the buffer to the Socket
            End Using
        End Using
    End Sub
Can you explain me a little bit more ? :o
Added some comments.
08/11/2011 11:17 DeXeee#5
Oh, so this example is for phConnector ..

How can i send packet with srProxy ?
08/11/2011 11:55 lesderid#6
Quote:
Originally Posted by DeXeee View Post
Oh, so this example is for phConnector ..

How can i send packet with srProxy ?
Sorry, no idea what header format they use.
08/11/2011 13:54 sarkoplata#7
Quote:
Originally Posted by DeXeee View Post
Oh, so this example is for phConnector ..

How can i send packet with srProxy ?
Why ?
08/11/2011 21:39 DeXeee#8
Quote:
Originally Posted by sarkoplata View Post
Why ?
Becouse i want to use srProxy :D
08/11/2011 23:08 sarkoplata#9
Quote:
Originally Posted by DeXeee View Post
Becouse i want to use srProxy :D
too explanatory
08/11/2011 23:21 DeXeee#10
Quote:
Originally Posted by sarkoplata View Post
too explanatory
I am sure that i need to change something here :

Code:
Public Sub SendPacket(ByVal OpCode As String, ByVal sData As String, ByVal Enc As Boolean)
        Using buffer As New IO.MemoryStream
            Using w As New IO.BinaryWriter(buffer)
                w.Write(CUShort(0)) ' Size is 0 because it 'cannot' be known yet.
                w.Write(CUShort("&H" + OpCode)) ' Converts the string Opcode to a UInt16, reading the Opcode as a hexadecimal representation
                If Enc = True Then
                    w.Write(CUShort(3)) ' Encryption flag phConnector
                Else
                    w.Write(CUShort(1)) ' No-encryption flag phConnector
                End If
                For n = 0 To sData.Length / 2 - 1 ' Each byte is two characters and starting from 0 so decreasing by 1
                    w.Write(CByte("&H" & sData.Substring(n * 2, 2))) ' Writes every byte
                Next

                w.BaseStream.Position = 0 ' Resets the position to write the size
                w.Write(CUShort(w.BaseStream.Length - 6)) ' Writes the size to the '0' placeholder
                w.Flush() ' Makes sure the data is written to the buffer
                Client.Send(buffer.ToArray) ' Sends the buffer to the Socket
            End Using
        End Using
    End Sub
I will try something :D

Tnx for help anyway :)
08/24/2011 17:00 DeXeee#11
I tried everything and i can't send packet :S

I am using SrProxy

I was trying something like this :

Code:
Public Client As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Client.Connect("127.0.0.1", 9000)
        If Client.Connected Then
            Label2.Text = "Connected"
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Client.Send("0x01004F70020004")   <<<---- Here is the problem !!
    End Sub
Is there any other way to just send packet, becouse this .Send don't want to work :confused:


With AutoIT its working :

Code:
TCPSend($socket, "0x01004F70020004")
08/24/2011 22:11 slider2009#12
use SendPacket code in page one it should work well with u
08/25/2011 00:37 DeXeee#13
Quote:
Originally Posted by slider2009 View Post
use SendPacket code in page one it should work well with u
Not working =/ Its only for phConnector :(

Loool ! Bro ty so much i find what i need to change :D

HAHAH , the problem was in :
Code:
If Enc = True Then
                    w.Write(CUShort(3))
                Else
                    w.Write(CUShort(2)) <<<---- For SrProxy this have to be 2 !!! For ph its 1
                End If
08/25/2011 19:00 s2k#14
The Packet structure in PhConnector is same as in SrProxy and Nuconnector:
Quote:
LENGTH (Int16) OPCODE(Int16) ENCRYPTION(Int16) DATA

For encryption you have these options:
"0100 - Send to SERVER"
"0200 - Send to CLIENT"
"0300 - Send to SERVER encrypted"
"0400 - Send to CLIENT encrypted"
your old code has a bug because you are sending a string, you have to send bytes.
something like this:

Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  
        '01004F70020004
        Dim Packet As Byte() = {1, 0, 79, 112, 2, 0, 4}

        
        Client.Send(Packet)
    End Sub

btw: you are injecting the packet to sr_client. in the "SendPacket" code you only can choose the encryption, but not the direction.

i changed that code so you can define the direction:

Code:
 Public Sub SendPacket(ByVal OpCode As String, ByVal sData As String, ByVal direction As Byte, ByVal Enc As Boolean)
        Using buffer As New IO.MemoryStream
            Using w As New IO.BinaryWriter(buffer)
                w.Write(CUShort(0)) ' Size is 0 because it 'cannot' be known yet.
                w.Write(CUShort("&H" + OpCode)) ' Converts the string Opcode to a UInt16, reading the Opcode as a hexadecimal representation
                If Enc = True Then
                    If direction = 1 Then 'send to server
                        w.Write(CUShort(3)) ' Encryption flag phConnector
                    ElseIf direction = 2 Then 'send to client
                        w.Write(CUShort(4))
                    End If
                Else
                    If direction = 1 Then 'send to server
                        w.Write(CUShort(1)) ' Encryption flag phConnector
                    ElseIf direction = 2 Then 'send to client
                        w.Write(CUShort(2))
                    End If
                End If

                For n As Integer = 0 To sData.Length / 2 - 1 ' Each byte is two characters and starting from 0 so decreasing by 1
                    w.Write(CByte("&H" & sData.Substring(n * 2, 2))) ' Writes every byte
                Next

                w.BaseStream.Position = 0 ' Resets the position to write the size
                w.Write(CUShort(w.BaseStream.Length - 6)) ' Writes the size to the '0' placeholder
                w.Flush() ' Makes sure the data is written to the buffer
                Client.Send(buffer.ToArray) ' Sends the buffer to the Socket
            End Using
        End Using
    End Sub
you can use it this way:

Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  
        '0100 4F70 0200 04

        'dont use encryption unless you know what you are doing
        'direction= 1 send to server, 2= send to client
        SendPacket("704F", "04", 2, False)

    End Sub
08/29/2011 00:13 DeXeee#15
About receiving packets :

I am trying on this way, but i only get " ? " or nothing ...

Code:
  Public Client As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Load Sub
        Client.Connect("127.0.0.1", 9000)
        
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        Dim inStream(10024) As Byte
        Client.Receive(inStream, 0, CInt(Client.ReceiveBufferSize), SocketFlags.None)
        Dim returndata As String = _
        System.Text.Encoding.ASCII.GetString(inStream)
        MsgBox("Data from Server : " + returndata)

       
    End Sub
I am working on this for 2 - 3 days and i don't know where i'am wrong :S