Jump to content
YOUR-AD-HERE
HOSTING
TOOLS

Locked Http Downloader using winsock


dEEpEst

Recommended Posts

Credits: Dickyb0b

 

[LENGUAJE=C+]#include "stdafx.h"

#include

#include

#include

#include

#include

using namespace std;

#pragma comment(lib,"ws2_32.lib")

#pragma comment(linker,"/SUBSYSTEM:WINDOWS")

 

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)

{

WORD sockVersion;

WSADATA wsaData;

int nret;

sockVersion = MAKEWORD(2, 2); // Initialize Winsock as before

SOCKET theSocket;

nret = WSAStartup(sockVersion, &wsaData);

cout

 

// Store information about the server

LPHOSTENT hostEntry;

hostEntry = gethostbyname("192.168.1.4"); // Specifying the server by its name; // another option:

if (!hostEntry)

{

nret = WSAGetLastError();

WSACleanup();

}

 

 

 

theSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);

 

if (theSocket == INVALID_SOCKET)

{

nret = WSAGetLastError();

// ReportError(nret, "socket()");

WSACleanup();

}

 

SOCKADDR_IN serverInfo;

in_addr iaHost;

serverInfo.sin_family = AF_INET;

iaHost.s_addr = inet_addr("192.168.1.4");

hostEntry = gethostbyaddr((const char *)&iaHost, sizeof(struct in_addr), AF_INET);

serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);

serverInfo.sin_port = htons(80);

 

nret = connect(theSocket, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr));

 

if (nret == SOCKET_ERROR)

{

 

}

else

{

 

std::string sendbuffer = "GET /Test.exe HTTP/1.1\r\n"

"Host: 192.168.1.4\r\n\r\n";

 

nret = send(theSocket, sendbuffer.c_str(), sendbuffer.size(), 0);

 

std::string rbuffer;

rbuffer.resize(1024,0);

size_t sfind;

std::fstream fs;

fs.open ("Test.exe", std::ios::binary | std::ios::out);

 

 

nret = recv(theSocket, &rbuffer[0],1024,0);

if(nret > 0)

{

sfind = rbuffer.find("\r\n\r\n");

if(sfind != string::npos)

{

 

fs.write (rbuffer.c_str()+sfind+4,((nret)-(sfind+4)));

}

}

 

while(1)

{

 

nret = recv(theSocket, &rbuffer[0],1024,0);

if(nret > 0)

{

fs.write (rbuffer.c_str(),nret);

}

else

{

break;

}

}

 

 

 

fs.close();

}

 

return 0;

}[/LENGUAJE]

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.