-
Notifications
You must be signed in to change notification settings - Fork 216
/
cmsmap.py
executable file
·2041 lines (1896 loc) · 97.2 KB
/
cmsmap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
import smtplib, base64, os, sys, getopt, urllib2, urllib, re, socket, time, httplib, tarfile
import itertools, urlparse, threading, Queue, multiprocessing, cookielib, datetime, zipfile
import platform, signal
from thirdparty.multipart import multipartpost
from distutils.version import LooseVersion
class Initialize:
def __init__(self):
self.agent = agent
self.headers={'User-Agent':self.agent,}
self.ospath = dataPath
self.forceUpdate = None
# Wordpress
self.wp_plugins = os.path.join(self.ospath,"wp_plugins.txt")
self.wp_plugins_small = os.path.join(self.ospath,"wp_plugins_small.txt")
self.wp_themes_small = os.path.join(self.ospath,"wp_themes_small.txt")
# Joomla
self.joo_plugins = os.path.join(self.ospath,"joo_plugins.txt")
self.joo_plugins_small = os.path.join(self.ospath,"joo_plugins_small.txt")
# Drupal
self.dru_plugins = os.path.join(self.ospath,"dru_plugins.txt")
self.dru_plugins_small = os.path.join(self.ospath,"dru_plugins_small.txt")
# ExploitDB
self.wp_exploitdb_url = "http://www.exploit-db.com/search/?action=search&filter_page=1&filter_description=Wordpress"
self.joo_exploitdb_url = "http://www.exploit-db.com/search/?action=search&filter_page=1&filter_description=Joomla"
def UpdateRun(self):
if self.forceUpdate == 'C':
self.CMSmapUpdate()
elif self.forceUpdate == 'W':
self.GetWordPressPlugins()
msg = "Downloading WordPress plugins from ExploitDB website"; report.message(msg)
self.GetExploitDBPlugins(self.wp_exploitdb_url, self.wp_plugins_small, 'Wordpress', 'wp-content/plugins/(.+?)/')
msg = "Downloading WordPress themes from ExploitDB website"; report.message(msg)
self.GetExploitDBPlugins(self.wp_exploitdb_url, self.wp_themes_small, 'Wordpress', 'wp-content/themes/([\w\-\_]*)/')
elif self.forceUpdate == 'J':
msg = "Downloading Joomla components from ExploitDB website"; report.message(msg)
self.GetExploitDBPlugins(self.joo_exploitdb_url, self.joo_plugins_small, 'Joomla', '\?option=(com.+?)\&')
elif self.forceUpdate == 'D':
self.GetDrupalPlugins()
elif self.forceUpdate == 'A':
self.CMSmapUpdate()
self.GetWordPressPlugins()
msg = "Downloading WordPress plugins from ExploitDB website"; report.message(msg)
self.GetExploitDBPlugins(self.wp_exploitdb_url, self.wp_plugins_small, 'Wordpress', 'wp-content/plugins/(.+?)/')
msg = "Downloading WordPress themes from ExploitDB website"; report.message(msg)
self.GetExploitDBPlugins(self.wp_exploitdb_url, self.wp_themes_small, 'Wordpress', 'wp-content/themes/([\w\-\_]*)/')
msg = "Downloading Joomla components from ExploitDB website"; report.message(msg)
self.GetExploitDBPlugins(self.joo_exploitdb_url, self.joo_plugins_small, 'Joomla', '\?option=(com.+?)\&')
self.GetDrupalPlugins()
else:
msg = "Not Valid Option Provided: use (C)MSmap, (W)ordpress plugins and themes, (J)oomla components, (D)rupal modules, (A)ll"; report.message(msg)
msg = "Assuming: (C)MSmap update"; report.message(msg)
self.CMSmapUpdate()
self.SortUniqueFile()
def SortUniqueFile(self) :
for list in [self.wp_plugins,
self.wp_plugins_small,
self.wp_themes_small,
self.joo_plugins,
self.joo_plugins_small ,
self.dru_plugins,
self.dru_plugins_small]:
readlist = sorted(set([line.strip() for line in open(list)]))
f = open(list, "w")
for plugin in readlist:
f.write("%s\n" % plugin)
f.close()
sys.exit()
def CMSmapUpdate(self):
success = False
if not self.ospath+".git":
msg = "Git Repository Not Found. Please download the latest version of CMSmap from GitHub repository"; report.error(msg)
msg = "Example: git clone https://github.com/Dionach/cmsmap"; report.error(msg)
else:
msg = "Updating CMSmap to the latest version from GitHub repository... "; report.message(msg)
os.chdir(self.ospath)
process = os.system("git pull")
if process == 0 : success = True
if success :
msg = "CMSmap is now updated to the latest version!"; report.message(msg)
else :
msg = " Updated could not be completed. Please download the latest version of CMSmap from GitHub repository"; report.error(msg)
msg = " Example: git clone https://github.com/Dionach/cmsmap"; report.error(msg)
def GetWordPressPlugins(self):
msg = "Downloading wordpress plugins from svn website"; report.message(msg)
f = open(self.wp_plugins, "a")
htmltext = urllib2.urlopen("http://plugins.svn.wordpress.org").read()
regex = '">(.+?)/</a></li>'
pattern = re.compile(regex)
plugins = re.findall(pattern,htmltext)
if plugins :
msg = str(len(plugins))+" plugins found"; report.message(msg)
for plugin in plugins:
try:
f.write("%s\n" % plugin.encode('utf-8'))
except:
pass
sys.stdout.write("\r%d%%" %((100*(plugins.index(plugin)))/len(plugins)))
sys.stdout.flush()
sys.stdout.write("\r")
sys.stdout.flush()
msg ="Wordpress Plugin File: %s" % (self.wp_plugins); report.message(msg)
else:
msg = "unable to extract plugins from wordpress svn website"; report.error(msg)
f.close()
def GetJoomlaPlugins(self):
# Not Implemented yet
pass
def GetDrupalPlugins(self):
# Download Drupal Plugins from Drupal website
msg = "Downloading drupal modules from drupal.org"; report.message(msg)
f = open(self.dru_plugins_small, "a")
for page in range(0,int(10)):
htmltext = urllib2.urlopen("https://drupal.org/project/project_module?page="+str(page)+"&f[4]=sm_field_project_type:full&text=&solrsort=iss_project_release_usage+desc&").read()
regex = '<h2><a href="/project/(\w*?)">'
pattern = re.compile(regex)
self.dru_plugins_extracted = re.findall(pattern,htmltext)
self.dru_plugins_extracted = sorted(set(self.dru_plugins_extracted))
for plugin in self.dru_plugins_extracted:
f.write("%s\n" % plugin)
sys.stdout.write("\r%d%%" %((100*(page+1))/int(10)))
sys.stdout.flush()
f.close()
sys.stdout.write("\r")
sys.stdout.flush()
msg = "Drupal Plugin File: "+ self.dru_plugins_small; report.message(msg)
def GetExploitDBPlugins(self,exploitdb_url,plugins_small,filter_description,regex):
self.exploitdb_url = exploitdb_url
self.plugins_small = plugins_small
self.filter_description = filter_description
self.regex = regex
# Append to file
f = open(self.plugins_small, "a")
htmltext = urllib2.urlopen(self.exploitdb_url).read()
regex ='filter_page=(.+?)\t\t\t.*>>></a>'
pattern = re.compile(regex)
self.pages = re.findall(pattern,htmltext)
if self.pages:
self.pages = self.pages[0]
msg = str(self.pages)+" total pages"; msg = report.verbose(msg)
# Search all page
for self.page in range(1,int(self.pages)):
time.sleep(1)
self.exploitdb_url_page = "http://www.exploit-db.com/search/?action=search&filter_page="+str(self.page)+"&filter_description="+self.filter_description
request = urllib2.Request(self.exploitdb_url_page,None,self.headers)
htmltext = urllib2.urlopen(request).read()
pattern = re.compile('<a href="http://www.exploit-db.com/download/(.+?)/">')
self.ExploitID = re.findall(pattern,htmltext)
# Search in a single page
for self.Eid in self.ExploitID:
htmltext = urllib2.urlopen("http://www.exploit-db.com/download/"+str(self.Eid)+"/").read()
pattern = re.compile(self.regex)
self.ExploitDBplugins = re.findall(pattern,htmltext)
sys.stdout.write("\r%d%%"%((100*(int(self.page)+1))/int(self.pages)))
sys.stdout.flush()
# Sorted Unique
self.ExploitDBplugins = sorted(set(self.ExploitDBplugins))
for self.plugin in self.ExploitDBplugins:
sys.stdout.write("\r%d%%"% (((100*(int(self.page)+1))/int(self.pages))))
if not re.search('.php',self.plugin):
try:
f.write("%s\n" % self.plugin)
except IndexError:
pass
f.close()
sys.stdout.write("\r")
msg = "File: " +self.plugins_small; report.message(msg)
class Scanner:
# Detect type of CMS -> Maybe add it to the main after Initialiazer
def __init__(self):
self.agent = agent
self.headers={'User-Agent':self.agent,}
self.url = None
self.force = None
self.threads = None
self.file = None
self.notExistingCode = 404
self.notValidLen = []
def ForceCMSType(self):
GenericChecks(self.url).HTTPSCheck()
GenericChecks(self.url).HeadersCheck()
GenericChecks(self.url).RobotsTXT()
if self.force == 'W':
WPScan(self.url,self.threads).WPrun()
elif self.force == 'J':
JooScan(self.url,self.threads).Joorun()
elif self.force == 'D':
DruScan(self.url,"default",self.threads).Drurun()
else:
msg = "Not Valid Option Provided: use (W)ordpress, (J)oomla, (D)rupal"; report.error(msg)
sys.exit()
def FindCMSType(self):
req = urllib2.Request(self.url,None,self.headers)
try:
htmltext = urllib2.urlopen(req).read()
# WordPress
req = urllib2.Request(self.url+"/wp-config.php")
try:
htmltext = urllib2.urlopen(req).read()
if len(htmltext) not in self.notValidLen and self.force is None:
self.force = 'W'
except urllib2.HTTPError, e:
#print e.code
if e.code == 403 and len(htmltext) not in self.notValidLen and self.force is None:
self.force = 'W'
else:
#print e.code
msg = "WordPress Config File Not Found: "+self.url+"/wp-config.php"
report.verbose(msg)
# Joomla
req = urllib2.Request(self.url+"/configuration.php")
try:
htmltext = urllib2.urlopen(req).read()
if len(htmltext) not in self.notValidLen and self.force is None:
self.force = 'J'
except urllib2.HTTPError, e:
if e.code == 403 and len(e.read()) not in self.notValidLen and self.force is None:
self.force = 'J'
else:
#print e.code
msg = "Joomla Config File Not Found: "+self.url+"/configuration.php"
report.verbose(msg)
# Drupal
req = urllib2.Request(self.url+"/sites/default/settings.php")
try:
htmltext = urllib2.urlopen(req).read()
if len(htmltext) not in self.notValidLen and self.force is None:
self.force = 'D'
except urllib2.HTTPError, e:
pUrl = urlparse.urlparse(self.url)
netloc = pUrl.netloc.lower()
req = urllib2.Request(self.url+"/sites/"+netloc+"/settings.php")
try:
urllib2.urlopen(req)
if len(e.read()) not in self.notValidLen and self.force is None:
self.force = 'D'
except urllib2.HTTPError, e:
if e.code == 403 and len(e.read()) not in self.notValidLen and self.force is None:
self.force = 'D'
else:
if verbose:
#print e.code
msg = "Drupal Config File Not Found: "+self.url+"/sites/default/settings.php"
report.verbose(msg)
if self.force is None :
msg = "CMS detection failed :("; report.error(msg)
msg = "Use -f to force CMSmap to scan (W)ordpress, (J)oomla or (D)rupal"; report.error(msg)
sys.exit()
except urllib2.URLError, e:
msg = "Website Unreachable: "+self.url
report.error(msg)
sys.exit()
def CheckURL(self):
pUrl = urlparse.urlparse(self.url)
#clean up supplied URLs
netloc = pUrl.netloc.lower()
scheme = pUrl.scheme.lower()
path = pUrl.path.lower()
if not scheme:
self.url = "http://" + self.url
report.status("No HTTP/HTTPS provided. Assuming HTTP...")
if path.endswith("asp" or "aspx"):
report.error("You are not scanning a PHP website")
sys.exit()
if path.endswith("txt" or "php"):
self.url = re.findall(re.compile('(.+?)/[A-Za-z0-9]+\.txt|php'),self.url)[0]
def NotExisitingCode(self):
self.NotExisitingFile = ["/N0W43H3r3.php","/N0W"+time.strftime('%d%m%H%M%S')+".php", "/N0WaY/N0WaY12/N0WaY123.php"]
# check without URL redirection
for file in self.NotExisitingFile :
req = urllib2.Request(self.url+file,None, self.headers)
noRedirOpener = urllib2.build_opener(NoRedirects())
try:
htmltext = noRedirOpener.open(req).read()
self.notValidLen.append(len(htmltext))
except urllib2.HTTPError, e:
#print e.code
self.notValidLen.append(len(e.read()))
self.notExistingCode = e.code
except urllib2.URLError, e:
msg = "Website Unreachable: "+self.url
report.error(msg)
sys.exit()
# check with URL redirection
for file in self.NotExisitingFile :
req = urllib2.Request(self.url+file,None, self.headers)
try:
htmltext = urllib2.urlopen(req).read()
self.notValidLen.append(len(htmltext))
except urllib2.HTTPError, e:
#print e.code
self.notValidLen.append(len(e.read()))
self.notExistingCode = e.code
except urllib2.URLError, e:
msg = "Website Unreachable: "+self.url
report.error(msg)
sys.exit()
self.notValidLen = sorted(set(self.notValidLen))
class WPScan:
# Scan WordPress site
def __init__(self,url,threads):
self.headers={'User-Agent':agent,}
self.url = url
self.currentVer = None
self.latestVer = None
self.queue_num = 5
self.thread_num = threads
self.pluginPath = "/wp-content/plugins/"
self.themePath = "/wp-content/themes/"
self.feed = "/?feed=rss2"
self.author = "/?author="
self.forgottenPsw = "/wp-login.php?action=lostpassword"
self.weakpsw = ['password', 'admin','123456','Password1'] # 5th attempt is the username
self.usernames = []
self.pluginsFound = []
self.themesFound = []
self.timthumbsFound = []
self.notValidLen = []
self.theme = None
self.notExistingCode = 404
self.confFiles=['','.php~','.php.txt','.php.old','.php_old','.php-old','.php.save','.php.swp','.php.swo','.php_bak','.php-bak','.php.original','.php.old','.php.orig','.php.bak','.save','.old','.bak','.orig','.original','.txt']
self.genChecker = GenericChecks(url)
self.genChecker.NotExisitingLength()
self.plugins_small = [line.strip() for line in open(os.path.join(dataPath, 'wp_plugins_small.txt'))]
self.plugins = [line.strip() for line in open(os.path.join(dataPath, 'wp_plugins.txt'))]
self.versions = [line.strip() for line in open(os.path.join(dataPath, 'wp_versions.txt'))]
self.themes = [line.strip() for line in open(os.path.join(dataPath, 'wp_themes.txt'))]
self.themes_small = [line.strip() for line in open(os.path.join(dataPath, 'wp_themes_small.txt'))]
self.timthumbs = [line.strip() for line in open(os.path.join(dataPath, 'wp_timthumbs.txt'))]
searcher.cmstype = "Wordpress"
def WPrun(self):
msg = "CMS Detection: Wordpress"; report.info(msg)
self.WPNotExisitingCode()
self.WPVersion()
self.WPCurrentTheme()
self.WPConfigFiles()
self.WPHello()
self.WPFeed()
self.WPAuthor()
bruter.usrlist = self.usernames
bruter.pswlist = self.weakpsw
bruter.WPXMLRPC_brute()
self.WPForgottenPassword()
self.WPXMLRPC_pingback()
self.WPXMLRPC_BF()
self.genChecker.AutocompleteOff('/wp-login.php')
self.WPDefaultFiles()
if FullScan : self.genChecker.CommonFiles()
self.WPpluginsIndex()
self.WPplugins()
searcher.query = self.pluginsFound; searcher.Plugins()
if FullScan : self.WPThemes(); searcher.query = self.themesFound; searcher.Themes()
self.WPTimThumbs()
self.WPDirsListing()
def WPVersion(self):
try:
req = urllib2.Request(self.url+'/readme.html',None,self.headers)
htmltext = urllib2.urlopen(req).read()
regex = '.*wordpress-logo.png" /></a>\n.*<br />.* (\d+\.\d+[\.\d+]*)\n</h1>'
pattern = re.compile(regex)
version = re.findall(pattern,htmltext)
if version:
msg = "Wordpress Version: "+version[0]; report.info(msg)
except urllib2.HTTPError, e:
try:
req = urllib2.Request(self.url,None,self.headers)
htmltext = urllib2.urlopen(req).read()
version = re.findall('<meta name="generator" content="WordPress (\d+\.\d+[\.\d+]*)"', htmltext)
if version:
msg = "Wordpress Version: "+version[0]; report.info(msg)
except urllib2.HTTPError, e:
pass
if version:
if version[0] in self.versions :
for ver in self.versions:
searcher.query = ver; searcher.Core()
if ver == version[0]:
break
def WPCurrentTheme(self):
try:
req = urllib2.Request(self.url,None,self.headers)
htmltext = urllib2.urlopen(req).read()
regex = '/wp-content/themes/(.+?)/'
pattern = re.compile(regex)
CurrentTheme = re.findall(pattern,htmltext)
if CurrentTheme:
self.theme = CurrentTheme[0]
msg = "Wordpress Theme: "+self.theme ; report.info(msg)
searcher.query = [self.theme]; searcher.Themes()
except urllib2.HTTPError, e:
#print e.code
pass
def WPConfigFiles(self):
for file in self.confFiles:
req = urllib2.Request(self.url+"/wp-config"+file,None,self.headers)
try:
htmltext = urllib2.urlopen(req).read()
if len(htmltext) not in self.notValidLen:
msg = "Configuration File Found: " +self.url+"/wp-config"+file; report.high(msg)
except urllib2.HTTPError, e:
pass
def WPDefaultFiles(self):
# Check for default files
self.defFilesFound = []
msg = "Default WordPress Files:"; report.message(msg)
self.defFiles=['/readme.html',
'/license.txt',
'/xmlrpc.php',
'/wp-config-sample.php',
'/wp-includes/images/crystal/license.txt',
'/wp-includes/images/crystal/license.txt',
'/wp-includes/js/plupload/license.txt',
'/wp-includes/js/plupload/changelog.txt',
'/wp-includes/js/tinymce/license.txt',
'/wp-includes/js/tinymce/plugins/spellchecker/changelog.txt',
'/wp-includes/js/swfupload/license.txt',
'/wp-includes/ID3/license.txt',
'/wp-includes/ID3/readme.txt',
'/wp-includes/ID3/license.commercial.txt',
'/wp-content/themes/twentythirteen/fonts/COPYING.txt',
'/wp-content/themes/twentythirteen/fonts/LICENSE.txt'
]
for file in self.defFiles:
req = urllib2.Request(self.url+file,None,self.headers)
try:
htmltext = urllib2.urlopen(req).read()
if len(htmltext) not in self.notValidLen:
self.defFilesFound.append(self.url+file)
except urllib2.HTTPError, e:
#print e.code
pass
for file in self.defFilesFound:
msg = file; report.info(msg)
def WPFeed(self):
msg = "Enumerating Wordpress Usernames via \"Feed\" ..."; report.message(msg)
try:
req = urllib2.Request(self.url+self.feed,None,self.headers)
htmltext = urllib2.urlopen(req).read()
wpUsers = re.findall("<dc:creator><!\[CDATA\[(.+?)\]\]></dc:creator>", htmltext,re.IGNORECASE)
wpUsers2 = re.findall("<dc:creator>(.+?)</dc:creator>", htmltext,re.IGNORECASE)
if wpUsers :
self.usernames = wpUsers + self.usernames
self.usernames = sorted(set(self.usernames))
#for user in self.usernames:
#msg = user; report.medium(msg)
except urllib2.HTTPError, e:
#print e.code
pass
def WPAuthor(self):
msg = "Enumerating Wordpress Usernames via \"Author\" ..."; report.message(msg)
for user in range(1,20):
try:
req = urllib2.Request(self.url+self.author+str(user),None,self.headers)
htmltext = urllib2.urlopen(req).read()
wpUser = re.findall("author author-(.+?) ", htmltext,re.IGNORECASE)
if wpUser : self.usernames = wpUser + self.usernames
wpUser = re.findall("/author/(.+?)/feed/", htmltext,re.IGNORECASE)
if wpUser : self.usernames = wpUser + self.usernames
except urllib2.HTTPError, e:
#print e.code
pass
self.usernames = sorted(set(self.usernames))
for user in self.usernames:
msg = user; report.medium(msg)
def WPForgottenPassword(self):
# Username Enumeration via Forgotten Password
query_args = {"user_login": "N0t3xist!1234"}
data = urllib.urlencode(query_args)
# HTTP POST Request
req = urllib2.Request(self.url+self.forgottenPsw, data,self.headers)
try:
htmltext = urllib2.urlopen(req).read()
if re.findall(re.compile('Invalid username'),htmltext):
msg = "Forgotten Password Allows Username Enumeration: "+self.url+self.forgottenPsw; report.info(msg)
except urllib2.HTTPError, e:
#print e.code
pass
def WPHello(self):
try:
req = urllib2.Request(self.url+"/wp-content/plugins/hello.php",None,self.headers)
htmltext = urllib2.urlopen(req).read()
fullPath = re.findall(re.compile('Fatal error.*>/(.+?/)hello.php'),htmltext)
if fullPath :
msg = "Wordpress Hello Plugin Full Path Disclosure: "+"/"+fullPath[0]+"hello.php"; report.low(msg)
except urllib2.HTTPError, e:
#print e.code
pass
def WPDirsListing(self):
msg = "Checking for Directory Listing Enabled ..."; report.info(msg)
report.WriteTextFile(msg)
GenericChecks(self.url).DirectoryListing('/wp-content/')
if self.theme: GenericChecks(self.url).DirectoryListing('/wp-content/'+self.theme)
GenericChecks(self.url).DirectoryListing('/wp-includes/')
GenericChecks(self.url).DirectoryListing('/wp-admin/')
for plugin in self.pluginsFound:
GenericChecks(self.url).DirectoryListing('/wp-content/plugins/'+plugin)
def WPNotExisitingCode(self):
req = urllib2.Request(self.url+self.pluginPath+"N0WayThatYouAreHere"+time.strftime('%d%m%H%M%S')+"/",None, self.headers)
noRedirOpener = urllib2.build_opener(NoRedirects())
try:
htmltext = noRedirOpener.open(req).read()
print htmltext
self.notValidLen.append(len(htmltext))
except urllib2.HTTPError, e:
self.notValidLen.append(len(e.read()))
self.notExistingCode = e.code
def WPpluginsIndex(self):
try:
req = urllib2.Request(self.url,None,self.headers)
htmltext = urllib2.urlopen(req).read()
self.pluginsFound = re.findall(re.compile('/wp-content/plugins/(.+?)/'),htmltext)
self.pluginsFound = sorted(set(self.pluginsFound))
except urllib2.HTTPError, e:
#print e.code
pass
def WPplugins(self):
msg = "Searching Wordpress Plugins ..."; report.message(msg)
if not FullScan : self.plugins = self.plugins_small
# Create Code
q = Queue.Queue(self.queue_num)
# Spawn all threads into code
for u in range(self.thread_num):
t = ThreadScanner(self.url,self.pluginPath,"/",self.pluginsFound,self.notExistingCode,self.notValidLen,q)
t.daemon = True
t.start()
# Add all plugins to the queue
for r,i in enumerate(self.plugins):
q.put(i)
sys.stdout.write("\r"+str(100*int(r+1)/len(self.plugins))+"%")
sys.stdout.flush()
q.join()
sys.stdout.write("\r")
def WPTimThumbs(self):
msg = "Searching Wordpress TimThumbs ..."; report.message(msg)
# Create Code
q = Queue.Queue(self.queue_num)
# Spawn all threads into code
for u in range(self.thread_num):
t = ThreadScanner(self.url,"/","",self.timthumbsFound,self.notExistingCode,self.notValidLen,q)
t.daemon = True
t.start()
# Add all plugins to the queue
for r,i in enumerate(self.timthumbs):
q.put(i)
sys.stdout.write("\r"+str(100*int(r+1)/len(self.timthumbs))+"%")
sys.stdout.flush()
q.join()
sys.stdout.write("\r")
if self.timthumbsFound:
for timthumbsFound in self.timthumbsFound:
msg = self.url+"/"+timthumbsFound; report.medium(msg)
msg= " Timthumbs Potentially Vulnerable to File Upload: http://www.exploit-db.com/wordpress-timthumb-exploitation"; report.medium(msg)
def WPThemes(self):
msg = "Searching Wordpress Themes ..."; report.message(msg)
if not FullScan : self.themes = self.themes_small
# Create Code
q = Queue.Queue(self.queue_num)
# Spawn all threads into code
for u in range(self.thread_num):
t = ThreadScanner(self.url,self.themePath,"/",self.themesFound,self.notExistingCode,self.notValidLen,q)
t.daemon = True
t.start()
# Add all theme to the queue
for r,i in enumerate(self.themes):
q.put(i)
sys.stdout.write("\r"+str(100*int(r+1)/len(self.themes))+"%")
sys.stdout.flush()
q.join()
sys.stdout.write("\r")
for themesFound in self.themesFound:
msg = themesFound; report.info(msg)
def WPXMLRPC_pingback(self):
msg = "Checking XML-RPC Pingback Vulnerability ..."; report.verbose(msg)
self.postdata = '''<methodCall><methodName>pingback.ping</methodName><params>
<param><value><string>http://N0tB3th3re0484940:22/</string></value></param>
<param><value><string>'''+self.url+'''</string></value></param>
</params></methodCall>'''
try:
req = urllib2.Request(self.url+'/xmlrpc.php',self.postdata,self.headers)
opener = urllib2.build_opener(MyHandler())
htmltext = opener.open(req).read()
if re.search('<name>16</name>',htmltext):
msg = "Website vulnerable to XML-RPC Pingback Force Vulnerability"; report.low(msg)
except urllib2.HTTPError, e:
#print e.code
pass
def WPXMLRPC_BF(self):
msg = "Checking XML-RPC Brute Force Vulnerability ..."; report.verbose(msg)
self.headers['Content-Type'] ='text/xml'
self.postdata = '''<methodCall><methodName>wp.getUsersBlogs</methodName><params>
<param><value><string>admin</string></value></param>
<param><value><string></string></value></param>
</params></methodCall>'''
try:
req = urllib2.Request(self.url+'/xmlrpc.php',self.postdata,self.headers)
#opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1))
opener = urllib2.build_opener(MyHandler())
htmltext = opener.open(req).read()
if re.search('<int>403</int>',htmltext):
msg = "Website vulnerable to XML-RPC Brute Force Vulnerability"; report.medium(msg)
except urllib2.HTTPError, e:
print e.code
pass
class MyResponse(httplib.HTTPResponse):
def read(self, amt=None):
self.length = None
return httplib.HTTPResponse.read(self, amt)
class MyHandler(urllib2.HTTPHandler):
def do_open(self, http_class, req):
h = httplib.HTTPConnection
h.response_class = MyResponse
return urllib2.HTTPHandler.do_open(self, h, req)
class JooScan:
# Scan Joomla site
def __init__(self,url,threads):
self.headers={'User-Agent':agent,}
self.url = url
self.queue_num = 5
self.thread_num = threads
self.usernames = []
self.pluginPath = "/components/"
self.pluginsFound = []
self.notValidLen = []
self.notExistingCode = 404
self.weakpsw = ['password', 'admin','123456','Password1'] # 5th attempt is the username
self.confFiles=['','.php~','.php.txt','.php.old','.php_old','.php-old','.php.save','.php.swp','.php.swo','.php_bak','.php-bak','.php.original','.php.old','.php.orig','.php.bak','.save','.old','.bak','.orig','.original','.txt']
self.excludeEDBPlugins = ['com_banners','com_contact','com_content','com_users']
self.genChecker = GenericChecks(url)
self.genChecker.NotExisitingLength()
self.plugins_small = [line.strip() for line in open(os.path.join(dataPath, 'joo_plugins_small.txt'))]
self.plugins = [line.strip() for line in open(os.path.join(dataPath, 'joo_plugins.txt'))]
self.versions = [line.strip() for line in open(os.path.join(dataPath, 'joo_versions.txt'))]
searcher.cmstype = "Joomla"
def Joorun(self):
msg = "CMS Detection: Joomla"; report.info(msg)
self.JooNotExisitingCode()
self.JooVersion()
self.JooTemplate()
self.JooConfigFiles()
self.JooFeed()
bruter.usrlist = self.usernames
bruter.pswlist = self.weakpsw
bruter.Joorun()
self.genChecker.AutocompleteOff('/administrator/index.php')
self.JooDefaultFiles()
if FullScan : self.genChecker.CommonFiles()
self.JooModulesIndex()
self.JooComponents()
if not FullScan : searcher.exclude = self.excludeEDBPlugins
searcher.query = self.pluginsFound; searcher.Plugins()
self.JooDirsListing()
def JooVersion(self):
try:
htmltext = urllib2.urlopen(self.url+'/joomla.xml').read()
regex = '<version>(.+?)</version>'
pattern = re.compile(regex)
version = re.findall(pattern,htmltext)
if version:
msg = "Joomla Version: "+version[0]; report.info(msg)
if version[0] in self.versions :
for ver in self.versions:
searcher.query = ver; searcher.Core()
if ver == version[0]:
break
except urllib2.HTTPError, e:
#print e.code
pass
def JooTemplate(self):
try:
htmltext = urllib2.urlopen(self.url+'/index.php').read()
WebTemplate = re.findall("/templates/(.+?)/", htmltext,re.IGNORECASE)
htmltext = urllib2.urlopen(self.url+'/administrator/index.php').read()
AdminTemplate = re.findall("/administrator/templates/(.+?)/", htmltext,re.IGNORECASE)
if WebTemplate[0] :
msg = "Joomla Website Template: "+WebTemplate[0]; report.info(msg)
searcher.query = WebTemplate[0]; searcher.Themes()
if AdminTemplate[0] :
msg = "Joomla Administrator Template: "+AdminTemplate[0]; report.info(msg)
searcher.query = AdminTemplate[0]; searcher.Themes()
except urllib2.HTTPError, e:
#print e.code
pass
def JooConfigFiles(self):
for file in self.confFiles:
req = urllib2.Request(self.url+"/configuration"+file)
try:
htmltext = urllib2.urlopen(req).read()
if len(htmltext) not in self.notValidLen:
msg = "Configuration File Found: " +self.url+"/configuration"+file; report.high(msg)
except urllib2.HTTPError, e:
#print e.code
pass
def JooDefaultFiles(self):
self.defFilesFound = []
msg = "Joomla Default Files: "; report.message(msg)
# Check for default files
self.defFiles=['/README.txt',
'/htaccess.txt',
'/administrator/templates/hathor/LICENSE.txt',
'/web.config.txt',
'/joomla.xml',
'/robots.txt.dist',
'/LICENSE.txt',
'/media/jui/fonts/icomoon-license.txt',
'/media/editors/tinymce/jscripts/tiny_mce/license.txt',
'/media/editors/tinymce/jscripts/tiny_mce/plugins/style/readme.txt',
'/libraries/idna_convert/ReadMe.txt',
'/libraries/simplepie/README.txt',
'/libraries/simplepie/LICENSE.txt',
'/libraries/simplepie/idn/ReadMe.txt',
]
for file in self.defFiles:
req = urllib2.Request(self.url+file,None,self.headers)
try:
htmltext = urllib2.urlopen(req).read()
if len(htmltext) not in self.notValidLen:
self.defFilesFound.append(self.url+file)
except urllib2.HTTPError, e:
#print e.code
pass
for file in self.defFilesFound:
msg = file; report.info(msg)
def JooFeed(self):
try:
htmltext = urllib2.urlopen(self.url+'/?format=feed').read()
jooUsers = re.findall("<author>(.+?) \((.+?)\)</author>", htmltext,re.IGNORECASE)
if jooUsers:
msg = "Enumerating Joomla Usernames via \"Feed\" ..."; report.message(msg)
jooUsers = sorted(set(jooUsers))
for user in jooUsers :
self.usernames.append(user[1])
msg = user[1]+" "+user[0]; report.info(msg)
except urllib2.HTTPError, e:
#print e.code
pass
def JooDirsListing(self):
msg = "Checking for Directory Listing Enabled ..."; report.info(msg)
report.WriteTextFile(msg)
GenericChecks(self.url).DirectoryListing('/administrator/')
GenericChecks(self.url).DirectoryListing('/bin/')
GenericChecks(self.url).DirectoryListing('/cache/')
GenericChecks(self.url).DirectoryListing('/cli/')
GenericChecks(self.url).DirectoryListing('/components/')
GenericChecks(self.url).DirectoryListing('/images/')
GenericChecks(self.url).DirectoryListing('/includes/')
GenericChecks(self.url).DirectoryListing('/language/')
GenericChecks(self.url).DirectoryListing('/layouts/')
GenericChecks(self.url).DirectoryListing('/libraries/')
GenericChecks(self.url).DirectoryListing('/media/')
GenericChecks(self.url).DirectoryListing('/modules/')
GenericChecks(self.url).DirectoryListing('/plugins/')
GenericChecks(self.url).DirectoryListing('/templates/')
GenericChecks(self.url).DirectoryListing('/tmp/')
for plugin in self.pluginsFound:
GenericChecks(self.url).DirectoryListing('/components/'+plugin)
def JooNotExisitingCode(self):
req = urllib2.Request(self.url+self.pluginPath+"/N0WayThatYouAreHere"+time.strftime('%d%m%H%M%S')+"/",None, self.headers)
noRedirOpener = urllib2.build_opener(NoRedirects())
try:
htmltext = noRedirOpener.open(req).read()
self.notValidLen.append(len(htmltext))
except urllib2.HTTPError, e:
#print e.code
self.notValidLen.append(len(e.read()))
self.notExistingCode = e.code
def JooModulesIndex(self):
try:
req = urllib2.Request(self.url,None,self.headers)
htmltext = urllib2.urlopen(req).read()
self.pluginsFound = re.findall(re.compile('/modules/(.+?)/'),htmltext)
self.pluginsFound = sorted(set(self.pluginsFound))
except urllib2.HTTPError, e:
#print e.code
pass
def JooComponents(self):
msg = "Searching Joomla Components ..."; report.message(msg)
if not FullScan : self.plugins = self.plugins_small
# Create Code
q = Queue.Queue(self.queue_num)
# Spawn all threads into code
for u in range(self.thread_num):
t = ThreadScanner(self.url,self.pluginPath,"/",self.pluginsFound,self.notExistingCode,self.notExistingCode,q)
t.daemon = True
t.start()
# Add all plugins to the queue
for r,i in enumerate(self.plugins):
q.put(i)
sys.stdout.write("\r"+str(100*int(r+1)/len(self.plugins))+"%")
sys.stdout.flush()
q.join()
sys.stdout.write("\r")
class DruScan:
# Scan Drupal site
def __init__(self,url,netloc,threads):
self.headers={'User-Agent':agent,}
self.url = url
self.queue_num = 5
self.thread_num = threads
self.notExistingCode = 404
self.notValidLen = []
self.netloc = netloc
self.pluginPath = "/modules/"
self.forgottenPsw = "/?q=user/password"
self.weakpsw = ['password', 'admin','123456','Password1'] # 5th attempt is the username
self.confFiles=['','.php~','.php.txt','.php.old','.php_old','.php-old','.php.save','.php.swp','.php.swo','.php_bak','.php-bak','.php.original','.php.old','.php.orig','.php.bak','.save','.old','.bak','.orig','.original','.txt']
self.usernames = []
self.pluginsFound = []
self.genChecker = GenericChecks(url)
self.genChecker.NotExisitingLength()
self.plugins_small = [line.strip() for line in open(os.path.join(dataPath, 'dru_plugins_small.txt'))]
self.plugins = [line.strip() for line in open(os.path.join(dataPath, 'dru_plugins.txt'))]
self.versions = [line.strip() for line in open(os.path.join(dataPath, 'dru_versions.txt'))]
searcher.cmstype = "Drupal"
def Drurun(self):
msg = "CMS Detection: Drupal"; report.info(msg)
self.DruNotExisitingCode()
self.DruVersion()
self.DruCurrentTheme()
self.DruConfigFiles()
self.DruViews()
self.DruBlog()
bruter.usrlist = self.usernames
bruter.pswlist = self.weakpsw
bruter.Drurun()
self.genChecker.AutocompleteOff('/?q=user')
self.DruDefaultFiles()
if FullScan : self.genChecker.CommonFiles()
self.DruForgottenPassword()
self.DruModulesIndex()
self.DruModules()
searcher.query = self.pluginsFound; searcher.Plugins()
self.DruDirsListing()
def DruVersion(self):
try:
htmltext = urllib2.urlopen(self.url+'/CHANGELOG.txt').read()
regex = 'Drupal (\d+\.\d+),'
pattern = re.compile(regex)
version = re.findall(pattern,htmltext)
if version:
self.DruVersion = version[0]
msg = "Drupal Version: "+version[0]; report.info(msg)
self.DruCore()
if version[0] in self.versions :
for ver in self.versions:
searcher.query = ver; searcher.Core()
if ver == version[0]:
break
except urllib2.HTTPError, e:
#print e.code
pass
def DruCore(self):
if LooseVersion("7") <= LooseVersion(str(self.DruVersion)) <= LooseVersion("7.31"):
msg = "Drupal Vulnerable to SA-CORE-2014-005"; report.high(msg)
def DruCurrentTheme(self):
try:
htmltext = urllib2.urlopen(self.url+'/index.php').read()
DruTheme = re.findall("/themes/(.+?)/", htmltext,re.IGNORECASE)
if DruTheme :
self.Drutheme = DruTheme[0]
msg = "Drupal Theme: "+ self.Drutheme ; report.info(msg)
searcher.query = [self.Drutheme] ; searcher.Themes()
return DruTheme[0]
except urllib2.HTTPError, e:
#print e.code
pass
def DruConfigFiles(self):
for file in self.confFiles:
req = urllib2.Request(self.url+"/sites/"+self.netloc+"/settings"+file)
try:
htmltext = urllib2.urlopen(req).read()
if len(htmltext) not in self.notValidLen:
msg = "Configuration File Found: " +self.url+"/sites/"+self.netloc+"/settings"+file; report.high(msg)
except urllib2.HTTPError, e:
#print e.code
pass
def DruDefaultFiles(self):
self.defFilesFound = []
msg = "Drupal Default Files: "; report.message(msg)
report.WriteTextFile(msg)
self.defFiles=['/README.txt',
'/INSTALL.mysql.txt',
'/MAINTAINERS.txt',
'/profiles/standard/translations/README.txt',
'/profiles/minimal/translations/README.txt',
'/INSTALL.pgsql.txt',
'/UPGRADE.txt',
'/CHANGELOG.txt',
'/INSTALL.sqlite.txt',
'/LICENSE.txt',
'/INSTALL.txt',
'/COPYRIGHT.txt',
'/web.config',
'/modules/README.txt',
'/modules/simpletest/files/README.txt',
'/modules/simpletest/files/javascript-1.txt',
'/modules/simpletest/files/php-1.txt',
'/modules/simpletest/files/sql-1.txt',
'/modules/simpletest/files/html-1.txt',
'/modules/simpletest/tests/common_test_info.txt',
'/modules/filter/tests/filter.url-output.txt',
'/modules/filter/tests/filter.url-input.txt',
'/modules/search/tests/UnicodeTest.txt',
'/themes/README.txt',
'/themes/stark/README.txt',
'/sites/README.txt',
'/sites/all/modules/README.txt',
'/sites/all/themes/README.txt',
'/modules/simpletest/files/html-2.html',
'/modules/color/preview.html',
'/themes/bartik/color/preview.html'
]
for file in self.defFiles:
req = urllib2.Request(self.url+file,None,self.headers)
try:
htmltext = urllib2.urlopen(req).read()
if len(htmltext) not in self.notValidLen:
self.defFilesFound.append(self.url+file)
except urllib2.HTTPError, e:
#print e.code
pass
for file in self.defFilesFound:
msg = file; report.info(msg)
def DruViews(self):
self.views = "/?q=admin/views/ajax/autocomplete/user/"
self.alphanum = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
usernames = []
msg = "Enumerating Drupal Usernames via \"Views\" Module..."; report.message(msg)
req = urllib2.Request(self.url+"/?q=admin/views/ajax/autocomplete/user/NotExisingUser1234!",None, self.headers)
noRedirOpener = urllib2.build_opener(NoRedirects())
try:
htmltext = noRedirOpener.open(req).read()
#If NotExisingUser1234 returns [ ], then enumerate users
if htmltext == '[ ]':
for letter in self.alphanum:
htmltext = urllib2.urlopen(self.url+self.views+letter).read()
regex = '"(.+?)"'
pattern = re.compile(regex)
usernames = usernames + re.findall(pattern,htmltext)
usernames = sorted(set(usernames))
for user in usernames:
msg = user; report.info(msg)
except urllib2.HTTPError, e:
pass