Remote Process Killing C++

Posts 1–12 of 12 · Page 1 of 1
Remote Process Killing C++
Good Day all,

It's me again.. Yet again I am stumped as always. I am trying to create a remote process killer which in my infrastructure I gotta clean out some processes from some computers "out side the box". I thought if I can make a cool C++ program that accepts the ip or hostname, domain, userid and the process then proceeds to add the inputs into a system command I use very often to eliminate a suspicious process. I always seem to bump into an issue at the end. Remember I am a beginner so sorry for my bad syntax. I would really appreciate the assistance.

Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>

using namespace std;

char pcname[256];
char domain[256];
char userid[256];
char process[256];


int main()
{
    cout << "Remote Process Kill Utility \n";
    cout << "Please Provide target hostname \n ->";
    cin >> pcname;
    
    cout << "\nDomain \n ->";
    cin >> domain;
    
    cout << "\nUser id \n ->";
    cin >> userid;
    
    cout << "\nProcess name *Example explorer.exe \n ->";
    cin >> process;
    
    system("cls");
    system("Loading..");
    system("taskkill /s " + pcname + " /u " + domain + "\\" + userid + " /fi " "username ne nt*" "/im " + process + "");
    return 0;
}






Update..


Oh man... So close... Can someone help me add quotes to a system command string. It like totally ignores the quotes.

Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>

using namespace std;

static string pcname;
static string domain;
static string userid;
static string process;


int main()
{
    cout << "Remote Process Kill Utility \n";
    cout << "------------------------------\n";
    cout << "Please Provide target hostname \n ->";
    cin >> pcname;
    
    cout << "\nDomain \n ->";
    cin >> domain;
    
    cout << "\nUser id \n ->";
    cin >> userid;
    
    cout << "\nProcess name *Example explorer.exe \n ->";
    cin >> process;
    
    system("cls");
    system("echo Loading..");
    system(("echo taskkill /s " + pcname + " /u " + domain + "\\" + userid + " /fi " + """username ne nt*""" + " /im " + process + "").c_str());
    system("pause");
    return 0;
}
output:

Taskkill /s pcname /u domain\userid /fi "username ne nt*" /IM process

I can't add the quotes between username and nt!! sooo close yet so far!!!
use sprintf to get everything into one string. For example:


Code:
char string[50];

sprintf(string, "echo taskkill /s   %s  /u  %s \\  %s  /fi username ne nt*  /im  %s ", pcname, domain, process);

system(string)
This way you can make your string the way you want it. When you see the function sprintf above and look at "%s". This means that you are going to replace the %s with a string, and after the comma I put in order the strings like pcname and stuff that you wanted where it said %s.
Sweet.. Would that accept quote marks? It's essential that the quotes is added otherwise the command won't work.

Taskkill /s pcname /u domain\userid /fi "username ne nt*" /IM process

Those quotes is what allows the command to go through successfully.
Quotes are made like this:

Code:
char* string = "We got \"Quotes\"";
"\" works!!!!! omg! SUCCESS!!!!! You guys are the best!


Code:
#include <windows.h>

using namespace std;

static string pcname;
static string domain;
static string userid;
static string process;

int main()
{
    cout << "Remote Process Kill Utility \n";
    cout << "------------------------------\n";
    cout << "Please Provide target hostname \n->";
    cin >> pcname;
    
    cout << "\nDomain \n->";
    cin >> domain;
    
    cout << "\nUser id \n->";
    cin >> userid;
    
    cout << "\nProcess name *Example explorer.exe \n->";
    cin >> process;
    
    system("cls");
    system("echo Loading..");
    system(("taskkill /s " + pcname + " /u " + domain + "\\" + userid + " /fi " + "\"username ne nt*\"" + " /im " + process + "").c_str());
    system("exit");
    return 0;
}
Open sourced!! I love it! Remote Process Elimination! Now I think i can fit other sweet commands in this... You guys rock!
You are very welcome. It is good that you are doing programs like this because you are learning more and more and eventually you will make epic stuff. Good luck.
I hope so! >.< I love it! I'm using it so much. I wish I can make a window application with this type of program instead of it being a bland cmd prompt. I also made a Remote Process Viewer which will record and log processes running in the background of a remote computer. I love it.

Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>

using namespace std;

static string pcname;
static string session;

int main()
{
    cout << "Please enter Session ID\n->";
    cin >> session;
    system("cls");
    cout << "Remote Process Viewer \n";
    cout << "------------------------\n";
    cout << "Please Provide Target Hostname\n->";
    cin >> pcname;
    
    system(("tasklist /s " + pcname + " /fo list >> Library\\Log_Session_" + session + ".log").c_str());
    system("cls");
    system("echo Please check Library for Results listed under your session id");
    system("pause");
    return EXIT_SUCCESS;
You will need to create a folder called Library with Remote Process Viewer.
Update!!

I included a cool option side to either eliminate via process or pid. Gotta love this.

Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>

using namespace std;

static string pcname;
static string domain;
static string userid;
static string processh;
static string pidn;
static string doover;
static string cnl;

int pid()
{
    cout << "Remote PID Kill Utility \n";
    cout << "------------------------------\n";
    cout << "Please Provide target hostname \n\n\n\n>";
    cin >> pcname;
    
    cout << "\nDomain \n->";
    cin >> domain;
    
    cout << "\nUser id \n->";
    cin >> userid;
    
    cout << "\nPID Number of Target process \n->";
    cin >> pidn;
    
    system("cls");
    system("echo Loading..");
    system(("taskkill /s " + pcname + " /u " + domain + "\\" + userid + " /fi " + "\"username ne nt*\"" + " /PID " + pidn + "").c_str());
    cout << "\necho Retry? Y / N";
    cin >> doover;
    if (doover == "Y" || doover == "y")
    {
               system("cls");
               pid();
    }
    else if (doover == "N" || doover == "n")
    {
         system("exit");
    }
}

int process()
{
    cout << "Remote Process Kill Utility \n";
    cout << "------------------------------\n";
    cout << "Please Provide target hostname \n>";
    cin >> pcname;
    
    cout << "\nDomain \n->";
    cin >> domain;
    
    cout << "\nUser id \n->";
    cin >> userid;
    
    cout << "\nProcess name *Example explorer.exe \n->";
    cin >> processh;
    
    system("cls");
    system("echo Loading..");
    system(("taskkill /s " + pcname + " /u " + domain + "\\" + userid + " /fi " + "\"username ne nt*\"" + " /im " + processh + "").c_str());
    cout << "\nRetry? Y / N";
    cin >> doover;
    if (doover == "Y" || doover == "y")
    {
               system("cls");
               process();
    }
    else if (doover == "N" || doover == "n")
    {
               system("exit");
    }
}

int main()
{
    SetConsoleTitle("Remote Process Killer");
    system("cls");
    system("color 0f");
    system("echo Please Select your Method of Process Removal");
    cout << "\n\n";
    system("echo Type 1 for Process ID\n");
    system("echo Type 2 for PID");
    cout << "\n\n\n>";
    cin >> cnl;
    
    if (cnl == "1")
    {
            system("cls");
            process();
    }
    else if (cnl == "2")
    {
            system("cls");
            pid();
    }
    return 0;
}
Feel free to trim it up or add to it if you feel! I love this.



OOOOh! I got an idea. Is there any way I can make this into an window application or is there any way I can turn the process viewer to show up in a separate window with the results of the processes instead of logs in a folder. I would like to minimize the amount of effort as possible.
Quote Originally Posted by xephora View Post
Update!!

I included a cool option side to either eliminate via process or pid. Gotta love this.

Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>

using namespace std;

static string pcname;
static string domain;
static string userid;
static string processh;
static string pidn;
static string doover;
static string cnl;

int pid()
{
    cout << "Remote PID Kill Utility \n";
    cout << "------------------------------\n";
    cout << "Please Provide target hostname \n\n\n\n>";
    cin >> pcname;
    
    cout << "\nDomain \n->";
    cin >> domain;
    
    cout << "\nUser id \n->";
    cin >> userid;
    
    cout << "\nPID Number of Target process \n->";
    cin >> pidn;
    
    system("cls");
    system("echo Loading..");
    system(("taskkill /s " + pcname + " /u " + domain + "\\" + userid + " /fi " + "\"username ne nt*\"" + " /PID " + pidn + "").c_str());
    cout << "\necho Retry? Y / N";
    cin >> doover;
    if (doover == "Y" || doover == "y")
    {
               system("cls");
               pid();
    }
    else if (doover == "N" || doover == "n")
    {
         system("exit");
    }
}

int process()
{
    cout << "Remote Process Kill Utility \n";
    cout << "------------------------------\n";
    cout << "Please Provide target hostname \n>";
    cin >> pcname;
    
    cout << "\nDomain \n->";
    cin >> domain;
    
    cout << "\nUser id \n->";
    cin >> userid;
    
    cout << "\nProcess name *Example explorer.exe \n->";
    cin >> processh;
    
    system("cls");
    system("echo Loading..");
    system(("taskkill /s " + pcname + " /u " + domain + "\\" + userid + " /fi " + "\"username ne nt*\"" + " /im " + processh + "").c_str());
    cout << "\nRetry? Y / N";
    cin >> doover;
    if (doover == "Y" || doover == "y")
    {
               system("cls");
               process();
    }
    else if (doover == "N" || doover == "n")
    {
               system("exit");
    }
}

int main()
{
    SetConsoleTitle("Remote Process Killer");
    system("cls");
    system("color 0f");
    system("echo Please Select your Method of Process Removal");
    cout << "\n\n";
    system("echo Type 1 for Process ID\n");
    system("echo Type 2 for PID");
    cout << "\n\n\n>";
    cin >> cnl;
    
    if (cnl == "1")
    {
            system("cls");
            process();
    }
    else if (cnl == "2")
    {
            system("cls");
            pid();
    }
    return 0;
}
Feel free to trim it up or add to it if you feel! I love this.



OOOOh! I got an idea. Is there any way I can make this into an window application or is there any way I can turn the process viewer to show up in a separate window with the results of the processes instead of logs in a folder. I would like to minimize the amount of effort as possible.

Spend time on Win32
Any book recommendation or video tutorials that you learned from? I see a bunch in buy.com, however the books are for different platforms such as windows NT or windows 2000.
Quote Originally Posted by xephora View Post
Any book recommendation or video tutorials that you learned from? I see a bunch in buy.com, however the books are for different platforms such as windows NT or windows 2000.
Google 'theforger win32 tutorial' -- that's a good online one. I'd link you directly, but it'd be a pain since I'm posting this from a phone.
If you want an actual book, the definitive Windows API guide is "Programming Windows" by Charles Petzold. I have it, and it's great.
Thanks alot I will definitely check the tutorial out! If i find that book I shall buy it as well! Sorry for the late reply!
Posts 1–12 of 12 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us