command and control system

silvine

New member
Joined
Oct 30, 2016
Messages
3
Programming Experience
10+
Imports System.IO
Imports System.Net
Imports System.Net.Sockets

Imports System.Text
Imports System.Text.Encoding

Public Class Form1

   

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


        Dim host As String = Nothing
        Dim port As Integer = 8000

        host = "192.168.0.100"

        Dim tempHost As IPHostEntry = Nothing
        Dim tempSocket As Socket = Nothing
        Dim socketAddr As SocketAddress = Nothing
        Try

            tempHost = Dns.GetHostEntry(host)

            Dim address As IPAddress
            For Each address In tempHost.AddressList
                Dim endpoin As New IPEndPoint(address, port)

                tempSocket = New Socket(endpoin.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
                tempSocket.Connect(endpoin)
                If tempSocket.Connected Then
                    socketAddr = endpoin.Serialize()
                    TextBox1.Text = socketAddr.ToString
                    Exit For
                End If
            Next
            tempSocket.Close()

        Catch ex As Exception

        End Try

        Dim ascii As Encoding = Encoding.ASCII
        Dim [get] As String = "! ls /"

        Dim ByteGet As [Byte]() = ascii.GetBytes([get])
        Dim recvBytes(255) As [Byte]
        Dim strRetPage As [String] = Nothing

        Dim socket As Socket = Nothing

        Dim endpoint As New IPEndPoint(0, 0)
        Dim clonedEndPoint As IPEndPoint = CType(endpoint.Create(socketAddr), IPEndPoint)

        Console.WriteLine("clonedIP ENDPOINt : " + clonedEndPoint.ToString())


        socket = New Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
        socket.Connect(clonedEndPoint)

        Try

            'Dim buffer() As Byte = ASCII.GetBytes(Messages.HELLO)
            socket.Send(ByteGet, ByteGet.Length, 0)



            Dim i As Int32 = 0
            i = socket.Receive(recvBytes, recvBytes.Length, 0)


            If i > 0 Then
                Dim result As String = ascii.GetString(recvBytes, 0, i)
                MsgBox(result)
            End If

        Catch ex As Exception

            MsgBox("1" + ex.Message)

        End Try
fin:
        socket.Disconnect(True)
        socket.Close(20)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim url() As Byte = {127, 0, 0, 1}
        Dim uri As New IPAddress(url)
        Dim baseURL As IPEndPoint = CType(New IPEndPoint(uri, 1234), IPEndPoint)
        Dim pReq As TcpClient = CType(New TcpClient(baseURL), TcpClient)

        Try

            pReq.Connect(IPAddress.Parse("192.168.0.100"), 8000)

        Catch

        End Try



        Try

            Dim stream As NetworkStream = pReq.GetStream()

            Dim r As New IO.BinaryReader(stream)
            Dim w As New IO.BinaryWriter(stream)

            w.Write(Messages.GET0)

            'w.Write(Messages.BYE)

        Catch ex As Exception
            MsgBox("1" + ex.Message)
        End Try


    End Sub
End Class
Public Class Messages

    'handshake messages
    Public Const HELLO As String = "Elohim"
    Public Const BYE As String = "Bail"

    'acknowledgement messages
    Public Const OK As String = "OK "
    Public Const ERR As String = "ERR"
    Public Const RETRY As String = "RET"
    'tcp messages
    Public Const TX As String = "TX "
    Public Const RX As String = "RX "
    'get drives
    Public Const GET0 As String = "ls ./"
    'get folders
    Public Const GET1 As String = "GE1"
    'get files
    Public Const GET2 As String = "GE2"
    'get single file TX to RX
    Public Const GET3 As String = "GE3"



End Class

Public Class TestIPEndPoint

End Class


This is my code.

My setup is;
A laptop �� i7 win10
A linux computer ��
Visual studio 2008

I have a working server one coded in c for linux.
Now I'm developing a client in vb.net
Interesting project, no?

However, when sending commands to the server, I get the command echo's
Back to me, like its not understood by linux server.

I can connect via net cat �� just fine to the server and issue commands.

The query is this : SELECT charset FROM characterMap WHERE Windows.charmap === Linux.charmap
 

silvine

New member
Joined
Oct 30, 2016
Messages
3
Programming Experience
10+
One must apologise in advance.

The question is; why isn't the ! ls / command creating a directory listing?

It works from nc, but not vb.net.
 
Top Bottom