Skip to content

Commit

Permalink
✨ Adding support for custom User Agents
Browse files Browse the repository at this point in the history
  • Loading branch information
caffeinewriter committed Jul 7, 2015
1 parent 0a8a277 commit 9da2349
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions wp-fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
def main():
parser = argparse.ArgumentParser("Detects WP version from readme.html or meta tag")
parser.add_argument("-t", "--target", action="append", dest="targets", help="Add a target to scan")
parser.add_argument("-u", "--user-agent", action="store", dest="ua", help="A custom UA string to use in requests to the server")
parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", help="Turn on verbose mode. Useful for seeing the details of errors")

args = parser.parse_args()

if args.targets != None:
scan(args.targets, args.verbose)
scan(args.targets, args.verbose, args.ua)

def scan(targets, verbose):
def scan(targets, verbose, ua):
for target in targets:
if not target[:5] == "http:" and not target[:6] == "https:":
target = "http://" + target
Expand All @@ -22,14 +23,20 @@ def scan(targets, verbose):
target = target + '/readme.html'
url = urlparse(target)
try:
r = requests.get(url.geturl())
if not ua:
r = requests.get(url.geturl())
else:
r = requests.get(url.geturl(), headers={'User-Agent': ua})
except requests.exceptions.ConnectionError, e:
print "Error: Unable to connect to " + tlurl.netloc
if verbose:
print e
else:
if r.status_code != 200:
t = requests.get(tlurl.geturl())
if not ua:
t = requests.get(tlurl.geturl())
else:
t = requests.get(tlurl.geturl(), headers={'User-Agent': ua})
w = re.compile(r'<meta name\=\"generator\" content\=\"(WordPress \d+\.\d+\.?(\d+)?)\" \/>', re.I)
n = w.search(t.text)
if n:
Expand Down

0 comments on commit 9da2349

Please sign in to comment.