-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharguments.cpp
More file actions
161 lines (143 loc) · 5.29 KB
/
arguments.cpp
File metadata and controls
161 lines (143 loc) · 5.29 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <iostream>
#include <cstring>
using namespace std;
void showhelp() {
cout << "Version: " << version << "\n"
<< "Usage: dirforce -u/--host [host] -w/--wordlist [wordlist.txt]\n\n"
<< "\033[1;37mOptions: \033[0;37m\n"
<< " -u or -host: Specifies the host (required).\n"
<< " -w or -wordlist: Specifies the wordlist (required).\n"
<< " -t or -thread: Specifies the number of threads to create.\n"
<< " -m or -method: Specifies the HTTP method.\n"
<< " -r or -request: Specifies to import the request from a file.\n"
<< " -s or -suffixe: Adds a string at the beginning of every path in the wordlist.\n"
<< " -p or -preffixe: Adds a string at the end of every path in the wordlist.\n"
<< " --custom-header-o: Outputs a specific header value.\n"
<< " -e or -extension: Adds an extension after each word in the wordlist (e.g., -e php,html will send requests to word, word.php, and word.html).\n"
<< " -f or -filter: Hides responses that contain the specified string.\n"
<< " --lite: Outputs in lite mode (complete URL, no color, no logo).\n"
<< " --norobot: Disables the use of the robots.txt file.\n"
<< "\033[1;37mDocumentation:\033[0;37m https://github.com/guendouzaimed/dirforce\n"
<< "Please report any bug or issue in the tool.";
exit(0);
}
int arguments(int argc, char* argv[])
{
//set default variable
http_method = "HEAD"; custom_header_str = "Content-Length";
sslOption = 0; threadCounter = 30; requestOption = 0;
extension.push_back("");
for (int i = 1; i < argc; i++){
if (strncmp(argv[i], "-u", 2) == 0 || strncmp(argv[i], "--host", 5) == 0){
if (i + 1 < argc) {
host = argv[i + 1];
i++;
}
}
if (strncmp(argv[i], "-w", 2) == 0 || strncmp(argv[i], "--wordlist", 10) == 0){
if (i + 1 < argc){
wordlistfile = argv[i + 1];
i++;
}
}
if (strncmp(argv[i], "-t", 2) == 0 || strncmp(argv[i], "--thread", 8) == 0){
if (i + 1 < argc){
threadCounter = stoi(argv[i + 1]);
i++;
}
}
if (strncmp(argv[i], "-m", 2) == 0 || strncmp(argv[i], "--method", 8) == 0){
if (i + 1 < argc){
http_method = argv[i + 1];
i++;
}
}
if (strncmp(argv[i], "-r", 2) == 0 || strncmp(argv[i], "--request", 9) == 0){
if (i + 1 < argc){
requestOption = 1;
string line;
ifstream requestfile(argv[i+1]);
while (getline(requestfile, line)) {
readrequest += line + "\n";
}
readrequest += "\n";
i++;
}
}
if (strncmp(argv[i], "-s", 2) == 0 || strncmp(argv[i], "--suffixe", 9) == 0){
if (i + 1 < argc){
suffixe = argv[i + 1];
i++;
}
}
if (strncmp(argv[i], "-p", 2) == 0 || strncmp(argv[i], "--preffixe", 10) == 0){
if (i + 1 < argc){
preffixe = argv[i + 1];
i++;
}
}
if (strncmp(argv[i], "--custom-header-o", 17) == 0){
if (i + 1 < argc){
custom_header_str = argv[i + 1];
i++;
}
}
if (strncmp(argv[i], "-e", 2) == 0 || strncmp(argv[i], "--extension", 11) == 0){
if (i + 1 < argc){
string str = argv[i + 1];
stringstream ss(str);
string ext;
while(getline(ss, ext, ',')) {
extension.push_back("." + ext);
}
i++;
}
}
if (strncmp(argv[i], "-f", 2) == 0 || strncmp(argv[i], "--filter", 8) == 0){
if (i + 1 < argc){
filterOption = true;
filterStr = argv[i + 1];
}
}
if (strncmp(argv[i], "--lite", 6) == 0) {
liteOutput = true;
}
if (strncmp(argv[i], "--norobot", 9) == 0) {
robotxtOption = false;
}
if (strncmp(argv[i], "-h", 2) == 0 || strncmp(argv[i], "--help", 6) == 0){
showhelp();
}
}
if (host.find("https") == string::npos) {
if (host.find("http") == string::npos) {
sslOption = 0;
} else {
sslOption = 0;
host = host.substr(7);
}
} else {
sslOption = 1;
host = host.substr(8);
}
size_t slash_index = host.find("/");
if(slash_index == string::npos) {
//*host = *host
address = "/";
} else if (slash_index == host.size() - 1) {
host = host.substr(0, slash_index);
address = "/";
//cout << "2";
} else if (slash_index != host.size()) {
if (host[host.size() - 1] == '/') {//4
address = host.substr(slash_index);
host = host.substr(0, slash_index);
//cout << "4";
} else {
//cout << "3";
address = host.substr(slash_index) + "/";
host = host.substr(0, slash_index);
}
}
return 0;
}