-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtinyclient.c
More file actions
42 lines (34 loc) · 1.26 KB
/
Copy pathtinyclient.c
File metadata and controls
42 lines (34 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Cliente TCP minimal — hace GET / a un host:port y vuelca la respuesta.
// Uso: ./tinyclient <host> <port>
#include "../0x260/0x265_hacking.h"
#include <netdb.h>
int main(int argc, char *argv[]) {
int sockfd, recv_length;
struct sockaddr_in target_addr;
struct hostent *target;
char buffer[2048];
char request[256];
if (argc < 3) {
printf("Uso: %s <host> <port>\n", argv[0]);
return 1;
}
target = gethostbyname(argv[1]);
if (!target) fatal("gethostbyname");
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) fatal("socket");
target_addr.sin_family = AF_INET;
target_addr.sin_port = htons(atoi(argv[2]));
memcpy(&target_addr.sin_addr, target->h_addr_list[0], target->h_length);
memset(&target_addr.sin_zero, 0, 8);
if (connect(sockfd, (struct sockaddr *) &target_addr, sizeof(struct sockaddr)) == -1)
fatal("connect");
snprintf(request, sizeof(request),
"GET / HTTP/1.0\r\nHost: %s\r\nUser-Agent: tinyclient\r\n\r\n",
argv[1]);
send(sockfd, request, strlen(request), 0);
while ((recv_length = recv(sockfd, buffer, sizeof(buffer) - 1, 0)) > 0) {
buffer[recv_length] = '\0';
printf("%s", buffer);
}
close(sockfd);
return 0;
}