|
@@ -0,0 +1,244 @@
|
|
|
+#include <netdb.h>
|
|
|
+#include <netinet/in.h>
|
|
|
+#include <stdio.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <string.h>
|
|
|
+#include <termios.h>
|
|
|
+#include <unistd.h>
|
|
|
+
|
|
|
+void doprocessing(int sock);
|
|
|
+char *cmds[10];
|
|
|
+
|
|
|
+void set_raw(int fd) {
|
|
|
+ struct termios tio_raw;
|
|
|
+ tcgetattr(fd, &tio_raw);
|
|
|
+ cfmakeraw(&tio_raw);
|
|
|
+ tcsetattr(fd, TCSANOW, &tio_raw);
|
|
|
+}
|
|
|
+
|
|
|
+int drain(int fd) {
|
|
|
+ struct timeval tv;
|
|
|
+ fd_set set;
|
|
|
+ int ret;
|
|
|
+ char buffer[21];
|
|
|
+ int total = 0;
|
|
|
+
|
|
|
+ printf("draining... \n");
|
|
|
+
|
|
|
+ do {
|
|
|
+ FD_ZERO(&set);
|
|
|
+ FD_SET(fd, &set);
|
|
|
+ tv.tv_sec = 0;
|
|
|
+
|
|
|
+ tv.tv_usec = 50000;
|
|
|
+
|
|
|
+ ret = select(fd + 1, &set, NULL, NULL, &tv);
|
|
|
+ if (ret == 1) {
|
|
|
+ total += read(fd, buffer, 20);
|
|
|
+ }
|
|
|
+ } while (ret != 0);
|
|
|
+ printf(" [%d]\n", total);
|
|
|
+ return total;
|
|
|
+}
|
|
|
+
|
|
|
+int main(int argc, char *argv[]) {
|
|
|
+ int sockfd, newsockfd, portno, clilen;
|
|
|
+ char buffer[256];
|
|
|
+ struct sockaddr_in serv_addr, cli_addr;
|
|
|
+ int n, pid;
|
|
|
+
|
|
|
+
|
|
|
+ sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
+
|
|
|
+ if (sockfd < 0) {
|
|
|
+ perror("ERROR opening socket");
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (argc != 3) {
|
|
|
+ printf("I need a listening port number, and command/door to call.\n");
|
|
|
+ exit(2);
|
|
|
+ }
|
|
|
+
|
|
|
+ int listen_port = atoi(argv[1]);
|
|
|
+ char *command = strdup(argv[2]);
|
|
|
+ char *cp;
|
|
|
+ int cmd_count;
|
|
|
+ cp = command;
|
|
|
+ cmds[cmd_count] = cp;
|
|
|
+ cmd_count++;
|
|
|
+ while (*cp != 0) {
|
|
|
+ if (*cp == ' ') {
|
|
|
+ *cp = 0;
|
|
|
+ cp++;
|
|
|
+ cmds[cmd_count] = cp;
|
|
|
+ cmd_count++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ cp++;
|
|
|
+ }
|
|
|
+ cmds[cmd_count] = (char *)NULL;
|
|
|
+
|
|
|
+ if (listen_port == 0) {
|
|
|
+ printf("I need a listening port number as a parameter.\n");
|
|
|
+ exit(2);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ bzero((char *)&serv_addr, sizeof(serv_addr));
|
|
|
+ portno = listen_port;
|
|
|
+
|
|
|
+ serv_addr.sin_family = AF_INET;
|
|
|
+ serv_addr.sin_addr.s_addr = INADDR_ANY;
|
|
|
+ serv_addr.sin_port = htons(portno);
|
|
|
+
|
|
|
+ int flag = 1;
|
|
|
+ if (-1 == setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag))) {
|
|
|
+ perror("setsockopt fail");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
|
|
|
+ perror("ERROR on binding");
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * process will go in sleep mode and will wait
|
|
|
+ * for the incoming connection
|
|
|
+ */
|
|
|
+ printf("Listening for connections on %d\n", listen_port);
|
|
|
+
|
|
|
+ listen(sockfd, 5);
|
|
|
+ clilen = sizeof(cli_addr);
|
|
|
+
|
|
|
+ while (1) {
|
|
|
+ newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
|
|
|
+
|
|
|
+ if (newsockfd < 0) {
|
|
|
+ perror("ERROR on accept");
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ set_raw(newsockfd);
|
|
|
+
|
|
|
+
|
|
|
+ pid = fork();
|
|
|
+
|
|
|
+ if (pid < 0) {
|
|
|
+ perror("ERROR on fork");
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pid == 0) {
|
|
|
+
|
|
|
+ close(sockfd);
|
|
|
+ doprocessing(newsockfd);
|
|
|
+ exit(0);
|
|
|
+ } else {
|
|
|
+ close(newsockfd);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ free((void *)command);
|
|
|
+}
|
|
|
+
|
|
|
+#define CRNL "\r\n"
|
|
|
+
|
|
|
+void doprocessing(int sock) {
|
|
|
+ int n;
|
|
|
+ char buffer[256];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ std::string ayt = std::string((const char *)"\x00\xff\xfd\xf6", 4);
|
|
|
+ std::string ayt_resp = std::string((const char *)"\xff\xfb\x00", 3);
|
|
|
+ std::string ayt2 = std::string((const char *)"\xff\xfb\x00", 3);
|
|
|
+ std::string ayt2_resp = std::string((const char *)"\xff\xfd\x00", 3);
|
|
|
+
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ https:
|
|
|
+ https:
|
|
|
+ https:
|
|
|
+ https:
|
|
|
+ https:
|
|
|
+ https:
|
|
|
+ https:
|
|
|
+ https:
|
|
|
+ http:
|
|
|
+ https:
|
|
|
+
|
|
|
+ */
|
|
|
+ write(sock, "\xff\xfb\x01", 3);
|
|
|
+
|
|
|
+ write(sock, "\xff\xfb\x03", 3);
|
|
|
+
|
|
|
+ write(sock, "\xff\xfd\x10", 3);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ drain(sock);
|
|
|
+
|
|
|
+
|
|
|
+ struct termios tio_raw;
|
|
|
+ tcgetattr(sock, &tio_raw);
|
|
|
+ cfmakeraw(&tio_raw);
|
|
|
+ tcsetattr(sock, TCSANOW, &tio_raw);
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sprintf(buffer, "Welcome socket %d" CRNL, sock);
|
|
|
+ write(sock, buffer, strlen(buffer));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ FILE *fp;
|
|
|
+
|
|
|
+ fp = fopen("door32.sys", "w");
|
|
|
+ if (fp == NULL) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ fprintf(fp, "%d\n", 2);
|
|
|
+ fprintf(fp, "%d\n", sock);
|
|
|
+ fprintf(fp, "38400\n");
|
|
|
+ fprintf(fp, "Fake Door32 BBS\n");
|
|
|
+ fprintf(fp, "1\n");
|
|
|
+ fprintf(fp, "%s\n%s\n", "Bugz Laundry", "Bugz");
|
|
|
+ fprintf(fp, "%d\n", 100);
|
|
|
+ fprintf(fp, "%d\n", 120);
|
|
|
+ fprintf(fp, "1\n1\n");
|
|
|
+ fclose(fp);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ execv(cmds[0], cmds);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ bzero(buffer,256);
|
|
|
+
|
|
|
+ n = read(sock,buffer,255);
|
|
|
+
|
|
|
+ if (n < 0) {
|
|
|
+ perror("ERROR reading from socket");
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ printf("Here is the message: %s\n",buffer);
|
|
|
+ n = write(sock,"I got your message",18);
|
|
|
+
|
|
|
+ if (n < 0) {
|
|
|
+ perror("ERROR writing to socket");
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
+ */
|
|
|
+}
|