new option -t

This commit is contained in:
Miroslav Stampar 2010-11-08 11:22:47 +00:00
parent 4e6d1b5118
commit a3de10e3a2
4 changed files with 39 additions and 6 deletions

View File

@ -425,6 +425,13 @@ def dataToSessionFile(data):
conf.sessionFP.write(data) conf.sessionFP.write(data)
conf.sessionFP.flush() conf.sessionFP.flush()
def dataToTrafficFile(data):
if not conf.trafficFile:
return
conf.trafficFP.write(data)
conf.trafficFP.flush()
def dataToDumpFile(dumpFile, data): def dataToDumpFile(dumpFile, data):
dumpFile.write(data) dumpFile.write(data)
dumpFile.flush() dumpFile.flush()
@ -1560,3 +1567,10 @@ def runningAsAdmin():
isAdmin = True isAdmin = True
return isAdmin return isAdmin
def logHTTPTraffic(requestLogMsg, responseLogMsg):
kb.locks.reqLock.acquire()
dataToTrafficFile("%s\n" % requestLogMsg)
dataToTrafficFile("%s\n" % responseLogMsg)
dataToTrafficFile("%s\n" % (160*'#'))
kb.locks.reqLock.release()

View File

@ -1031,6 +1031,7 @@ def __setConfAttributes():
conf.start = True conf.start = True
conf.threadContinue = True conf.threadContinue = True
conf.threadException = False conf.threadException = False
conf.trafficFP = None
conf.wFileType = None conf.wFileType = None
def __setKnowledgeBaseAttributes(): def __setKnowledgeBaseAttributes():
@ -1080,6 +1081,7 @@ def __setKnowledgeBaseAttributes():
kb.locks = advancedDict() kb.locks = advancedDict()
kb.locks.cacheLock = threading.Lock() kb.locks.cacheLock = threading.Lock()
kb.locks.reqLock = threading.Lock()
kb.locks.seqLock = None kb.locks.seqLock = None
kb.nullConnection = None kb.nullConnection = None
@ -1212,6 +1214,10 @@ def __mergeOptions(inputOptions):
if not conf.has_key(key) or conf[key] is None or value is not None: if not conf.has_key(key) or conf[key] is None or value is not None:
conf[key] = value conf[key] = value
def __setTrafficOutputFP():
if conf.trafficFile:
conf.trafficFP = codecs.open(conf.trafficFile, "w+", conf.dataEncoding)
def __basicOptionValidation(): def __basicOptionValidation():
if conf.limitStart is not None and not (isinstance(conf.limitStart, int) and conf.limitStart > 0): if conf.limitStart is not None and not (isinstance(conf.limitStart, int) and conf.limitStart > 0):
errMsg = "value for --start (limitStart) option must be an integer value greater than zero (>0)" errMsg = "value for --start (limitStart) option must be an integer value greater than zero (>0)"
@ -1271,6 +1277,7 @@ def init(inputOptions=advancedDict()):
__setRequestFromFile() __setRequestFromFile()
__setMultipleTargets() __setMultipleTargets()
__setTamperingFunctions() __setTamperingFunctions()
__setTrafficOutputFP()
parseTargetUrl() parseTargetUrl()
parseTargetDirect() parseTargetDirect()

View File

@ -456,6 +456,10 @@ def cmdLineParser():
help="Save and resume all data retrieved " help="Save and resume all data retrieved "
"on a session file") "on a session file")
miscellaneous.add_option("-t", dest="trafficFile",
help="Save all HTTP traffic data "
"into a textual file")
miscellaneous.add_option("--flush-session", dest="flushSession", miscellaneous.add_option("--flush-session", dest="flushSession",
action="store_true", default=False, action="store_true", default=False,
help="Flush session file for current target") help="Flush session file for current target")

View File

@ -20,6 +20,7 @@ from lib.core.agent import agent
from lib.core.common import readInput from lib.core.common import readInput
from lib.core.common import getFilteredPageContent from lib.core.common import getFilteredPageContent
from lib.core.common import getUnicode from lib.core.common import getUnicode
from lib.core.common import logHTTPTraffic
from lib.core.convert import urlencode from lib.core.convert import urlencode
from lib.core.common import urlEncodeCookieValues from lib.core.common import urlEncodeCookieValues
from lib.core.data import conf from lib.core.data import conf
@ -61,6 +62,13 @@ class Connect:
delay = 0.00001 * (conf.cpuThrottle ** 2) delay = 0.00001 * (conf.cpuThrottle ** 2)
time.sleep(delay) time.sleep(delay)
kb.locks.reqLock.acquire()
kb.lastRequestUID += 1
requestID = kb.lastRequestUID
kb.locks.reqLock.release()
url = kwargs.get('url', conf.url).replace(" ", "%20") url = kwargs.get('url', conf.url).replace(" ", "%20")
get = kwargs.get('get', None) get = kwargs.get('get', None)
post = kwargs.get('post', None) post = kwargs.get('post', None)
@ -76,14 +84,12 @@ class Connect:
page = "" page = ""
cookieStr = "" cookieStr = ""
requestMsg = "HTTP request:\n%s " % conf.method requestMsg = "HTTP request [#%d]:\n%s " % (requestID, conf.method)
requestMsg += "%s" % urlparse.urlsplit(url)[2] or "/" requestMsg += "%s" % urlparse.urlsplit(url)[2] or "/"
responseMsg = "HTTP response " responseMsg = "HTTP response "
requestHeaders = "" requestHeaders = ""
responseHeaders = "" responseHeaders = ""
kb.lastRequestUID += 1
try: try:
if silent: if silent:
socket.setdefaulttimeout(3) socket.setdefaulttimeout(3)
@ -277,12 +283,14 @@ class Connect:
page = sanitizeAsciiString(page) page = sanitizeAsciiString(page)
parseResponse(page, responseHeaders) parseResponse(page, responseHeaders)
responseMsg += "(%s - %d):\n" % (status, code) responseMsg += "[#%d] (%s - %d):\n" % (requestID, status, code)
logHTTPTraffic(requestMsg, "%s%s\n%s" % (responseMsg, headers, page))
if conf.verbose <= 5: if conf.verbose <= 5:
responseMsg += getUnicode(responseHeaders.__str__()) responseMsg += getUnicode(headers.__str__())
elif conf.verbose > 5: elif conf.verbose > 5:
responseMsg += "%s\n%s\n" % (responseHeaders, page) responseMsg += "%s\n%s\n" % (headers, page)
logger.log(7, responseMsg) logger.log(7, responseMsg)