[LSS - winsock]how do I find an existing socket and use it ?

Ask for Help on Using the Language With Memory Hacking Software

Moderators: g3nuin3, SpeedWing, WhiteHat, mezzo

[LSS - winsock]how do I find an existing socket and use it ?

Postby mezzo » Tue Apr 01, 2008 1:30 pm

I was checking some source code out for winsock programming and I
found following on the msdn site, a small 'client send' bit of code:

#define DEFAULT_BUFLEN 512

char *sendbuf = "this is a test";
char recvbuf[DEFAULT_BUFLEN];

int iResult;

// Send an initial buffer
iResult = send( ConnectSocket, sendbuf, (int)strlen(sendbuf), 0 );
if (iResult == SOCKET_ERROR) {
printf("send failed: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}

printf("Bytes Sent: %ld\n", iResult);

// shutdown the connection for sending since no more data will be sent
// the client can still use the ConnectSocket for receiving data
iResult = shutdown(ConnectSocket, SD_SEND);
if (iResult == SOCKET_ERROR) {
printf("shutdown failed: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}

// Receive data until the server closes the connection
do {

iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
if ( iResult > 0 )
printf("Bytes received: %d\n", iResult);
else if ( iResult == 0 )
printf("Connection closed\n");
else
printf("recv failed: %d\n", WSAGetLastError());

} while( iResult > 0 );


That together with the winsock example in the helpfile allows me to create
sockets and send data over them.

My question, if I attach to a program, how would I 'hijjack' an existing socket to send data over it ?
Is there an API call that will list sockets in use? Or how would I tackle this ?
Any and all hints are welcome.
(it has to be scripted, no manual netstat's or such)
- No thanks, I already have a penguin -
User avatar
mezzo
El Mariachi
 
Posts: 739
Joined: Mon Apr 30, 2007 10:27 pm
Location: Antwerp

Postby L. Spiro » Tue Apr 01, 2008 1:38 pm

If I were personally attempting this I would create a thread in the target process to send data using one of its connections.

I am not aware of API that lists connections but I am pretty sure there is one. I have not done a lot of net coding, which is why I exposed pretty-much all of the winsocks library to scripts.


L. Spiro
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan


Return to Help

Who is online

Users browsing this forum: No registered users and 0 guests

cron