Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rework:solve problem of saving result of --sql-query in CSV file
  • Loading branch information
Aridhi-Dhia-eddine committed Apr 12, 2024
commit cc7c5e79505f41d76f2eeb8e118fef5953bbde99
39 changes: 38 additions & 1 deletion lib/core/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import hashlib
import os

import csv

import re
import shutil
import tempfile
Expand Down Expand Up @@ -709,7 +712,41 @@ def dbColumns(self, dbColumnsDict, colConsider, dbs):

def sqlQuery(self, query, queryRes):
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):
self.lister("files saved to", fileData, sort=False, content_type=CONTENT_TYPE.FILE_READ)

Expand Down
4 changes: 3 additions & 1 deletion plugins/generic/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ def sqlQuery(self, query):
inject.goStacked(query)

output = NULL

except SqlmapNoneDataException as ex:
logger.warning(ex)


return output


def sqlShell(self):
infoMsg = "calling %s shell. To quit type " % Backend.getIdentifiedDbms()
Expand Down