├── LICENSE
├── README.md
├── build
├── Makefile
├── afterinstall.sh
└── beforeremove.sh
└── src
├── Makefile
├── colors.h
├── helpers.c
├── helpers.h
├── helpers.o
├── main.c
├── main.h
├── main.o
├── shareenum
├── smb.c
├── smb.h
├── smb.o
├── smbresult.c
├── smbresult.h
└── smbresult.o
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | shareenum Copyright (C) 2014 Lucas Morris and Crowe Horwath LLP
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | shareenum
2 | ==
3 |
4 | This is a tool that attempts to enumerate the permissions shares, directories, and files on Microsoft Windows systems. Using an implementation of the Samba (http://www.samba.org/) libsmbclient libraries this tool makes a SMB connection to a host and recursively gathers information over the file and directory entities, compared to several other share enumeration tools that use RPC calls to gather similar information. Both ways work, this was a bit easier to implement and ends up being a lot faster.
5 |
6 | ```sh
7 | shareenum -o output.csv -u DOMAIN\\username -p Password1 192.168.1.1
8 | ```
9 |
10 | License
11 | --
12 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/
17 |
18 | Command Line Arguments
19 | --
20 | Usage: shareenum -o FILE TARGET
21 |
22 | | Option | Description | Default |
23 | | --- | --- | --- |
24 | | TARGET | Full path or a file of paths to list the shares, files and directories within. Can be just an IP, a hostname, or even a full path inside a share, such as smb://COOL-DC.DOMAIN/NETLOGON. | |
25 | |-o FILE | File to write results to in CSV format. | |
26 | |-u USER | Username, otherwise go anonymous. If using a domain, it should be in the format of DOMAIN\\user. | Null Session |
27 | |-p PASS | Password, otherwise go anonymous. This can be a NTLM has in the format LMHASH:NTLMHASH. If so, we'll pass the hash. | Null Session |
28 | |-r NUM | How many levels into the share or directory should we go. Depending on the setting, this can pull a listing of every file and directory. | No Recursion |
29 | |-t NUM | Seconds to wait before connection timeout. | 3 seconds |
30 | |-s NUM | In the event that the scan needs restarted, skip the first NUM lines in the input file. All output will be appended to the output file so previous results will not be lost. | First Line |
31 | |-d NUM | How many seconds should we wait between each target. | No Delay |
32 |
33 | > TARGET and FILE are required.
34 |
35 | Download
36 | --
37 | We have provided deb binary files for Kali Linux to aid with installation. These binary files include both shareenum itself, as well as the correct Samba versions of the libraries to allow Shareenum to execute. You can download the latest releases here:
38 |
39 | https://github.com/emperorcow/shareenum/releases
40 |
41 | Installation
42 | --
43 | To install these binaries, its as simple as:
44 |
45 | ```sh
46 | dpkg -i shareenum_version.deb
47 | ```
48 |
49 | Make sure that you get the correct version for your system (i386 for 32bit and amd64 for 64bit).
50 |
51 |
52 |
--------------------------------------------------------------------------------
/build/Makefile:
--------------------------------------------------------------------------------
1 | GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always)
2 | SAMBAROOT=/usr/local/samba/lib
3 | BINFILE=../src/shareenum
4 | DSTDIR=/usr/local/shareenum
5 |
6 | install:
7 | mkdir -p $(DSTDIR)/bin/
8 | cp $(BINFILE) $(DSTDIR)/bin/
9 |
10 | deb:
11 | fpm -s dir -t deb -n "shareenum" -v $(GIT_VERSION) --before-remove beforeremove.sh --after-install afterinstall.sh --url https://github.com/emperorcow/shareenum --description "Tool for gathering permissions from MS shares" $(DSTDIR)/
12 |
13 | libprep:
14 | mkdir -p $(DSTDIR)/lib/
15 | cp /usr/lib/x86_64-linux-gnu/libsmbclient.so.0 $(DSTDIR)/lib/
16 | cp /usr/lib/x86_64-linux-gnu/libsamba-util.so.0 $(DSTDIR)/lib/
17 | cp $(SAMBAROOT)/private/libreplace.so $(DSTDIR)/lib/
18 | cp $(SAMBAROOT)/private/libmsrpc3.so $(DSTDIR)/lib/
19 | cp $(SAMBAROOT)/private/liblibcli_lsa3.so $(DSTDIR)/lib/
20 | cp $(SAMBAROOT)/private/liblibsmb.so $(DSTDIR)/lib/
21 | cp $(SAMBAROOT)/private/libsamba-security.so $(DSTDIR)/lib/
22 | cp $(SAMBAROOT)/private/liberrors.so $(DSTDIR)/lib/
23 | cp $(SAMBAROOT)/libsmbconf.so.0 $(DSTDIR)/lib/
24 | cp $(SAMBAROOT)/libndr.so.0 $(DSTDIR)/lib/
25 | cp $(SAMBAROOT)/private/libgse.so $(DSTDIR)/lib/
26 | cp $(SAMBAROOT)/libndr-standard.so.0 $(DSTDIR)/lib/
27 | cp $(SAMBAROOT)/private/libdcerpc-samba.so $(DSTDIR)/lib/
28 | cp $(SAMBAROOT)/private/libcli_smb_common.so $(DSTDIR)/lib/
29 | cp $(SAMBAROOT)/private/libutil_cmdline.so $(DSTDIR)/lib/
30 | cp $(SAMBAROOT)/private/libsmbregistry.so $(DSTDIR)/lib/
31 | cp $(SAMBAROOT)/private/libsecrets3.so $(DSTDIR)/lib/
32 | cp $(SAMBAROOT)/private/libtevent.so.0 $(DSTDIR)/lib/
33 | cp $(SAMBAROOT)/private/libndr-samba.so $(DSTDIR)/lib/
34 | cp $(SAMBAROOT)/libsamba-credentials.so.0 $(DSTDIR)/lib/
35 | cp $(SAMBAROOT)/private/libsamba-sockets.so $(DSTDIR)/lib/
36 | cp $(SAMBAROOT)/libdcerpc-binding.so.0 $(DSTDIR)/lib/
37 | cp $(SAMBAROOT)/private/libcliauth.so $(DSTDIR)/lib/
38 | cp $(SAMBAROOT)/libgensec.so.0 $(DSTDIR)/lib/
39 | cp $(SAMBAROOT)/libtevent-util.so.0 $(DSTDIR)/lib/
40 | cp $(SAMBAROOT)/private/libsamba3-util.so $(DSTDIR)/lib/
41 | cp $(SAMBAROOT)/libwbclient.so.0 $(DSTDIR)/lib/
42 | cp $(SAMBAROOT)/private/libcli_cldap.so $(DSTDIR)/lib/
43 | cp $(SAMBAROOT)/private/libkrb5samba.so $(DSTDIR)/lib/
44 | cp $(SAMBAROOT)/private/libcom_err-samba4.so.0 $(DSTDIR)/lib/
45 | cp $(SAMBAROOT)/private/libasn1util.so $(DSTDIR)/lib/
46 | cp $(SAMBAROOT)/libsamba-hostconfig.so.0 $(DSTDIR)/lib/
47 | cp $(SAMBAROOT)/libndr-nbt.so.0 $(DSTDIR)/lib/
48 | cp $(SAMBAROOT)/private/libsmb_transport.so $(DSTDIR)/lib/
49 | cp $(SAMBAROOT)/private/libCHARSET3.so $(DSTDIR)/lib/
50 | cp $(SAMBAROOT)/private/libinterfaces.so $(DSTDIR)/lib/
51 | cp $(SAMBAROOT)/private/libccan.so $(DSTDIR)/lib/
52 | cp $(SAMBAROOT)/private/libdbwrap.so $(DSTDIR)/lib/
53 | cp $(SAMBAROOT)/private/libutil_tdb.so $(DSTDIR)/lib/
54 | cp $(SAMBAROOT)/private/libutil_reg.so $(DSTDIR)/lib/
55 | cp $(SAMBAROOT)/private/libsmbd_shim.so $(DSTDIR)/lib/
56 | cp $(SAMBAROOT)/private/libutil_setid.so $(DSTDIR)/lib/
57 | cp $(SAMBAROOT)/private/libtdb-wrap.so $(DSTDIR)/lib/
58 | cp $(SAMBAROOT)/private/libserver-role.so $(DSTDIR)/lib/
59 | cp $(SAMBAROOT)/private/libkrb5-samba4.so.26 $(DSTDIR)/lib/
60 | cp $(SAMBAROOT)/private/libaddns.so $(DSTDIR)/lib/
61 | cp $(SAMBAROOT)/private/libgssapi-samba4.so.2 $(DSTDIR)/lib/
62 | cp $(SAMBAROOT)/private/libauthkrb5.so $(DSTDIR)/lib/
63 | cp $(SAMBAROOT)/private/libcli-nbt.so $(DSTDIR)/lib/
64 | cp $(SAMBAROOT)/private/libldb.so.1 $(DSTDIR)/lib/
65 | cp $(SAMBAROOT)/private/libsamdb-common.so $(DSTDIR)/lib/
66 | cp $(SAMBAROOT)/private/libldbsamba.so $(DSTDIR)/lib/
67 | cp $(SAMBAROOT)/private/libsamba-modules.so $(DSTDIR)/lib/
68 | cp $(SAMBAROOT)/libsamdb.so.0 $(DSTDIR)/lib/
69 | cp $(SAMBAROOT)/private/libwinbind-client.so $(DSTDIR)/lib/
70 | cp $(SAMBAROOT)/private/libcli-ldap-common.so $(DSTDIR)/lib/
71 | cp $(SAMBAROOT)/private/libasn1-samba4.so.8 $(DSTDIR)/lib/
72 | cp $(SAMBAROOT)/private/libutil_ntdb.so $(DSTDIR)/lib/
73 | cp $(SAMBAROOT)/private/libntdb.so.0 $(DSTDIR)/lib/
74 | cp $(SAMBAROOT)/private/libheimbase-samba4.so.1 $(DSTDIR)/lib/
75 | cp $(SAMBAROOT)/private/libhx509-samba4.so.5 $(DSTDIR)/lib/
76 | cp $(SAMBAROOT)/private/libhcrypto-samba4.so.5 $(DSTDIR)/lib/
77 | cp $(SAMBAROOT)/private/libroken-samba4.so.19 $(DSTDIR)/lib/
78 | cp $(SAMBAROOT)/private/libwind-samba4.so.0 $(DSTDIR)/lib/
79 | cp $(SAMBAROOT)/libndr-krb5pac.so.0 $(DSTDIR)/lib/
80 | cp $(SAMBAROOT)/private/libauth_sam_reply.so $(DSTDIR)/lib/
81 | cp $(SAMBAROOT)/private/libflag_mapping.so $(DSTDIR)/lib/
82 | cp $(SAMBAROOT)/private/libtdb.so.1 $(DSTDIR)/lib/
83 | echo "Done."
84 |
--------------------------------------------------------------------------------
/build/afterinstall.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | SRC="/usr/local/shareenum/bin/shareenum"
3 | DST="/usr/bin/shareenum"
4 | if [ -f $DST ]; then
5 | rm $DST
6 | fi
7 | ln -s $SRC $DST
8 |
--------------------------------------------------------------------------------
/build/beforeremove.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | BINFILE="/usr/bin/shareenum"
3 | if [ -f $BINFILE ]; then
4 | rm /usr/bin/shareenum
5 | fi
6 |
--------------------------------------------------------------------------------
/src/Makefile:
--------------------------------------------------------------------------------
1 | GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always)
2 |
3 | CC=gcc
4 | CFLAGS=-DGIT_VERSION=\"$(GIT_VERSION)\" -I.
5 | LDFLAGS=-Wl,-lsmbclient -ltalloc -ltdb -ldl
6 |
7 | SOURCES=helpers.c smbresult.c smb.c main.c
8 | OBJECTS=$(SOURCES:.c=.o)
9 |
10 | all: shareenum
11 |
12 | debug: CFLAGS += -g -O0 -DDEBUG -lresolv
13 | debug: shareenum
14 |
15 | %.o: %.c
16 | $(CC) -c $< -o $@ $(CFLAGS)
17 |
18 | shareenum: $(OBJECTS)
19 | $(CC) -o shareenum $(OBJECTS) $(LDFLAGS)
20 |
21 | clean:
22 | rm shareenum *.o
23 |
--------------------------------------------------------------------------------
/src/colors.h:
--------------------------------------------------------------------------------
1 | /* To colorize the output strings we can use "ANSI codes on linux
2 | * Using these defines to make it easier across the board for
3 | * everyone, plus make it easier to change if we want.
4 | */
5 |
6 | #define ANSI_COLOR_BOLDBLACK "\x1b[1;30m"
7 | #define ANSI_COLOR_BLACK "\x1b[1;30m"
8 | #define ANSI_COLOR_BOLDRED "\x1b[1;31m"
9 | #define ANSI_COLOR_RED "\x1b[0;31m"
10 | #define ANSI_COLOR_BOLDGREEN "\x1b[1;32m"
11 | #define ANSI_COLOR_GREEN "\x1b[0;32m"
12 | #define ANSI_COLOR_BOLDYELLOW "\x1b[1;33m"
13 | #define ANSI_COLOR_YELLOW "\x1b[0;33m"
14 | #define ANSI_COLOR_BOLDBLUE "\x1b[1;34m"
15 | #define ANSI_COLOR_BLUE "\x1b[0;34m"
16 | #define ANSI_COLOR_BOLDMAGENTA "\x1b[1;35m"
17 | #define ANSI_COLOR_MAGENTA "\x1b[0;35m"
18 | #define ANSI_COLOR_BOLDCYAN "\x1b[1;36m"
19 | #define ANSI_COLOR_CYAN "\x1b[0;36m"
20 | #define ANSI_COLOR_BOLDWHITE "\x1b[1;37m"
21 | #define ANSI_COLOR_WHITE "\x1b[1;37m"
22 | #define ANSI_COLOR_RESET "\x1b[0m"
23 |
24 |
--------------------------------------------------------------------------------
/src/helpers.c:
--------------------------------------------------------------------------------
1 | #include "helpers.h"
2 |
3 | int file_countlines(FILE * fh ) {
4 | int nlines = 0;
5 | int partial = 0;
6 | char buf[10] = "";
7 |
8 | //Reset the file back to the beginning so we can count.
9 | rewind(fh);
10 |
11 | //Loop through the file and pull down the size of the buffer.
12 | while ( fgets( buf, sizeof(buf), fh ) != NULL ) {
13 | //If we have a newline char in the buffer, increase the counter
14 | if ( strchr(buf,'\n') ) {
15 | nlines++;
16 | partial = 0;
17 | //Otherwise we need to account for the fact that we may have a
18 | //partial line at the end
19 | } else {
20 | partial = 1;
21 | }
22 | }
23 |
24 | //Return us back to the beginning of the file. Might not be
25 | //the best idea, but this function will not be used in
26 | //this program for doing to the middle of a while.
27 | rewind(fh);
28 | return nlines += partial;
29 | }
30 |
31 | int file_exists(const char * filename) {
32 | //See if we can access the filename. F_OK is just an existence test
33 | //it doesn't check any permissions.
34 | if(access(filename, F_OK) != -1) {
35 | return 1;
36 | }
37 | return 0;
38 | }
39 |
40 | int numdigits(int n) {
41 | int c = 0;
42 |
43 | //Loop until we have no digits left in N.
44 | while(n!=0) {
45 | //Divide by 10 and increment our counter.
46 | n/=10;
47 | ++c;
48 | }
49 | return c;
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/src/helpers.h:
--------------------------------------------------------------------------------
1 | #include //Standard GNU IO Lib
2 | #include //"Strings" as if C had them, just helper functions
3 | #include //The GNU Standard Library
4 | #include //Unix system standard libraries
5 |
6 | /* Get the number of lines that are in a file. Attempts to count as
7 | * efficiently as possible and should be somewhat compiler optimized.
8 | *
9 | * PARAMETERS:
10 | * FILE - Pointer to a C file handle. Will be reset to the beginning
11 | * Position of the file after this is run.
12 | *
13 | * RETURN (int): Number of lines in the file.
14 | */
15 | int file_countlines(FILE * fh);
16 |
17 | /* Determines if a file exists within the filesystem path.
18 | *
19 | * PARAMETERS:
20 | * char * - Pointer to a string containing the path to
21 | * the target file.
22 | *
23 | * RETURN (int): 0 if the file does not exist, 1 if it does.
24 | */
25 | int file_exists(const char * filename);
26 |
27 | /* Determine the number of digits in an integer
28 | *
29 | * PARAMETERS:
30 | * int - Number to test
31 | *
32 | * RETURN (int): The number of digits in the integer.
33 | */
34 | int numdigits(int n);
35 |
--------------------------------------------------------------------------------
/src/helpers.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CroweCybersecurity/shareenum/db728dda2097a759232b9cc860c2dd58dd2360c7/src/helpers.o
--------------------------------------------------------------------------------
/src/main.c:
--------------------------------------------------------------------------------
1 | #include "main.h"
2 |
3 | const char banner[] = ANSI_COLOR_BOLDBLUE" _____ "ANSI_COLOR_RED" _ "ANSI_COLOR_BOLDYELLOW" "ANSI_COLOR_BOLDBLUE" "ANSI_COLOR_GREEN" "ANSI_COLOR_RED" _____\n"\
4 | ANSI_COLOR_BOLDBLUE" / ___|"ANSI_COLOR_RED"| | "ANSI_COLOR_BOLDYELLOW" "ANSI_COLOR_BOLDBLUE" "ANSI_COLOR_GREEN" "ANSI_COLOR_RED"| ___|\n"\
5 | ANSI_COLOR_BOLDBLUE" \\ `--. "ANSI_COLOR_RED"| |__ "ANSI_COLOR_BOLDYELLOW" __ _ "ANSI_COLOR_BOLDBLUE" _ __ "ANSI_COLOR_GREEN" ___ "ANSI_COLOR_RED"| |__ _ __ _ _ _ __ ___\n"\
6 | ANSI_COLOR_BOLDBLUE" `--. \\"ANSI_COLOR_RED"| '_ \\ "ANSI_COLOR_BOLDYELLOW" / _` |"ANSI_COLOR_BOLDBLUE"| '__|"ANSI_COLOR_GREEN" / _ \\"ANSI_COLOR_RED"| __| | '_ \\ | | | || '_ ` _ \\\n"\
7 | ANSI_COLOR_BOLDBLUE" /\\__/ /"ANSI_COLOR_RED"| | | |"ANSI_COLOR_BOLDYELLOW"| (_| |"ANSI_COLOR_BOLDBLUE"| | "ANSI_COLOR_GREEN"| __/"ANSI_COLOR_RED"| |___ | | | || |_| || | | | | |\n"\
8 | ANSI_COLOR_BOLDBLUE" \\____/ "ANSI_COLOR_RED"|_| |_|"ANSI_COLOR_BOLDYELLOW" \\__,_|"ANSI_COLOR_BOLDBLUE"|_| "ANSI_COLOR_GREEN" \\___|"ANSI_COLOR_RED"\\____/ |_| |_| \\__,_||_| |_| |_|\n"\
9 | ANSI_COLOR_RESET;
10 |
11 | int main(int argc, char * argv[]) {
12 | FILE * outfile;
13 | char * target = NULL;
14 | int linedelay = 0; // -r command line option
15 | int recursion = 0; // -r command line option
16 | int startline = 0; // -s command line argument
17 | int c; //For getopt
18 | const char * l; //For length of the hash, if we got one
19 | char hash[33]; //To store our hash if the user gave us.
20 |
21 | //Print a header so we know the versions
22 | fprintf(stdout, "%s", banner);
23 | #ifdef DEBUG
24 | fprintf(stdout, ANSI_COLOR_BOLDWHITE"%*s %s-DEBUG\n\n"ANSI_COLOR_RESET, 61-strlen(GIT_VERSION), "Version", GIT_VERSION);
25 | #else
26 | fprintf(stdout, ANSI_COLOR_BOLDWHITE"%*s %s\n\n"ANSI_COLOR_RESET, 67-strlen(GIT_VERSION), "Version", GIT_VERSION);
27 | #endif
28 |
29 |
30 | /*************************************************************************************
31 | * COMMAND LINE ARGUMENTS
32 | ************************************************************************************/
33 |
34 | /* Get all of our command line options with GetOpt
35 | * Basically, here we use getopt to loop through the arguments
36 | * It will pull one argument letter at a time and then
37 | * we use a case statement to process only that argument and
38 | * its value out to things. Mostly just setting variables,
39 | * maybe doing some processing
40 | */
41 | opterr = 0;
42 | while ((c = getopt(argc, argv, "r:n:o:t:d:u:p:s:")) != -1) {
43 | switch (c) {
44 | case 'u': //Get the username
45 | gUsername = optarg;
46 | break;
47 | case 'p': //Get the password, but check if its a hash first.
48 | //Get the length of the string quickly.
49 | for (l = optarg; *l; ++l);
50 |
51 | //If the length is 65 (LM:NL) and there's a : in the right place
52 | if((l - optarg) == 65 && optarg[32] == ':') {
53 | //Copy over the last 32 characters into a temp buffer
54 | strncpy(hash, optarg + 33, 32);
55 |
56 | //Make sure the last character is a null
57 | //because we're good C programmers
58 | hash[32] = '\0';
59 |
60 | //Set the value of hash to our global
61 | gPassword = hash;
62 |
63 | //And set the "bool" to true as well.
64 | gPassIsHash = 1;
65 | } else {
66 | //If its not a hash, just set the password.
67 | gPassword = optarg;
68 | }
69 |
70 | break;
71 | case 'r': //How deep are we going?
72 | recursion = atoi(optarg);
73 | break;
74 | case 'd': //How many seconds are we waiting between targets.
75 | linedelay = atoi(optarg);
76 | break;
77 | case 't': //How many seconds are we timing out.
78 | gTimeout = atoi(optarg);
79 | break;
80 | case 's': //What line in the file should we start at
81 | //Added because its a useful feature that McAtee
82 | //thought up and the program kept crashing after
83 | //a while during testing.
84 | startline = atoi(optarg);
85 | break;
86 | case 'o': //What is our output file.
87 | //Open the file
88 | outfile = fopen (optarg, "a");
89 | //Turn off buffering of the output file so McAtee
90 | //can get his tail on instantly.
91 | setvbuf(outfile , NULL , _IONBF , 0);
92 | break;
93 | case '?': //If getopt doesn't know what the character is it comes here.
94 | if (isprint (optopt))
95 | //Yell at the user for being dumb and giving us
96 | //something we don't want.
97 | fprintf(stderr, "Unknown option '-%c'.\n", optopt);
98 |
99 | usage();
100 |
101 | return 1;
102 | default:
103 | abort();
104 | }
105 | }
106 |
107 | /*************************************************************************************
108 | * CHECK AND SETUP
109 | ************************************************************************************/
110 |
111 | //Get the target (IP or file) from the last item in argv. Optind
112 | //is from getopt telling us where it stopped.
113 | target = argv[optind];
114 |
115 | //If target isn't set, complain because its mandatory.
116 | if(target == NULL) {
117 | fprintf(stderr, ANSI_COLOR_BOLDRED "ERROR: No target specified!\n" ANSI_COLOR_RESET);
118 | usage();
119 | exit(1);
120 | }
121 |
122 | //If the outfile didn't open properly or isn't set, yell because its mandatory.
123 | if(outfile == NULL) {
124 | fprintf(stderr, ANSI_COLOR_BOLDRED "ERROR: No output file specified!\n" ANSI_COLOR_RESET);
125 | usage();
126 | exit(1);
127 | }
128 |
129 | //Tell the user what creds we're using, if any. Because we want to make sure they know.
130 | fprintf(stdout, "\n");
131 | fprintf(stdout, ANSI_COLOR_BOLDGREEN "Username: " ANSI_COLOR_RESET "%s\n", gUsername);
132 | if(gPassIsHash == 1)
133 | fprintf(stdout, ANSI_COLOR_BOLDGREEN "Hash: " ANSI_COLOR_RESET "%s\n", gPassword);
134 | else
135 | fprintf(stdout, ANSI_COLOR_BOLDGREEN "Password: " ANSI_COLOR_RESET "%s\n", gPassword);
136 | fprintf(stdout, "\n");
137 |
138 | //If debugging is on, print out the other variables we got on the cmd line.
139 | #ifdef DEBUG
140 | fprintf(stdout, "Target: %s\n", argv[optind]);
141 | fprintf(stdout, "Start Point: %d\n", startline);
142 | #endif
143 |
144 | //Wait three seconds because McAtee
145 | sleep(3);
146 |
147 | //Try and turn off buffering on stdout.
148 | setbuf(stdout, NULL);
149 |
150 | /*************************************************************************************
151 | * RUNNING OF SHARES
152 | ************************************************************************************/
153 |
154 | if(startline == 0) //If we're starting at 0, print the headers.
155 | fprintf(outfile, "\"USER\",\"HOST\",\"SHARE\",\"OBJECT\",\"TYPE\",\"PRINCIPAL\",\"NTFS_PERMISSIONS\",\"HIDDEN\"\n");
156 |
157 | smbresultlist *head = NULL; //Struct to hold the results info
158 |
159 | //If the target we got is a file.
160 | if(file_exists(target)) {
161 | FILE *infile = fopen ( target, "r" ); //Open the file
162 | int current = 0; //Set a counter for where we're at in the file
163 | int total = file_countlines(infile); //Count the total number of lines in the file
164 | char infile_buf[1024]; //And a buffer to read the file into!
165 |
166 | if ( infile != NULL ) { //If our input file loaded properly...
167 | while ( fgets ( infile_buf, sizeof(infile_buf), infile ) != NULL ) { //Read our file one line at a time into the buffer
168 | current++; //We did it! Increment where we're at
169 |
170 | if(current < startline) continue; //Go ahead and skip until we get the line we want if set.
171 |
172 | if (infile_buf[strlen(infile_buf) - 1] == '\n') { //Check to make sure that our file doesn't have any newlines or returns
173 | infile_buf[strlen(infile_buf) - 1] = '\0';
174 | }
175 | if (infile_buf[strlen(infile_buf) - 1] == '\r') {
176 | infile_buf[strlen(infile_buf) - 1] = '\0';
177 | }
178 |
179 |
180 | head = runtarget(infile_buf, recursion); //Run the target and get results
181 | printsmbresultlist(head, outfile, infile_buf, current, total);
182 | }
183 | } else {
184 | perror ( target ); //If the file didn't load, print the error.
185 | }
186 |
187 | sleep(linedelay); //We'll delay as long as our user asked.
188 |
189 | //Otherwise we'll assume our target is an IP or hostname and won't do anything fancy
190 | } else {
191 |
192 | head = runtarget(target, recursion); //Run the target and get results
193 | printsmbresultlist(head, outfile, target, 1, 1);
194 | }
195 |
196 | fclose(outfile); //Close our file handle, because we're good programmers
197 | }
198 |
199 | int printsmbresultlist(smbresultlist *head, FILE *outfile, char *target, int cur, int total) {
200 | uint headlen = 0; //Hold the length of our linked list at output time.
201 | int totallen = numdigits(total); //And the number of digits in that total for pretty output
202 | smbresult *tmp; //Item to hold the temp results as we loop through objects
203 | char *outbuf; //Output buffer to hold some stuff.
204 | int numsuccess = 0;
205 | int numerror = 0;
206 |
207 |
208 | headlen = smbresultlist_length(head);
209 |
210 | fprintf(stdout, ANSI_COLOR_BOLDBLUE "(%*d/%d) " ANSI_COLOR_BOLDCYAN "%-25s " ANSI_COLOR_RESET, totallen, cur, total, target);
211 |
212 | while(smbresultlist_pop(&head, &tmp)) { //Loop through the llist of results and put them in tmp
213 | char *token;
214 |
215 | if(tmp->statuscode > 0) {
216 | fprintf(outfile, "\"%s\",\"%s\",\"%s\",\"\",\"\",\"\",\"%s (Code: %d)\",\"\"\n", gUsername, tmp->host, tmp->share, strerror(tmp->statuscode), tmp->statuscode);
217 | numerror++;
218 | } else {
219 | token = strtok(tmp->acl, ",");
220 | while(token != NULL) {
221 | if(smbresult_tocsv(*tmp, &outbuf, token) > 0) { //Convert tmp to a CSV
222 | fprintf(outfile, "\"%s\",%s\n", gUsername, outbuf); //Print it to our file
223 | fflush(outfile);
224 | }
225 | token = strtok(NULL, ",");
226 | }
227 | numsuccess++;
228 | }
229 | }
230 |
231 | //Now we print a message to the user so they know sutff is happening
232 | if(numerror == 0 && numsuccess > 0) { //Only success
233 | fprintf(stdout, "[" ANSI_COLOR_GREEN "x" ANSI_COLOR_RESET "] Got information on %d objects.\n", numsuccess);
234 | } else if (numerror > 0 && numsuccess == 0) { //Only errors
235 | if(numerror == 1) { //Give the user the error directly if there's only 1
236 | fprintf(stdout, "[" ANSI_COLOR_RED "!" ANSI_COLOR_RESET "] Error (%d): %s\n", tmp->statuscode, strerror(tmp->statuscode));
237 | } else {
238 | fprintf(stdout, "[" ANSI_COLOR_RED "!" ANSI_COLOR_RESET "] Errors on %d objects.\n", numerror);
239 | }
240 | } else if (numerror > 0 && numsuccess > 0) { //Both success and error
241 | fprintf(stdout, "[" ANSI_COLOR_BOLDYELLOW "*" ANSI_COLOR_RESET "] Got %d objects with errors on %d.\n", numsuccess, numerror);
242 | } else { //No success or errors, we got nothing.
243 | fprintf(stdout, "[" ANSI_COLOR_MAGENTA "!" ANSI_COLOR_RESET "] Received no information.\n");
244 | }
245 |
246 | free(tmp);
247 | }
248 |
249 | //If you don't get this, try again harder
250 | void usage() {
251 | printf("Usage: shareenum -o FILE TARGET\n");
252 | printf(" TARGET - REQUIRED Full path or a file of paths to list the shares, files\n");
253 | printf(" and directories within. Can be just an IP, a hostname, or even a\n");
254 | printf(" full path inside a share, such as smb://COOL-DC.DOMAIN/NETLOGON.\n");
255 | printf(" -o FILE - REQUIRED File to write results to in CSV format.\n");
256 | printf(" -u USER - Username, otherwise go anonymous. If using a domain, it should\n");
257 | printf(" be in the format of DOMAIN\\\\user.\n");
258 | printf(" -p PASS - Password, otherwise go anonymous. This can be a NTLM has in\n");
259 | printf(" the format LMHASH:NTLMHASH. If so, we'll pass the hash.\n");
260 | printf(" -r NUM - How many levels into the share or directory should we go.\n");
261 | printf(" Depending on the setting, this can pull a listing of every file\n");
262 | printf(" and directory. (Default: None)\n");
263 | printf(" -t NUM - Seconds to wait before connection timeout. (Default: 3s)\n");
264 | printf(" -s NUM - In the event that the scan needs restarted, skip the first NUM\n");
265 | printf(" lines in the input file. All output will be appended to the\n");
266 | printf(" output file so previous results will not be lost. (Default: 0)\n");
267 | printf(" -d NUM - How many seconds should we wait between each target. (Default: 0)\n");
268 | }
269 |
--------------------------------------------------------------------------------
/src/main.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include "helpers.h"
6 | #include "colors.h"
7 | #include "smb.h"
8 |
9 | /* Globals for the options we got from the command line.
10 | * These are most likely going to be externs in other C
11 | * files and should be considered READ ONLY!
12 | */
13 | char * gUsername = NULL;
14 | char * gPassword = NULL;
15 | int gPassIsHash = 0;
16 | int gTimeout = 0;
17 |
18 | /* Print the usage
19 | *
20 | * PARAMETERS: none
21 | * RETURN: none
22 | */
23 | void usage();
24 |
--------------------------------------------------------------------------------
/src/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CroweCybersecurity/shareenum/db728dda2097a759232b9cc860c2dd58dd2360c7/src/main.o
--------------------------------------------------------------------------------
/src/shareenum:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CroweCybersecurity/shareenum/db728dda2097a759232b9cc860c2dd58dd2360c7/src/shareenum
--------------------------------------------------------------------------------
/src/smb.c:
--------------------------------------------------------------------------------
1 | #include "smb.h"
2 |
3 | smbresultlist* runtarget(char *target, int maxdepth) {
4 | SMBCCTX *context;
5 | char buf[256];
6 | smbresultlist *res = NULL;
7 |
8 | //Try to create a context, if it's null that means we failed, so let the user know.
9 | if((context = create_context()) == NULL) {
10 | smbresult *tmp = createSMBResultEmpty();
11 | parse_smburl(target, &tmp->host, &tmp->share, &tmp->object);
12 | tmp->statuscode = errno;
13 | smbresultlist_push(&res, tmp);
14 | return res;
15 | }
16 |
17 | //Check to see if the target has smb:// in front, if not add it.
18 | if(strncmp("smb://", target, 6) != 0) {
19 | snprintf(buf, sizeof(buf), "smb://%s", target);
20 | } else {
21 | strncpy(buf, target, strlen(target) + 1);
22 | }
23 |
24 | //Browse to our file and get the goods
25 | res = browse(context, buf, maxdepth, 0);
26 |
27 | //Delete our context, so there's less segfaults.
28 | delete_context(context);
29 | return res;
30 | }
31 |
32 | static smbresultlist* browse(SMBCCTX *ctx, char *path, int maxdepth, int depth) {
33 | SMBCFILE *fd;
34 | struct smbc_dirent *dirent;
35 |
36 | char fullpath[2560] = "";
37 |
38 | char acl[1024] = "";
39 | int aclret;
40 |
41 | char mode[128] = "";
42 | int moderet;
43 |
44 | smbresultlist *thisresults = NULL;
45 | smbresultlist *subresults = NULL;
46 |
47 |
48 | //Try and get a directory listing of the object we just opened.
49 | //This could be a workgroup, server, share, or directory and
50 | //we'll get the full listing. If it doesn't work, return our error.
51 | //Errors will happen a lot in normal usage due to access denied.
52 | if ((fd = smbc_getFunctionOpendir(ctx)(ctx, path)) == NULL) {
53 | smbresult *tmp = createSMBResultEmpty();
54 | parse_smburl(path, &tmp->host, &tmp->share, &tmp->object);
55 | tmp->statuscode = errno;
56 | smbresultlist_push(&thisresults, tmp);
57 | return thisresults;
58 | }
59 |
60 | //Get the current entity of the directory item we're working on.
61 | while ((dirent = smbc_getFunctionReaddir(ctx)(ctx, fd)) != NULL) {
62 | smbresult *thisresult = createSMBResultEmpty();
63 |
64 | //Check to see if what we're working on is blank, or one of the
65 | //special directory characters. If so, skip them.
66 | if(strcmp(dirent->name, "") == 0) continue;
67 | if(strcmp(dirent->name, ".") == 0) continue;
68 | if(strcmp(dirent->name, "..") == 0) continue;
69 |
70 | //Create the full path for this object by concating it with the
71 | //parent path.
72 | sprintf(fullpath, "%s/%s", path, dirent->name);
73 |
74 | //Parse out the various parts of the path for pretty output.
75 | parse_smburl(fullpath, &thisresult->host, &thisresult->share, &thisresult->object);
76 |
77 | //Set the type so we have it
78 | thisresult->type = dirent->smbc_type;
79 |
80 | //Get the "dos_attr.mode" extended attribute which is the file permissions.
81 | moderet = smbc_getFunctionGetxattr(ctx)(ctx, fullpath, "system.dos_attr.mode", &mode, sizeof(mode));
82 | if(moderet == -1 && errno == 13) {
83 | thisresult->mode = -1;
84 | } else {
85 | //The ACL is returned as a string pointer, but we need to convert it to a long so we can
86 | //do binary comparison on the settings eventually.
87 | thisresult->mode = strtol(acl, NULL, 16);
88 | }
89 |
90 | //Get the ACL ACEs for the NTFS permissions. The + is so we lookup SIDs to names
91 | aclret = smbc_getFunctionGetxattr(ctx)(ctx, fullpath, "system.nt_sec_desc.acl.*+", acl, sizeof(acl));
92 | if(aclret < 0) {
93 | char permerrbuf[100];
94 | sprintf(permerrbuf, "Unable to pull permissions (%d): %s", errno, strerror(errno));
95 | thisresult->acl = strdup(permerrbuf);
96 | thisresult->statuscode = errno;
97 | } else {
98 | thisresult->acl = strdup(acl);
99 | }
100 |
101 | smbresultlist_push(&thisresults, thisresult);
102 |
103 | //If we have a directory or share we want to recurse to our max depth
104 | if(depth < maxdepth) {
105 | switch (thisresult->type) {
106 | case SMBC_FILE_SHARE:
107 | case SMBC_DIR:
108 | subresults = browse(ctx, fullpath, maxdepth, depth++);
109 | smbresultlist_merge(&thisresults, &subresults);
110 | }
111 | }
112 | }
113 |
114 |
115 | //Try to close the directory that we had opened. If it failed, it'll return > 0.
116 | if(smbc_getFunctionClosedir(ctx)(ctx, fd) > 0) {
117 | smbresult *tmp = createSMBResultEmpty();
118 | parse_smburl(path, &tmp->host, &tmp->share, &tmp->object);
119 | tmp->statuscode = errno;
120 | smbresultlist_push(&thisresults, tmp);
121 | }
122 |
123 | //Finally, we're done, lets return to the user.
124 | return thisresults;
125 | }
126 |
127 | size_t smbresult_tocsv(smbresult data, char **buf, char *ace) {
128 | if(data.statuscode < 0) {
129 | return 0;
130 | }
131 |
132 | //parsehidden returns 0 or 1, so we need a quick if statement
133 | char hidden = ' ';
134 | if(parse_hidden(data.mode))
135 | hidden = 'X';
136 |
137 | //We need to parse the access entry, here are the variables we'll use to hold them
138 | char * principal = "";
139 | unsigned int atype = 0;
140 | unsigned int aflags = 0;
141 | unsigned int amask = 0;
142 |
143 | //Parse the entry, if we can't then just quit because we got bad data.
144 | if(ace != NULL) {
145 | if(parse_acl(ace, &principal, &atype, &aflags, &amask) == 0) {
146 | return 0;
147 | }
148 | }
149 |
150 | //We need to determine the length of our new string
151 | size_t size = snprintf(NULL, 0, "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%c\"",
152 | data.host,
153 | data.share,
154 | data.object,
155 | parse_type(data.type),
156 | principal,
157 | parse_accessmask(amask),
158 | hidden
159 | );
160 |
161 | //Otherwise, just a simple sprintf to the buffer the user gave us.
162 | char *buffer = malloc(size+1);
163 | snprintf(buffer, size+1, "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%c\"",
164 | data.host,
165 | data.share,
166 | data.object,
167 | parse_type(data.type),
168 | principal,
169 | parse_accessmask(amask),
170 | hidden
171 | );
172 |
173 | *buf = strdup(buffer);
174 |
175 | free(buffer);
176 |
177 | return size+1;
178 | }
179 |
180 | void parse_smburl(char *url, char **host, char **share, char **object) {
181 | char buf[2048];
182 | char *token;
183 | char *last;
184 | const char sep[2] = "/";
185 |
186 | //Zero out our buffer to make sure we don't have any stray characters later
187 | memset(buf, 0, sizeof(buf));
188 |
189 | //Remove the protocol from the URL
190 | if(strncmp("smb://", url, 6) == 0)
191 | strncpy(buf, url+6, strlen(url) - 5);
192 | else
193 | strncpy(buf, url, strlen(url));
194 |
195 | //Tokenize the URL by /, get the first one, it should be our host.
196 | token = strtok(buf, sep);
197 | if(token == NULL)
198 | return;
199 | *host = strdup(token);
200 |
201 | //Get the second one, it should be our share
202 | token = strtok(NULL, sep);
203 | if(token == NULL)
204 | return;
205 | *share = strdup(token);
206 |
207 | //Finally, we take the rest of the string and its our object path
208 | *object = strdup(token + strlen(token) + 1);
209 | }
210 |
211 | char* parse_type(int type) {
212 | //We need to translate the type to something readable for our output
213 | switch(type) {
214 | case -1:
215 | return "ERROR";
216 | case SMBC_WORKGROUP:
217 | return "WORKGROUP";
218 | case SMBC_SERVER:
219 | return "SERVER";
220 | case SMBC_FILE_SHARE:
221 | return "FILE_SHARE";
222 | case SMBC_PRINTER_SHARE:
223 | return "PRINTER_SHARE";
224 | case SMBC_COMMS_SHARE:
225 | return "COMMS_SHARE";
226 | case SMBC_IPC_SHARE:
227 | return "IPC_SHARE";
228 | case SMBC_DIR:
229 | return "DIR";
230 | case SMBC_FILE:
231 | return "FILE";
232 | case SMBC_LINK:
233 | return "LINK";
234 | default:
235 | return "UNKNOWN";
236 | }
237 | }
238 |
239 | int parse_acl(const char * ace, char ** princ, unsigned int * i1, unsigned int * i2, unsigned int * i3) {
240 | unsigned int *atype = i1;
241 | unsigned int *aflags = i2;
242 | unsigned int *amask = i3;
243 |
244 | char *p = strchr(ace, ':');
245 | if(!p) {
246 | return 0;
247 | }
248 | *p = '\0';
249 | p++;
250 |
251 | *princ = malloc(strlen(ace) + 1);
252 | if(!*princ) {
253 | return 0;
254 | }
255 | strcpy(*princ, ace);
256 |
257 | if(sscanf(p, "%u/%u/%x", atype, aflags, amask) == 3) {
258 | return 1;
259 | } else {
260 | return 0;
261 | }
262 | }
263 |
264 | char * parse_accessmask(unsigned int acl) {
265 | char tmpaccess[128] = "";
266 |
267 | if(acl & ACCESS_FILE_READ_DATA)
268 | strcat(tmpaccess, "READ|");
269 | if(acl & ACCESS_FILE_WRITE_DATA)
270 | strcat(tmpaccess, "WRITE|");
271 | if(acl & ACCESS_FILE_APPEND_DATA)
272 | strcat(tmpaccess, "APPEND|");
273 | if(acl & ACCESS_FILE_READ_EA)
274 | strcat(tmpaccess, "READEA|");
275 | if(acl & ACCESS_FILE_WRITE_EA)
276 | strcat(tmpaccess, "WRITEEA|");
277 | if(acl & ACCESS_FILE_EXECUTE)
278 | strcat(tmpaccess, "EXECUTE|");
279 | if(acl & ACCESS_STANDARD_DELETE)
280 | strcat(tmpaccess, "DELETE|");
281 |
282 | if(tmpaccess[strlen(tmpaccess)-1] == '|') {
283 | tmpaccess[strlen(tmpaccess)-1] = '\0';
284 | }
285 |
286 | return strdup(tmpaccess);
287 | }
288 |
289 | uint parse_hidden(long acl) {
290 | //Check to see if the hidden flag is set, if so lets return it
291 | if (acl & SMBC_DOS_MODE_HIDDEN)
292 | return 1;
293 | else
294 | return 0;
295 | }
296 |
297 | static void auth_fn(
298 | const char *pServer,
299 | const char *pShare,
300 | char *pWorkgroup,
301 | int maxLenWorkgroup,
302 | char *pUsername,
303 | int maxLenUsername,
304 | char *pPassword,
305 | int maxLenPassword) {
306 |
307 | //Get our external globals that we got from the command line
308 | extern char *gUsername;
309 | extern char *gPassword;
310 |
311 | //We're always going to operate on a blank workgroup of WORKGROUP
312 | char workgroup[256] = { '\0' };
313 |
314 | //Get the username, if its set, from the globals we set in the main.
315 | if(gUsername != NULL)
316 | strncpy(pUsername, gUsername, maxLenUsername - 1);
317 |
318 | //Same with the the password. If its a hash, it'll also just be a string.
319 | if(gPassword != NULL)
320 | strncpy(pPassword, gPassword, maxLenPassword - 1);
321 |
322 | //Finally copy our blank workgroup over also.
323 | strncpy(pWorkgroup, workgroup, maxLenWorkgroup - 1);
324 | }
325 |
326 | static SMBCCTX* create_context(void) {
327 | SMBCCTX *ctx;
328 | extern int gTimeout;
329 | extern int gPassIsHash;
330 |
331 | //Create the Samba context struct , if it didn't work quit.
332 | if((ctx = smbc_new_context()) == NULL)
333 | return NULL;
334 |
335 | #ifdef DEBUG
336 | //Set the options for our context. a
337 | //If its enabled at the command line, turn on Samba library debugging
338 | smbc_setDebug(ctx, 1);
339 |
340 | //We want to log our errors to STDERR instead of STDOUT
341 | smbc_setOptionDebugToStderr(ctx, 1);
342 | #endif
343 |
344 | //set protocols
345 | smbc_setOptionProtocols(ctx, "CORE", "SMB3");
346 |
347 | //Set the function that the Samba library will call when it needs
348 | //to authenticate
349 | smbc_setFunctionAuthData(ctx, auth_fn);
350 | //Set the timeout, we get the command line option as seconds and the
351 | //function takes milliseconds.
352 | smbc_setTimeout(ctx, 200);
353 | //If we got a hash at the command line, let the context know we're
354 | //giving it a hash
355 | smbc_setOptionUseNTHash(ctx, gPassIsHash);
356 |
357 | //Initialize our context with the options that we have set or null on fail.
358 | if(smbc_init_context(ctx) == NULL) {
359 | smbc_free_context(ctx, 1);
360 | return NULL;
361 | }
362 |
363 | return ctx;
364 | }
365 |
366 | static void delete_context(SMBCCTX *ctx) {
367 | //Trying to fix the error: no talloc stackframe at ../source3/libsmb/cliconnect.c:2637, leaking memory
368 | //TALLOC_CTX *frame = talloc_stackframe();
369 |
370 | //First we need to purge the cache of servers the context has.
371 | //This should also free all the used memory allocations.
372 | smbc_getFunctionPurgeCachedServers(ctx)(ctx);
373 |
374 | //We're done with the frame, free it up now.
375 | //TALLOC_FREE(frame);
376 |
377 | //Next we need to free the context itself, and free all the
378 | //memory it used.
379 | smbc_free_context(ctx, 1);
380 | }
381 |
382 |
383 |
--------------------------------------------------------------------------------
/src/smb.h:
--------------------------------------------------------------------------------
1 | #include //Unix standard libraries
2 | #include //Directory entities
3 | #include //Error numbers and information
4 | #include //C "string" library
5 | #include //GNU standard library
6 | #include //Enable C99 booleans for the talloc stuff in samba
7 | #include //Samba client headers
8 | #include //Samba TALLOC stack
9 | #include "smbresult.h"
10 |
11 | /* Run a check against a host. This creates a Samba context, browses to the path
12 | * creates a result object, and then clears the context after its finished.
13 | *
14 | * PARAMETERS:
15 | * char * - Pointer to a string containing the full path to our target.
16 | * int - How deep into the structure should we go.
17 | *
18 | * RETURN (smb_result): The result of our run of this host.
19 | */
20 | smbresultlist* runtarget(char *target, int maxdepth);
21 |
22 | /* Takes a smbresult object and converts it to a string formatted in CSV
23 | * formatting including field terminators in the format:
24 | * "host","share","object","type","permissions","hidden"
25 | * PARAMETERS:
26 | * data - The smbresult containing the data to format.
27 | * buf - Pointer to the string buffer where we should put the output.
28 | * ace - An access control entry string in the format PRINCIPAL:TYPE/FLAGS/MASK
29 | * RETURN (size_t): The size of the string we put in buf. 0 if error
30 | */
31 | size_t smbresult_tocsv(smbresult data, char **buf, char *ace);
32 |
33 | /* This is the function that browses a system and attempts to list all of the shares.
34 | *
35 | * PARAMETERS:
36 | * SMBCCTX * - Pointer to the samba context that should be used during browse
37 | * char * - The path to browse. Should be something like "smb://IP -or- HOST/.
38 | * If you give it a share it'll list the directories but can also do
39 | * printers, files, directories, etc.
40 | * int - How many levels down should be go.
41 | * int - What is the current depth that we're at.
42 | *
43 | * RETURN (smb_result): The result of our run on this host. Will be aggregated if
44 | * recursion is in use.
45 | */
46 | static smbresultlist* browse(SMBCCTX *ctx, char *path, int maxdepth, int depth);
47 |
48 | /* Parse out a smb uri string into its various components. Should typically be in
49 | * the format of: smb://TARGET/SHARE/DIRECTORY/FILE
50 | *
51 | * PARAMETERS:
52 | * char * - The current URL including all of the info we're splitting up
53 | * char * - The host or IP that we're operating against.
54 | * char * - The name of the share, printer, etc. that we've found.
55 | * char * - The full path of the current object that we're browsing.
56 | * RETURN (void): None
57 | */
58 | void parse_smburl(char *url, char **host, char **share, char **object);
59 |
60 | /* Parse the type (Dir, File, etc.) of targeted object into something human readable
61 | * PARAMETERS:
62 | * uint - The smbc_type of the current object
63 | * RETURN (char *): The human readable name of the type
64 | */
65 | char * parse_type(int type);
66 |
67 | /* Parse the ACL and determine the type of access we have (write, read only, etc.)
68 | * PARAMETERS:
69 | * ace - The access control entity string in the format Principle:Type/Flag/Access Mask
70 | * print - Pointer to the string for the user principle
71 | * atype - Pointer to the int that will hold the access mask type
72 | * aflags - Pointer to hold the bitmask of ACE flags
73 | * amask - Pointer to hold the access mask
74 | * RETURN (int): 1 if we were successful, 0 if we failed
75 | */
76 | int parse_acl(const char * ace, char ** princ, unsigned int * atype, unsigned int * aflags, unsigned int * amask);
77 |
78 | /* Parse the access mask into a string that can be output
79 | * PARAMETERS:
80 | * amask - The bitmask of access flags to parse
81 | * RETURN (char *): A string containing all of the access values
82 | */
83 | char * parse_accessmask(unsigned int amask);
84 |
85 | /* Parse the ACL to determine if the hidden flag is set
86 | * PARAMETERS:
87 | * long - An ACL that we have received from Samba, represented as a series of bytes
88 | * RETURN (char *): A string containing our human readable access
89 | */
90 | uint parse_hidden(long acl);
91 |
92 | /* The authentication function that will be passed into the Samba context. Whenever
93 | * it needs to authenticate it will call this function to get the data we need.
94 | * The variables are the username, server info, share, etc. that we may authenticate
95 | * with and are set by reference for samba.
96 | *
97 | * PARAMETERS:
98 | * These parameters are defined and set by the Samba libraries and cannot be changed.
99 | * They are mostly self explanatory and represent pointers to the various buffers
100 | * that need to have information added for authentication.
101 | */
102 | static void auth_fn( const char *pServer,
103 | const char *pShare,
104 | char *pWorkgroup,
105 | int maxLenWorkgroup,
106 | char *pUsername,
107 | int maxLenUsername,
108 | char *pPassword,
109 | int maxLenPassword);
110 |
111 | /* Create a Samba context for us to handle all of our connections with. This will pull
112 | * several options from extern global variables set in the main function from the
113 | * command line.
114 | *
115 | * PARAMETERS: None
116 | *
117 | * RETURN (SMBCCTX *): Pointer to the samba context we have created.
118 | */
119 | static SMBCCTX* create_context(void);
120 |
121 | /* This will delete the a Samba context, clear the set of cached hosts that were stored
122 | * in memory, and then free the context's used memory.
123 | *
124 | * PARAMETERS:
125 | * SMBCCTX * - Pointer to the Samba context that should be freed.
126 | *
127 | * RETURN (void): None
128 | */
129 | static void delete_context(SMBCCTX *ctx);
130 |
131 |
132 | /* ACE TYPE CONSTANTS
133 | * Constants for the type field within ACE strings
134 | */
135 | #define ACE_TYPE_ALLOW 0
136 | #define ACE_TYPE_DENY 1
137 |
138 | /* ACE FLAG CONSTANTS
139 | * Flags within the ACE strings
140 | */
141 | #define ACE_FLAG_OBJECT_INHERIT 1
142 | #define ACE_FLAG_CONTAINER_INHERIT 2
143 | #define ACE_FLAG_NO_PROPAGATE_INHERIT 4
144 | #define ACE_INHERIT_ONLY 8
145 | #define ACE_INHERITED 16
146 |
147 | /* ACCESS MASK CONSTANTS
148 | *
149 | * Generic access rights
150 | *
151 | * These are required by all object types and are mapped to a set
152 | * of general or generic standard/object specific access rights
153 | * which are shown in the in-line comments
154 | *
155 | * Bytes 28-31 - Generic Items
156 | * Bytes 25-27 - Unused / Reserved
157 | * Byte 24 - SACL
158 | */
159 | #define ACCESS_GENERIC_READ 0x80000000 //FILE_READ_ATTRIBUTES && FILE_READ_DATA && FILE_READ_EA && STANDARD_RIGHTS_READ && SYNCHRONIZE
160 | #define ACCESS_GENERIC_WRITE 0x40000000 //FILE_APPEND_DATA && FILE_WRITE_ATTRIBUTES && FILE_WRITE_DATA && FILE_WRITE_EA && STANDARD_RIGHTS_WRITE && SYNCHRONIZE
161 | #define ACCESS_GENERIC_EXECUTE 0x20000000 //FILE_EXECUTE && FILE_READ_ATTRIBUTES && STANDARD_RIGHTS_EXECUTE && SYNCHRONIZE
162 | #define ACCESS_GENERIC_ALL 0x10000000 //GENERIC_READ && GENERIC_WRITE && GENERIC_EXECUTE
163 | #define ACCESS_SYSTEM_SECURITY 0x01000000 //Allows access to get or set the SACL for the object
164 |
165 | /* Standard access rights
166 | *
167 | * These are the standard rights that all objects will have at a
168 | * minimum and map to very high level access, such as modifying
169 | * the access or deleting the object
170 | *
171 | * Bytes 16-20 - Used
172 | * Bytes 21-23 - Appear unused at this point
173 | */
174 | #define ACCESS_STANDARD_SYNCHRONIZE 0x00100000 //Allow the program to wait until our object is in a signaled state
175 | #define ACCESS_STANDARD_WRITE_OWNER 0x00080000 //The right to change the owner
176 | #define ACCESS_STANDARD_WRITE_DAC 0x00040000 //The right to change the DACL of the object
177 | #define ACCESS_STANDARD_READ_CONTROL 0x00020000 //The right to read the security descriptor
178 | #define ACCESS_STANDARD_DELETE 0x00010000 //The right to delete the object
179 |
180 | /* Object specific access rights
181 | *
182 | * These are for the specific access rights (in our case) for
183 | * files and directories which are what we care about. The
184 | * bits are the same for files and directories, so bit 1
185 | * is READ for files and LIST for directories but is the same
186 | * bit because the access is the same.
187 | *
188 | * Bytes 0-8 - Used
189 | * Bytes 9-16 - Appear unused at this point
190 | */
191 | #define ACCESS_FILE_WRITE_ATTRIBUTES 0x00000100 //BOTH - Write attributes to the file (archive, read only, etc.)
192 | #define ACCESS_FILE_READ_ATTRIBUTES 0x00000080 //BOTH - Read the attributes set ont he file
193 | #define ACCESS_FILE_DELETE_CHILD 0x00000040 //BOTH - Allows the delete of an entire directory tree, including files inside even if they're read only
194 | #define ACCESS_FILE_EXECUTE 0x00000020 //FILE - Run and/or execute the file
195 | #define ACCESS_FILE_TRAVERSE 0x00000020 //DIR - The right to move into a directory, BYPASS_TRAVERSE_CHECKING user right can bypass this
196 | #define ACCESS_FILE_WRITE_EA 0x00000010 //BOTH - Write extended attributes
197 | #define ACCESS_FILE_READ_EA 0x00000008 //BOTH - Read extended attributes
198 | #define ACCESS_FILE_APPEND_DATA 0x00000004 //FILE - Allow appending to the file (will not overwrite data)
199 | #define ACCESS_FILE_ADD_SUBDIRECTORY 0x00000004 //DIR - Allow creating subdirectories
200 | #define ACCESS_FILE_WRITE_DATA 0x00000002 //FILE - Allow writing data into a file
201 | #define ACCESS_FILE_ADD_FILE 0x00000002 //DIR - Allow adding a file to a directory
202 | #define ACCESS_FILE_READ_DATA 0x00000001 //FILE - Allow opening and reading from a file
203 | #define ACCESS_FILE_LIST_DIRECTORY 0x00000001 //DIR - Allow reading a file list from a directory
204 |
205 |
--------------------------------------------------------------------------------
/src/smb.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CroweCybersecurity/shareenum/db728dda2097a759232b9cc860c2dd58dd2360c7/src/smb.o
--------------------------------------------------------------------------------
/src/smbresult.c:
--------------------------------------------------------------------------------
1 | #include "smbresult.h"
2 |
3 | smbresult* createSMBResultEmpty() {
4 | return createSMBResult("", "", "", 0, "", 0, 0);
5 | }
6 |
7 | smbresult* createSMBResult(char *host, char *share, char *object, int type, char *acl, unsigned int mode, int statuscode) {
8 | smbresult *tmp = malloc(sizeof(smbresult));
9 | tmp->host = strdup(host);
10 | tmp->share = strdup(share);
11 | tmp->object = strdup(object);
12 | tmp->type = type;
13 | tmp->acl = acl;
14 | tmp->mode = mode;
15 | tmp->statuscode = statuscode;
16 | return tmp;
17 | }
18 |
19 | void smbresultlist_push(smbresultlist **head, smbresult *data) {
20 | //Here we declare our new node for our list
21 | smbresultlist *newnode = malloc(sizeof(smbresultlist));
22 |
23 | newnode->data = data; //We take the new data and store it
24 | newnode->next = *head; //Then we set the next node to our last one
25 | *head = newnode; //And set our current node to the new one
26 | }
27 |
28 | int smbresultlist_pop(smbresultlist **head, smbresult **data) {
29 | smbresultlist *tmp = NULL; //Tmp variable to hold our list head
30 | tmp = *head; //Set the head to the tmp
31 |
32 | if(tmp == NULL) { //If tmp is null, we've reached the end.
33 | return 0;
34 | }
35 |
36 | *head = tmp->next; //Otherwise, set the head to the next item
37 | *data = tmp->data; //Extract the data to the data pointer
38 |
39 | free(tmp); //And free the memory
40 |
41 | return 1; //Finally, return that it worked
42 | }
43 |
44 | uint smbresultlist_merge(smbresultlist **dst, smbresultlist **src) {
45 | smbresult *tmp; //Tmp variable to hold the current data
46 |
47 | //Pop the current one of src and push it onto dst
48 | while(smbresultlist_pop(src, &tmp) > 0) {
49 | smbresultlist_push(dst, tmp);
50 | }
51 | }
52 |
53 | uint smbresultlist_length(smbresultlist *head) {
54 | uint len = 0; //Tmp variable to hold the length
55 | smbresultlist *cur; //Tmp variable to hold the current pointer
56 |
57 | //Loop through each pointer and set cur to the next pointer
58 | for(cur = head; cur != NULL; cur = cur->next) {
59 | len++; //Add to our counter
60 | }
61 |
62 | return len; //And now we have the length
63 | }
64 |
65 | void smbresultlist_freeall(smbresultlist *head) {
66 | smbresultlist *tmp; //Tmp variable to hold the head pointer
67 |
68 | while(head != NULL) { //Loop through each item
69 | tmp = head; //Get the current smbresultlist
70 | head = head->next; //Set head to the next one
71 | free(tmp); //And free the current one
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/smbresult.h:
--------------------------------------------------------------------------------
1 | #include //Unix standard libraries
2 | #include //C "string" library
3 | #include //GNU Standard Lib
4 |
5 | /* Data type that includes the result for every object that is identified
6 | * within our recursive scanning.
7 | * host - The hostname or IP of our target
8 | * share - The name of the share
9 | * object - The full path in the share to the object
10 | * type - The type of object (printer, file share, etc.)
11 | * acl - string containing the permissions
12 | * statuscode - The result of pulling object data, 0 for success and >0 for smb error codes.
13 | */
14 | typedef struct smbresult {
15 | char* host;
16 | char* share;
17 | char* object;
18 | int type;
19 | char* acl;
20 | unsigned int mode;
21 | int statuscode;
22 | } smbresult;
23 |
24 | /* Create an empty smbresult with all of the strings pointing to empty strings ("")
25 | * and all of the other items set to 0.
26 | * PARAMETERS: None
27 | * RETURN (smbresult): A pointer to an empty SMB result
28 | */
29 | smbresult* createSMBResultEmpty();
30 |
31 | /* Create a smbresult with all of the methods and variables set.
32 | * PARAMETERS:
33 | * host - Hostname
34 | * share - Share name
35 | * object - Full path to the object
36 | * type - Type of object
37 | * acl - ACL for the object
38 | * statuscode - The return code for the object, 0 for success and >0 as error codes
39 | * RETURN (smbresult): A pointer to the smbresult
40 | */
41 | smbresult* createSMBResult(char* host, char* share, char* object, int type, char* acl, unsigned int mode, int statuscode);
42 |
43 | /* So we're typically going to have a large number of results, we'll
44 | * keep a linked list of our results so we can have a dynamic number.
45 | * There are also several associated functions for management of the
46 | * list.
47 | * data - The smbresult that contains our current data
48 | * next - A link to the next item in the linked list
49 | */
50 | typedef struct smbresultlist {
51 | smbresult* data;
52 | struct smbresultlist* next;
53 | } smbresultlist;
54 |
55 | /* This function will add a smbresult to the beginning of our
56 | * linked list. In the event there isn't anything, it will
57 | * create the list.
58 | * PARAMETERS:
59 | * head - A pointer to the first item in our linked list
60 | * data - The smbresult that we want to add
61 | * RETURN (void): None
62 | */
63 | void smbresultlist_push(smbresultlist** head, smbresult *data);
64 |
65 | /* This function will pull the first item off the linked list,
66 | * reset the head, and free the item. Useful to iterate through
67 | * items on our list when we're done.
68 | * PARAMETERS:
69 | * head - A pointer to the first item in our linked list
70 | * data - The smbresult that we're gathering to use. This
71 | * will be freed and won't be on the list.
72 | * RETURN (int): 0 if we failed and 1 if we succeeded.
73 | */
74 | int smbresultlist_pop(smbresultlist** head, smbresult **data);
75 |
76 | /* Takes two lists of smbresults and merges them together in no
77 | * particular order.
78 | * PARAMETERS:
79 | * dst - A pointer to the first item it the destination list.
80 | * src - A pointer to the first item in the source list.
81 | * RETURN (int): 0 if we failed and 1 if we succeeded.
82 | */
83 | uint smbresultlist_merge(smbresultlist** dst, smbresultlist** src);
84 |
85 | /* Given a head pointer to the list, this will return the
86 | * number of items currently on it.
87 | * PARAMETERS:
88 | * head - A pointer to the first item in our linked list
89 | * RETURN (uint): The number of items on our list
90 | */
91 | uint smbresultlist_length(smbresultlist* head);
92 |
93 | /* Given a pointer to the head of the list, this will iterate
94 | * through the entire list and destroy each item, freeing as
95 | * it goes. This will destroy the list.
96 | * PARAMETERS:
97 | * head - A pointer to the first item in our linked list
98 | * RETURN (void): None
99 | */
100 | void smbresultlist_freeall(smbresultlist* head);
101 |
--------------------------------------------------------------------------------
/src/smbresult.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CroweCybersecurity/shareenum/db728dda2097a759232b9cc860c2dd58dd2360c7/src/smbresult.o
--------------------------------------------------------------------------------