plunder 2.0.0a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,140 @@
1
+ //
2
+ // Plunder - SMB scanning and auditing tool
3
+ // Copyright (C) 2017 Joshua Stone
4
+ //
5
+ // This program is free software; you can redistribute it and/or
6
+ // modify it under the terms of the GNU General Public License
7
+ // as published by the Free Software Foundation; either version 2
8
+ // of the License, or (at your option) any later version.
9
+ //
10
+ // This program is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU General Public License
16
+ // along with this program; if not, write to the Free Software
17
+ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
+ //
19
+
20
+ #include "hash.h"
21
+
22
+ int score(char *string, int bins) {
23
+ unsigned long hash = 5381;
24
+ int c;
25
+ while((c = *string++)) {
26
+ hash = ((hash << 5) + hash) + c;
27
+ }
28
+ return hash % bins;
29
+ }
30
+
31
+ hash hash_init(uint32_t size) {
32
+ hash h;
33
+
34
+ h.bins = (cons **) malloc(size * sizeof(cons*));
35
+ h.count = 0;
36
+ h.size = size;
37
+
38
+ memset(h.bins, 0, size * sizeof(cons*));
39
+
40
+ return h;
41
+ }
42
+
43
+ cons *hash_get(hash h, char *s) {
44
+ uint32_t index = score(s, h.size);
45
+ if(h.bins[index] != NULL) {
46
+ return h.bins[index];
47
+ } else {
48
+ return 0;
49
+ }
50
+ }
51
+
52
+ void hash_put(hash *h, char *s, uint32_t value) {
53
+ uint32_t index = score(s, h->size);
54
+ cons *c;
55
+
56
+ c = (cons *) malloc(sizeof(cons));
57
+
58
+ c->index = value;
59
+ c->next = h->bins[index];
60
+
61
+ h->bins[index] = c;
62
+ h->count++;
63
+ }
64
+
65
+ void hash_info(hash h) {
66
+ int size =
67
+ sizeof(hash) +
68
+ sizeof(cons*) * h.size +
69
+ sizeof(cons) * h.count;
70
+
71
+ printf("\nHash Info:\n\n");
72
+
73
+ printf("Hash size: %d MB\n", megabytes(size));
74
+ printf("Hash bins: %d\n", h.size);
75
+ printf("Hash entries: %d\n", h.count);
76
+
77
+ putchar(10);
78
+ }
79
+
80
+ void hash_free(hash h) {
81
+ for(int i = 0; i < h.size; i++) {
82
+ cons *node = h.bins[i];
83
+ cons *next;
84
+ while(node) {
85
+ next = node->next;
86
+ free(node);
87
+ node = next;
88
+ }
89
+ }
90
+ }
91
+
92
+ int hash_count_nodes(hash h, int bin) {
93
+ int count = 0;
94
+ cons *node = h.bins[bin];
95
+ while(node) {
96
+ count++;
97
+ node = node->next;
98
+ }
99
+ return count;
100
+ }
101
+
102
+ void hash_write(hash h, FILE *fd) {
103
+ fwrite(&h, sizeof(hash), 1, fd);
104
+ for(uint32_t i = 0; i < h.size; i++) {
105
+ uint32_t count = hash_count_nodes(h, i);
106
+ if(count > 0) {
107
+ fwrite(&i, sizeof(uint32_t), 1, fd);
108
+ fwrite(&count, sizeof(uint32_t), 1, fd);
109
+
110
+ cons *node = h.bins[i];
111
+ while(node) {
112
+ fwrite(&node->index, sizeof(uint32_t), 1, fd);
113
+ node = node->next;
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ hash hash_read(FILE *fd) {
120
+ uint32_t bin, count;
121
+ hash h;
122
+
123
+ fread(&h, sizeof(hash), 1, fd);
124
+ h.bins = (cons **) malloc(h.size * sizeof(cons*));
125
+ memset(h.bins, 0, h.size * sizeof(cons*));
126
+
127
+ while(!feof(fd)) {
128
+ fread(&bin, sizeof(uint32_t), 1, fd);
129
+ fread(&count, sizeof(uint32_t), 1, fd);
130
+ for(; count > 0; count--) {
131
+ cons *node;
132
+ node = (cons *) malloc(sizeof(cons));
133
+ fread(&node->index, sizeof(uint32_t), 1, fd);
134
+ node->next = h.bins[bin];
135
+ h.bins[bin] = node;
136
+ }
137
+ }
138
+
139
+ return h;
140
+ }
@@ -0,0 +1,52 @@
1
+ //
2
+ // Plunder - SMB scanning and auditing tool
3
+ // Copyright (C) 2017 Joshua Stone
4
+ //
5
+ // This program is free software; you can redistribute it and/or
6
+ // modify it under the terms of the GNU General Public License
7
+ // as published by the Free Software Foundation; either version 2
8
+ // of the License, or (at your option) any later version.
9
+ //
10
+ // This program is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU General Public License
16
+ // along with this program; if not, write to the Free Software
17
+ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
+ //
19
+
20
+ #ifndef HASH_H
21
+ #define HASH_H
22
+
23
+ #include <stdint.h>
24
+ #include <stdlib.h>
25
+ #include <string.h>
26
+ #include <stdio.h>
27
+
28
+ #include "utilities.h"
29
+
30
+ #pragma pack(4)
31
+
32
+ typedef struct cons {
33
+ uint32_t index;
34
+ struct cons *next;
35
+ } cons;
36
+
37
+ typedef struct hash {
38
+ cons **bins;
39
+ uint32_t count;
40
+ uint32_t size;
41
+ } hash;
42
+
43
+ hash hash_init(uint32_t size);
44
+ cons *hash_get(hash h, char *s);
45
+ void hash_put(hash *h, char *s, uint32_t value);
46
+ void hash_info(hash h);
47
+ void hash_free(hash h);
48
+ int hash_count_nodes(hash h, int bin);
49
+ void hash_write(hash h, FILE *fd);
50
+ hash hash_read(FILE *fd);
51
+
52
+ #endif
@@ -0,0 +1,90 @@
1
+ //
2
+ // Plunder - SMB scanning and auditing tool
3
+ // Copyright (C) 2017 Joshua Stone
4
+ //
5
+ // This program is free software; you can redistribute it and/or
6
+ // modify it under the terms of the GNU General Public License
7
+ // as published by the Free Software Foundation; either version 2
8
+ // of the License, or (at your option) any later version.
9
+ //
10
+ // This program is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU General Public License
16
+ // along with this program; if not, write to the Free Software
17
+ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
+ //
19
+
20
+ #include <stdio.h>
21
+ #include <stdint.h>
22
+ #include <time.h>
23
+ #include <ctype.h>
24
+
25
+ #include "vault.h"
26
+ #include "utilities.h"
27
+ #include "hash.h"
28
+ #include "fsdb-c.h"
29
+
30
+ int main(int argc, char **argv) {
31
+ char line[1024];
32
+
33
+ printf("\nStarting FSDB test program\n");
34
+
35
+ fsdb f = fsdb_init(1 << 18);
36
+
37
+ printf("Vault starts at %p\n", f.strings.base);
38
+
39
+ FILE *in = fopen("../../data/test.log", "r");
40
+
41
+ while(fgets(line, 1023, in)) { // && count++ < 1000) {
42
+ line[strlen(line) - 1] = '/';
43
+ fsdb_insert_path(&f, line);
44
+ }
45
+
46
+ fclose(in);
47
+
48
+ hexdump(f.strings.base, 256);
49
+ hexdump(f.paths.base, 256);
50
+ hexdump(f.index.base, 256);
51
+
52
+ vault_info(f.strings, "String");
53
+ vault_info(f.paths, "Path");
54
+ vault_info(f.index, "Index");
55
+ hash_info(f.hash);
56
+
57
+ printf("Testing read of %d path names... ", f.count);
58
+ fflush(stdout);
59
+ clock_t start = clock();
60
+ for(int i = 1; i < f.count; i++) {
61
+ char *name = fsdb_get_id(f, i);
62
+ for(char *p = name; *p; p++) *p = tolower(*p);
63
+ if(strstr(name, "web.config")) {
64
+ puts(name);
65
+ }
66
+ free(name);
67
+ }
68
+ clock_t end = clock();
69
+ printf("done (%5.2f sec ).\n", (double)(end - start) / CLOCKS_PER_SEC);
70
+
71
+ printf("\nThere are %d paths in the system.\n", f.index.count);
72
+ printf("Type an index at the prompt to see a path.\n");
73
+ printf("^d at the prompt to exit.\n\n");
74
+
75
+ while(1) {
76
+ printf("\x1b[34;1mplunder \x1b[31;1m$\x1b[0m ");
77
+ fflush(stdout);
78
+
79
+ if(!fgets(line, 1023, stdin)) {
80
+ break;
81
+ }
82
+
83
+ char *name = fsdb_get_id(f, atoi(line));
84
+ printf("%s\n", name);
85
+ free(name);
86
+ }
87
+
88
+ putchar(10);
89
+ printf("Exiting FSDB test program\n\n");
90
+ }
@@ -0,0 +1,125 @@
1
+ //
2
+ // Plunder - SMB scanning and auditing tool
3
+ // Copyright (C) 2017 Joshua Stone
4
+ //
5
+ // This program is free software; you can redistribute it and/or
6
+ // modify it under the terms of the GNU General Public License
7
+ // as published by the Free Software Foundation; either version 2
8
+ // of the License, or (at your option) any later version.
9
+ //
10
+ // This program is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU General Public License
16
+ // along with this program; if not, write to the Free Software
17
+ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
+ //
19
+
20
+ #include "utilities.h"
21
+
22
+ // --------------------------------------------------------------
23
+ // Contents:
24
+ //
25
+ // 1. Hexdump utility
26
+ // 2. Numeric utilities
27
+ //
28
+ // --------------------------------------------------------------
29
+
30
+ // --------------------------------------------------------------
31
+ // 1. Hexdump utility
32
+ //
33
+ // The following code provides a color-coded hex dump utility
34
+ // so that in testing the program, the user can easily observe
35
+ // the contents of memory.
36
+ // --------------------------------------------------------------
37
+
38
+ #define PRINTABLE(c) (c >= ' ' && c <= '~')
39
+
40
+ #define COL_PREFIX "\x1b[38;5;"
41
+ #define COL_SUFFIX "m"
42
+ #define COL_RESET "\x1b[0m"
43
+
44
+ #define COL_NULL 243
45
+ #define COL_CTRL 209
46
+ #define COL_PUNCT 69
47
+ #define COL_NUMS 105
48
+ #define COL_CAPS 141
49
+ #define COL_MINS 177
50
+ #define COL_HYPER 76
51
+ #define COL_OTHER 231
52
+
53
+ int hexdump_cur_col = COL_OTHER;
54
+
55
+ int get_color(char c) {
56
+ if(c == 0) { return COL_NULL; } // NULLs are special
57
+ else if(c < ' ') { return COL_CTRL; } // control chars
58
+ else if(c < '0') { return COL_PUNCT; } // punctuation
59
+ else if(c < ':') { return COL_NUMS; } // numbers
60
+ else if(c < 'A') { return COL_PUNCT; } // more punctuation
61
+ else if(c < '[') { return COL_CAPS; } // capital letters
62
+ else if(c < 'a') { return COL_PUNCT; } // more punctuation
63
+ else if(c < '{') { return COL_MINS; } // miniscule letters
64
+ else if(c < 0x7f) { return COL_PUNCT; } // even more punctuation
65
+ else { return COL_HYPER; } // hyper-ASCII
66
+ }
67
+
68
+ void print_hex(char c) {
69
+ int color = get_color(c);
70
+
71
+ if(color != hexdump_cur_col) {
72
+ printf("%s%d%s", COL_PREFIX, color, COL_SUFFIX);
73
+ hexdump_cur_col = color;
74
+ }
75
+
76
+ printf("%02x ", c & 0xff);
77
+ }
78
+
79
+ void hexdump(void *ptr, uint32_t len) {
80
+ char *cursor;
81
+ char *end;
82
+ uint32_t offset;
83
+ char line[17];
84
+ int i;
85
+
86
+ line[16] = 0;
87
+ offset = 0;
88
+ end = ptr + len;
89
+
90
+ printf("\nHex dump starting at %p:\n\n", ptr);
91
+
92
+ for(cursor = (char *)ptr; cursor < end; ) {
93
+ memset(line, ' ', 16);
94
+ printf(" # %06x : ", offset);
95
+
96
+ for(i = 0; i < 16 && cursor < end; i++, cursor++, offset++) {
97
+ print_hex((*cursor) & 0xff);
98
+ line[i] = PRINTABLE(*cursor) ? *((char *)cursor) : '.';
99
+ }
100
+
101
+ for(; i < 16; i++) {
102
+ printf(" ");
103
+ }
104
+
105
+ printf(" %s[%s]\n", COL_RESET, line);
106
+ hexdump_cur_col = COL_OTHER;
107
+ }
108
+
109
+ putchar(10);
110
+ }
111
+
112
+ // --------------------------------------------------------------
113
+ // 2. Numeric utilities
114
+ //
115
+ // Functions for juggling numbers in C that can get annoying
116
+ // because of type casting, etc.
117
+ // --------------------------------------------------------------
118
+
119
+ float percentage(int a, int b) {
120
+ return 100.0 * (float) a / (float) b;
121
+ }
122
+
123
+ int megabytes(int bytes) {
124
+ return bytes >> 20;
125
+ }
@@ -0,0 +1,32 @@
1
+ //
2
+ // Plunder - SMB scanning and auditing tool
3
+ // Copyright (C) 2017 Joshua Stone
4
+ //
5
+ // This program is free software; you can redistribute it and/or
6
+ // modify it under the terms of the GNU General Public License
7
+ // as published by the Free Software Foundation; either version 2
8
+ // of the License, or (at your option) any later version.
9
+ //
10
+ // This program is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU General Public License
16
+ // along with this program; if not, write to the Free Software
17
+ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
+ //
19
+
20
+ #ifndef UTILITIES_H
21
+ #define UTILITIES_H
22
+
23
+ #include <stdint.h>
24
+ #include <stdio.h>
25
+ #include <stdlib.h>
26
+ #include <string.h>
27
+
28
+ void hexdump(void *ptr, uint32_t len);
29
+ float percentage(int a, int b);
30
+ int megabytes(int bytes);
31
+
32
+ #endif
@@ -0,0 +1,78 @@
1
+ //
2
+ // Plunder - SMB scanning and auditing tool
3
+ // Copyright (C) 2017 Joshua Stone
4
+ //
5
+ // This program is free software; you can redistribute it and/or
6
+ // modify it under the terms of the GNU General Public License
7
+ // as published by the Free Software Foundation; either version 2
8
+ // of the License, or (at your option) any later version.
9
+ //
10
+ // This program is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU General Public License
16
+ // along with this program; if not, write to the Free Software
17
+ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
+ //
19
+
20
+ #include "vault.h"
21
+
22
+ vault vault_init(uint32_t size) {
23
+ vault v;
24
+
25
+ v.base = (uint8_t *) malloc(size);
26
+ v.top = 4;
27
+ v.count = 0;
28
+ v.size = size;
29
+
30
+ memset(v.base, 0, size);
31
+
32
+ v.base[0] = 0xaa;
33
+ v.base[1] = 0xbb;
34
+ v.base[2] = 0xcc;
35
+ v.base[3] = 0xdd;
36
+
37
+ return v;
38
+ }
39
+
40
+ uint8_t *vault_get(vault v, uint32_t offset) {
41
+ return v.base + offset;
42
+ }
43
+
44
+ uint32_t vault_insert_bytes(vault *v, void *p, uint32_t bytes) {
45
+ uint8_t *location;
46
+
47
+ while(v->top + bytes >= v->size) {
48
+ v->size = v->size * 3 / 2;
49
+ v->base = (uint8_t *) realloc(v->base, v->size);
50
+ }
51
+
52
+ location = v->base + v->top;
53
+ memcpy(location, p, bytes);
54
+ v->top += bytes;
55
+ v->count += 1;
56
+
57
+ return location - v->base;
58
+ }
59
+
60
+ uint32_t vault_insert_string(vault *v, char *s) {
61
+ uint32_t len = strlen(s) + 1;
62
+
63
+ return vault_insert_bytes(v, s, len);
64
+ }
65
+
66
+ void vault_info(vault v, char *name) {
67
+ printf("\nVault '%s' Info:\n\n", name);
68
+ printf("Base Pointer: %p\n", v.base);
69
+ printf("Top index: %d\n", v.top);
70
+ printf("Entry count: %d\n", v.count);
71
+ printf("Buffer size: %d MB\n", megabytes(v.size));
72
+ printf("Capacity: %5.2f%%\n", percentage(v.top, v.size));
73
+ putchar(10);
74
+ }
75
+
76
+ void vault_free(vault v) {
77
+ free(v.base);
78
+ }