mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-02-22 06:20:34 +03:00
Rework:solve problem of saving result of --sql-query in CSV file
This commit is contained in:
parent
4851c69b2a
commit
cc7c5e7950
|
@ -7,6 +7,9 @@ See the file 'LICENSE' for copying permission
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import csv
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -709,6 +712,40 @@ class Dump(object):
|
||||||
|
|
||||||
def sqlQuery(self, query, queryRes):
|
def sqlQuery(self, query, queryRes):
|
||||||
self.string(query, queryRes, content_type=CONTENT_TYPE.SQL_QUERY)
|
self.string(query, queryRes, content_type=CONTENT_TYPE.SQL_QUERY)
|
||||||
|
print ("mon output est ",queryRes)
|
||||||
|
|
||||||
|
#code to extract columns from the request
|
||||||
|
deb="SELECT"
|
||||||
|
fin="FROM"
|
||||||
|
temp1=(query.upper()).find(deb)
|
||||||
|
#print ("mon output est ",temp1)
|
||||||
|
temp2=(query.upper()).find(fin)
|
||||||
|
#print ("mon output est ",temp2)
|
||||||
|
T=len(deb)-temp1+1
|
||||||
|
temp_res=query[T:temp2]
|
||||||
|
temp_res=(temp_res.strip()).split(',')
|
||||||
|
print ("mon output est ",temp_res)
|
||||||
|
#******************************************
|
||||||
|
#dictionarie for every value in queryRes
|
||||||
|
dt_save=[]
|
||||||
|
for i in range (len(queryRes)):
|
||||||
|
s=queryRes[i]
|
||||||
|
d={}
|
||||||
|
for j in range(len(temp_res)):
|
||||||
|
d.update({temp_res[j]:s[j]})
|
||||||
|
dt_save.append(d)
|
||||||
|
print(dt_save)
|
||||||
|
#*******************************************
|
||||||
|
file_csv="data_save.csv"
|
||||||
|
if(len(queryRes)!=0):
|
||||||
|
with open(file_csv,mode='w',newline='') as file_csv:
|
||||||
|
writer=csv.DictWriter(file_csv,fieldnames=temp_res)
|
||||||
|
writer.writeheader()
|
||||||
|
for part in dt_save:
|
||||||
|
writer.writerow(part)
|
||||||
|
print("data saved in csv format under "+"'"+os.path.realpath("data_save.csv")+"'")
|
||||||
|
else:
|
||||||
|
print("data don't exist to create CSV file")
|
||||||
|
|
||||||
def rFile(self, fileData):
|
def rFile(self, fileData):
|
||||||
self.lister("files saved to", fileData, sort=False, content_type=CONTENT_TYPE.FILE_READ)
|
self.lister("files saved to", fileData, sort=False, content_type=CONTENT_TYPE.FILE_READ)
|
||||||
|
|
|
@ -82,8 +82,10 @@ class Custom(object):
|
||||||
except SqlmapNoneDataException as ex:
|
except SqlmapNoneDataException as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
|
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
def sqlShell(self):
|
def sqlShell(self):
|
||||||
infoMsg = "calling %s shell. To quit type " % Backend.getIdentifiedDbms()
|
infoMsg = "calling %s shell. To quit type " % Backend.getIdentifiedDbms()
|
||||||
infoMsg += "'x' or 'q' and press ENTER"
|
infoMsg += "'x' or 'q' and press ENTER"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user