#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "windows.h"
int main()
{
char *buffer;
char requete[1500];
int lSize = 0;
size_t result = 0;
WSADATA WSAData;
int erreur = WSAStartup(MAKEWORD(2,2), &WSAData);
SOCKET sock;
SOCKADDR_IN sin;
FILE* image = fopen("C:\\Users\\Dardanboy\\Pictures\\w.png", "rb");
if (image == NULL){printf("Erreur !\n"); system("PAUSE"); return 0;}
fseek (image , 0 , SEEK_END);
lSize = ftell (image);
rewind (image);
// allocate memory to contain the whole file:
buffer = (char*) malloc (sizeof(char)*lSize);
if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
// copy the file into the buffer:
result = fread (buffer,1,lSize,image);
if (result != lSize)
{
printf("lSize (taille image) = %d, result = %d, buffer = %02x\n", lSize, result, buffer);
fputs ("Reading error",stderr); exit (3);
}
printf("lSize (taille image) = %d, result = %d, buffer = %x\n", lSize, result, buffer);
sprintf(requete, "POST /upload/cible_envoi.php HTTP/1.1\r\n"
"Accept: text/html, application/xhtml+xml, */*\r\n"
"Referer: http://dardanboy.franceserv.com/upload/upload.php\r\n"
"Accept-Language: fr-CH\r\n"
"User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)\r\n"
"Content-Type: multipart/form-data; boundary=---------------------------7db2c7420378\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"Host: dardanboy.franceserv.com\r\n"
"Content-Length: 292\r\n"
"Connection: Keep-Alive\r\n"
"Cache-Control: no-cache\r\n\r\n"
"-----------------------------7db2c7420378\r\n"
"Content-Disposition: form-data; name=\"monfichier\"; filename=\"w.png\"\r\n"
"Content-Type: image/x-png\r\n\r\n"
"%s\r\n"
"-----------------------------7db2c7420378--\r\n\r\n"
"\r\n", buffer);
sock = socket(AF_INET, SOCK_STREAM, 0);
/* Configuration de la connexion */
sin.sin_addr.s_addr = inet_addr("178.33.214.192"); // ip de l'hébergeur
sin.sin_family = AF_INET;
sin.sin_port = htons(80);
if(!erreur)
{
/* connexion grâce à connect */
if(connect(sock, (SOCKADDR*)&sin, sizeof(sin)) != SOCKET_ERROR)
{
printf("Connexion à %s sur le port %d\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port));
printf("strlen(requete) = %d sizeof(requete) = %d\n", strlen(requete), sizeof(requete));
printf("\n\nrequete = %s\n\n", requete);
send(sock, requete, strlen(requete), 0);
/* On ferme la connexion */
fclose (image);
free (buffer);
closesocket(sock);
WSACleanup();
return 1;
}
else{
fclose (image);
free (buffer);
closesocket(sock);
WSACleanup();
printf("ERREUR: Impossible de se connecter à %s sur le port %d !", inet_ntoa(sin.sin_addr), htons(sin.sin_port));
system("PAUSE");
return 0;
}
}
else{
printf("ERREUR !\n");
system("PAUSE");
return 0;
}
return 0;
}