-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.cpp
54 lines (46 loc) · 1.87 KB
/
file.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <cstdlib>
#include <array>
#include <memory>
#include <stdexcept>
#include <string>
void executeShellCommand(const std::string &command) {
int result = system(command.c_str());
if (result != 0) {
std::cerr << "Error executing command: " << command << std::endl;
}
}
std::string getCommandOutput(const std::string &command) {
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, int (*)(FILE*)> pipe(popen(command.c_str(), "r"), pclose);
if (!pipe) {
throw std::runtime_error("popen() failed!");
}
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
return result;
}
int main() {
try {
// Set the locale for character type functions to C
if (setlocale(LC_CTYPE, "C") == NULL) {
std::cerr << "Error setting locale to C" << std::endl;
return 1;
}
// Generate a random string of alphabetic characters and save it to cc.txt
executeShellCommand("cat /dev/urandom | tr -dc '[:alpha:]' | fold -w 1000 | head -n 1 > cc.txt");
// Create an encrypted zip archive containing cc.txt
executeShellCommand("zip -e cctest.zip cc.txt");
// Display the first 64 bytes of the cctest.zip file in hexadecimal format
std::string xxdOutput = getCommandOutput("xxd -l64 cctest.zip");
std::cout << "Hex dump of the first 64 bytes of cctest.zip:\n" << xxdOutput << std::endl;
// Attempt to crack the password of cctest.zip using fcrackzip
std::string fcrackzipOutput = getCommandOutput("fcrackzip -v -u -D -p ~/wordlists/rockyou.txt cctest.zip");
std::cout << "fcrackzip output:\n" << fcrackzipOutput << std::endl;
} catch (const std::exception &e) {
std::cerr << "An error occurred: " << e.what() << std::endl;
}
return 0;
}