Skip to content

Commit 6021acb

Browse files
liuruikairk700
authored andcommitted
add option -e, -V; add pthread_join
1 parent 1630813 commit 6021acb

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/dirbuster-ng.c

+37-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ int parse_arguments(int argc, char **argv)
99
int index;
1010
int c;
1111
int opterr = 0;
12-
while ((c = getopt(argc, argv, "hqvw:d:n:t:X:K:u:U:W:")) != -1) {
12+
while ((c = getopt(argc, argv, "hqvVw:d:e:n:t:X:K:u:U:W:")) != -1) {
1313
switch (c) {
1414
case 'v':
1515
return;
@@ -25,6 +25,12 @@ int parse_arguments(int argc, char **argv)
2525
case 'd':
2626
conf0.dict = optarg;
2727
break;
28+
case 'e':
29+
conf0.ext = explode(optarg, ',');
30+
break;
31+
case 'V':
32+
conf0.verbose = 1;
33+
break;
2834
case 't':
2935
conf0.timeout = atoi(optarg);
3036
break;
@@ -148,6 +154,7 @@ void* dbng_engine(void* queue_arg)
148154
output("FOUND %s (response code %d)\n",trim(url),http_code);
149155
outputToFile("%s (HTTP code %d)\n",trim(url),http_code);
150156
}
157+
if(conf0.verbose) output("[%d] %s\n", http_code, trim(url));
151158
free(url);
152159
}
153160
curl_easy_cleanup(curl);
@@ -165,12 +172,31 @@ int load_dict(struct queue* db_queue) {
165172
exit(1);
166173
}
167174

168-
while (!feof(dict_fh)) {
175+
if(conf0.ext.nb_strings) {
176+
int i;
177+
while (!feof(dict_fh)) {
178+
if(!fgets(buffer,4096*sizeof(char),dict_fh)) break;
179+
size_t entry_len = strlen(buffer);
180+
//fgets would also store the trailing newline
181+
if(buffer[entry_len-1]=='\n') entry_len-=1;
182+
for(i=0; i<conf0.ext.nb_strings; ++i) {
183+
strncpy(buffer+entry_len, conf0.ext.strlist[i], 4096-entry_len);
184+
buffer[4096-1] = '\0';
185+
queue_add(db_queue,buffer);
186+
}
187+
}
188+
}
189+
else {
190+
while (!feof(dict_fh)) {
169191
fgets(buffer,4096*sizeof(char),dict_fh);
170192
//handling of recursion ??
171193
//( dup the queue to keep an initial copy, save found dirs)
172194
queue_add(db_queue,buffer);
195+
}
173196
}
197+
198+
free(buffer);
199+
strlfree(&(conf0.ext));
174200

175201
}
176202

@@ -186,6 +212,8 @@ int init_config(dbng_config* conf0) {
186212
conf0->proxy_auth = NULL;
187213
conf0->http_auth = NULL;
188214
conf0->output_file = NULL;
215+
conf0->ext = (stringlist){NULL, 0};
216+
conf0->verbose = 0;
189217
}
190218

191219
int init_workers(struct queue* db_queue) {
@@ -197,7 +225,11 @@ int init_workers(struct queue* db_queue) {
197225
for (i=0;i< conf0.nb_workers;i++) {
198226
ret = pthread_create(&conf0.workers[i],NULL,dbng_engine,(void*) db_queue);
199227
}
200-
228+
229+
void *res;
230+
for (i=0;i< conf0.nb_workers;i++) {
231+
ret = pthread_join(conf0.workers[i], &res);
232+
}
201233
}
202234

203235
int init_workloads(struct queue* db_queue) {
@@ -228,6 +260,7 @@ Options:\n -w <nb_threads>\tDefines the number of threads to use to make the att
228260
-X <proxy_server:port>\tUse an HTTP proxy server to perform the queries\n\
229261
-K <username:password>\tSets an username/password couple for proxy auth\n\
230262
-d <dict>\tLoads an external textfile to use as a dictionary\n\
263+
-e <ext>\tSpecify a list of extensions that would be appended to each word in the dict; seperated by comma\n\
231264
-t <seconds>\tSets the timeout in seconds for each http query\n\
232265
-W <file>\t Saves the program's result inside a file\n\
233266
-u <ua>\tuse a predefined user-agent, corresponding to the most used browsers/crawlers:\n\
@@ -244,6 +277,7 @@ Options:\n -w <nb_threads>\tDefines the number of threads to use to make the att
244277
\t\tbspid: Baidu Spider\n\
245278
-q\t Enable quiet mode (relevent only with the -W flag)\n\
246279
-h\t Prints this help then exits\n\
280+
-V \t Verbose. Print each request url and response code\n\
247281
-v\t Prints the program version then exits\n");
248282

249283
exit(0);

src/dirbuster-ng_config.h

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <pthread.h>
22
#include <stdio.h>
3+
#include "utils.h"
34

45
typedef struct dbng_config {
56

@@ -15,5 +16,7 @@ typedef struct dbng_config {
1516
char* proxy_auth;
1617
char* http_auth;
1718
FILE* output_file;
19+
stringlist ext;
20+
uint8_t verbose;
1821

1922
} dbng_config;

0 commit comments

Comments
 (0)