Skip to content

Instantly share code, notes, and snippets.

@su8
Created May 23, 2022 21:29
Show Gist options
  • Select an option

  • Save su8/4ff3c8de5bf58a301c61846730c08b1a to your computer and use it in GitHub Desktop.

Select an option

Save su8/4ff3c8de5bf58a301c61846730c08b1a to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include "json.hpp"
static void do_help(const std::string &str);
static void do_cat(const std::string &str);
static void do_whoami(const std::string &str);
static void do_nmap(const std::string &str);
static void do_scan(const std::string &str);
static void do_connect(const std::string &str);
static void do_crackssh(const std::string &str);
static inline void processInput(const std::string &str);
struct Opt
{
const char *cmd;
void (*my_func)(const std::string &str);
};
struct Opt opt[] = {
{"ls", do_ls},
{"help", do_help},
{"cat", do_cat},
{"whoami", do_whoami},
{"nmap", do_nmap},
{"scan", do_scan},
{"connect", do_connect},
{"crackssh", do_crackssh}};
int main(void)
{
while (1)
{
std::string userInput;
getline(std::cin, userInput);
std::cout << "> " << userInput << '\n';
if (userInput.size() == 0)
{
continue;
}
if (userInput == "exit")
{
break;
}
processInput(userInput);
}
return EXIT_SUCCESS;
}
static inline void processInput(const std::string &str)
{
unsigned short int x = 0;
char buf[256] = {'\0'};
char matchCmd = 0;
const char *strPtr = str.c_str();
char *bufPtr = buf;
for (; x < sizeof(opt[0]) / sizeof(struct Opt); x++)
{
if (!(strcmp(opt[x].cmd, strPtr)))
{
matchCmd = 1;
break;
}
if (matchCmd == 1)
{
for (x = 0; x < 255 || *strPtr; x++, strPtr++)
{
if (*strPtr == '"' || *strPtr == '\'')
{
continue;
}
*bufPtr++ = *strPtr;
}
*bufPtr = '\0';
opt[x].my_func((std::string)buf);
}
}
}
static void do_help(const std::string &str)
{
(void)str;
static const char helpMsg[] = "ls: lists all directories and files in the current directory"
"cat: reads the contents of the given file"
"cat file.txt"
"\n"
"Networking:"
"scan: shows computers linked to the current computer"
"connect: connects to the given IP"
"connect IP"
"whoami: shows your own computer"
"\n"
"Security:"
"nmap: shows a list of the open ports of given ip"
"\n"
"Misc:"
"help: shows this helpful help page";
puts(helpMsg);
}
static void do_cat(const std::string &str)
{
}
static void do_whoami(const std::string &str)
{
puts("frost@localhost 1.1.1.1");
}
static void do_nmap(const std::string &str)
{
}
static void do_scan(const std::string &str)
{
}
static void do_connect(const std::string &str)
{
}
static void do_crackssh(const std::string &str)
{
}
static void do_ls(const std::string &str)
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment