72 lines
1.4 KiB
C
72 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <arpa/inet.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netdb.h>
|
|
#include <netinet/in.h>
|
|
|
|
int main() {
|
|
int sock;
|
|
struct sockaddr_in srv;
|
|
struct addrinfo hints, *addr;
|
|
|
|
char pas[256];
|
|
char res[10];
|
|
int reslen = 0;
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
hints.ai_family = AF_INET; // IPv4
|
|
hints.ai_socktype = SOCK_STREAM; // TCP
|
|
|
|
int status = getaddrinfo("076.moe", NULL, &hints, &addr);
|
|
if (status != 0) {
|
|
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
|
|
exit(1);
|
|
}
|
|
|
|
sock = socket(AF_INET, SOCK_STREAM, 0);
|
|
if (sock == -1) {
|
|
perror("ソケットを作成に失敗");
|
|
exit(1);
|
|
}
|
|
|
|
srv.sin_addr = ((struct sockaddr_in *)(addr->ai_addr))->sin_addr;
|
|
srv.sin_family = AF_INET;
|
|
srv.sin_port = htons(9951);
|
|
|
|
freeaddrinfo(addr);
|
|
|
|
if (connect(sock, (struct sockaddr *)&srv, sizeof(srv)) < 0) {
|
|
perror("接続に失敗");
|
|
close(sock);
|
|
exit(1);
|
|
}
|
|
|
|
printf("パスワード: ");
|
|
fgets(pas, sizeof(pas), stdin);
|
|
pas[strcspn(pas, "\n")] = 0;
|
|
|
|
if (send(sock, pas, strlen(pas), 0) < 0) {
|
|
perror("送信に失敗");
|
|
close(sock);
|
|
exit(1);
|
|
}
|
|
|
|
reslen = recv(sock, res, sizeof(res) -1, 0);
|
|
if (reslen < 0) {
|
|
perror("受取に失敗");
|
|
close(sock);
|
|
exit(1);
|
|
}
|
|
|
|
res[reslen] = '\0';
|
|
|
|
printf("Pwned: %s\n", res);
|
|
|
|
close(sock);
|
|
return 0;
|
|
}
|