99import contextlib
1010import cookielib
1111import copy
12+ import hashlib
1213import httplib
1314import inspect
15+ import json
1416import logging
1517import ntpath
1618import os
2325import tempfile
2426import time
2527import urllib
28+ import urllib2
2629import urlparse
2730import unicodedata
2831
99102from lib .core .settings import FORM_SEARCH_REGEX
100103from lib .core .settings import GENERIC_DOC_ROOT_DIRECTORY_NAMES
101104from lib .core .settings import GIT_PAGE
105+ from lib .core .settings import GITHUB_REPORT_OAUTH_TOKEN
102106from lib .core .settings import GOOGLE_ANALYTICS_COOKIE_PREFIX
103107from lib .core .settings import HASHDB_MILESTONE_VALUE
104108from lib .core .settings import HOST_ALIASES
@@ -876,7 +880,7 @@ def readInput(message, default=None, checkBatch=True):
876880 message = "\n %s" % message
877881 kb .prependFlag = False
878882
879- if conf .answers :
883+ if conf .get ( " answers" ) :
880884 for item in conf .answers .split (',' ):
881885 question = item .split ('=' )[0 ].strip ()
882886 answer = item .split ('=' )[1 ] if len (item .split ('=' )) > 1 else None
@@ -892,7 +896,7 @@ def readInput(message, default=None, checkBatch=True):
892896 break
893897
894898 if retVal is None :
895- if checkBatch and conf .batch :
899+ if checkBatch and conf .get ( " batch" ) :
896900 if isListLike (default ):
897901 options = "," .join (getUnicode (opt , UNICODE_ENCODING ) for opt in default )
898902 elif default :
@@ -2843,6 +2847,43 @@ def unhandledExceptionMessage():
28432847
28442848 return maskSensitiveData (errMsg )
28452849
2850+ def createGithubIssue (errMsg , excMsg ):
2851+ """
2852+ Automatically create a Github issue with unhandled exception information
2853+ """
2854+
2855+ msg = "\n do you want to automatically create a new (anonymized) issue "
2856+ msg += "with the unhandled exception information at "
2857+ msg += "the official Github repository? [y/N] "
2858+ test = readInput (msg , default = "N" )
2859+ if test [0 ] in ("y" , "Y" ):
2860+ ex = None
2861+ errMsg = errMsg [errMsg .find ("\n " ):]
2862+
2863+ for match in re .finditer (r'File "(.+?)", line' , excMsg ):
2864+ file = match .group (1 ).replace ('\\ ' , "/" )
2865+ file = file [file .find ("sqlmap" ):].replace ("sqlmap/" , "" , 1 )
2866+ excMsg = excMsg .replace (match .group (1 ), file )
2867+
2868+ data = {"title" : "Unhandled exception (#%s)" % hashlib .md5 (excMsg ).hexdigest ()[:8 ], "body" : "```%s\n ```\n ```\n %s```" % (errMsg , excMsg )}
2869+ req = urllib2 .Request (url = "https://api.github.com/repos/sqlmapproject/sqlmap/issues" , data = json .dumps (data ), headers = {"Authorization" : "token %s" % GITHUB_REPORT_OAUTH_TOKEN })
2870+
2871+ try :
2872+ f = urllib2 .urlopen (req )
2873+ content = f .read ()
2874+ except Exception , ex :
2875+ content = None
2876+
2877+ issueUrl = re .search (r"https://github.com/sqlmapproject/sqlmap/issues/\d+" , content or "" )
2878+ if issueUrl :
2879+ infoMsg = "created Github issue can been found at the address '%s'" % issueUrl .group (0 )
2880+ logger .info (infoMsg )
2881+ else :
2882+ warnMsg = "something went wrong while creating a Github issue"
2883+ if ex :
2884+ warnMsg += " ('%s')" % ex
2885+ logger .warn (warnMsg )
2886+
28462887def maskSensitiveData (msg ):
28472888 """
28482889 Masks sensitive data in the supplied message
0 commit comments