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/srv.c
Views: 11766
1/*2* srv.c -- Example server for easy exploiting3*4* Usage: srv <port>5*6* Example:7*8* C:\> srv 12349* C:\> nload localhost 1234 -s code.s10*11*/12131415#include <stdio.h>16#include <string.h>17#include <errno.h>1819#if defined _WIN3220#include <winsock2.h>21#pragma comment(lib, "ws2_32.lib")22#else23#include <sys/socket.h>24#include <netinet/in.h>25#include <arpa/inet.h>26#include <netdb.h>27#include <unistd.h>28#endif2930#define SERVER_PORT 543231#define MAX_PENDING 1323334int ehlo, from;3536/* Main function */3738int main(int argc, char **argv) {39DWORD old;40struct sockaddr_in sin;41char buf[8092], *ptr;42int c, i, len, port;43int s, new_s, bytes;44#if defined _WIN3245int wsaret;46WSADATA wsaData;47#endif48int (*funct)();495051/* Command line parameters */52if (argv[1])53port = atoi(argv[1]);54else55port = SERVER_PORT;5657#if defined _WIN3258/* Initialize winsock */59wsaret = WSAStartup(0x101, &wsaData);60if(wsaret != 0)61return (0);6263/* Create a socket */64if ((s = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0)) < 0) {65fprintf(stderr, "%s: WSASocket - %s\n", argv[0], strerror(errno));66exit(1);67}68#else69if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {70fprintf(stderr, "%s: socket - %s\n", argv[0], strerror(errno));71exit(1);72}7374#endif7576/* Initialize the addres data structure */77memset((void *)&sin, 0, sizeof(sin));78sin.sin_family = AF_INET;79sin.sin_addr.s_addr = INADDR_ANY;80sin.sin_port = htons(port);8182/* Bind an address to the socket */83if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {84fprintf(stderr, "%s: bind - %s\n", argv[0], strerror(errno));85exit(1);86}8788/* Set the length of the listen queue */89if (listen(s, MAX_PENDING) < 0) {90fprintf(stderr, "%s: listen - %s\n", argv[0], strerror(errno));91exit(1);92}939495len = sizeof(sin);96new_s = accept(s, (struct sockaddr *)&sin, &len);9798memset(buf, 0, sizeof(buf));99bytes = recv(new_s, buf, sizeof(buf), 0);100101printf("recv'd %d\n", bytes);102103old = VirtualProtect(104buf,105sizeof(buf),106PAGE_EXECUTE_READWRITE,107&old);108109110/* Run the code */111fprintf(stderr,"Oops.. I'm 0wned, reprotect success: %lu.\n", old);112113__asm mov edi, new_s114115funct = (int (*)()) buf;116(int)(*funct)();117118return (0);119120}121122123124125